From d441d6f39bb846989d95bcf5caf387b42414718d Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Fri, 13 Sep 2013 12:51:20 +0200 Subject: Import Qt5x2 branch of QtWebkit for Qt 5.2 Importing a new snapshot of webkit. Change-Id: I2d01ad12cdc8af8cb015387641120a9d7ea5f10c Reviewed-by: Allan Sandfeld Jensen --- .../JavaScriptCore/API/JSCallbackObjectFunctions.h | 103 ++++++++++++++++----- 1 file changed, 82 insertions(+), 21 deletions(-) (limited to 'Source/JavaScriptCore/API/JSCallbackObjectFunctions.h') diff --git a/Source/JavaScriptCore/API/JSCallbackObjectFunctions.h b/Source/JavaScriptCore/API/JSCallbackObjectFunctions.h index 1a063e620..b92e3161e 100644 --- a/Source/JavaScriptCore/API/JSCallbackObjectFunctions.h +++ b/Source/JavaScriptCore/API/JSCallbackObjectFunctions.h @@ -51,7 +51,7 @@ inline JSCallbackObject* JSCallbackObject::asCallbackObject(JSVa template JSCallbackObject::JSCallbackObject(ExecState* exec, Structure* structure, JSClassRef jsClass, void* data) - : Parent(exec->globalData(), structure) + : Parent(exec->vm(), structure) , m_callbackObjectData(adoptPtr(new JSCallbackObjectData(data, jsClass))) { } @@ -59,8 +59,8 @@ JSCallbackObject::JSCallbackObject(ExecState* exec, Structure* structure // Global object constructor. // FIXME: Move this into a separate JSGlobalCallbackObject class derived from this one. template -JSCallbackObject::JSCallbackObject(JSGlobalData& globalData, JSClassRef jsClass, Structure* structure) - : Parent(globalData, structure) +JSCallbackObject::JSCallbackObject(VM& vm, JSClassRef jsClass, Structure* structure) + : Parent(vm, structure) , m_callbackObjectData(adoptPtr(new JSCallbackObjectData(0, jsClass))) { } @@ -68,18 +68,18 @@ JSCallbackObject::JSCallbackObject(JSGlobalData& globalData, JSClassRef template void JSCallbackObject::finishCreation(ExecState* exec) { - Base::finishCreation(exec->globalData()); + Base::finishCreation(exec->vm()); ASSERT(Parent::inherits(&s_info)); init(exec); } // This is just for Global object, so we can assume that Base::finishCreation is JSGlobalObject::finishCreation. template -void JSCallbackObject::finishCreation(JSGlobalData& globalData) +void JSCallbackObject::finishCreation(VM& vm) { ASSERT(Parent::inherits(&s_info)); ASSERT(Parent::isGlobalObject()); - Base::finishCreation(globalData); + Base::finishCreation(vm); init(jsCast(this)->globalExec()); } @@ -216,7 +216,7 @@ template bool JSCallbackObject::getOwnPropertyDescriptor(JSObject* object, ExecState* exec, PropertyName propertyName, PropertyDescriptor& descriptor) { JSCallbackObject* thisObject = jsCast(object); - PropertySlot slot; + PropertySlot slot(thisObject); if (thisObject->methodTable()->getOwnPropertySlot(thisObject, exec, propertyName, slot)) { // Ideally we should return an access descriptor, but returning a value descriptor is better than nothing. JSValue value = slot.getValue(exec, propertyName); @@ -283,7 +283,7 @@ void JSCallbackObject::put(JSCell* cell, ExecState* exec, PropertyName p if (StaticFunctionEntry* entry = staticFunctions->get(name)) { if (entry->attributes & kJSPropertyAttributeReadOnly) return; - thisObject->JSCallbackObject::putDirect(exec->globalData(), propertyName, value); // put as override property + thisObject->JSCallbackObject::putDirect(exec->vm(), propertyName, value); // put as override property return; } } @@ -293,6 +293,65 @@ void JSCallbackObject::put(JSCell* cell, ExecState* exec, PropertyName p return Parent::put(thisObject, exec, propertyName, value, slot); } +template +void JSCallbackObject::putByIndex(JSCell* cell, ExecState* exec, unsigned propertyIndex, JSValue value, bool shouldThrow) +{ + JSCallbackObject* thisObject = jsCast(cell); + JSContextRef ctx = toRef(exec); + JSObjectRef thisRef = toRef(thisObject); + RefPtr propertyNameRef; + JSValueRef valueRef = toRef(exec, value); + Identifier propertyName = Identifier(exec, String::number(propertyIndex)); + + for (JSClassRef jsClass = thisObject->classRef(); jsClass; jsClass = jsClass->parentClass) { + if (JSObjectSetPropertyCallback setProperty = jsClass->setProperty) { + if (!propertyNameRef) + propertyNameRef = OpaqueJSString::create(propertyName.impl()); + JSValueRef exception = 0; + bool result; + { + APICallbackShim callbackShim(exec); + result = setProperty(ctx, thisRef, propertyNameRef.get(), valueRef, &exception); + } + if (exception) + throwError(exec, toJS(exec, exception)); + if (result || exception) + return; + } + + if (OpaqueJSClassStaticValuesTable* staticValues = jsClass->staticValues(exec)) { + if (StaticValueEntry* entry = staticValues->get(propertyName.impl())) { + if (entry->attributes & kJSPropertyAttributeReadOnly) + return; + if (JSObjectSetPropertyCallback setProperty = entry->setProperty) { + if (!propertyNameRef) + propertyNameRef = OpaqueJSString::create(propertyName.impl()); + JSValueRef exception = 0; + bool result; + { + APICallbackShim callbackShim(exec); + result = setProperty(ctx, thisRef, propertyNameRef.get(), valueRef, &exception); + } + if (exception) + throwError(exec, toJS(exec, exception)); + if (result || exception) + return; + } + } + } + + if (OpaqueJSClassStaticFunctionsTable* staticFunctions = jsClass->staticFunctions(exec)) { + if (StaticFunctionEntry* entry = staticFunctions->get(propertyName.impl())) { + if (entry->attributes & kJSPropertyAttributeReadOnly) + return; + break; + } + } + } + + return Parent::putByIndex(thisObject, exec, propertyIndex, value, shouldThrow); +} + template bool JSCallbackObject::deleteProperty(JSCell* cell, ExecState* exec, PropertyName propertyName) { @@ -368,10 +427,11 @@ EncodedJSValue JSCallbackObject::construct(ExecState* exec) for (JSClassRef jsClass = jsCast*>(constructor)->classRef(); jsClass; jsClass = jsClass->parentClass) { if (JSObjectCallAsConstructorCallback callAsConstructor = jsClass->callAsConstructor) { - int argumentCount = static_cast(exec->argumentCount()); - Vector arguments(argumentCount); - for (int i = 0; i < argumentCount; i++) - arguments[i] = toRef(exec, exec->argument(i)); + size_t argumentCount = exec->argumentCount(); + Vector arguments; + arguments.reserveInitialCapacity(argumentCount); + for (size_t i = 0; i < argumentCount; ++i) + arguments.uncheckedAppend(toRef(exec, exec->argument(i))); JSValueRef exception = 0; JSObject* result; { @@ -384,7 +444,7 @@ EncodedJSValue JSCallbackObject::construct(ExecState* exec) } } - ASSERT_NOT_REACHED(); // getConstructData should prevent us from reaching here + RELEASE_ASSERT_NOT_REACHED(); // getConstructData should prevent us from reaching here return JSValue::encode(JSValue()); } @@ -434,10 +494,11 @@ EncodedJSValue JSCallbackObject::call(ExecState* exec) for (JSClassRef jsClass = jsCast*>(toJS(functionRef))->classRef(); jsClass; jsClass = jsClass->parentClass) { if (JSObjectCallAsFunctionCallback callAsFunction = jsClass->callAsFunction) { - int argumentCount = static_cast(exec->argumentCount()); - Vector arguments(argumentCount); - for (int i = 0; i < argumentCount; i++) - arguments[i] = toRef(exec, exec->argument(i)); + size_t argumentCount = exec->argumentCount(); + Vector arguments; + arguments.reserveInitialCapacity(argumentCount); + for (size_t i = 0; i < argumentCount; ++i) + arguments.uncheckedAppend(toRef(exec, exec->argument(i))); JSValueRef exception = 0; JSValue result; { @@ -450,7 +511,7 @@ EncodedJSValue JSCallbackObject::call(ExecState* exec) } } - ASSERT_NOT_REACHED(); // getCallData should prevent us from reaching here + RELEASE_ASSERT_NOT_REACHED(); // getCallData should prevent us from reaching here return JSValue::encode(JSValue()); } @@ -508,10 +569,10 @@ void* JSCallbackObject::getPrivate() template bool JSCallbackObject::inherits(JSClassRef c) const { - for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass) + for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass) { if (jsClass == c) return true; - + } return false; } @@ -566,7 +627,7 @@ JSValue JSCallbackObject::staticFunctionGetter(ExecState* exec, JSValue if (JSObjectCallAsFunctionCallback callAsFunction = entry->callAsFunction) { JSObject* o = JSCallbackFunction::create(exec, thisObj->globalObject(), callAsFunction, name); - thisObj->putDirect(exec->globalData(), propertyName, o, entry->attributes); + thisObj->putDirect(exec->vm(), propertyName, o, entry->attributes); return o; } } -- cgit v1.2.1