Changeset 15164 in webkit for trunk/JavaScriptCore/API
- Timestamp:
- Jul 5, 2006, 10:46:00 AM (19 years ago)
- Location:
- trunk/JavaScriptCore/API
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/API/JSObjectRef.cpp
r15149 r15164 33 33 34 34 #include "identifier.h" 35 #include "function.h" 36 #include "nodes.h" 35 37 #include "internal.h" 36 38 #include "object.h" … … 69 71 } 70 72 71 JSObjectRef JSFunctionMake(JSContextRef context, JSCallAsFunctionCallback callback) 72 { 73 JSLock lock; 74 ExecState* exec = toJS(context); 75 return toRef(new JSCallbackFunction(exec, callback)); 76 } 77 78 JSObjectRef JSConstructorMake(JSContextRef context, JSCallAsConstructorCallback callback) 79 { 80 JSLock lock; 81 ExecState* exec = toJS(context); 82 return toRef(new JSCallbackConstructor(exec, callback)); 73 JSObjectRef JSFunctionMake(JSContextRef context, JSCallAsFunctionCallback callAsFunction) 74 { 75 JSLock lock; 76 ExecState* exec = toJS(context); 77 return toRef(new JSCallbackFunction(exec, callAsFunction)); 78 } 79 80 JSObjectRef JSConstructorMake(JSContextRef context, JSCallAsConstructorCallback callAsConstructor) 81 { 82 JSLock lock; 83 ExecState* exec = toJS(context); 84 return toRef(new JSCallbackConstructor(exec, callAsConstructor)); 85 } 86 87 JSObjectRef JSFunctionMakeWithBody(JSContextRef context, JSCharBufferRef body, JSCharBufferRef sourceURL, int startingLineNumber) 88 { 89 JSLock lock; 90 91 ExecState* exec = toJS(context); 92 UString::Rep* bodyRep = toJS(body); 93 UString::Rep* sourceURLRep = toJS(sourceURL); 94 if (!bodyRep) 95 bodyRep = &UString::Rep::null; 96 RefPtr<FunctionBodyNode> bodyNode = Parser::parse(UString(sourceURLRep), startingLineNumber, bodyRep->data(), bodyRep->size(), NULL, NULL, NULL); 97 if (!bodyNode) 98 return NULL; 99 100 ScopeChain scopeChain; 101 scopeChain.push(exec->dynamicInterpreter()->globalObject()); 102 return toRef(static_cast<JSObject*>(new DeclaredFunctionImp(exec, "anonymous", bodyNode.get(), scopeChain))); 83 103 } 84 104 -
trunk/JavaScriptCore/API/JSObjectRef.h
r15149 r15164 110 110 111 111 // Will be assigned the built-in function prototype 112 JSObjectRef JSFunctionMake(JSContextRef context, JSCallAsFunctionCallback call back);112 JSObjectRef JSFunctionMake(JSContextRef context, JSCallAsFunctionCallback callAsFunction); 113 113 // Will be assigned the built-in object prototype 114 JSObjectRef JSConstructorMake(JSContextRef context, JSCallAsConstructorCallback callback); 114 JSObjectRef JSConstructorMake(JSContextRef context, JSCallAsConstructorCallback callAsConstructor); 115 116 // returns NULL if functionBody has a syntax error 117 JSObjectRef JSFunctionMakeWithBody(JSContextRef context, JSCharBufferRef body, JSCharBufferRef sourceURL, int startingLineNumber); 115 118 116 119 JSCharBufferRef JSObjectGetDescription(JSObjectRef object); … … 124 127 bool JSObjectDeleteProperty(JSContextRef context, JSObjectRef object, JSCharBufferRef propertyName); 125 128 129 // Only works with objects created by JSObjectMake 126 130 void* JSObjectGetPrivate(JSObjectRef object); 127 131 bool JSObjectSetPrivate(JSObjectRef object, void* data); -
trunk/JavaScriptCore/API/JSValueRef.h
r15149 r15164 32 32 /*! 33 33 @enum JSTypeCode 34 A constant identifying the type of a particularJSValueRef.34 A constant identifying the type of a JSValueRef. 35 35 @constant kJSTypeUndefined the unique undefined value 36 36 @constant kJSTypeNull the unique null value … … 38 38 @constant kJSTypeNumber a primitive number value 39 39 @constant kJSTypeString a primitive string value 40 @constant kJSTypeObject an object (meaning th is JSValueRef is a JSObjectRef40 @constant kJSTypeObject an object (meaning that this JSValueRef is a JSObjectRef) 41 41 */ 42 42 typedef enum { -
trunk/JavaScriptCore/API/testapi.c
r15163 r15164 501 501 JSValueRef exception; 502 502 503 result = JSEvaluate(context, goodSyntaxBuf, NULL, NULL, 0, NULL);503 result = JSEvaluate(context, goodSyntaxBuf, NULL, NULL, 1, NULL); 504 504 assert(result); 505 505 assert(JSValueIsEqual(context, result, jsOne)); 506 506 507 result = JSEvaluate(context, badSyntaxBuf, NULL, NULL, 0, &exception);507 result = JSEvaluate(context, badSyntaxBuf, NULL, NULL, 1, &exception); 508 508 assert(!result); 509 509 assert(!JSContextGetException(context)); … … 537 537 assert(!JSValueIsInstanceOf(context, JSNullMake(), arrayConstructor)); 538 538 539 JSCharBufferRef functionBuf; 540 541 functionBuf = JSCharBufferCreateUTF8("rreturn Array;"); 542 assert(!JSFunctionMakeWithBody(context, functionBuf, NULL, 1)); 543 JSCharBufferRelease(functionBuf); 544 545 functionBuf = JSCharBufferCreateUTF8("return Array;"); 546 JSObjectRef function = JSFunctionMakeWithBody(context, functionBuf, NULL, 1); 547 JSCharBufferRelease(functionBuf); 548 549 assert(JSObjectIsFunction(function)); 550 v = JSObjectCallAsFunction(context, function, NULL, 0, NULL, NULL); 551 assert(JSValueIsEqual(context, v, arrayConstructor)); 552 539 553 JSObjectRef myObject = JSObjectMake(context, MyObject_class(context), NULL); 540 554 assert(didInitialize); … … 548 562 549 563 JSCharBufferRef myConstructorBuf = JSCharBufferCreateUTF8("MyConstructor"); 550 JSObjectSetProperty(context, globalObject, myConstructorBuf, JSConstructorMake(context, myConstructor_callAsConstructor), kJSPropertyAttributeNone); 564 JSObjectSetProperty(context, globalObject, myConstructorBuf, JSConstructorMake(context, myConstructor_callAsConstructor), kJSPropertyAttributeNone); 551 565 JSCharBufferRelease(myConstructorBuf); 552 566 553 567 char* script = createStringWithContentsOfFile("testapi.js"); 554 568 JSCharBufferRef scriptBuf = JSCharBufferCreateUTF8(script); 555 result = JSEvaluate(context, scriptBuf, NULL, NULL, 0, &exception);569 result = JSEvaluate(context, scriptBuf, NULL, NULL, 1, &exception); 556 570 if (JSValueIsUndefined(result)) 557 571 printf("PASS: Test script executed successfully.\n");
Note:
See TracChangeset
for help on using the changeset viewer.