Ignore:
Timestamp:
Jul 15, 2006, 6:40:07 PM (19 years ago)
Author:
ggaren
Message:

Reviewed by Maciej.


  • JSObjectMakeFunctionWithBody includes a function name and named parameters now.
  • API/JSObjectRef.cpp: (JSObjectMakeFunctionWithBody):
  • API/JSObjectRef.h:
  • API/testapi.c: (assertEqualsAsUTF8String): More informative failure reporting. (main): Test more function cases.
File:
1 edited

Legend:

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

    r15462 r15463  
    9090}
    9191
    92 JSObjectRef JSObjectMakeFunctionWithBody(JSContextRef context, JSStringRef body, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception)
    93 {
    94     JSLock lock;
    95    
    96     ExecState* exec = toJS(context);
     92JSObjectRef JSObjectMakeFunctionWithBody(JSContextRef context, JSStringRef name, unsigned parameterCount, JSStringRef parameterNames[], JSStringRef body, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception)
     93{
     94    JSLock lock;
     95   
     96    ExecState* exec = toJS(context);
     97    UString::Rep* nameRep = name ? toJS(name) : &UString::Rep::null;
    9798    UString::Rep* bodyRep = toJS(body);
    98     UString jsSourceURL = UString(toJS(sourceURL));
    99 
    100     if (!bodyRep)
    101         bodyRep = &UString::Rep::null;
    102    
    103     int sid;
    104     int errLine;
    105     UString errMsg;
    106     RefPtr<FunctionBodyNode> bodyNode = Parser::parse(jsSourceURL, startingLineNumber, bodyRep->data(), bodyRep->size(), &sid, &errLine, &errMsg);
    107     if (!bodyNode) {
    108         if (exception)
    109             *exception = toRef(Error::create(exec, SyntaxError, errMsg, errLine, sid, jsSourceURL));
    110         return 0;
    111     }
    112 
    113     ScopeChain scopeChain;
    114     scopeChain.push(exec->dynamicInterpreter()->globalObject());
    115     return toRef(static_cast<JSObject*>(new DeclaredFunctionImp(exec, "anonymous", bodyNode.get(), scopeChain)));
     99    UString::Rep* sourceURLRep = sourceURL ? toJS(sourceURL) : &UString::Rep::null;
     100   
     101    Identifier nameIdentifier = nameRep ? Identifier(nameRep) : Identifier("anonymous");
     102   
     103    List args;
     104    for (unsigned i = 0; i < parameterCount; i++)
     105        args.append(jsString(UString(toJS(parameterNames[i]))));
     106    args.append(jsString(UString(bodyRep)));
     107
     108    JSObject* result = exec->dynamicInterpreter()->builtinFunction()->construct(exec, args, nameIdentifier, UString(sourceURLRep), startingLineNumber);
     109    if (exec->hadException()) {
     110        if (exception)
     111            *exception = toRef(exec->exception());
     112        exec->clearException();
     113        result = 0;
     114    }
     115    return toRef(result);
    116116}
    117117
Note: See TracChangeset for help on using the changeset viewer.