Ignore:
Timestamp:
Sep 22, 2008, 4:01:43 PM (17 years ago)
Author:
[email protected]
Message:

2008-09-22 Kelvin Sherlock <[email protected]>

Updated and tweaked by Sam Weinig.

Reviewed by Geoffrey Garen.

Bug 20020: Proposed enhancement to JavaScriptCore API
<https://bugs.webkit.org/show_bug.cgi?id=20020>

Add JSObjectMakeArray, JSObjectMakeDate, JSObjectMakeError, and JSObjectMakeRegExp
functions to create JavaScript Array, Date, Error, and RegExp objects, respectively.

  • API/JSObjectRef.cpp: The functions
  • API/JSObjectRef.h: Function prototype and documentation
  • JavaScriptCore.exp: Added functions to exported function list
  • API/tests/testapi.c: Added basic functionality tests.
  • kjs/DateConstructor.cpp: Replaced static JSObject* constructDate(ExecState* exec, JSObject*, const ArgList& args) with JSObject* constructDate(ExecState* exec, const ArgList& args). Added static JSObject* constructWithDateConstructor(ExecState* exec, JSObject*, const ArgList& args) function
  • kjs/DateConstructor.h: added prototype for JSObject* constructDate(ExecState* exec, const ArgList& args)
  • kjs/ErrorConstructor.cpp: removed static qualifier from ErrorInstance* constructError(ExecState* exec, const ArgList& args)
  • kjs/ErrorConstructor.h: added prototype for ErrorInstance* constructError(ExecState* exec, const ArgList& args)
  • kjs/RegExpConstructor.cpp: removed static qualifier from JSObject* constructRegExp(ExecState* exec, const ArgList& args)
  • kjs/RegExpConstructor.h: added prototype for JSObject* constructRegExp(ExecState* exec, const ArgList& args)
File:
1 edited

Legend:

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

    r35900 r36784  
    877877    ASSERT(count == 1); // jsCFString should not be enumerated
    878878
     879    JSValueRef argumentsArrayValues[] = { JSValueMakeNumber(context, 10), JSValueMakeNumber(context, 20) };
     880    o = JSObjectMakeArray(context, sizeof(argumentsArrayValues) / sizeof(JSValueRef), argumentsArrayValues, NULL);
     881    string = JSStringCreateWithUTF8CString("length");
     882    v = JSObjectGetProperty(context, o, string, NULL);
     883    assertEqualsAsNumber(v, 2);
     884    v = JSObjectGetPropertyAtIndex(context, o, 0, NULL);
     885    assertEqualsAsNumber(v, 10);
     886    v = JSObjectGetPropertyAtIndex(context, o, 1, NULL);
     887    assertEqualsAsNumber(v, 20);
     888
     889    o = JSObjectMakeArray(context, 0, NULL, NULL);
     890    v = JSObjectGetProperty(context, o, string, NULL);
     891    assertEqualsAsNumber(v, 0);
     892    JSStringRelease(string);
     893
     894    JSValueRef argumentsDateValues[] = { JSValueMakeNumber(context, 0) };
     895    o = JSObjectMakeDate(context, 1, argumentsDateValues, NULL);
     896    assertEqualsAsUTF8String(o, "Wed Dec 31 1969 16:00:00 GMT-0800 (PST)");
     897
     898    string = JSStringCreateWithUTF8CString("an error message");
     899    JSValueRef argumentsErrorValues[] = { JSValueMakeString(context, string) };
     900    o = JSObjectMakeError(context, 1, argumentsErrorValues, NULL);
     901    assertEqualsAsUTF8String(o, "Error: an error message");
     902    JSStringRelease(string);
     903
     904    string = JSStringCreateWithUTF8CString("foo");
     905    JSStringRef string2 = JSStringCreateWithUTF8CString("gi");
     906    JSValueRef argumentsRegExpValues[] = { JSValueMakeString(context, string), JSValueMakeString(context, string2) };
     907    o = JSObjectMakeRegExp(context, 2, argumentsRegExpValues, NULL);
     908    assertEqualsAsUTF8String(o, "/foo/gi");
     909    JSStringRelease(string);
     910    JSStringRelease(string2);
     911
    879912    JSClassDefinition nullDefinition = kJSClassDefinitionEmpty;
    880913    nullDefinition.attributes = kJSClassAttributeNoAutomaticPrototype;
Note: See TracChangeset for help on using the changeset viewer.