Ignore:
Timestamp:
Jul 3, 2006, 7:35:09 PM (19 years ago)
Author:
ggaren
Message:

Reviewed by Darin.


  • Refined value conversions in the API:
    • failed toNumber returns NaN
    • failed toObject returns NULL
    • failed toString returns empty string


  • Refined excpetion handling in the API:
    • failed value conversions do not throw exceptions
    • uncaught exceptions in JSEvaluate, JSObjectCallAsFunction, and JSObjectCallAsConstructor are returned through a JSValueRef* exception argument
    • removed JSContextHasException, because JSContextGetException does the same job


  • API/JSBase.h:
  • API/JSCharBufferRef.cpp: (JSValueCopyStringValue):
  • API/JSContextRef.cpp: (JSEvaluate):
  • API/JSContextRef.h:
  • API/JSNodeList.c: Added test code demonstrating how you would use toNumber, and why you probably don't need toUInt32, etc. (JSNodeListPrototype_item): (JSNodeList_getProperty):
  • API/JSObjectRef.cpp: (JSValueToObject): (JSObjectCallAsFunction): (JSObjectCallAsConstructor):
  • API/JSObjectRef.h:
  • API/JSValueRef.cpp: (JSValueToNumber):
  • API/JSValueRef.h:
  • API/minidom.c: (main):
  • API/testapi.c: (main): Added tests for new rules, and call to JSGCProtect to fix Intel crash
  • JavaScriptCore.exp:
File:
1 edited

Legend:

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

    r15133 r15149  
    7272}
    7373
    74 bool JSEvaluate(JSContextRef context, JSValueRef thisValue, JSCharBufferRef script, JSCharBufferRef sourceURL, int startingLineNumber, JSValueRef* returnValue)
     74JSValueRef JSEvaluate(JSContextRef context, JSCharBufferRef script, JSValueRef thisValue, JSCharBufferRef sourceURL, int startingLineNumber, JSValueRef* exception)
    7575{
    7676    JSLock lock;
     
    7979    UString::Rep* scriptRep = toJS(script);
    8080    UString::Rep* sourceURLRep = toJS(sourceURL);
     81    // Interpreter::evaluate sets thisValue to the global object if it is NULL
    8182    Completion completion = exec->dynamicInterpreter()->evaluate(UString(sourceURLRep), startingLineNumber, UString(scriptRep), jsThisValue);
    8283
    83     if (returnValue)
    84         *returnValue = completion.value() ? toRef(completion.value()) : toRef(jsUndefined());
    85 
    86     return completion.complType() != Throw;
     84    if (completion.complType() == Throw) {
     85        if (exception)
     86            *exception = completion.value();
     87        return NULL;
     88    }
     89   
     90    if (completion.value())
     91        return toRef(completion.value());
     92   
     93    // happens, for example, when the only statement is an empty (';') statement
     94    return toRef(jsUndefined());
    8795}
    8896
     
    93101    UString::Rep* rep = toJS(script);
    94102    return exec->dynamicInterpreter()->checkSyntax(UString(rep));
    95 }
    96 
    97 bool JSContextHasException(JSContextRef context)
    98 {
    99     ExecState* exec = toJS(context);
    100     return exec->hadException();
    101103}
    102104
Note: See TracChangeset for help on using the changeset viewer.