Changeset 221546 in webkit for trunk/Source/JavaScriptCore/API


Ignore:
Timestamp:
Sep 2, 2017, 9:42:51 PM (8 years ago)
Author:
[email protected]
Message:

Need an API to get the global context from JSObjectRef
https://bugs.webkit.org/show_bug.cgi?id=176291

Reviewed by Saam Barati.

Very simple additional API, starting off as SPI on principle.

  • API/JSObjectRef.cpp:

(JSObjectGetGlobalContext):

  • API/JSObjectRefPrivate.h:
  • API/tests/testapi.c:

(main):

Location:
trunk/Source/JavaScriptCore/API
Files:
3 edited

Legend:

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

    r216460 r221546  
    692692    return toRef(result);
    693693}
     694
     695JSGlobalContextRef JSObjectGetGlobalContext(JSObjectRef objectRef)
     696{
     697    JSObject* object = toJS(objectRef);
     698    if (!object)
     699        return nullptr;
     700    return reinterpret_cast<JSGlobalContextRef>(object->globalObject()->globalExec());
     701}
     702
  • trunk/Source/JavaScriptCore/API/JSObjectRefPrivate.h

    r216460 r221546  
    7070JS_EXPORT JSObjectRef JSObjectGetProxyTarget(JSObjectRef);
    7171
     72JS_EXPORT JSGlobalContextRef JSObjectGetGlobalContext(JSObjectRef object);
     73   
    7274#ifdef __cplusplus
    7375}
  • trunk/Source/JavaScriptCore/API/tests/testapi.c

    r220403 r221546  
    20412041    }
    20422042
     2043    // Check JSObjectGetGlobalContext
     2044    {
     2045        JSGlobalContextRef context = JSGlobalContextCreateInGroup(NULL, NULL);
     2046        {
     2047            JSObjectRef globalObject = JSContextGetGlobalObject(context);
     2048            assertTrue(JSObjectGetGlobalContext(globalObject) == context, "global object context is correct");
     2049            JSObjectRef object = JSObjectMake(context, NULL, NULL);
     2050            assertTrue(JSObjectGetGlobalContext(object) == context, "regular object context is correct");
     2051            JSStringRef returnFunctionSource = JSStringCreateWithUTF8CString("return this;");
     2052            JSObjectRef theFunction = JSObjectMakeFunction(context, NULL, 0, NULL, returnFunctionSource, NULL, 1, NULL);
     2053            assertTrue(JSObjectGetGlobalContext(theFunction) == context, "function object context is correct");
     2054            assertTrue(JSObjectGetGlobalContext(NULL) == NULL, "NULL object context is NULL");
     2055            JSStringRelease(returnFunctionSource);
     2056        }
     2057        JSGlobalContextRelease(context);
     2058    }
    20432059    failed = testTypedArrayCAPI() || failed;
    20442060    failed = testExecutionTimeLimit() || failed;
Note: See TracChangeset for help on using the changeset viewer.