Ignore:
Timestamp:
Oct 19, 2009, 12:59:32 PM (16 years ago)
Author:
[email protected]
Message:

Added a private API for getting a global context from a context, for
clients who want to preserve a context for a later callback.

Patch by Geoffrey Garen <[email protected]> on 2009-10-19
Reviewed by Sam Weinig.

  • API/APICast.h:

(toGlobalRef): Added an ASSERT, since this function is used more often
than before.

  • API/JSContextRef.cpp:
  • API/JSContextRefPrivate.h: Added. The new API.
  • API/tests/testapi.c:

(print_callAsFunction):
(main): Test the new API.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/API/tests/testapi.c

    r46598 r49802  
    2626#include "JavaScriptCore.h"
    2727#include "JSBasePrivate.h"
     28#include "JSContextRefPrivate.h"
    2829#include <math.h>
    2930#define ASSERT_DISABLED 0
     
    4243#endif
    4344
    44 static JSGlobalContextRef context = 0;
    45 static int failed = 0;
     45static JSGlobalContextRef context;
     46static int failed;
    4647static void assertEqualsAsBoolean(JSValueRef value, bool expectedValue)
    4748{
     
    619620}
    620621
    621 static JSValueRef print_callAsFunction(JSContextRef context, JSObjectRef functionObject, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
     622static JSValueRef print_callAsFunction(JSContextRef ctx, JSObjectRef functionObject, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
    622623{
    623624    UNUSED_PARAM(functionObject);
    624625    UNUSED_PARAM(thisObject);
    625626    UNUSED_PARAM(exception);
     627
     628    ASSERT(JSContextGetGlobalContext(ctx) == context);
    626629   
    627630    if (argumentCount > 0) {
    628         JSStringRef string = JSValueToStringCopy(context, arguments[0], NULL);
     631        JSStringRef string = JSValueToStringCopy(ctx, arguments[0], NULL);
    629632        size_t sizeUTF8 = JSStringGetMaximumUTF8CStringSize(string);
    630633        char* stringUTF8 = (char*)malloc(sizeUTF8);
     
    635638    }
    636639   
    637     return JSValueMakeUndefined(context);
     640    return JSValueMakeUndefined(ctx);
    638641}
    639642
     
    761764    JSGlobalContextRetain(context);
    762765    JSGlobalContextRelease(context);
     766    ASSERT(JSContextGetGlobalContext(context) == context);
    763767   
    764768    JSReportExtraMemoryCost(context, 0);
Note: See TracChangeset for help on using the changeset viewer.