Changeset 148162 in webkit


Ignore:
Timestamp:
Apr 10, 2013 6:25:33 PM (11 years ago)
Author:
oliver@apple.com
Message:

Set trap is not being called for API objects
https://bugs.webkit.org/show_bug.cgi?id=114403

Reviewed by Anders Carlsson.

Intercept putByIndex on the callback object and add tests
to make sure we don't regress in future.

  • API/JSCallbackObject.h:

(JSCallbackObject):

  • API/JSCallbackObjectFunctions.h:

(JSC::::putByIndex):
(JSC):

  • API/tests/testapi.c:

(PropertyCatchalls_setProperty):

  • API/tests/testapi.js:
Location:
trunk/Source/JavaScriptCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/API/JSCallbackObject.h

    r145119 r148162  
    182182   
    183183    static void put(JSCell*, ExecState*, PropertyName, JSValue, PutPropertySlot&);
     184    static void putByIndex(JSCell*, ExecState*, unsigned, JSValue, bool shouldThrow);
    184185
    185186    static bool deleteProperty(JSCell*, ExecState*, PropertyName);
  • trunk/Source/JavaScriptCore/API/JSCallbackObjectFunctions.h

    r147349 r148162  
    295295
    296296template <class Parent>
     297void JSCallbackObject<Parent>::putByIndex(JSCell* cell, ExecState* exec, unsigned propertyIndex, JSValue value, bool shouldThrow)
     298{
     299    JSCallbackObject* thisObject = jsCast<JSCallbackObject*>(cell);
     300    JSContextRef ctx = toRef(exec);
     301    JSObjectRef thisRef = toRef(thisObject);
     302    RefPtr<OpaqueJSString> propertyNameRef;
     303    JSValueRef valueRef = toRef(exec, value);
     304    Identifier propertyName = Identifier(exec, String::number(propertyIndex));
     305
     306    for (JSClassRef jsClass = thisObject->classRef(); jsClass; jsClass = jsClass->parentClass) {
     307        if (JSObjectSetPropertyCallback setProperty = jsClass->setProperty) {
     308            if (!propertyNameRef)
     309                propertyNameRef = OpaqueJSString::create(propertyName.impl());
     310            JSValueRef exception = 0;
     311            bool result;
     312            {
     313                APICallbackShim callbackShim(exec);
     314                result = setProperty(ctx, thisRef, propertyNameRef.get(), valueRef, &exception);
     315            }
     316            if (exception)
     317                throwError(exec, toJS(exec, exception));
     318            if (result || exception)
     319                return;
     320        }
     321
     322        if (OpaqueJSClassStaticValuesTable* staticValues = jsClass->staticValues(exec)) {
     323            if (StaticValueEntry* entry = staticValues->get(propertyName.impl())) {
     324                if (entry->attributes & kJSPropertyAttributeReadOnly)
     325                    return;
     326                if (JSObjectSetPropertyCallback setProperty = entry->setProperty) {
     327                    if (!propertyNameRef)
     328                        propertyNameRef = OpaqueJSString::create(propertyName.impl());
     329                    JSValueRef exception = 0;
     330                    bool result;
     331                    {
     332                        APICallbackShim callbackShim(exec);
     333                        result = setProperty(ctx, thisRef, propertyNameRef.get(), valueRef, &exception);
     334                    }
     335                    if (exception)
     336                        throwError(exec, toJS(exec, exception));
     337                    if (result || exception)
     338                        return;
     339                }
     340            }
     341        }
     342
     343        if (OpaqueJSClassStaticFunctionsTable* staticFunctions = jsClass->staticFunctions(exec)) {
     344            if (StaticFunctionEntry* entry = staticFunctions->get(propertyName.impl())) {
     345                if (entry->attributes & kJSPropertyAttributeReadOnly)
     346                    return;
     347                break;
     348            }
     349        }
     350    }
     351
     352    return Parent::putByIndex(thisObject, exec, propertyIndex, value, shouldThrow);
     353}
     354
     355template <class Parent>
    297356bool JSCallbackObject<Parent>::deleteProperty(JSCell* cell, ExecState* exec, PropertyName propertyName)
    298357{
  • trunk/Source/JavaScriptCore/API/tests/testapi.c

    r146711 r148162  
    492492    }
    493493
     494    if (JSStringIsEqualToUTF8CString(propertyName, "make_throw") || JSStringIsEqualToUTF8CString(propertyName, "0")) {
     495        *exception = JSValueMakeNumber(context, 5);
     496        return true;
     497    }
     498
    494499    return false;
    495500}
  • trunk/Source/JavaScriptCore/API/tests/testapi.js

    r113660 r148162  
    263263    var x = PropertyCatchalls.x;
    264264shouldBe("x", null);
     265var make_throw = 'make_throw';
     266shouldThrow("PropertyCatchalls[make_throw]=1");
     267make_throw = 0;
     268shouldThrow("PropertyCatchalls[make_throw]=1");
    265269
    266270for (var i = 0; i < 10; ++i) {
  • trunk/Source/JavaScriptCore/ChangeLog

    r148159 r148162  
     12013-04-10  Oliver Hunt  <oliver@apple.com>
     2
     3        Set trap is not being called for API objects
     4        https://bugs.webkit.org/show_bug.cgi?id=114403
     5
     6        Reviewed by Anders Carlsson.
     7
     8        Intercept putByIndex on the callback object and add tests
     9        to make sure we don't regress in future.
     10
     11        * API/JSCallbackObject.h:
     12        (JSCallbackObject):
     13        * API/JSCallbackObjectFunctions.h:
     14        (JSC::::putByIndex):
     15        (JSC):
     16        * API/tests/testapi.c:
     17        (PropertyCatchalls_setProperty):
     18        * API/tests/testapi.js:
     19
    1202013-04-10  Benjamin Poulain  <bpoulain@apple.com>
    221
Note: See TracChangeset for help on using the changeset viewer.