Changeset 34754 in webkit for trunk/JavaScriptCore/API
- Timestamp:
- Jun 23, 2008, 10:23:17 PM (17 years ago)
- Location:
- trunk/JavaScriptCore/API
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/API/JSCallbackConstructor.cpp
r34587 r34754 1 1 // -*- mode: c++; c-basic-offset: 4 -*- 2 2 /* 3 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.3 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. 4 4 * 5 5 * Redistribution and use in source and binary forms, with or without … … 57 57 } 58 58 59 ConstructType JSCallbackConstructor::getConstructData(ConstructData&) 60 { 61 return ConstructTypeNative; 62 } 63 64 JSObject* JSCallbackConstructor::construct(ExecState* exec, const ArgList &args) 59 static JSObject* constructJSCallback(ExecState* exec, JSObject* constructor, const ArgList& args) 65 60 { 66 61 JSContextRef ctx = toRef(exec); 67 JSObjectRef thisRef = toRef(this);62 JSObjectRef constructorRef = toRef(constructor); 68 63 69 if (m_callback) { 64 JSObjectCallAsConstructorCallback callback = static_cast<JSCallbackConstructor*>(constructor)->callback(); 65 if (callback) { 70 66 int argumentCount = static_cast<int>(args.size()); 71 67 Vector<JSValueRef, 16> arguments(argumentCount); … … 74 70 75 71 JSLock::DropAllLocks dropAllLocks; 76 return toJS( m_callback(ctx, thisRef, argumentCount, arguments.data(), toRef(exec->exceptionSlot())));72 return toJS(callback(ctx, constructorRef, argumentCount, arguments.data(), toRef(exec->exceptionSlot()))); 77 73 } 78 74 79 return toJS(JSObjectMake(ctx, m_class, 0)); 75 return toJS(JSObjectMake(ctx, static_cast<JSCallbackConstructor*>(constructor)->classRef(), 0)); 76 } 77 78 ConstructType JSCallbackConstructor::getConstructData(ConstructData& constructData) 79 { 80 constructData.native.function = constructJSCallback; 81 return ConstructTypeNative; 80 82 } 81 83 -
trunk/JavaScriptCore/API/JSCallbackConstructor.h
r34587 r34754 1 1 // -*- mode: c++; c-basic-offset: 4 -*- 2 2 /* 3 * Copyright (C) 2006 Apple Computer, Inc.All rights reserved.3 * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. 4 4 * 5 5 * Redistribution and use in source and binary forms, with or without … … 35 35 class JSCallbackConstructor : public JSObject { 36 36 public: 37 JSCallbackConstructor(ExecState* exec, JSClassRef jsClass, JSObjectCallAsConstructorCallback callback);37 JSCallbackConstructor(ExecState*, JSClassRef, JSObjectCallAsConstructorCallback); 38 38 virtual ~JSCallbackConstructor(); 39 40 virtual bool implementsHasInstance() const; 41 42 virtual ConstructType getConstructData(ConstructData&); 43 virtual JSObject* construct(ExecState*, const ArgList& args); 44 45 virtual const ClassInfo *classInfo() const { return &info; } 39 JSClassRef classRef() const { return m_class; } 40 JSObjectCallAsConstructorCallback callback() const { return m_callback; } 46 41 static const ClassInfo info; 47 42 48 43 private: 49 JSCallbackConstructor(); // prevent default construction 50 JSCallbackConstructor(const JSCallbackConstructor&); 44 virtual bool implementsHasInstance() const; 45 virtual ConstructType getConstructData(ConstructData&); 46 virtual const ClassInfo* classInfo() const { return &info; } 51 47 52 48 JSClassRef m_class; -
trunk/JavaScriptCore/API/JSCallbackFunction.cpp
r34587 r34754 1 1 // -*- mode: c++; c-basic-offset: 4 -*- 2 2 /* 3 * Copyright (C) 2006 Apple Computer, Inc.All rights reserved.3 * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. 4 4 * 5 5 * Redistribution and use in source and binary forms, with or without … … 47 47 // InternalFunction mish-mashes constructor and function behavior -- we should 48 48 // refactor the code so this override isn't necessary 49 bool JSCallbackFunction::implementsHasInstance() const { 49 bool JSCallbackFunction::implementsHasInstance() const 50 { 50 51 return false; 51 52 } 52 53 53 JSValue* JSCallbackFunction::call AsFunction(ExecState* exec, JSObject* thisObj, const ArgList &args)54 JSValue* JSCallbackFunction::call(ExecState* exec, JSObject* functionObject, JSValue* thisValue, const ArgList& args) 54 55 { 55 56 JSContextRef execRef = toRef(exec); 56 JSObjectRef thisRef = toRef(this);57 JSObjectRef thisObjRef = toRef(this Obj);57 JSObjectRef functionRef = toRef(functionObject); 58 JSObjectRef thisObjRef = toRef(thisValue->toThisObject(exec)); 58 59 59 60 int argumentCount = static_cast<int>(args.size()); … … 63 64 64 65 JSLock::DropAllLocks dropAllLocks; 65 return toJS(m_callback(execRef, thisRef, thisObjRef, argumentCount, arguments.data(), toRef(exec->exceptionSlot()))); 66 return toJS(static_cast<JSCallbackFunction*>(functionObject)->m_callback(execRef, functionRef, thisObjRef, argumentCount, arguments.data(), toRef(exec->exceptionSlot()))); 67 } 68 69 CallType JSCallbackFunction::getCallData(CallData& callData) 70 { 71 callData.native.function = call; 72 return CallTypeNative; 66 73 } 67 74 -
trunk/JavaScriptCore/API/JSCallbackFunction.h
r34587 r34754 1 1 // -*- mode: c++; c-basic-offset: 4 -*- 2 2 /* 3 * Copyright (C) 2006 Apple Computer, Inc.All rights reserved.3 * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. 4 4 * 5 5 * Redistribution and use in source and binary forms, with or without … … 28 28 #define JSCallbackFunction_h 29 29 30 #include "JSFunction.h" 30 31 #include "JSObjectRef.h" 31 #include "JSFunction.h"32 #include "JSObject.h"33 32 34 33 namespace KJS { 35 34 36 class JSCallbackFunction : public InternalFunction 37 { 35 class JSCallbackFunction : public InternalFunction { 38 36 public: 39 JSCallbackFunction(ExecState* exec, JSObjectCallAsFunctionCallback callback, const Identifier& name);37 JSCallbackFunction(ExecState*, JSObjectCallAsFunctionCallback, const Identifier& name); 40 38 41 virtual bool implementsHasInstance() const;42 virtual JSValue* callAsFunction(ExecState*, JSObject* thisObj, const ArgList &args);43 44 virtual const ClassInfo *classInfo() const { return &info; }45 39 static const ClassInfo info; 46 40 47 41 private: 48 JSCallbackFunction(); // prevent default construction 49 JSCallbackFunction(const JSCallbackFunction&); 50 42 virtual bool implementsHasInstance() const; 43 virtual CallType getCallData(CallData&); 44 virtual const ClassInfo* classInfo() const { return &info; } 45 46 static JSValue* call(ExecState*, JSObject*, JSValue*, const ArgList&); 47 51 48 JSObjectCallAsFunctionCallback m_callback; 52 49 }; -
trunk/JavaScriptCore/API/JSCallbackObject.h
r34587 r34754 1 1 // -*- mode: c++; c-basic-offset: 4 -*- 2 2 /* 3 * Copyright (C) 2006 Apple Computer, Inc.All rights reserved.3 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. 4 4 * Copyright (C) 2007 Eric Seidel <[email protected]> 5 5 * … … 36 36 37 37 template <class Base> 38 class JSCallbackObject : public Base 39 { 38 class JSCallbackObject : public Base { 40 39 public: 41 40 JSCallbackObject(ExecState*, JSClassRef, JSValue* prototype, void* data); … … 43 42 virtual ~JSCallbackObject(); 44 43 44 void setPrivate(void* data); 45 void* getPrivate(); 46 47 static const ClassInfo info; 48 49 JSClassRef classRef() const { return m_class; } 50 bool inherits(JSClassRef) const; 51 52 private: 45 53 virtual UString className() const; 46 54 … … 54 62 virtual bool deleteProperty(ExecState*, unsigned); 55 63 56 virtual ConstructType getConstructData(ConstructData&);57 virtual JSObject* construct(ExecState*, const ArgList& args);58 59 64 virtual bool implementsHasInstance() const; 60 65 virtual bool hasInstance(ExecState *exec, JSValue *value); 61 62 virtual CallType getCallData(CallData&);63 virtual JSValue* callAsFunction(ExecState*, JSObject* thisObj, const ArgList &args);64 66 65 67 virtual void getPropertyNames(ExecState*, PropertyNameArray&); … … 68 70 virtual UString toString(ExecState*) const; 69 71 70 void setPrivate(void* data); 71 void* getPrivate(); 72 73 virtual const ClassInfo *classInfo() const { return &info; } 74 static const ClassInfo info; 72 virtual ConstructType getConstructData(ConstructData&); 73 virtual CallType getCallData(CallData&); 74 virtual const ClassInfo* classInfo() const { return &info; } 75 75 76 bool inherits(JSClassRef) const;77 78 private:79 76 void init(ExecState*); 80 77 78 static JSValue* call(ExecState*, JSObject* functionObject, JSValue* thisValue, const ArgList&); 79 static JSObject* construct(ExecState*, JSObject* constructor, const ArgList&); 80 81 81 static JSValue* cachedValueGetter(ExecState*, const Identifier&, const PropertySlot&); 82 82 static JSValue* staticValueGetter(ExecState*, const Identifier&, const PropertySlot&); -
trunk/JavaScriptCore/API/JSCallbackObjectFunctions.h
r34659 r34754 26 26 */ 27 27 28 #include <wtf/Platform.h>29 28 #include "APICast.h" 30 29 #include "JSCallbackFunction.h" 31 30 #include "JSClassRef.h" 31 #include "JSGlobalObject.h" 32 32 #include "JSObjectRef.h" 33 #include "JS GlobalObject.h"33 #include "JSString.h" 34 34 #include "JSStringRef.h" 35 35 #include "PropertyNameArray.h" 36 #include "JSString.h"37 36 #include <wtf/Vector.h> 38 37 … … 48 47 } 49 48 50 // Global object constructor. FIXME: Move this into a JSGlobalCallbackObject subclass. 49 // Global object constructor. 50 // FIXME: Move this into a separate JSGlobalCallbackObject class derived from this one. 51 51 template <class Base> 52 52 JSCallbackObject<Base>::JSCallbackObject(JSClassRef jsClass) … … 238 238 239 239 template <class Base> 240 ConstructType JSCallbackObject<Base>::getConstructData(ConstructData&) 241 { 242 for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parentClass) 243 if (jsClass->callAsConstructor) 240 ConstructType JSCallbackObject<Base>::getConstructData(ConstructData& constructData) 241 { 242 for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parentClass) { 243 if (jsClass->callAsConstructor) { 244 constructData.native.function = construct; 244 245 return ConstructTypeNative; 245 246 } 247 } 246 248 return ConstructTypeNone; 247 249 } 248 250 249 251 template <class Base> 250 JSObject* JSCallbackObject<Base>::construct(ExecState* exec, const ArgList& args)252 JSObject* JSCallbackObject<Base>::construct(ExecState* exec, JSObject* constructor, const ArgList& args) 251 253 { 252 254 JSContextRef execRef = toRef(exec); 253 JSObjectRef thisRef = toRef(this);254 255 for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parentClass) {255 JSObjectRef constructorRef = toRef(constructor); 256 257 for (JSClassRef jsClass = static_cast<JSCallbackObject<Base>*>(constructor)->classRef(); jsClass; jsClass = jsClass->parentClass) { 256 258 if (JSObjectCallAsConstructorCallback callAsConstructor = jsClass->callAsConstructor) { 257 259 int argumentCount = static_cast<int>(args.size()); … … 260 262 arguments[i] = toRef(args[i]); 261 263 JSLock::DropAllLocks dropAllLocks; 262 return toJS(callAsConstructor(execRef, thisRef, argumentCount, arguments.data(), toRef(exec->exceptionSlot())));263 } 264 } 265 266 ASSERT (0); // getConstructData should prevent us from reaching here264 return toJS(callAsConstructor(execRef, constructorRef, argumentCount, arguments.data(), toRef(exec->exceptionSlot()))); 265 } 266 } 267 268 ASSERT_NOT_REACHED(); // getConstructData should prevent us from reaching here 267 269 return 0; 268 270 } … … 295 297 296 298 template <class Base> 297 CallType JSCallbackObject<Base>::getCallData(CallData&) 298 { 299 for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parentClass) 300 if (jsClass->callAsFunction) 299 CallType JSCallbackObject<Base>::getCallData(CallData& callData) 300 { 301 for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parentClass) { 302 if (jsClass->callAsFunction) { 303 callData.native.function = call; 301 304 return CallTypeNative; 302 305 } 306 } 303 307 return CallTypeNone; 304 308 } 305 309 306 310 template <class Base> 307 JSValue* JSCallbackObject<Base>::call AsFunction(ExecState* exec, JSObject* thisObj, const ArgList &args)311 JSValue* JSCallbackObject<Base>::call(ExecState* exec, JSObject* functionObject, JSValue* thisValue, const ArgList& args) 308 312 { 309 313 JSContextRef execRef = toRef(exec); 310 JSObjectRef thisRef = toRef(this);311 JSObjectRef thisObjRef = toRef(this Obj);312 313 for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parentClass) {314 JSObjectRef functionRef = toRef(functionObject); 315 JSObjectRef thisObjRef = toRef(thisValue->toThisObject(exec)); 316 317 for (JSClassRef jsClass = static_cast<JSCallbackObject<Base>*>(functionObject)->m_class; jsClass; jsClass = jsClass->parentClass) { 314 318 if (JSObjectCallAsFunctionCallback callAsFunction = jsClass->callAsFunction) { 315 319 int argumentCount = static_cast<int>(args.size()); … … 318 322 arguments[i] = toRef(args[i]); 319 323 JSLock::DropAllLocks dropAllLocks; 320 return toJS(callAsFunction(execRef, thisRef, thisObjRef, argumentCount, arguments.data(), toRef(exec->exceptionSlot())));324 return toJS(callAsFunction(execRef, functionRef, thisObjRef, argumentCount, arguments.data(), toRef(exec->exceptionSlot()))); 321 325 } 322 326 } -
trunk/JavaScriptCore/API/JSObjectRef.cpp
r34659 r34754 122 122 args.append(jsString(exec, UString(bodyRep))); 123 123 124 JSObject* result = exec->dynamicGlobalObject()->functionConstructor()->construct(exec, args, nameID, UString(sourceURLRep), startingLineNumber);124 JSObject* result = constructFunction(exec, args, nameID, UString(sourceURLRep), startingLineNumber); 125 125 if (exec->hadException()) { 126 126 if (exception) … … 268 268 bool JSObjectIsFunction(JSContextRef, JSObjectRef object) 269 269 { 270 JSObject* jsObject = toJS(object);271 return jsObject->implementsCall();270 CallData callData; 271 return toJS(object)->getCallData(callData) != CallTypeNone; 272 272 } 273 273 … … 286 286 argList.append(toJS(arguments[i])); 287 287 288 JSValueRef result = toRef(jsObject->callAsFunction(exec, jsThisObject, argList)); // returns NULL if object->implementsCall() is false 288 CallData callData; 289 CallType callType = jsObject->getCallData(callData); 290 if (callType == CallTypeNone) 291 return 0; 292 293 JSValueRef result = toRef(call(exec, jsObject, callType, callData, jsThisObject, argList)); 289 294 if (exec->hadException()) { 290 295 if (exception) … … 308 313 ExecState* exec = toJS(ctx); 309 314 JSObject* jsObject = toJS(object); 310 315 316 ConstructData constructData; 317 ConstructType constructType = jsObject->getConstructData(constructData); 318 if (constructType == ConstructTypeNone) 319 return 0; 320 311 321 ArgList argList; 312 322 for (size_t i = 0; i < argumentCount; i++) 313 323 argList.append(toJS(arguments[i])); 314 315 JSObjectRef result = toRef(jsObject->construct(exec, argList)); // returns NULL if object->implementsCall() is false 324 JSObjectRef result = toRef(construct(exec, jsObject, constructType, constructData, argList)); 316 325 if (exec->hadException()) { 317 326 if (exception)
Note:
See TracChangeset
for help on using the changeset viewer.