Changeset 87588 in webkit
- Timestamp:
- May 27, 2011 5:28:56 PM (13 years ago)
- Location:
- trunk/Source/JavaScriptCore
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/API/JSCallbackObject.h
r87586 r87588 189 189 static EncodedJSValue JSC_HOST_CALL construct(ExecState*); 190 190 191 static JSValue staticValueGetter(ExecState*, JSValue, const Identifier&);191 JSValue getStaticValue(ExecState*, const Identifier&); 192 192 static JSValue staticFunctionGetter(ExecState*, JSValue, const Identifier&); 193 193 static JSValue callbackGetter(ExecState*, JSValue, const Identifier&); -
trunk/Source/JavaScriptCore/API/JSCallbackObjectFunctions.h
r84660 r87588 150 150 if (OpaqueJSClassStaticValuesTable* staticValues = jsClass->staticValues(exec)) { 151 151 if (staticValues->contains(propertyName.impl())) { 152 slot.setCustom(this, staticValueGetter); 153 return true; 152 JSValue value = getStaticValue(exec, propertyName); 153 if (value) { 154 slot.setValue(value); 155 return true; 156 } 154 157 } 155 158 } … … 226 229 if (result || exception) 227 230 return; 228 } else 229 throwError(exec, createReferenceError(exec, "Attempt to set a property that is not settable.")); 231 } 230 232 } 231 233 } … … 516 518 517 519 template <class Base> 518 JSValue JSCallbackObject<Base>::staticValueGetter(ExecState* exec, JSValue slotBase, const Identifier& propertyName) 519 { 520 JSCallbackObject* thisObj = asCallbackObject(slotBase); 521 522 JSObjectRef thisRef = toRef(thisObj); 520 JSValue JSCallbackObject<Base>::getStaticValue(ExecState* exec, const Identifier& propertyName) 521 { 522 JSObjectRef thisRef = toRef(this); 523 523 RefPtr<OpaqueJSString> propertyNameRef; 524 524 525 for (JSClassRef jsClass = thisObj->classRef(); jsClass; jsClass = jsClass->parentClass)525 for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass) 526 526 if (OpaqueJSClassStaticValuesTable* staticValues = jsClass->staticValues(exec)) 527 527 if (StaticValueEntry* entry = staticValues->get(propertyName.impl())) … … 543 543 } 544 544 545 return throwError(exec, createReferenceError(exec, "Static value property defined with NULL getProperty callback."));545 return JSValue(); 546 546 } 547 547 -
trunk/Source/JavaScriptCore/API/tests/testapi.c
r87586 r87588 312 312 } 313 313 314 static bool MyObject_set_nullGetForwardSet(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception) 315 { 316 UNUSED_PARAM(ctx); 317 UNUSED_PARAM(object); 318 UNUSED_PARAM(propertyName); 319 UNUSED_PARAM(value); 320 UNUSED_PARAM(exception); 321 return false; // Forward to parent class. 322 } 323 314 324 static JSStaticValue evilStaticValues[] = { 315 325 { "nullGetSet", 0, 0, kJSPropertyAttributeNone }, 326 { "nullGetForwardSet", 0, MyObject_set_nullGetForwardSet, kJSPropertyAttributeNone }, 316 327 { 0, 0, 0, 0 } 317 328 }; -
trunk/Source/JavaScriptCore/API/tests/testapi.js
r87586 r87588 95 95 shouldBe("'throwOnHasInstance' instanceof MyObject", "an exception"); 96 96 97 MyObject.nullGetForwardSet = 1; 98 shouldBe("MyObject.nullGetForwardSet", 1); 99 97 100 var foundMyPropertyName = false; 98 101 var foundRegularType = false; … … 163 166 shouldBe("(new Object()) instanceof MyObject", false); 164 167 165 shouldThrow("MyObject.nullGetSet = 1");166 should Throw("MyObject.nullGetSet");168 MyObject.nullGetSet = 1; 169 shouldBe("MyObject.nullGetSet", 1); 167 170 shouldThrow("MyObject.nullCall()"); 168 171 shouldThrow("MyObject.hasPropertyLie"); -
trunk/Source/JavaScriptCore/ChangeLog
r87586 r87588 1 2011-05-27 Geoffrey Garen <ggaren@apple.com> 2 3 Reviewed by Oliver Hunt. 4 5 JS API is too aggressive about throwing exceptions for NULL get or set operations 6 https://bugs.webkit.org/show_bug.cgi?id=61678 7 8 * API/JSCallbackObject.h: Changed our staticValueGetter to a regular 9 function that returns a JSValue, so it can fail and still forward to 10 normal property lookup. 11 12 * API/JSCallbackObjectFunctions.h: 13 (JSC::::getOwnPropertySlot): Don't throw an exception when failing to 14 access a static property -- just forward the access. This allows objects 15 to observe get/set operations but still let the JS object manage lifetime. 16 17 (JSC::::put): Ditto. 18 19 (JSC::::getStaticValue): Same as JSCallbackObject.h. 20 21 * API/tests/testapi.c: 22 (MyObject_set_nullGetForwardSet): 23 * API/tests/testapi.js: Updated tests to reflect slightly less strict 24 behavior, which matches headerdoc claims. 25 1 26 2011-05-27 Geoffrey Garen <ggaren@apple.com> 2 27
Note: See TracChangeset
for help on using the changeset viewer.