Changeset 36784 in webkit for trunk/JavaScriptCore/API
- Timestamp:
- Sep 22, 2008, 4:01:43 PM (17 years ago)
- Location:
- trunk/JavaScriptCore/API
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/API/JSObjectRef.cpp
r36726 r36784 1 1 /* 2 2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. 3 * Copyright (C) 2008 Kelvin W Sherlock ([email protected]) 3 4 * 4 5 * Redistribution and use in source and binary forms, with or without … … 28 29 29 30 #include "APICast.h" 31 #include "DateConstructor.h" 32 #include "ErrorConstructor.h" 30 33 #include "FunctionConstructor.h" 34 #include "JSArray.h" 31 35 #include "JSCallbackConstructor.h" 32 36 #include "JSCallbackFunction.h" … … 41 45 #include "ObjectPrototype.h" 42 46 #include "PropertyNameArray.h" 47 #include "RegExpConstructor.h" 43 48 #include "identifier.h" 44 49 #include <wtf/Platform.h> … … 128 133 result = 0; 129 134 } 135 return toRef(result); 136 } 137 138 JSObjectRef JSObjectMakeArray(JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) 139 { 140 ExecState* exec = toJS(ctx); 141 exec->globalData().heap->registerThread(); 142 JSLock lock(exec); 143 144 JSObject* result; 145 if (argumentCount) { 146 ArgList argList; 147 for (size_t i = 0; i < argumentCount; ++i) 148 argList.append(toJS(arguments[i])); 149 150 result = constructArray(exec, argList); 151 } else 152 result = constructEmptyArray(exec); 153 154 if (exec->hadException()) { 155 if (exception) 156 *exception = toRef(exec->exception()); 157 exec->clearException(); 158 result = 0; 159 } 160 161 return toRef(result); 162 } 163 164 JSObjectRef JSObjectMakeDate(JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) 165 { 166 ExecState* exec = toJS(ctx); 167 exec->globalData().heap->registerThread(); 168 JSLock lock(exec); 169 170 ArgList argList; 171 for (size_t i = 0; i < argumentCount; ++i) 172 argList.append(toJS(arguments[i])); 173 174 JSObject* result = constructDate(exec, argList); 175 if (exec->hadException()) { 176 if (exception) 177 *exception = toRef(exec->exception()); 178 exec->clearException(); 179 result = 0; 180 } 181 182 return toRef(result); 183 } 184 185 JSObjectRef JSObjectMakeError(JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) 186 { 187 ExecState* exec = toJS(ctx); 188 exec->globalData().heap->registerThread(); 189 JSLock lock(exec); 190 191 ArgList argList; 192 for (size_t i = 0; i < argumentCount; ++i) 193 argList.append(toJS(arguments[i])); 194 195 JSObject* result = constructError(exec, argList); 196 if (exec->hadException()) { 197 if (exception) 198 *exception = toRef(exec->exception()); 199 exec->clearException(); 200 result = 0; 201 } 202 203 return toRef(result); 204 } 205 206 JSObjectRef JSObjectMakeRegExp(JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) 207 { 208 ExecState* exec = toJS(ctx); 209 exec->globalData().heap->registerThread(); 210 JSLock lock(exec); 211 212 ArgList argList; 213 for (size_t i = 0; i < argumentCount; ++i) 214 argList.append(toJS(arguments[i])); 215 216 JSObject* result = constructRegExp(exec, argList); 217 if (exec->hadException()) { 218 if (exception) 219 *exception = toRef(exec->exception()); 220 exec->clearException(); 221 result = 0; 222 } 223 130 224 return toRef(result); 131 225 } -
trunk/JavaScriptCore/API/JSObjectRef.h
r34606 r36784 1 1 /* 2 2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. 3 * Copyright (C) 2008 Kelvin W Sherlock ([email protected]) 3 4 * 4 5 * Redistribution and use in source and binary forms, with or without … … 430 431 431 432 /*! 433 @function 434 @abstract Creates a JavaScript Array object. 435 @param ctx The execution context to use. 436 @param argumentCount An integer count of the number of arguments in arguments. 437 @param arguments A JSValue array of data to populate the Array with. Pass NULL if argumentCount is 0. 438 @param exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. 439 @result A JSObject that is an Array. 440 @discussion The behavior of this function does not exactly match the behavior of the built-in Array constructor. Specifically, if one argument 441 is supplied, this function returns an array with one element. 442 */ 443 JS_EXPORT JSObjectRef JSObjectMakeArray(JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception); 444 445 /*! 446 @function 447 @abstract Creates a JavaScript Date object, as if by invoking the built-in Date constructor. 448 @param ctx The execution context to use. 449 @param argumentCount An integer count of the number of arguments in arguments. 450 @param arguments A JSValue array of arguments to pass to the Date Constructor. Pass NULL if argumentCount is 0. 451 @param exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. 452 @result A JSObject that is a Date. 453 */ 454 JS_EXPORT JSObjectRef JSObjectMakeDate(JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception); 455 456 /*! 457 @function 458 @abstract Creates a JavaScript Error object, as if by invoking the built-in Error constructor. 459 @param ctx The execution context to use. 460 @param argumentCount An integer count of the number of arguments in arguments. 461 @param arguments A JSValue array of arguments to pass to the Error Constructor. Pass NULL if argumentCount is 0. 462 @param exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. 463 @result A JSObject that is a Error. 464 */ 465 JS_EXPORT JSObjectRef JSObjectMakeError(JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception); 466 467 /*! 468 @function 469 @abstract Creates a JavaScript RegExp object, as if by invoking the built-in RegExp constructor. 470 @param ctx The execution context to use. 471 @param argumentCount An integer count of the number of arguments in arguments. 472 @param arguments A JSValue array of arguments to pass to the RegExp Constructor. Pass NULL if argumentCount is 0. 473 @param exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. 474 @result A JSObject that is a RegExp. 475 */ 476 JS_EXPORT JSObjectRef JSObjectMakeRegExp(JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception); 477 478 /*! 432 479 @function 433 480 @abstract Creates a function with a given script as its body. -
trunk/JavaScriptCore/API/tests/testapi.c
r35900 r36784 877 877 ASSERT(count == 1); // jsCFString should not be enumerated 878 878 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 879 912 JSClassDefinition nullDefinition = kJSClassDefinitionEmpty; 880 913 nullDefinition.attributes = kJSClassAttributeNoAutomaticPrototype;
Note:
See TracChangeset
for help on using the changeset viewer.