Changeset 67129 in webkit for trunk/JavaScriptCore/API


Ignore:
Timestamp:
Sep 9, 2010, 5:13:29 PM (15 years ago)
Author:
[email protected]
Message:

<http://webkit.org/b/45502> JSObjectSetPrivateProperty does not handle NULL values as it claims

Reviewed by Oliver Hunt.

  • API/JSObjectRef.cpp:

(JSObjectSetPrivateProperty): Don't call toJS if we have a NULL value as that will cause an assertion
failure. Instead map NULL directly to the null JSValue.

  • API/tests/testapi.c:

(main): Add test coverage for the NULL value case.

Location:
trunk/JavaScriptCore/API
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/API/JSObjectRef.cpp

    r60762 r67129  
    383383    APIEntryShim entryShim(exec);
    384384    JSObject* jsObject = toJS(object);
    385     JSValue jsValue = toJS(exec, value);
     385    JSValue jsValue = value ? toJS(exec, value) : JSValue();
    386386    Identifier name(propertyName->identifier(&exec->globalData()));
    387387    if (jsObject->inherits(&JSCallbackObject<JSGlobalObject>::info)) {
  • trunk/JavaScriptCore/API/tests/testapi.c

    r63277 r67129  
    934934    if (!JSObjectSetPrivateProperty(context, myObject, privatePropertyName, aHeapRef)) {
    935935        printf("FAIL: Could not set private property.\n");
    936         failed = 1;       
    937     } else {
     936        failed = 1;
     937    } else
    938938        printf("PASS: Set private property.\n");
    939     }
    940939    aStackRef = 0;
    941940    if (JSObjectSetPrivateProperty(context, aHeapRef, privatePropertyName, aHeapRef)) {
    942941        printf("FAIL: JSObjectSetPrivateProperty should fail on non-API objects.\n");
    943         failed = 1;       
    944     } else {
     942        failed = 1;
     943    } else
    945944        printf("PASS: Did not allow JSObjectSetPrivateProperty on a non-API object.\n");
    946     }
    947945    if (JSObjectGetPrivateProperty(context, myObject, privatePropertyName) != aHeapRef) {
    948946        printf("FAIL: Could not retrieve private property.\n");
     
    955953    } else
    956954        printf("PASS: JSObjectGetPrivateProperty return NULL.\n");
    957    
     955
    958956    if (JSObjectGetProperty(context, myObject, privatePropertyName, 0) == aHeapRef) {
    959957        printf("FAIL: Accessed private property through ordinary property lookup.\n");
     
    961959    } else
    962960        printf("PASS: Cannot access private property through ordinary property lookup.\n");
    963    
     961
    964962    JSGarbageCollect(context);
    965    
     963
    966964    for (int i = 0; i < 10000; i++)
    967965        JSObjectMake(context, 0, 0);
     
    974972        printf("PASS: Private property does not appear to have been collected.\n");
    975973    JSStringRelease(lengthStr);
    976    
     974
     975    if (!JSObjectSetPrivateProperty(context, myObject, privatePropertyName, 0)) {
     976        printf("FAIL: Could not set private property to NULL.\n");
     977        failed = 1;
     978    } else
     979        printf("PASS: Set private property to NULL.\n");
     980    if (JSObjectGetPrivateProperty(context, myObject, privatePropertyName)) {
     981        printf("FAIL: Could not retrieve private property.\n");
     982        failed = 1;
     983    } else
     984        printf("PASS: Retrieved private property.\n");
     985
    977986    JSStringRef validJSON = JSStringCreateWithUTF8CString("{\"aProperty\":true}");
    978987    JSValueRef jsonObject = JSValueMakeFromJSONString(context, validJSON);
Note: See TracChangeset for help on using the changeset viewer.