Changeset 15164 in webkit for trunk/JavaScriptCore/API


Ignore:
Timestamp:
Jul 5, 2006, 10:46:00 AM (19 years ago)
Author:
ggaren
Message:

Reviewed by Maciej.


Implemented JSFunctionMakeWithBody, which parses a script as a function body
in the global scope, and returns the resulting anonymous function.


I also removed private data from JSCallbackFunction. It never worked,
since JSCallbackFunction doesn't inherit from JSCallbackObject.

  • API/JSCallbackConstructor.cpp: Removed.
  • API/JSCallbackConstructor.h: Removed.
  • API/JSCallbackFunction.cpp: (KJS::JSCallbackFunction::JSCallbackFunction): (KJS::JSCallbackFunction::implementsConstruct): (KJS::JSCallbackFunction::construct): (KJS::JSCallbackFunction::implementsCall): (KJS::JSCallbackFunction::callAsFunction):
  • API/JSCallbackFunction.h:
  • API/JSCallbackObject.cpp: (KJS::JSCallbackObject::staticFunctionGetter):
  • API/JSObjectRef.cpp: (JSFunctionMake): (JSFunctionMakeWithCallbacks):
  • API/JSObjectRef.h:
  • API/JSValueRef.h:
  • API/minidom.c: (main):
  • API/testapi.c: (main):
  • JavaScriptCore.exp: Programmatically added all symbols exported by API object files, and sorted results
  • JavaScriptCore.xcodeproj/project.pbxproj:
Location:
trunk/JavaScriptCore/API
Files:
4 edited

Legend:

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

    r15149 r15164  
    3333
    3434#include "identifier.h"
     35#include "function.h"
     36#include "nodes.h"
    3537#include "internal.h"
    3638#include "object.h"
     
    6971}
    7072
    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));
     73JSObjectRef JSFunctionMake(JSContextRef context, JSCallAsFunctionCallback callAsFunction)
     74{
     75    JSLock lock;
     76    ExecState* exec = toJS(context);
     77    return toRef(new JSCallbackFunction(exec, callAsFunction));
     78}
     79
     80JSObjectRef JSConstructorMake(JSContextRef context, JSCallAsConstructorCallback callAsConstructor)
     81{
     82    JSLock lock;
     83    ExecState* exec = toJS(context);
     84    return toRef(new JSCallbackConstructor(exec, callAsConstructor));
     85}
     86
     87JSObjectRef 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)));
    83103}
    84104
  • trunk/JavaScriptCore/API/JSObjectRef.h

    r15149 r15164  
    110110
    111111// Will be assigned the built-in function prototype
    112 JSObjectRef JSFunctionMake(JSContextRef context, JSCallAsFunctionCallback callback);
     112JSObjectRef JSFunctionMake(JSContextRef context, JSCallAsFunctionCallback callAsFunction);
    113113// Will be assigned the built-in object prototype
    114 JSObjectRef JSConstructorMake(JSContextRef context, JSCallAsConstructorCallback callback);
     114JSObjectRef JSConstructorMake(JSContextRef context, JSCallAsConstructorCallback callAsConstructor);
     115
     116// returns NULL if functionBody has a syntax error
     117JSObjectRef JSFunctionMakeWithBody(JSContextRef context, JSCharBufferRef body, JSCharBufferRef sourceURL, int startingLineNumber);
    115118
    116119JSCharBufferRef JSObjectGetDescription(JSObjectRef object);
     
    124127bool JSObjectDeleteProperty(JSContextRef context, JSObjectRef object, JSCharBufferRef propertyName);
    125128
     129// Only works with objects created by JSObjectMake
    126130void* JSObjectGetPrivate(JSObjectRef object);
    127131bool JSObjectSetPrivate(JSObjectRef object, void* data);
  • trunk/JavaScriptCore/API/JSValueRef.h

    r15149 r15164  
    3232/*!
    3333  @enum JSTypeCode
    34   A constant identifying the type of a particular JSValueRef.
     34  A constant identifying the type of a JSValueRef.
    3535  @constant kJSTypeUndefined the unique undefined value
    3636  @constant kJSTypeNull the unique null value
     
    3838  @constant kJSTypeNumber a primitive number value
    3939  @constant kJSTypeString a primitive string value
    40   @constant kJSTypeObject an object (meaning this JSValueRef is a JSObjectRef
     40  @constant kJSTypeObject an object (meaning that this JSValueRef is a JSObjectRef)
    4141*/
    4242typedef enum {
  • trunk/JavaScriptCore/API/testapi.c

    r15163 r15164  
    501501    JSValueRef exception;
    502502
    503     result = JSEvaluate(context, goodSyntaxBuf, NULL, NULL, 0, NULL);
     503    result = JSEvaluate(context, goodSyntaxBuf, NULL, NULL, 1, NULL);
    504504    assert(result);
    505505    assert(JSValueIsEqual(context, result, jsOne));
    506506   
    507     result = JSEvaluate(context, badSyntaxBuf, NULL, NULL, 0, &exception);
     507    result = JSEvaluate(context, badSyntaxBuf, NULL, NULL, 1, &exception);
    508508    assert(!result);
    509509    assert(!JSContextGetException(context));
     
    537537    assert(!JSValueIsInstanceOf(context, JSNullMake(), arrayConstructor));
    538538   
     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                                                 
    539553    JSObjectRef myObject = JSObjectMake(context, MyObject_class(context), NULL);
    540554    assert(didInitialize);
     
    548562
    549563    JSCharBufferRef myConstructorBuf = JSCharBufferCreateUTF8("MyConstructor");
    550     JSObjectSetProperty(context, globalObject, myConstructorBuf, JSConstructorMake(context, myConstructor_callAsConstructor), kJSPropertyAttributeNone); 
     564    JSObjectSetProperty(context, globalObject, myConstructorBuf, JSConstructorMake(context, myConstructor_callAsConstructor), kJSPropertyAttributeNone);
    551565    JSCharBufferRelease(myConstructorBuf);
    552566
    553567    char* script = createStringWithContentsOfFile("testapi.js");
    554568    JSCharBufferRef scriptBuf = JSCharBufferCreateUTF8(script);
    555     result = JSEvaluate(context, scriptBuf, NULL, NULL, 0, &exception);
     569    result = JSEvaluate(context, scriptBuf, NULL, NULL, 1, &exception);
    556570    if (JSValueIsUndefined(result))
    557571        printf("PASS: Test script executed successfully.\n");
Note: See TracChangeset for help on using the changeset viewer.