Ignore:
Timestamp:
May 20, 2013, 2:10:19 PM (12 years ago)
Author:
[email protected]
Message:

Make C API more robust against null contexts
https://bugs.webkit.org/show_bug.cgi?id=116462

Reviewed by Anders Carlsson.

Handle null contexts in a non-crashy way. It's a bug to ever call the
API with a null context, and the absence of a context means we can't
produce a meaningful result, so we still assert in debug builds.

Now where possible we detect and early return, returning null for any
pointer type, NaN for doubles, and false for any boolean result.

  • API/JSBase.cpp:

(JSEvaluateScript):
(JSCheckScriptSyntax):
(JSReportExtraMemoryCost):

  • API/JSContextRef.cpp:

(JSContextGetGlobalObject):
(JSContextGetGroup):
(JSContextGetGlobalContext):
(JSContextCreateBacktrace):

  • API/JSObjectRef.cpp:

(JSObjectMake):
(JSObjectMakeFunctionWithCallback):
(JSObjectMakeConstructor):
(JSObjectMakeFunction):
(JSObjectMakeArray):
(JSObjectMakeDate):
(JSObjectMakeError):
(JSObjectMakeRegExp):
(JSObjectGetPrototype):
(JSObjectSetPrototype):
(JSObjectHasProperty):
(JSObjectGetProperty):
(JSObjectSetProperty):
(JSObjectGetPropertyAtIndex):
(JSObjectSetPropertyAtIndex):
(JSObjectDeleteProperty):
(JSObjectCopyPropertyNames):

  • API/JSValueRef.cpp:

(JSValueGetType):
(JSValueIsUndefined):
(JSValueIsNull):
(JSValueIsBoolean):
(JSValueIsNumber):
(JSValueIsString):
(JSValueIsObject):
(JSValueIsObjectOfClass):
(JSValueIsEqual):
(JSValueIsStrictEqual):
(JSValueIsInstanceOfConstructor):
(JSValueMakeUndefined):
(JSValueMakeNull):
(JSValueMakeBoolean):
(JSValueMakeNumber):
(JSValueMakeString):
(JSValueMakeFromJSONString):
(JSValueCreateJSONString):
(JSValueToBoolean):
(JSValueToNumber):
(JSValueToStringCopy):
(JSValueToObject):
(JSValueProtect):

  • API/JSWeakObjectMapRefPrivate.cpp:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/API/JSWeakObjectMapRefPrivate.cpp

    r147962 r150381  
    5555void JSWeakObjectMapSet(JSContextRef ctx, JSWeakObjectMapRef map, void* key, JSObjectRef object)
    5656{
     57    if (!ctx) {
     58        ASSERT_NOT_REACHED();
     59        return;
     60    }
    5761    ExecState* exec = toJS(ctx);
    5862    APIEntryShim entryShim(exec);
     
    6670JSObjectRef JSWeakObjectMapGet(JSContextRef ctx, JSWeakObjectMapRef map, void* key)
    6771{
     72    if (!ctx) {
     73        ASSERT_NOT_REACHED();
     74        return 0;
     75    }
    6876    ExecState* exec = toJS(ctx);
    6977    APIEntryShim entryShim(exec);
     
    7381void JSWeakObjectMapRemove(JSContextRef ctx, JSWeakObjectMapRef map, void* key)
    7482{
     83    if (!ctx) {
     84        ASSERT_NOT_REACHED();
     85        return;
     86    }
    7587    ExecState* exec = toJS(ctx);
    7688    APIEntryShim entryShim(exec);
Note: See TracChangeset for help on using the changeset viewer.