summaryrefslogtreecommitdiff
path: root/Source/JavaScriptCore/API/JSCallbackObjectFunctions.h
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@nokia.com>2012-05-25 15:09:11 +0200
committerSimon Hausmann <simon.hausmann@nokia.com>2012-05-25 15:09:11 +0200
commita89b2ebb8e192c5e8cea21079bda2ee2c0c7dddd (patch)
treeb7abd9f49ae1d4d2e426a5883bfccd42b8e2ee12 /Source/JavaScriptCore/API/JSCallbackObjectFunctions.h
parent8d473cf9743f1d30a16a27114e93bd5af5648d23 (diff)
downloadqtwebkit-a89b2ebb8e192c5e8cea21079bda2ee2c0c7dddd.tar.gz
Imported WebKit commit eb5c1b8fe4d4b1b90b5137433fc58a91da0e6878 (http://svn.webkit.org/repository/webkit/trunk@118516)
Diffstat (limited to 'Source/JavaScriptCore/API/JSCallbackObjectFunctions.h')
-rw-r--r--Source/JavaScriptCore/API/JSCallbackObjectFunctions.h314
1 files changed, 165 insertions, 149 deletions
diff --git a/Source/JavaScriptCore/API/JSCallbackObjectFunctions.h b/Source/JavaScriptCore/API/JSCallbackObjectFunctions.h
index fdc58fccf..160f48887 100644
--- a/Source/JavaScriptCore/API/JSCallbackObjectFunctions.h
+++ b/Source/JavaScriptCore/API/JSCallbackObjectFunctions.h
@@ -129,54 +129,56 @@ bool JSCallbackObject<Parent>::getOwnPropertySlot(JSCell* cell, ExecState* exec,
JSObjectRef thisRef = toRef(thisObject);
RefPtr<OpaqueJSString> propertyNameRef;
- for (JSClassRef jsClass = thisObject->classRef(); jsClass; jsClass = jsClass->parentClass) {
- // optional optimization to bypass getProperty in cases when we only need to know if the property exists
- if (JSObjectHasPropertyCallback hasProperty = jsClass->hasProperty) {
- if (!propertyNameRef)
- propertyNameRef = OpaqueJSString::create(propertyName.ustring());
- APICallbackShim callbackShim(exec);
- if (hasProperty(ctx, thisRef, propertyNameRef.get())) {
- slot.setCustom(thisObject, callbackGetter);
- return true;
- }
- } else if (JSObjectGetPropertyCallback getProperty = jsClass->getProperty) {
- if (!propertyNameRef)
- propertyNameRef = OpaqueJSString::create(propertyName.ustring());
- JSValueRef exception = 0;
- JSValueRef value;
- {
+ if (StringImpl* name = propertyName.publicName()) {
+ for (JSClassRef jsClass = thisObject->classRef(); jsClass; jsClass = jsClass->parentClass) {
+ // optional optimization to bypass getProperty in cases when we only need to know if the property exists
+ if (JSObjectHasPropertyCallback hasProperty = jsClass->hasProperty) {
+ if (!propertyNameRef)
+ propertyNameRef = OpaqueJSString::create(name);
APICallbackShim callbackShim(exec);
- value = getProperty(ctx, thisRef, propertyNameRef.get(), &exception);
- }
- if (exception) {
- throwError(exec, toJS(exec, exception));
- slot.setValue(jsUndefined());
- return true;
- }
- if (value) {
- slot.setValue(toJS(exec, value));
- return true;
- }
- }
-
- if (OpaqueJSClassStaticValuesTable* staticValues = jsClass->staticValues(exec)) {
- if (staticValues->contains(propertyName.impl())) {
- JSValue value = thisObject->getStaticValue(exec, propertyName);
+ if (hasProperty(ctx, thisRef, propertyNameRef.get())) {
+ slot.setCustom(thisObject, callbackGetter);
+ return true;
+ }
+ } else if (JSObjectGetPropertyCallback getProperty = jsClass->getProperty) {
+ if (!propertyNameRef)
+ propertyNameRef = OpaqueJSString::create(name);
+ JSValueRef exception = 0;
+ JSValueRef value;
+ {
+ APICallbackShim callbackShim(exec);
+ value = getProperty(ctx, thisRef, propertyNameRef.get(), &exception);
+ }
+ if (exception) {
+ throwError(exec, toJS(exec, exception));
+ slot.setValue(jsUndefined());
+ return true;
+ }
if (value) {
- slot.setValue(value);
+ slot.setValue(toJS(exec, value));
return true;
}
}
- }
-
- if (OpaqueJSClassStaticFunctionsTable* staticFunctions = jsClass->staticFunctions(exec)) {
- if (staticFunctions->contains(propertyName.impl())) {
- slot.setCustom(thisObject, staticFunctionGetter);
- return true;
+
+ if (OpaqueJSClassStaticValuesTable* staticValues = jsClass->staticValues(exec)) {
+ if (staticValues->contains(name)) {
+ JSValue value = thisObject->getStaticValue(exec, propertyName);
+ if (value) {
+ slot.setValue(value);
+ return true;
+ }
+ }
+ }
+
+ if (OpaqueJSClassStaticFunctionsTable* staticFunctions = jsClass->staticFunctions(exec)) {
+ if (staticFunctions->contains(name)) {
+ slot.setCustom(thisObject, staticFunctionGetter);
+ return true;
+ }
}
}
}
-
+
return Parent::getOwnPropertySlot(thisObject, exec, propertyName, slot);
}
@@ -233,53 +235,55 @@ void JSCallbackObject<Parent>::put(JSCell* cell, ExecState* exec, PropertyName p
RefPtr<OpaqueJSString> propertyNameRef;
JSValueRef valueRef = toRef(exec, value);
- for (JSClassRef jsClass = thisObject->classRef(); jsClass; jsClass = jsClass->parentClass) {
- if (JSObjectSetPropertyCallback setProperty = jsClass->setProperty) {
- if (!propertyNameRef)
- propertyNameRef = OpaqueJSString::create(propertyName.ustring());
- 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)
+ if (StringImpl* name = propertyName.publicName()) {
+ for (JSClassRef jsClass = thisObject->classRef(); jsClass; jsClass = jsClass->parentClass) {
+ if (JSObjectSetPropertyCallback setProperty = jsClass->setProperty) {
+ if (!propertyNameRef)
+ propertyNameRef = OpaqueJSString::create(name);
+ 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 (JSObjectSetPropertyCallback setProperty = entry->setProperty) {
- if (!propertyNameRef)
- propertyNameRef = OpaqueJSString::create(propertyName.ustring());
- 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)
+ }
+
+ if (OpaqueJSClassStaticValuesTable* staticValues = jsClass->staticValues(exec)) {
+ if (StaticValueEntry* entry = staticValues->get(name)) {
+ if (entry->attributes & kJSPropertyAttributeReadOnly)
return;
+ if (JSObjectSetPropertyCallback setProperty = entry->setProperty) {
+ if (!propertyNameRef)
+ propertyNameRef = OpaqueJSString::create(name);
+ 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)
+
+ if (OpaqueJSClassStaticFunctionsTable* staticFunctions = jsClass->staticFunctions(exec)) {
+ if (StaticFunctionEntry* entry = staticFunctions->get(name)) {
+ if (entry->attributes & kJSPropertyAttributeReadOnly)
+ return;
+ thisObject->JSCallbackObject<Parent>::putDirect(exec->globalData(), propertyName, value); // put as override property
return;
- thisObject->JSCallbackObject<Parent>::putDirect(exec->globalData(), propertyName, value); // put as override property
- return;
+ }
}
}
}
-
+
return Parent::put(thisObject, exec, propertyName, value, slot);
}
@@ -291,39 +295,41 @@ bool JSCallbackObject<Parent>::deleteProperty(JSCell* cell, ExecState* exec, Pro
JSObjectRef thisRef = toRef(thisObject);
RefPtr<OpaqueJSString> propertyNameRef;
- for (JSClassRef jsClass = thisObject->classRef(); jsClass; jsClass = jsClass->parentClass) {
- if (JSObjectDeletePropertyCallback deleteProperty = jsClass->deleteProperty) {
- if (!propertyNameRef)
- propertyNameRef = OpaqueJSString::create(propertyName.ustring());
- JSValueRef exception = 0;
- bool result;
- {
- APICallbackShim callbackShim(exec);
- result = deleteProperty(ctx, thisRef, propertyNameRef.get(), &exception);
+ if (StringImpl* name = propertyName.publicName()) {
+ for (JSClassRef jsClass = thisObject->classRef(); jsClass; jsClass = jsClass->parentClass) {
+ if (JSObjectDeletePropertyCallback deleteProperty = jsClass->deleteProperty) {
+ if (!propertyNameRef)
+ propertyNameRef = OpaqueJSString::create(name);
+ JSValueRef exception = 0;
+ bool result;
+ {
+ APICallbackShim callbackShim(exec);
+ result = deleteProperty(ctx, thisRef, propertyNameRef.get(), &exception);
+ }
+ if (exception)
+ throwError(exec, toJS(exec, exception));
+ if (result || exception)
+ return true;
}
- if (exception)
- throwError(exec, toJS(exec, exception));
- if (result || exception)
- return true;
- }
-
- if (OpaqueJSClassStaticValuesTable* staticValues = jsClass->staticValues(exec)) {
- if (StaticValueEntry* entry = staticValues->get(propertyName.impl())) {
- if (entry->attributes & kJSPropertyAttributeDontDelete)
- return false;
- return true;
+
+ if (OpaqueJSClassStaticValuesTable* staticValues = jsClass->staticValues(exec)) {
+ if (StaticValueEntry* entry = staticValues->get(name)) {
+ if (entry->attributes & kJSPropertyAttributeDontDelete)
+ return false;
+ return true;
+ }
}
- }
-
- if (OpaqueJSClassStaticFunctionsTable* staticFunctions = jsClass->staticFunctions(exec)) {
- if (StaticFunctionEntry* entry = staticFunctions->get(propertyName.impl())) {
- if (entry->attributes & kJSPropertyAttributeDontDelete)
- return false;
- return true;
+
+ if (OpaqueJSClassStaticFunctionsTable* staticFunctions = jsClass->staticFunctions(exec)) {
+ if (StaticFunctionEntry* entry = staticFunctions->get(name)) {
+ if (entry->attributes & kJSPropertyAttributeDontDelete)
+ return false;
+ return true;
+ }
}
}
}
-
+
return Parent::deleteProperty(thisObject, exec, propertyName);
}
@@ -509,25 +515,30 @@ JSValue JSCallbackObject<Parent>::getStaticValue(ExecState* exec, PropertyName p
JSObjectRef thisRef = toRef(this);
RefPtr<OpaqueJSString> propertyNameRef;
- for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass)
- if (OpaqueJSClassStaticValuesTable* staticValues = jsClass->staticValues(exec))
- if (StaticValueEntry* entry = staticValues->get(propertyName.impl()))
- if (JSObjectGetPropertyCallback getProperty = entry->getProperty) {
- if (!propertyNameRef)
- propertyNameRef = OpaqueJSString::create(propertyName.ustring());
- JSValueRef exception = 0;
- JSValueRef value;
- {
- APICallbackShim callbackShim(exec);
- value = getProperty(toRef(exec), thisRef, propertyNameRef.get(), &exception);
- }
- if (exception) {
- throwError(exec, toJS(exec, exception));
- return jsUndefined();
+ if (StringImpl* name = propertyName.publicName()) {
+ for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass) {
+ if (OpaqueJSClassStaticValuesTable* staticValues = jsClass->staticValues(exec)) {
+ if (StaticValueEntry* entry = staticValues->get(name)) {
+ if (JSObjectGetPropertyCallback getProperty = entry->getProperty) {
+ if (!propertyNameRef)
+ propertyNameRef = OpaqueJSString::create(name);
+ JSValueRef exception = 0;
+ JSValueRef value;
+ {
+ APICallbackShim callbackShim(exec);
+ value = getProperty(toRef(exec), thisRef, propertyNameRef.get(), &exception);
+ }
+ if (exception) {
+ throwError(exec, toJS(exec, exception));
+ return jsUndefined();
+ }
+ if (value)
+ return toJS(exec, value);
}
- if (value)
- return toJS(exec, value);
}
+ }
+ }
+ }
return JSValue();
}
@@ -542,19 +553,21 @@ JSValue JSCallbackObject<Parent>::staticFunctionGetter(ExecState* exec, JSValue
if (Parent::getOwnPropertySlot(thisObj, exec, propertyName, slot2))
return slot2.getValue(exec, propertyName);
- for (JSClassRef jsClass = thisObj->classRef(); jsClass; jsClass = jsClass->parentClass) {
- if (OpaqueJSClassStaticFunctionsTable* staticFunctions = jsClass->staticFunctions(exec)) {
- if (StaticFunctionEntry* entry = staticFunctions->get(propertyName.impl())) {
- if (JSObjectCallAsFunctionCallback callAsFunction = entry->callAsFunction) {
-
- JSObject* o = JSCallbackFunction::create(exec, thisObj->globalObject(), callAsFunction, propertyName.ustring());
- thisObj->putDirect(exec->globalData(), propertyName, o, entry->attributes);
- return o;
+ if (StringImpl* name = propertyName.publicName()) {
+ for (JSClassRef jsClass = thisObj->classRef(); jsClass; jsClass = jsClass->parentClass) {
+ if (OpaqueJSClassStaticFunctionsTable* staticFunctions = jsClass->staticFunctions(exec)) {
+ if (StaticFunctionEntry* entry = staticFunctions->get(name)) {
+ if (JSObjectCallAsFunctionCallback callAsFunction = entry->callAsFunction) {
+
+ JSObject* o = JSCallbackFunction::create(exec, thisObj->globalObject(), callAsFunction, name);
+ thisObj->putDirect(exec->globalData(), propertyName, o, entry->attributes);
+ return o;
+ }
}
}
}
}
-
+
return throwError(exec, createReferenceError(exec, "Static function property defined with NULL callAsFunction callback."));
}
@@ -566,24 +579,27 @@ JSValue JSCallbackObject<Parent>::callbackGetter(ExecState* exec, JSValue slotPa
JSObjectRef thisRef = toRef(thisObj);
RefPtr<OpaqueJSString> propertyNameRef;
- for (JSClassRef jsClass = thisObj->classRef(); jsClass; jsClass = jsClass->parentClass)
- if (JSObjectGetPropertyCallback getProperty = jsClass->getProperty) {
- if (!propertyNameRef)
- propertyNameRef = OpaqueJSString::create(propertyName.ustring());
- JSValueRef exception = 0;
- JSValueRef value;
- {
- APICallbackShim callbackShim(exec);
- value = getProperty(toRef(exec), thisRef, propertyNameRef.get(), &exception);
- }
- if (exception) {
- throwError(exec, toJS(exec, exception));
- return jsUndefined();
+ if (StringImpl* name = propertyName.publicName()) {
+ for (JSClassRef jsClass = thisObj->classRef(); jsClass; jsClass = jsClass->parentClass) {
+ if (JSObjectGetPropertyCallback getProperty = jsClass->getProperty) {
+ if (!propertyNameRef)
+ propertyNameRef = OpaqueJSString::create(name);
+ JSValueRef exception = 0;
+ JSValueRef value;
+ {
+ APICallbackShim callbackShim(exec);
+ value = getProperty(toRef(exec), thisRef, propertyNameRef.get(), &exception);
+ }
+ if (exception) {
+ throwError(exec, toJS(exec, exception));
+ return jsUndefined();
+ }
+ if (value)
+ return toJS(exec, value);
}
- if (value)
- return toJS(exec, value);
}
-
+ }
+
return throwError(exec, createReferenceError(exec, "hasProperty callback returned true for a property that doesn't exist."));
}