Changeset 266236 in webkit for trunk/Source/JavaScriptCore/API/APICallbackFunction.h
- Timestamp:
- Aug 27, 2020, 9:41:27 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/API/APICallbackFunction.h
r261464 r266236 80 80 VM& vm = getVM(globalObject); 81 81 auto scope = DECLARE_THROW_SCOPE(vm); 82 JSObject* constructor = callFrame->jsCallee(); 82 JSValue callee = callFrame->jsCallee(); 83 T* constructor = jsCast<T*>(callFrame->jsCallee()); 83 84 JSContextRef ctx = toRef(globalObject); 84 85 JSObjectRef constructorRef = toRef(constructor); 85 86 86 JSObjectCallAsConstructorCallback callback = jsCast<T*>(constructor)->constructCallback();87 JSObjectCallAsConstructorCallback callback = constructor->constructCallback(); 87 88 if (callback) { 89 JSValue prototype; 90 JSValue newTarget = callFrame->newTarget(); 91 // If we are doing a derived class construction get the .prototype property off the new target first so we behave closer to normal JS. 92 if (newTarget != constructor) { 93 prototype = newTarget.get(globalObject, vm.propertyNames->prototype); 94 RETURN_IF_EXCEPTION(scope, { }); 95 } 96 88 97 size_t argumentCount = callFrame->argumentCount(); 89 98 Vector<JSValueRef, 16> arguments; … … 98 107 result = callback(ctx, constructorRef, argumentCount, arguments.data(), &exception); 99 108 } 109 100 110 if (exception) { 101 111 throwException(globalObject, scope, toJS(globalObject, exception)); … … 105 115 if (!result) 106 116 return throwVMTypeError(globalObject, scope); 107 return JSValue::encode(toJS(result)); 117 118 JSObject* newObject = toJS(result); 119 // This won't trigger proxy traps on newObject's prototype handler but that's probably desirable here anyway. 120 if (newTarget != constructor && newObject->getPrototypeDirect(vm) == constructor->get(globalObject, vm.propertyNames->prototype)) { 121 RETURN_IF_EXCEPTION(scope, { }); 122 newObject->setPrototype(vm, globalObject, prototype); 123 RETURN_IF_EXCEPTION(scope, { }); 124 } 125 126 return JSValue::encode(newObject); 108 127 } 109 128 110 return JSValue::encode(toJS(JSObjectMake(ctx, jsCast<JSCallbackConstructor*>(c onstructor)->classRef(), nullptr)));129 return JSValue::encode(toJS(JSObjectMake(ctx, jsCast<JSCallbackConstructor*>(callee)->classRef(), nullptr))); 111 130 } 112 131
Note:
See TracChangeset
for help on using the changeset viewer.