diff options
author | Ben Murdoch <benm@google.com> | 2010-06-15 19:36:43 +0100 |
---|---|---|
committer | Ben Murdoch <benm@google.com> | 2010-06-16 14:52:28 +0100 |
commit | 545e470e52f0ac6a3a072bf559c796b42c6066b6 (patch) | |
tree | c0c14763654d84d37577dde512c3d3b4699a9e86 /JavaScriptCore/runtime | |
parent | 719298a66237d38ea5c05f1547123ad8aacbc237 (diff) | |
download | external_webkit-545e470e52f0ac6a3a072bf559c796b42c6066b6.zip external_webkit-545e470e52f0ac6a3a072bf559c796b42c6066b6.tar.gz external_webkit-545e470e52f0ac6a3a072bf559c796b42c6066b6.tar.bz2 |
Merge webkit.org at r61121: Initial merge by git.
Change-Id: Icd6db395c62285be384d137164d95d7466c98760
Diffstat (limited to 'JavaScriptCore/runtime')
47 files changed, 1130 insertions, 1042 deletions
diff --git a/JavaScriptCore/runtime/ArrayConstructor.cpp b/JavaScriptCore/runtime/ArrayConstructor.cpp index 674d00a..589739a 100644 --- a/JavaScriptCore/runtime/ArrayConstructor.cpp +++ b/JavaScriptCore/runtime/ArrayConstructor.cpp @@ -26,6 +26,7 @@ #include "ArrayPrototype.h" #include "Error.h" +#include "ExceptionHelpers.h" #include "JSArray.h" #include "JSFunction.h" #include "Lookup.h" @@ -35,7 +36,7 @@ namespace JSC { ASSERT_CLASS_FITS_IN_CELL(ArrayConstructor); -static JSValue JSC_HOST_CALL arrayConstructorIsArray(ExecState*); +static EncodedJSValue JSC_HOST_CALL arrayConstructorIsArray(ExecState*); ArrayConstructor::ArrayConstructor(ExecState* exec, JSGlobalObject* globalObject, NonNullPassRefPtr<Structure> structure, ArrayPrototype* arrayPrototype, Structure* prototypeFunctionStructure) : InternalFunction(&exec->globalData(), globalObject, structure, Identifier(exec, arrayPrototype->classInfo()->className)) @@ -56,7 +57,7 @@ static inline JSObject* constructArrayWithSizeQuirk(ExecState* exec, const ArgLi if (args.size() == 1 && args.at(0).isNumber()) { uint32_t n = args.at(0).toUInt32(exec); if (n != args.at(0).toNumber(exec)) - return throwError(exec, RangeError, "Array size is not a small enough positive integer."); + return throwError(exec, createRangeError(exec, "Array size is not a small enough positive integer.")); return new (exec) JSArray(exec->lexicalGlobalObject()->arrayStructure(), n); } @@ -64,9 +65,10 @@ static inline JSObject* constructArrayWithSizeQuirk(ExecState* exec, const ArgLi return new (exec) JSArray(exec->lexicalGlobalObject()->arrayStructure(), args); } -static JSObject* constructWithArrayConstructor(ExecState* exec, JSObject*, const ArgList& args) +static EncodedJSValue JSC_HOST_CALL constructWithArrayConstructor(ExecState* exec) { - return constructArrayWithSizeQuirk(exec, args); + ArgList args(exec); + return JSValue::encode(constructArrayWithSizeQuirk(exec, args)); } // ECMA 15.4.2 @@ -76,10 +78,10 @@ ConstructType ArrayConstructor::getConstructData(ConstructData& constructData) return ConstructTypeHost; } -static JSValue JSC_HOST_CALL callArrayConstructor(ExecState* exec) +static EncodedJSValue JSC_HOST_CALL callArrayConstructor(ExecState* exec) { ArgList args(exec); - return constructArrayWithSizeQuirk(exec, args); + return JSValue::encode(constructArrayWithSizeQuirk(exec, args)); } // ECMA 15.6.1 @@ -90,9 +92,9 @@ CallType ArrayConstructor::getCallData(CallData& callData) return CallTypeHost; } -JSValue JSC_HOST_CALL arrayConstructorIsArray(ExecState* exec) +EncodedJSValue JSC_HOST_CALL arrayConstructorIsArray(ExecState* exec) { - return jsBoolean(exec->argument(0).inherits(&JSArray::info)); + return JSValue::encode(jsBoolean(exec->argument(0).inherits(&JSArray::info))); } } // namespace JSC diff --git a/JavaScriptCore/runtime/ArrayPrototype.cpp b/JavaScriptCore/runtime/ArrayPrototype.cpp index c7dea3b..699fbe6 100644 --- a/JavaScriptCore/runtime/ArrayPrototype.cpp +++ b/JavaScriptCore/runtime/ArrayPrototype.cpp @@ -40,27 +40,27 @@ namespace JSC { ASSERT_CLASS_FITS_IN_CELL(ArrayPrototype); -static JSValue JSC_HOST_CALL arrayProtoFuncToString(ExecState*); -static JSValue JSC_HOST_CALL arrayProtoFuncToLocaleString(ExecState*); -static JSValue JSC_HOST_CALL arrayProtoFuncConcat(ExecState*); -static JSValue JSC_HOST_CALL arrayProtoFuncJoin(ExecState*); -static JSValue JSC_HOST_CALL arrayProtoFuncPop(ExecState*); -static JSValue JSC_HOST_CALL arrayProtoFuncPush(ExecState*); -static JSValue JSC_HOST_CALL arrayProtoFuncReverse(ExecState*); -static JSValue JSC_HOST_CALL arrayProtoFuncShift(ExecState*); -static JSValue JSC_HOST_CALL arrayProtoFuncSlice(ExecState*); -static JSValue JSC_HOST_CALL arrayProtoFuncSort(ExecState*); -static JSValue JSC_HOST_CALL arrayProtoFuncSplice(ExecState*); -static JSValue JSC_HOST_CALL arrayProtoFuncUnShift(ExecState*); -static JSValue JSC_HOST_CALL arrayProtoFuncEvery(ExecState*); -static JSValue JSC_HOST_CALL arrayProtoFuncForEach(ExecState*); -static JSValue JSC_HOST_CALL arrayProtoFuncSome(ExecState*); -static JSValue JSC_HOST_CALL arrayProtoFuncIndexOf(ExecState*); -static JSValue JSC_HOST_CALL arrayProtoFuncFilter(ExecState*); -static JSValue JSC_HOST_CALL arrayProtoFuncMap(ExecState*); -static JSValue JSC_HOST_CALL arrayProtoFuncReduce(ExecState*); -static JSValue JSC_HOST_CALL arrayProtoFuncReduceRight(ExecState*); -static JSValue JSC_HOST_CALL arrayProtoFuncLastIndexOf(ExecState*); +static EncodedJSValue JSC_HOST_CALL arrayProtoFuncToString(ExecState*); +static EncodedJSValue JSC_HOST_CALL arrayProtoFuncToLocaleString(ExecState*); +static EncodedJSValue JSC_HOST_CALL arrayProtoFuncConcat(ExecState*); +static EncodedJSValue JSC_HOST_CALL arrayProtoFuncJoin(ExecState*); +static EncodedJSValue JSC_HOST_CALL arrayProtoFuncPop(ExecState*); +static EncodedJSValue JSC_HOST_CALL arrayProtoFuncPush(ExecState*); +static EncodedJSValue JSC_HOST_CALL arrayProtoFuncReverse(ExecState*); +static EncodedJSValue JSC_HOST_CALL arrayProtoFuncShift(ExecState*); +static EncodedJSValue JSC_HOST_CALL arrayProtoFuncSlice(ExecState*); +static EncodedJSValue JSC_HOST_CALL arrayProtoFuncSort(ExecState*); +static EncodedJSValue JSC_HOST_CALL arrayProtoFuncSplice(ExecState*); +static EncodedJSValue JSC_HOST_CALL arrayProtoFuncUnShift(ExecState*); +static EncodedJSValue JSC_HOST_CALL arrayProtoFuncEvery(ExecState*); +static EncodedJSValue JSC_HOST_CALL arrayProtoFuncForEach(ExecState*); +static EncodedJSValue JSC_HOST_CALL arrayProtoFuncSome(ExecState*); +static EncodedJSValue JSC_HOST_CALL arrayProtoFuncIndexOf(ExecState*); +static EncodedJSValue JSC_HOST_CALL arrayProtoFuncFilter(ExecState*); +static EncodedJSValue JSC_HOST_CALL arrayProtoFuncMap(ExecState*); +static EncodedJSValue JSC_HOST_CALL arrayProtoFuncReduce(ExecState*); +static EncodedJSValue JSC_HOST_CALL arrayProtoFuncReduceRight(ExecState*); +static EncodedJSValue JSC_HOST_CALL arrayProtoFuncLastIndexOf(ExecState*); } @@ -149,23 +149,23 @@ static void putProperty(ExecState* exec, JSObject* obj, const Identifier& proper obj->put(exec, propertyName, value, slot); } -JSValue JSC_HOST_CALL arrayProtoFuncToString(ExecState* exec) +EncodedJSValue JSC_HOST_CALL arrayProtoFuncToString(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); bool isRealArray = isJSArray(&exec->globalData(), thisValue); if (!isRealArray && !thisValue.inherits(&JSArray::info)) - return throwError(exec, TypeError); + return throwVMTypeError(exec); JSArray* thisObj = asArray(thisValue); HashSet<JSObject*>& arrayVisitedElements = exec->globalData().arrayVisitedElements; if (arrayVisitedElements.size() >= MaxSmallThreadReentryDepth) { if (arrayVisitedElements.size() >= exec->globalData().maxReentryDepth) - return throwError(exec, RangeError, "Maximum call stack size exceeded."); + return throwVMError(exec, createStackOverflowError(exec)); } bool alreadyVisited = !arrayVisitedElements.add(thisObj).second; if (alreadyVisited) - return jsEmptyString(exec); // return an empty string, avoiding infinite recursion. + return JSValue::encode(jsEmptyString(exec)); // return an empty string, avoiding infinite recursion. unsigned length = thisObj->get(exec, exec->propertyNames().length).toUInt32(exec); unsigned totalSize = length ? length - 1 : 0; @@ -193,11 +193,11 @@ JSValue JSC_HOST_CALL arrayProtoFuncToString(ExecState* exec) } arrayVisitedElements.remove(thisObj); if (!totalSize) - return jsEmptyString(exec); + return JSValue::encode(jsEmptyString(exec)); Vector<UChar> buffer; buffer.reserveCapacity(totalSize); if (!buffer.data()) - return throwOutOfMemoryError(exec); + return JSValue::encode(throwOutOfMemoryError(exec)); for (unsigned i = 0; i < length; i++) { if (i) @@ -206,25 +206,25 @@ JSValue JSC_HOST_CALL arrayProtoFuncToString(ExecState* exec) buffer.append(rep->characters(), rep->length()); } ASSERT(buffer.size() == totalSize); - return jsString(exec, UString::adopt(buffer)); + return JSValue::encode(jsString(exec, UString::adopt(buffer))); } -JSValue JSC_HOST_CALL arrayProtoFuncToLocaleString(ExecState* exec) +EncodedJSValue JSC_HOST_CALL arrayProtoFuncToLocaleString(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); if (!thisValue.inherits(&JSArray::info)) - return throwError(exec, TypeError); + return throwVMTypeError(exec); JSObject* thisObj = asArray(thisValue); HashSet<JSObject*>& arrayVisitedElements = exec->globalData().arrayVisitedElements; if (arrayVisitedElements.size() >= MaxSmallThreadReentryDepth) { if (arrayVisitedElements.size() >= exec->globalData().maxReentryDepth) - return throwError(exec, RangeError, "Maximum call stack size exceeded."); + return throwVMError(exec, createStackOverflowError(exec)); } bool alreadyVisited = !arrayVisitedElements.add(thisObj).second; if (alreadyVisited) - return jsEmptyString(exec); // return an empty string, avoding infinite recursion. + return JSValue::encode(jsEmptyString(exec)); // return an empty string, avoding infinite recursion. JSStringBuilder strBuffer; unsigned length = thisObj->get(exec, exec->propertyNames().length).toUInt32(exec); @@ -238,7 +238,7 @@ JSValue JSC_HOST_CALL arrayProtoFuncToLocaleString(ExecState* exec) JSValue conversionFunction = o->get(exec, exec->propertyNames().toLocaleString); UString str; CallData callData; - CallType callType = conversionFunction.getCallData(callData); + CallType callType = getCallData(conversionFunction, callData); if (callType != CallTypeNone) str = call(exec, conversionFunction, callType, callData, element, exec->emptyList()).toString(exec); else @@ -247,10 +247,10 @@ JSValue JSC_HOST_CALL arrayProtoFuncToLocaleString(ExecState* exec) } } arrayVisitedElements.remove(thisObj); - return strBuffer.build(exec); + return JSValue::encode(strBuffer.build(exec)); } -JSValue JSC_HOST_CALL arrayProtoFuncJoin(ExecState* exec) +EncodedJSValue JSC_HOST_CALL arrayProtoFuncJoin(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); JSObject* thisObj = thisValue.toThisObject(exec); @@ -258,12 +258,12 @@ JSValue JSC_HOST_CALL arrayProtoFuncJoin(ExecState* exec) HashSet<JSObject*>& arrayVisitedElements = exec->globalData().arrayVisitedElements; if (arrayVisitedElements.size() >= MaxSmallThreadReentryDepth) { if (arrayVisitedElements.size() >= exec->globalData().maxReentryDepth) - return throwError(exec, RangeError, "Maximum call stack size exceeded."); + return throwVMError(exec, createStackOverflowError(exec)); } bool alreadyVisited = !arrayVisitedElements.add(thisObj).second; if (alreadyVisited) - return jsEmptyString(exec); // return an empty string, avoding infinite recursion. + return JSValue::encode(jsEmptyString(exec)); // return an empty string, avoding infinite recursion. JSStringBuilder strBuffer; @@ -319,10 +319,10 @@ JSValue JSC_HOST_CALL arrayProtoFuncJoin(ExecState* exec) strBuffer.append(element.toString(exec)); } arrayVisitedElements.remove(thisObj); - return strBuffer.build(exec); + return JSValue::encode(strBuffer.build(exec)); } -JSValue JSC_HOST_CALL arrayProtoFuncConcat(ExecState* exec) +EncodedJSValue JSC_HOST_CALL arrayProtoFuncConcat(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); JSArray* arr = constructEmptyArray(exec); @@ -349,14 +349,14 @@ JSValue JSC_HOST_CALL arrayProtoFuncConcat(ExecState* exec) ++i; } arr->setLength(n); - return arr; + return JSValue::encode(arr); } -JSValue JSC_HOST_CALL arrayProtoFuncPop(ExecState* exec) +EncodedJSValue JSC_HOST_CALL arrayProtoFuncPop(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); if (isJSArray(&exec->globalData(), thisValue)) - return asArray(thisValue)->pop(); + return JSValue::encode(asArray(thisValue)->pop()); JSObject* thisObj = thisValue.toThisObject(exec); JSValue result; @@ -369,16 +369,16 @@ JSValue JSC_HOST_CALL arrayProtoFuncPop(ExecState* exec) thisObj->deleteProperty(exec, length - 1); putProperty(exec, thisObj, exec->propertyNames().length, jsNumber(exec, length - 1)); } - return result; + return JSValue::encode(result); } -JSValue JSC_HOST_CALL arrayProtoFuncPush(ExecState* exec) +EncodedJSValue JSC_HOST_CALL arrayProtoFuncPush(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); if (isJSArray(&exec->globalData(), thisValue) && exec->argumentCount() == 1) { JSArray* array = asArray(thisValue); array->push(exec, exec->argument(0)); - return jsNumber(exec, array->length()); + return JSValue::encode(jsNumber(exec, array->length())); } JSObject* thisObj = thisValue.toThisObject(exec); @@ -387,10 +387,10 @@ JSValue JSC_HOST_CALL arrayProtoFuncPush(ExecState* exec) thisObj->put(exec, length + n, exec->argument(n)); length += exec->argumentCount(); putProperty(exec, thisObj, exec->propertyNames().length, jsNumber(exec, length)); - return jsNumber(exec, length); + return JSValue::encode(jsNumber(exec, length)); } -JSValue JSC_HOST_CALL arrayProtoFuncReverse(ExecState* exec) +EncodedJSValue JSC_HOST_CALL arrayProtoFuncReverse(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); JSObject* thisObj = thisValue.toThisObject(exec); @@ -412,10 +412,10 @@ JSValue JSC_HOST_CALL arrayProtoFuncReverse(ExecState* exec) else thisObj->deleteProperty(exec, lk1); } - return thisObj; + return JSValue::encode(thisObj); } -JSValue JSC_HOST_CALL arrayProtoFuncShift(ExecState* exec) +EncodedJSValue JSC_HOST_CALL arrayProtoFuncShift(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); JSObject* thisObj = thisValue.toThisObject(exec); @@ -436,10 +436,10 @@ JSValue JSC_HOST_CALL arrayProtoFuncShift(ExecState* exec) thisObj->deleteProperty(exec, length - 1); putProperty(exec, thisObj, exec->propertyNames().length, jsNumber(exec, length - 1)); } - return result; + return JSValue::encode(result); } -JSValue JSC_HOST_CALL arrayProtoFuncSlice(ExecState* exec) +EncodedJSValue JSC_HOST_CALL arrayProtoFuncSlice(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); // http://developer.netscape.com/docs/manuals/js/client/jsref/array.htm#1193713 or 15.4.4.10 @@ -482,17 +482,17 @@ JSValue JSC_HOST_CALL arrayProtoFuncSlice(ExecState* exec) resObj->put(exec, n, v); } resObj->setLength(n); - return result; + return JSValue::encode(result); } -JSValue JSC_HOST_CALL arrayProtoFuncSort(ExecState* exec) +EncodedJSValue JSC_HOST_CALL arrayProtoFuncSort(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); JSObject* thisObj = thisValue.toThisObject(exec); JSValue function = exec->argument(0); CallData callData; - CallType callType = function.getCallData(callData); + CallType callType = getCallData(function, callData); if (thisObj->classInfo() == &JSArray::info) { if (isNumericCompareFunction(exec, callType, callData)) @@ -501,13 +501,13 @@ JSValue JSC_HOST_CALL arrayProtoFuncSort(ExecState* exec) asArray(thisObj)->sort(exec, function, callType, callData); else asArray(thisObj)->sort(exec); - return thisObj; + return JSValue::encode(thisObj); } unsigned length = thisObj->get(exec, exec->propertyNames().length).toUInt32(exec); if (!length) - return thisObj; + return JSValue::encode(thisObj); // "Min" sort. Not the fastest, but definitely less code than heapsort // or quicksort, and much less swapping than bubblesort/insertionsort. @@ -541,10 +541,10 @@ JSValue JSC_HOST_CALL arrayProtoFuncSort(ExecState* exec) thisObj->put(exec, themin, iObj); } } - return thisObj; + return JSValue::encode(thisObj); } -JSValue JSC_HOST_CALL arrayProtoFuncSplice(ExecState* exec) +EncodedJSValue JSC_HOST_CALL arrayProtoFuncSplice(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); JSObject* thisObj = thisValue.toThisObject(exec); @@ -555,7 +555,7 @@ JSValue JSC_HOST_CALL arrayProtoFuncSplice(ExecState* exec) // FIXME: Firefox returns an empty array. if (!exec->argumentCount()) - return jsUndefined(); + return JSValue::encode(jsUndefined()); unsigned length = thisObj->get(exec, exec->propertyNames().length).toUInt32(exec); double relativeBegin = exec->argument(0).toInteger(exec); @@ -602,10 +602,10 @@ JSValue JSC_HOST_CALL arrayProtoFuncSplice(ExecState* exec) thisObj->put(exec, k + begin, exec->argument(k + 2)); putProperty(exec, thisObj, exec->propertyNames().length, jsNumber(exec, length - deleteCount + additionalArgs)); - return result; + return JSValue::encode(result); } -JSValue JSC_HOST_CALL arrayProtoFuncUnShift(ExecState* exec) +EncodedJSValue JSC_HOST_CALL arrayProtoFuncUnShift(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); JSObject* thisObj = thisValue.toThisObject(exec); @@ -625,19 +625,19 @@ JSValue JSC_HOST_CALL arrayProtoFuncUnShift(ExecState* exec) thisObj->put(exec, k, exec->argument(k)); JSValue result = jsNumber(exec, length + nrArgs); putProperty(exec, thisObj, exec->propertyNames().length, result); - return result; + return JSValue::encode(result); } -JSValue JSC_HOST_CALL arrayProtoFuncFilter(ExecState* exec) +EncodedJSValue JSC_HOST_CALL arrayProtoFuncFilter(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); JSObject* thisObj = thisValue.toThisObject(exec); JSValue function = exec->argument(0); CallData callData; - CallType callType = function.getCallData(callData); + CallType callType = getCallData(function, callData); if (callType == CallTypeNone) - return throwError(exec, TypeError); + return throwVMTypeError(exec); JSObject* applyThis = exec->argument(1).isUndefinedOrNull() ? exec->globalThisValue() : exec->argument(1).toObject(exec); JSArray* resultArray = constructEmptyArray(exec); @@ -663,7 +663,7 @@ JSValue JSC_HOST_CALL arrayProtoFuncFilter(ExecState* exec) resultArray->put(exec, filterIndex++, v); } if (k == length) - return resultArray; + return JSValue::encode(resultArray); } for (; k < length && !exec->hadException(); ++k) { PropertySlot slot(thisObj); @@ -684,19 +684,19 @@ JSValue JSC_HOST_CALL arrayProtoFuncFilter(ExecState* exec) if (result.toBoolean(exec)) resultArray->put(exec, filterIndex++, v); } - return resultArray; + return JSValue::encode(resultArray); } -JSValue JSC_HOST_CALL arrayProtoFuncMap(ExecState* exec) +EncodedJSValue JSC_HOST_CALL arrayProtoFuncMap(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); JSObject* thisObj = thisValue.toThisObject(exec); JSValue function = exec->argument(0); CallData callData; - CallType callType = function.getCallData(callData); + CallType callType = getCallData(function, callData); if (callType == CallTypeNone) - return throwError(exec, TypeError); + return throwVMTypeError(exec); JSObject* applyThis = exec->argument(1).isUndefinedOrNull() ? exec->globalThisValue() : exec->argument(1).toObject(exec); @@ -737,7 +737,7 @@ JSValue JSC_HOST_CALL arrayProtoFuncMap(ExecState* exec) resultArray->put(exec, k, result); } - return resultArray; + return JSValue::encode(resultArray); } // Documentation for these three is available at: @@ -745,16 +745,16 @@ JSValue JSC_HOST_CALL arrayProtoFuncMap(ExecState* exec) // http://developer-test.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Objects:Array:forEach // http://developer-test.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Objects:Array:some -JSValue JSC_HOST_CALL arrayProtoFuncEvery(ExecState* exec) +EncodedJSValue JSC_HOST_CALL arrayProtoFuncEvery(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); JSObject* thisObj = thisValue.toThisObject(exec); JSValue function = exec->argument(0); CallData callData; - CallType callType = function.getCallData(callData); + CallType callType = getCallData(function, callData); if (callType == CallTypeNone) - return throwError(exec, TypeError); + return throwVMTypeError(exec); JSObject* applyThis = exec->argument(1).isUndefinedOrNull() ? exec->globalThisValue() : exec->argument(1).toObject(exec); @@ -776,7 +776,7 @@ JSValue JSC_HOST_CALL arrayProtoFuncEvery(ExecState* exec) cachedCall.setArgument(2, thisObj); JSValue result = cachedCall.call(); if (!result.toBoolean(cachedCall.newCallFrame(exec))) - return jsBoolean(false); + return JSValue::encode(jsBoolean(false)); } } for (; k < length && !exec->hadException(); ++k) { @@ -799,19 +799,19 @@ JSValue JSC_HOST_CALL arrayProtoFuncEvery(ExecState* exec) } } - return result; + return JSValue::encode(result); } -JSValue JSC_HOST_CALL arrayProtoFuncForEach(ExecState* exec) +EncodedJSValue JSC_HOST_CALL arrayProtoFuncForEach(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); JSObject* thisObj = thisValue.toThisObject(exec); JSValue function = exec->argument(0); CallData callData; - CallType callType = function.getCallData(callData); + CallType callType = getCallData(function, callData); if (callType == CallTypeNone) - return throwError(exec, TypeError); + return throwVMTypeError(exec); JSObject* applyThis = exec->argument(1).isUndefinedOrNull() ? exec->globalThisValue() : exec->argument(1).toObject(exec); @@ -845,19 +845,19 @@ JSValue JSC_HOST_CALL arrayProtoFuncForEach(ExecState* exec) call(exec, function, callType, callData, applyThis, eachArguments); } - return jsUndefined(); + return JSValue::encode(jsUndefined()); } -JSValue JSC_HOST_CALL arrayProtoFuncSome(ExecState* exec) +EncodedJSValue JSC_HOST_CALL arrayProtoFuncSome(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); JSObject* thisObj = thisValue.toThisObject(exec); JSValue function = exec->argument(0); CallData callData; - CallType callType = function.getCallData(callData); + CallType callType = getCallData(function, callData); if (callType == CallTypeNone) - return throwError(exec, TypeError); + return throwVMTypeError(exec); JSObject* applyThis = exec->argument(1).isUndefinedOrNull() ? exec->globalThisValue() : exec->argument(1).toObject(exec); @@ -879,7 +879,7 @@ JSValue JSC_HOST_CALL arrayProtoFuncSome(ExecState* exec) cachedCall.setArgument(2, thisObj); JSValue result = cachedCall.call(); if (result.toBoolean(cachedCall.newCallFrame(exec))) - return jsBoolean(true); + return JSValue::encode(jsBoolean(true)); } } for (; k < length && !exec->hadException(); ++k) { @@ -899,25 +899,25 @@ JSValue JSC_HOST_CALL arrayProtoFuncSome(ExecState* exec) break; } } - return result; + return JSValue::encode(result); } -JSValue JSC_HOST_CALL arrayProtoFuncReduce(ExecState* exec) +EncodedJSValue JSC_HOST_CALL arrayProtoFuncReduce(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); JSObject* thisObj = thisValue.toThisObject(exec); JSValue function = exec->argument(0); CallData callData; - CallType callType = function.getCallData(callData); + CallType callType = getCallData(function, callData); if (callType == CallTypeNone) - return throwError(exec, TypeError); + return throwVMTypeError(exec); unsigned i = 0; JSValue rv; unsigned length = thisObj->get(exec, exec->propertyNames().length).toUInt32(exec); if (!length && exec->argumentCount() == 1) - return throwError(exec, TypeError); + return throwVMTypeError(exec); JSArray* array = 0; if (isJSArray(&exec->globalData(), thisObj)) array = asArray(thisObj); @@ -934,7 +934,7 @@ JSValue JSC_HOST_CALL arrayProtoFuncReduce(ExecState* exec) break; } if (!rv) - return throwError(exec, TypeError); + return throwVMTypeError(exec); i++; } @@ -954,7 +954,7 @@ JSValue JSC_HOST_CALL arrayProtoFuncReduce(ExecState* exec) rv = cachedCall.call(); } if (i == length) // only return if we reached the end of the array - return rv; + return JSValue::encode(rv); } for (; i < length && !exec->hadException(); ++i) { @@ -970,25 +970,25 @@ JSValue JSC_HOST_CALL arrayProtoFuncReduce(ExecState* exec) rv = call(exec, function, callType, callData, jsNull(), eachArguments); } - return rv; + return JSValue::encode(rv); } -JSValue JSC_HOST_CALL arrayProtoFuncReduceRight(ExecState* exec) +EncodedJSValue JSC_HOST_CALL arrayProtoFuncReduceRight(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); JSObject* thisObj = thisValue.toThisObject(exec); JSValue function = exec->argument(0); CallData callData; - CallType callType = function.getCallData(callData); + CallType callType = getCallData(function, callData); if (callType == CallTypeNone) - return throwError(exec, TypeError); + return throwVMTypeError(exec); unsigned i = 0; JSValue rv; unsigned length = thisObj->get(exec, exec->propertyNames().length).toUInt32(exec); if (!length && exec->argumentCount() == 1) - return throwError(exec, TypeError); + return throwVMTypeError(exec); JSArray* array = 0; if (isJSArray(&exec->globalData(), thisObj)) array = asArray(thisObj); @@ -1005,7 +1005,7 @@ JSValue JSC_HOST_CALL arrayProtoFuncReduceRight(ExecState* exec) break; } if (!rv) - return throwError(exec, TypeError); + return throwVMTypeError(exec); i++; } @@ -1023,7 +1023,7 @@ JSValue JSC_HOST_CALL arrayProtoFuncReduceRight(ExecState* exec) rv = cachedCall.call(); } if (i == length) // only return if we reached the end of the array - return rv; + return JSValue::encode(rv); } for (; i < length && !exec->hadException(); ++i) { @@ -1040,10 +1040,10 @@ JSValue JSC_HOST_CALL arrayProtoFuncReduceRight(ExecState* exec) rv = call(exec, function, callType, callData, jsNull(), eachArguments); } - return rv; + return JSValue::encode(rv); } -JSValue JSC_HOST_CALL arrayProtoFuncIndexOf(ExecState* exec) +EncodedJSValue JSC_HOST_CALL arrayProtoFuncIndexOf(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); // JavaScript 1.5 Extension by Mozilla @@ -1069,13 +1069,13 @@ JSValue JSC_HOST_CALL arrayProtoFuncIndexOf(ExecState* exec) if (!e) continue; if (JSValue::strictEqual(exec, searchElement, e)) - return jsNumber(exec, index); + return JSValue::encode(jsNumber(exec, index)); } - return jsNumber(exec, -1); + return JSValue::encode(jsNumber(exec, -1)); } -JSValue JSC_HOST_CALL arrayProtoFuncLastIndexOf(ExecState* exec) +EncodedJSValue JSC_HOST_CALL arrayProtoFuncLastIndexOf(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); // JavaScript 1.6 Extension by Mozilla @@ -1090,7 +1090,7 @@ JSValue JSC_HOST_CALL arrayProtoFuncLastIndexOf(ExecState* exec) if (d < 0) { d += length; if (d < 0) - return jsNumber(exec, -1); + return JSValue::encode(jsNumber(exec, -1)); } if (d < length) index = static_cast<int>(d); @@ -1101,10 +1101,10 @@ JSValue JSC_HOST_CALL arrayProtoFuncLastIndexOf(ExecState* exec) if (!e) continue; if (JSValue::strictEqual(exec, searchElement, e)) - return jsNumber(exec, index); + return JSValue::encode(jsNumber(exec, index)); } - return jsNumber(exec, -1); + return JSValue::encode(jsNumber(exec, -1)); } } // namespace JSC diff --git a/JavaScriptCore/runtime/BooleanConstructor.cpp b/JavaScriptCore/runtime/BooleanConstructor.cpp index bc12858..953bddc 100644 --- a/JavaScriptCore/runtime/BooleanConstructor.cpp +++ b/JavaScriptCore/runtime/BooleanConstructor.cpp @@ -45,9 +45,10 @@ JSObject* constructBoolean(ExecState* exec, const ArgList& args) return obj; } -static JSObject* constructWithBooleanConstructor(ExecState* exec, JSObject*, const ArgList& args) +static EncodedJSValue JSC_HOST_CALL constructWithBooleanConstructor(ExecState* exec) { - return constructBoolean(exec, args); + ArgList args(exec); + return JSValue::encode(constructBoolean(exec, args)); } ConstructType BooleanConstructor::getConstructData(ConstructData& constructData) @@ -57,9 +58,9 @@ ConstructType BooleanConstructor::getConstructData(ConstructData& constructData) } // ECMA 15.6.1 -static JSValue JSC_HOST_CALL callBooleanConstructor(ExecState* exec) +static EncodedJSValue JSC_HOST_CALL callBooleanConstructor(ExecState* exec) { - return jsBoolean(exec->argument(0).toBoolean(exec)); + return JSValue::encode(jsBoolean(exec->argument(0).toBoolean(exec))); } CallType BooleanConstructor::getCallData(CallData& callData) diff --git a/JavaScriptCore/runtime/BooleanPrototype.cpp b/JavaScriptCore/runtime/BooleanPrototype.cpp index dbb27b2..7ffd095 100644 --- a/JavaScriptCore/runtime/BooleanPrototype.cpp +++ b/JavaScriptCore/runtime/BooleanPrototype.cpp @@ -22,6 +22,7 @@ #include "BooleanPrototype.h" #include "Error.h" +#include "ExceptionHelpers.h" #include "JSFunction.h" #include "JSString.h" #include "ObjectPrototype.h" @@ -32,8 +33,8 @@ namespace JSC { ASSERT_CLASS_FITS_IN_CELL(BooleanPrototype); // Functions -static JSValue JSC_HOST_CALL booleanProtoFuncToString(ExecState*); -static JSValue JSC_HOST_CALL booleanProtoFuncValueOf(ExecState*); +static EncodedJSValue JSC_HOST_CALL booleanProtoFuncToString(ExecState*); +static EncodedJSValue JSC_HOST_CALL booleanProtoFuncValueOf(ExecState*); // ECMA 15.6.4 @@ -51,35 +52,35 @@ BooleanPrototype::BooleanPrototype(ExecState* exec, JSGlobalObject* globalObject // ECMA 15.6.4.2 + 15.6.4.3 -JSValue JSC_HOST_CALL booleanProtoFuncToString(ExecState* exec) +EncodedJSValue JSC_HOST_CALL booleanProtoFuncToString(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); if (thisValue == jsBoolean(false)) - return jsNontrivialString(exec, "false"); + return JSValue::encode(jsNontrivialString(exec, "false")); if (thisValue == jsBoolean(true)) - return jsNontrivialString(exec, "true"); + return JSValue::encode(jsNontrivialString(exec, "true")); if (!thisValue.inherits(&BooleanObject::info)) - return throwError(exec, TypeError); + return throwVMTypeError(exec); if (asBooleanObject(thisValue)->internalValue() == jsBoolean(false)) - return jsNontrivialString(exec, "false"); + return JSValue::encode(jsNontrivialString(exec, "false")); ASSERT(asBooleanObject(thisValue)->internalValue() == jsBoolean(true)); - return jsNontrivialString(exec, "true"); + return JSValue::encode(jsNontrivialString(exec, "true")); } -JSValue JSC_HOST_CALL booleanProtoFuncValueOf(ExecState* exec) +EncodedJSValue JSC_HOST_CALL booleanProtoFuncValueOf(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); if (thisValue.isBoolean()) - return thisValue; + return JSValue::encode(thisValue); if (!thisValue.inherits(&BooleanObject::info)) - return throwError(exec, TypeError); + return throwVMTypeError(exec); - return asBooleanObject(thisValue)->internalValue(); + return JSValue::encode(asBooleanObject(thisValue)->internalValue()); } } // namespace JSC diff --git a/JavaScriptCore/runtime/CallData.h b/JavaScriptCore/runtime/CallData.h index 5294e54..32e1094 100644 --- a/JavaScriptCore/runtime/CallData.h +++ b/JavaScriptCore/runtime/CallData.h @@ -29,6 +29,7 @@ #ifndef CallData_h #define CallData_h +#include "JSValue.h" #include "NativeFunctionWrapper.h" namespace JSC { @@ -37,7 +38,6 @@ namespace JSC { class ExecState; class FunctionExecutable; class JSObject; - class JSValue; class ScopeChainNode; enum CallType { @@ -46,7 +46,7 @@ namespace JSC { CallTypeJS }; - typedef JSValue (JSC_HOST_CALL *NativeFunction)(ExecState*); + typedef EncodedJSValue (JSC_HOST_CALL *NativeFunction)(ExecState*); union CallData { struct { diff --git a/JavaScriptCore/runtime/ConstructData.cpp b/JavaScriptCore/runtime/ConstructData.cpp index a7b97e6..0d27e25 100644 --- a/JavaScriptCore/runtime/ConstructData.cpp +++ b/JavaScriptCore/runtime/ConstructData.cpp @@ -33,27 +33,10 @@ namespace JSC { -JSObject* construct(ExecState* exec, JSValue object, ConstructType constructType, const ConstructData& constructData, const ArgList& args) +JSObject* construct(ExecState* exec, JSValue constructorObject, ConstructType constructType, const ConstructData& constructData, const ArgList& args) { - if (constructType == ConstructTypeHost) - return constructData.native.function(exec, asObject(object), args); - - ASSERT(constructType == ConstructTypeJS); - JSFunction* jsFunction = asFunction(object); - - ASSERT(!jsFunction->isHostFunction()); - Structure* structure; - JSValue prototype = jsFunction->get(exec, exec->propertyNames().prototype); - if (prototype.isObject()) - structure = asObject(prototype)->inheritorID(); - else - structure = exec->lexicalGlobalObject()->emptyObjectStructure(); - JSObject* thisObj = new (exec) JSObject(structure); - - JSValue result = exec->interpreter()->executeConstruct(jsFunction->jsExecutable(), exec, jsFunction, thisObj, args, jsFunction->scope().node(), exec->exceptionSlot()); - if (exec->hadException() || !result.isObject()) - return thisObj; - return asObject(result); + ASSERT(constructType == ConstructTypeJS || constructType == ConstructTypeHost); + return exec->interpreter()->executeConstruct(exec, asObject(constructorObject), constructType, constructData, args, exec->exceptionSlot()); } } // namespace JSC diff --git a/JavaScriptCore/runtime/ConstructData.h b/JavaScriptCore/runtime/ConstructData.h index 6b954a6..3d5f732 100644 --- a/JavaScriptCore/runtime/ConstructData.h +++ b/JavaScriptCore/runtime/ConstructData.h @@ -29,13 +29,14 @@ #ifndef ConstructData_h #define ConstructData_h +#include "JSValue.h" + namespace JSC { class ArgList; class ExecState; class FunctionExecutable; class JSObject; - class JSValue; class ScopeChainNode; enum ConstructType { @@ -44,7 +45,7 @@ namespace JSC { ConstructTypeJS }; - typedef JSObject* (*NativeConstructor)(ExecState*, JSObject*, const ArgList&); + typedef EncodedJSValue (JSC_HOST_CALL *NativeConstructor)(ExecState*); union ConstructData { struct { diff --git a/JavaScriptCore/runtime/DateConstructor.cpp b/JavaScriptCore/runtime/DateConstructor.cpp index 015a01a..5b2f916 100644 --- a/JavaScriptCore/runtime/DateConstructor.cpp +++ b/JavaScriptCore/runtime/DateConstructor.cpp @@ -54,9 +54,9 @@ namespace JSC { ASSERT_CLASS_FITS_IN_CELL(DateConstructor); -static JSValue JSC_HOST_CALL dateParse(ExecState*); -static JSValue JSC_HOST_CALL dateNow(ExecState*); -static JSValue JSC_HOST_CALL dateUTC(ExecState*); +static EncodedJSValue JSC_HOST_CALL dateParse(ExecState*); +static EncodedJSValue JSC_HOST_CALL dateNow(ExecState*); +static EncodedJSValue JSC_HOST_CALL dateUTC(ExecState*); DateConstructor::DateConstructor(ExecState* exec, JSGlobalObject* globalObject, NonNullPassRefPtr<Structure> structure, Structure* prototypeFunctionStructure, DatePrototype* datePrototype) : InternalFunction(&exec->globalData(), globalObject, structure, Identifier(exec, datePrototype->classInfo()->className)) @@ -116,9 +116,10 @@ JSObject* constructDate(ExecState* exec, const ArgList& args) return new (exec) DateInstance(exec, value); } -static JSObject* constructWithDateConstructor(ExecState* exec, JSObject*, const ArgList& args) +static EncodedJSValue JSC_HOST_CALL constructWithDateConstructor(ExecState* exec) { - return constructDate(exec, args); + ArgList args(exec); + return JSValue::encode(constructDate(exec, args)); } ConstructType DateConstructor::getConstructData(ConstructData& constructData) @@ -128,7 +129,7 @@ ConstructType DateConstructor::getConstructData(ConstructData& constructData) } // ECMA 15.9.2 -static JSValue JSC_HOST_CALL callDate(ExecState* exec) +static EncodedJSValue JSC_HOST_CALL callDate(ExecState* exec) { time_t localTime = time(0); tm localTM; @@ -138,7 +139,7 @@ static JSValue JSC_HOST_CALL callDate(ExecState* exec) DateConversionBuffer time; formatDate(ts, date); formatTime(ts, time); - return jsMakeNontrivialString(exec, date, " ", time); + return JSValue::encode(jsMakeNontrivialString(exec, date, " ", time)); } CallType DateConstructor::getCallData(CallData& callData) @@ -147,17 +148,17 @@ CallType DateConstructor::getCallData(CallData& callData) return CallTypeHost; } -static JSValue JSC_HOST_CALL dateParse(ExecState* exec) +static EncodedJSValue JSC_HOST_CALL dateParse(ExecState* exec) { - return jsNumber(exec, parseDate(exec, exec->argument(0).toString(exec))); + return JSValue::encode(jsNumber(exec, parseDate(exec, exec->argument(0).toString(exec)))); } -static JSValue JSC_HOST_CALL dateNow(ExecState* exec) +static EncodedJSValue JSC_HOST_CALL dateNow(ExecState* exec) { - return jsNumber(exec, jsCurrentTime()); + return JSValue::encode(jsNumber(exec, jsCurrentTime())); } -static JSValue JSC_HOST_CALL dateUTC(ExecState* exec) +static EncodedJSValue JSC_HOST_CALL dateUTC(ExecState* exec) { int n = exec->argumentCount(); if (isnan(exec->argument(0).toNumber(exec)) @@ -167,7 +168,7 @@ static JSValue JSC_HOST_CALL dateUTC(ExecState* exec) || (n >= 5 && isnan(exec->argument(4).toNumber(exec))) || (n >= 6 && isnan(exec->argument(5).toNumber(exec))) || (n >= 7 && isnan(exec->argument(6).toNumber(exec)))) - return jsNaN(exec); + return JSValue::encode(jsNaN(exec)); GregorianDateTime t; int year = exec->argument(0).toInt32(exec); @@ -178,7 +179,7 @@ static JSValue JSC_HOST_CALL dateUTC(ExecState* exec) t.minute = exec->argument(4).toInt32(exec); t.second = exec->argument(5).toInt32(exec); double ms = (n >= 7) ? exec->argument(6).toNumber(exec) : 0; - return jsNumber(exec, timeClip(gregorianDateTimeToMS(exec, t, ms, true))); + return JSValue::encode(jsNumber(exec, timeClip(gregorianDateTimeToMS(exec, t, ms, true)))); } } // namespace JSC diff --git a/JavaScriptCore/runtime/DatePrototype.cpp b/JavaScriptCore/runtime/DatePrototype.cpp index c31a4d0..f8d2224 100644 --- a/JavaScriptCore/runtime/DatePrototype.cpp +++ b/JavaScriptCore/runtime/DatePrototype.cpp @@ -73,51 +73,51 @@ namespace JSC { ASSERT_CLASS_FITS_IN_CELL(DatePrototype); -static JSValue JSC_HOST_CALL dateProtoFuncGetDate(ExecState*); -static JSValue JSC_HOST_CALL dateProtoFuncGetDay(ExecState*); -static JSValue JSC_HOST_CALL dateProtoFuncGetFullYear(ExecState*); -static JSValue JSC_HOST_CALL dateProtoFuncGetHours(ExecState*); -static JSValue JSC_HOST_CALL dateProtoFuncGetMilliSeconds(ExecState*); -static JSValue JSC_HOST_CALL dateProtoFuncGetMinutes(ExecState*); -static JSValue JSC_HOST_CALL dateProtoFuncGetMonth(ExecState*); -static JSValue JSC_HOST_CALL dateProtoFuncGetSeconds(ExecState*); -static JSValue JSC_HOST_CALL dateProtoFuncGetTime(ExecState*); -static JSValue JSC_HOST_CALL dateProtoFuncGetTimezoneOffset(ExecState*); -static JSValue JSC_HOST_CALL dateProtoFuncGetUTCDate(ExecState*); -static JSValue JSC_HOST_CALL dateProtoFuncGetUTCDay(ExecState*); -static JSValue JSC_HOST_CALL dateProtoFuncGetUTCFullYear(ExecState*); -static JSValue JSC_HOST_CALL dateProtoFuncGetUTCHours(ExecState*); -static JSValue JSC_HOST_CALL dateProtoFuncGetUTCMilliseconds(ExecState*); -static JSValue JSC_HOST_CALL dateProtoFuncGetUTCMinutes(ExecState*); -static JSValue JSC_HOST_CALL dateProtoFuncGetUTCMonth(ExecState*); -static JSValue JSC_HOST_CALL dateProtoFuncGetUTCSeconds(ExecState*); -static JSValue JSC_HOST_CALL dateProtoFuncGetYear(ExecState*); -static JSValue JSC_HOST_CALL dateProtoFuncSetDate(ExecState*); -static JSValue JSC_HOST_CALL dateProtoFuncSetFullYear(ExecState*); -static JSValue JSC_HOST_CALL dateProtoFuncSetHours(ExecState*); -static JSValue JSC_HOST_CALL dateProtoFuncSetMilliSeconds(ExecState*); -static JSValue JSC_HOST_CALL dateProtoFuncSetMinutes(ExecState*); -static JSValue JSC_HOST_CALL dateProtoFuncSetMonth(ExecState*); -static JSValue JSC_HOST_CALL dateProtoFuncSetSeconds(ExecState*); -static JSValue JSC_HOST_CALL dateProtoFuncSetTime(ExecState*); -static JSValue JSC_HOST_CALL dateProtoFuncSetUTCDate(ExecState*); -static JSValue JSC_HOST_CALL dateProtoFuncSetUTCFullYear(ExecState*); -static JSValue JSC_HOST_CALL dateProtoFuncSetUTCHours(ExecState*); -static JSValue JSC_HOST_CALL dateProtoFuncSetUTCMilliseconds(ExecState*); -static JSValue JSC_HOST_CALL dateProtoFuncSetUTCMinutes(ExecState*); -static JSValue JSC_HOST_CALL dateProtoFuncSetUTCMonth(ExecState*); -static JSValue JSC_HOST_CALL dateProtoFuncSetUTCSeconds(ExecState*); -static JSValue JSC_HOST_CALL dateProtoFuncSetYear(ExecState*); -static JSValue JSC_HOST_CALL dateProtoFuncToDateString(ExecState*); -static JSValue JSC_HOST_CALL dateProtoFuncToGMTString(ExecState*); -static JSValue JSC_HOST_CALL dateProtoFuncToLocaleDateString(ExecState*); -static JSValue JSC_HOST_CALL dateProtoFuncToLocaleString(ExecState*); -static JSValue JSC_HOST_CALL dateProtoFuncToLocaleTimeString(ExecState*); -static JSValue JSC_HOST_CALL dateProtoFuncToString(ExecState*); -static JSValue JSC_HOST_CALL dateProtoFuncToTimeString(ExecState*); -static JSValue JSC_HOST_CALL dateProtoFuncToUTCString(ExecState*); -static JSValue JSC_HOST_CALL dateProtoFuncToISOString(ExecState*); -static JSValue JSC_HOST_CALL dateProtoFuncToJSON(ExecState*); +static EncodedJSValue JSC_HOST_CALL dateProtoFuncGetDate(ExecState*); +static EncodedJSValue JSC_HOST_CALL dateProtoFuncGetDay(ExecState*); +static EncodedJSValue JSC_HOST_CALL dateProtoFuncGetFullYear(ExecState*); +static EncodedJSValue JSC_HOST_CALL dateProtoFuncGetHours(ExecState*); +static EncodedJSValue JSC_HOST_CALL dateProtoFuncGetMilliSeconds(ExecState*); +static EncodedJSValue JSC_HOST_CALL dateProtoFuncGetMinutes(ExecState*); +static EncodedJSValue JSC_HOST_CALL dateProtoFuncGetMonth(ExecState*); +static EncodedJSValue JSC_HOST_CALL dateProtoFuncGetSeconds(ExecState*); +static EncodedJSValue JSC_HOST_CALL dateProtoFuncGetTime(ExecState*); +static EncodedJSValue JSC_HOST_CALL dateProtoFuncGetTimezoneOffset(ExecState*); +static EncodedJSValue JSC_HOST_CALL dateProtoFuncGetUTCDate(ExecState*); +static EncodedJSValue JSC_HOST_CALL dateProtoFuncGetUTCDay(ExecState*); +static EncodedJSValue JSC_HOST_CALL dateProtoFuncGetUTCFullYear(ExecState*); +static EncodedJSValue JSC_HOST_CALL dateProtoFuncGetUTCHours(ExecState*); +static EncodedJSValue JSC_HOST_CALL dateProtoFuncGetUTCMilliseconds(ExecState*); +static EncodedJSValue JSC_HOST_CALL dateProtoFuncGetUTCMinutes(ExecState*); +static EncodedJSValue JSC_HOST_CALL dateProtoFuncGetUTCMonth(ExecState*); +static EncodedJSValue JSC_HOST_CALL dateProtoFuncGetUTCSeconds(ExecState*); +static EncodedJSValue JSC_HOST_CALL dateProtoFuncGetYear(ExecState*); +static EncodedJSValue JSC_HOST_CALL dateProtoFuncSetDate(ExecState*); +static EncodedJSValue JSC_HOST_CALL dateProtoFuncSetFullYear(ExecState*); +static EncodedJSValue JSC_HOST_CALL dateProtoFuncSetHours(ExecState*); +static EncodedJSValue JSC_HOST_CALL dateProtoFuncSetMilliSeconds(ExecState*); +static EncodedJSValue JSC_HOST_CALL dateProtoFuncSetMinutes(ExecState*); +static EncodedJSValue JSC_HOST_CALL dateProtoFuncSetMonth(ExecState*); +static EncodedJSValue JSC_HOST_CALL dateProtoFuncSetSeconds(ExecState*); +static EncodedJSValue JSC_HOST_CALL dateProtoFuncSetTime(ExecState*); +static EncodedJSValue JSC_HOST_CALL dateProtoFuncSetUTCDate(ExecState*); +static EncodedJSValue JSC_HOST_CALL dateProtoFuncSetUTCFullYear(ExecState*); +static EncodedJSValue JSC_HOST_CALL dateProtoFuncSetUTCHours(ExecState*); +static EncodedJSValue JSC_HOST_CALL dateProtoFuncSetUTCMilliseconds(ExecState*); +static EncodedJSValue JSC_HOST_CALL dateProtoFuncSetUTCMinutes(ExecState*); +static EncodedJSValue JSC_HOST_CALL dateProtoFuncSetUTCMonth(ExecState*); +static EncodedJSValue JSC_HOST_CALL dateProtoFuncSetUTCSeconds(ExecState*); +static EncodedJSValue JSC_HOST_CALL dateProtoFuncSetYear(ExecState*); +static EncodedJSValue JSC_HOST_CALL dateProtoFuncToDateString(ExecState*); +static EncodedJSValue JSC_HOST_CALL dateProtoFuncToGMTString(ExecState*); +static EncodedJSValue JSC_HOST_CALL dateProtoFuncToLocaleDateString(ExecState*); +static EncodedJSValue JSC_HOST_CALL dateProtoFuncToLocaleString(ExecState*); +static EncodedJSValue JSC_HOST_CALL dateProtoFuncToLocaleTimeString(ExecState*); +static EncodedJSValue JSC_HOST_CALL dateProtoFuncToString(ExecState*); +static EncodedJSValue JSC_HOST_CALL dateProtoFuncToTimeString(ExecState*); +static EncodedJSValue JSC_HOST_CALL dateProtoFuncToUTCString(ExecState*); +static EncodedJSValue JSC_HOST_CALL dateProtoFuncToISOString(ExecState*); +static EncodedJSValue JSC_HOST_CALL dateProtoFuncToJSON(ExecState*); } @@ -437,411 +437,411 @@ bool DatePrototype::getOwnPropertyDescriptor(ExecState* exec, const Identifier& // Functions -JSValue JSC_HOST_CALL dateProtoFuncToString(ExecState* exec) +EncodedJSValue JSC_HOST_CALL dateProtoFuncToString(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); if (!thisValue.inherits(&DateInstance::info)) - return throwError(exec, TypeError); + return throwVMTypeError(exec); DateInstance* thisDateObj = asDateInstance(thisValue); const GregorianDateTime* gregorianDateTime = thisDateObj->gregorianDateTime(exec); if (!gregorianDateTime) - return jsNontrivialString(exec, "Invalid Date"); + return JSValue::encode(jsNontrivialString(exec, "Invalid Date")); DateConversionBuffer date; DateConversionBuffer time; formatDate(*gregorianDateTime, date); formatTime(*gregorianDateTime, time); - return jsMakeNontrivialString(exec, date, " ", time); + return JSValue::encode(jsMakeNontrivialString(exec, date, " ", time)); } -JSValue JSC_HOST_CALL dateProtoFuncToUTCString(ExecState* exec) +EncodedJSValue JSC_HOST_CALL dateProtoFuncToUTCString(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); if (!thisValue.inherits(&DateInstance::info)) - return throwError(exec, TypeError); + return throwVMTypeError(exec); DateInstance* thisDateObj = asDateInstance(thisValue); const GregorianDateTime* gregorianDateTime = thisDateObj->gregorianDateTimeUTC(exec); if (!gregorianDateTime) - return jsNontrivialString(exec, "Invalid Date"); + return JSValue::encode(jsNontrivialString(exec, "Invalid Date")); DateConversionBuffer date; DateConversionBuffer time; formatDateUTCVariant(*gregorianDateTime, date); formatTimeUTC(*gregorianDateTime, time); - return jsMakeNontrivialString(exec, date, " ", time); + return JSValue::encode(jsMakeNontrivialString(exec, date, " ", time)); } -JSValue JSC_HOST_CALL dateProtoFuncToISOString(ExecState* exec) +EncodedJSValue JSC_HOST_CALL dateProtoFuncToISOString(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); if (!thisValue.inherits(&DateInstance::info)) - return throwError(exec, TypeError); + return throwVMTypeError(exec); DateInstance* thisDateObj = asDateInstance(thisValue); const GregorianDateTime* gregorianDateTime = thisDateObj->gregorianDateTimeUTC(exec); if (!gregorianDateTime) - return jsNontrivialString(exec, "Invalid Date"); + return JSValue::encode(jsNontrivialString(exec, "Invalid Date")); // Maximum amount of space we need in buffer: 6 (max. digits in year) + 2 * 5 (2 characters each for month, day, hour, minute, second) + 4 (. + 3 digits for milliseconds) // 6 for formatting and one for null termination = 27. We add one extra character to allow us to force null termination. char buffer[28]; snprintf(buffer, sizeof(buffer) - 1, "%04d-%02d-%02dT%02d:%02d:%02d.%03dZ", 1900 + gregorianDateTime->year, gregorianDateTime->month + 1, gregorianDateTime->monthDay, gregorianDateTime->hour, gregorianDateTime->minute, gregorianDateTime->second, static_cast<int>(fmod(thisDateObj->internalNumber(), 1000))); buffer[sizeof(buffer) - 1] = 0; - return jsNontrivialString(exec, buffer); + return JSValue::encode(jsNontrivialString(exec, buffer)); } -JSValue JSC_HOST_CALL dateProtoFuncToDateString(ExecState* exec) +EncodedJSValue JSC_HOST_CALL dateProtoFuncToDateString(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); if (!thisValue.inherits(&DateInstance::info)) - return throwError(exec, TypeError); + return throwVMTypeError(exec); DateInstance* thisDateObj = asDateInstance(thisValue); const GregorianDateTime* gregorianDateTime = thisDateObj->gregorianDateTime(exec); if (!gregorianDateTime) - return jsNontrivialString(exec, "Invalid Date"); + return JSValue::encode(jsNontrivialString(exec, "Invalid Date")); DateConversionBuffer date; formatDate(*gregorianDateTime, date); - return jsNontrivialString(exec, date); + return JSValue::encode(jsNontrivialString(exec, date)); } -JSValue JSC_HOST_CALL dateProtoFuncToTimeString(ExecState* exec) +EncodedJSValue JSC_HOST_CALL dateProtoFuncToTimeString(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); if (!thisValue.inherits(&DateInstance::info)) - return throwError(exec, TypeError); + return throwVMTypeError(exec); DateInstance* thisDateObj = asDateInstance(thisValue); const GregorianDateTime* gregorianDateTime = thisDateObj->gregorianDateTime(exec); if (!gregorianDateTime) - return jsNontrivialString(exec, "Invalid Date"); + return JSValue::encode(jsNontrivialString(exec, "Invalid Date")); DateConversionBuffer time; formatTime(*gregorianDateTime, time); - return jsNontrivialString(exec, time); + return JSValue::encode(jsNontrivialString(exec, time)); } -JSValue JSC_HOST_CALL dateProtoFuncToLocaleString(ExecState* exec) +EncodedJSValue JSC_HOST_CALL dateProtoFuncToLocaleString(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); if (!thisValue.inherits(&DateInstance::info)) - return throwError(exec, TypeError); + return throwVMTypeError(exec); DateInstance* thisDateObj = asDateInstance(thisValue); - return formatLocaleDate(exec, thisDateObj, thisDateObj->internalNumber(), LocaleDateAndTime); + return JSValue::encode(formatLocaleDate(exec, thisDateObj, thisDateObj->internalNumber(), LocaleDateAndTime)); } -JSValue JSC_HOST_CALL dateProtoFuncToLocaleDateString(ExecState* exec) +EncodedJSValue JSC_HOST_CALL dateProtoFuncToLocaleDateString(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); if (!thisValue.inherits(&DateInstance::info)) - return throwError(exec, TypeError); + return throwVMTypeError(exec); DateInstance* thisDateObj = asDateInstance(thisValue); - return formatLocaleDate(exec, thisDateObj, thisDateObj->internalNumber(), LocaleDate); + return JSValue::encode(formatLocaleDate(exec, thisDateObj, thisDateObj->internalNumber(), LocaleDate)); } -JSValue JSC_HOST_CALL dateProtoFuncToLocaleTimeString(ExecState* exec) +EncodedJSValue JSC_HOST_CALL dateProtoFuncToLocaleTimeString(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); if (!thisValue.inherits(&DateInstance::info)) - return throwError(exec, TypeError); + return throwVMTypeError(exec); DateInstance* thisDateObj = asDateInstance(thisValue); - return formatLocaleDate(exec, thisDateObj, thisDateObj->internalNumber(), LocaleTime); + return JSValue::encode(formatLocaleDate(exec, thisDateObj, thisDateObj->internalNumber(), LocaleTime)); } -JSValue JSC_HOST_CALL dateProtoFuncGetTime(ExecState* exec) +EncodedJSValue JSC_HOST_CALL dateProtoFuncGetTime(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); if (!thisValue.inherits(&DateInstance::info)) - return throwError(exec, TypeError); + return throwVMTypeError(exec); - return asDateInstance(thisValue)->internalValue(); + return JSValue::encode(asDateInstance(thisValue)->internalValue()); } -JSValue JSC_HOST_CALL dateProtoFuncGetFullYear(ExecState* exec) +EncodedJSValue JSC_HOST_CALL dateProtoFuncGetFullYear(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); if (!thisValue.inherits(&DateInstance::info)) - return throwError(exec, TypeError); + return throwVMTypeError(exec); DateInstance* thisDateObj = asDateInstance(thisValue); const GregorianDateTime* gregorianDateTime = thisDateObj->gregorianDateTime(exec); if (!gregorianDateTime) - return jsNaN(exec); - return jsNumber(exec, 1900 + gregorianDateTime->year); + return JSValue::encode(jsNaN(exec)); + return JSValue::encode(jsNumber(exec, 1900 + gregorianDateTime->year)); } -JSValue JSC_HOST_CALL dateProtoFuncGetUTCFullYear(ExecState* exec) +EncodedJSValue JSC_HOST_CALL dateProtoFuncGetUTCFullYear(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); if (!thisValue.inherits(&DateInstance::info)) - return throwError(exec, TypeError); + return throwVMTypeError(exec); DateInstance* thisDateObj = asDateInstance(thisValue); const GregorianDateTime* gregorianDateTime = thisDateObj->gregorianDateTimeUTC(exec); if (!gregorianDateTime) - return jsNaN(exec); - return jsNumber(exec, 1900 + gregorianDateTime->year); + return JSValue::encode(jsNaN(exec)); + return JSValue::encode(jsNumber(exec, 1900 + gregorianDateTime->year)); } -JSValue JSC_HOST_CALL dateProtoFuncToGMTString(ExecState* exec) +EncodedJSValue JSC_HOST_CALL dateProtoFuncToGMTString(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); if (!thisValue.inherits(&DateInstance::info)) - return throwError(exec, TypeError); + return throwVMTypeError(exec); DateInstance* thisDateObj = asDateInstance(thisValue); const GregorianDateTime* gregorianDateTime = thisDateObj->gregorianDateTimeUTC(exec); if (!gregorianDateTime) - return jsNontrivialString(exec, "Invalid Date"); + return JSValue::encode(jsNontrivialString(exec, "Invalid Date")); DateConversionBuffer date; DateConversionBuffer time; formatDateUTCVariant(*gregorianDateTime, date); formatTimeUTC(*gregorianDateTime, time); - return jsMakeNontrivialString(exec, date, " ", time); + return JSValue::encode(jsMakeNontrivialString(exec, date, " ", time)); } -JSValue JSC_HOST_CALL dateProtoFuncGetMonth(ExecState* exec) +EncodedJSValue JSC_HOST_CALL dateProtoFuncGetMonth(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); if (!thisValue.inherits(&DateInstance::info)) - return throwError(exec, TypeError); + return throwVMTypeError(exec); DateInstance* thisDateObj = asDateInstance(thisValue); const GregorianDateTime* gregorianDateTime = thisDateObj->gregorianDateTime(exec); if (!gregorianDateTime) - return jsNaN(exec); - return jsNumber(exec, gregorianDateTime->month); + return JSValue::encode(jsNaN(exec)); + return JSValue::encode(jsNumber(exec, gregorianDateTime->month)); } -JSValue JSC_HOST_CALL dateProtoFuncGetUTCMonth(ExecState* exec) +EncodedJSValue JSC_HOST_CALL dateProtoFuncGetUTCMonth(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); if (!thisValue.inherits(&DateInstance::info)) - return throwError(exec, TypeError); + return throwVMTypeError(exec); DateInstance* thisDateObj = asDateInstance(thisValue); const GregorianDateTime* gregorianDateTime = thisDateObj->gregorianDateTimeUTC(exec); if (!gregorianDateTime) - return jsNaN(exec); - return jsNumber(exec, gregorianDateTime->month); + return JSValue::encode(jsNaN(exec)); + return JSValue::encode(jsNumber(exec, gregorianDateTime->month)); } -JSValue JSC_HOST_CALL dateProtoFuncGetDate(ExecState* exec) +EncodedJSValue JSC_HOST_CALL dateProtoFuncGetDate(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); if (!thisValue.inherits(&DateInstance::info)) - return throwError(exec, TypeError); + return throwVMTypeError(exec); DateInstance* thisDateObj = asDateInstance(thisValue); const GregorianDateTime* gregorianDateTime = thisDateObj->gregorianDateTime(exec); if (!gregorianDateTime) - return jsNaN(exec); - return jsNumber(exec, gregorianDateTime->monthDay); + return JSValue::encode(jsNaN(exec)); + return JSValue::encode(jsNumber(exec, gregorianDateTime->monthDay)); } -JSValue JSC_HOST_CALL dateProtoFuncGetUTCDate(ExecState* exec) +EncodedJSValue JSC_HOST_CALL dateProtoFuncGetUTCDate(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); if (!thisValue.inherits(&DateInstance::info)) - return throwError(exec, TypeError); + return throwVMTypeError(exec); DateInstance* thisDateObj = asDateInstance(thisValue); const GregorianDateTime* gregorianDateTime = thisDateObj->gregorianDateTimeUTC(exec); if (!gregorianDateTime) - return jsNaN(exec); - return jsNumber(exec, gregorianDateTime->monthDay); + return JSValue::encode(jsNaN(exec)); + return JSValue::encode(jsNumber(exec, gregorianDateTime->monthDay)); } -JSValue JSC_HOST_CALL dateProtoFuncGetDay(ExecState* exec) +EncodedJSValue JSC_HOST_CALL dateProtoFuncGetDay(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); if (!thisValue.inherits(&DateInstance::info)) - return throwError(exec, TypeError); + return throwVMTypeError(exec); DateInstance* thisDateObj = asDateInstance(thisValue); const GregorianDateTime* gregorianDateTime = thisDateObj->gregorianDateTime(exec); if (!gregorianDateTime) - return jsNaN(exec); - return jsNumber(exec, gregorianDateTime->weekDay); + return JSValue::encode(jsNaN(exec)); + return JSValue::encode(jsNumber(exec, gregorianDateTime->weekDay)); } -JSValue JSC_HOST_CALL dateProtoFuncGetUTCDay(ExecState* exec) +EncodedJSValue JSC_HOST_CALL dateProtoFuncGetUTCDay(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); if (!thisValue.inherits(&DateInstance::info)) - return throwError(exec, TypeError); + return throwVMTypeError(exec); DateInstance* thisDateObj = asDateInstance(thisValue); const GregorianDateTime* gregorianDateTime = thisDateObj->gregorianDateTimeUTC(exec); if (!gregorianDateTime) - return jsNaN(exec); - return jsNumber(exec, gregorianDateTime->weekDay); + return JSValue::encode(jsNaN(exec)); + return JSValue::encode(jsNumber(exec, gregorianDateTime->weekDay)); } -JSValue JSC_HOST_CALL dateProtoFuncGetHours(ExecState* exec) +EncodedJSValue JSC_HOST_CALL dateProtoFuncGetHours(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); if (!thisValue.inherits(&DateInstance::info)) - return throwError(exec, TypeError); + return throwVMTypeError(exec); DateInstance* thisDateObj = asDateInstance(thisValue); const GregorianDateTime* gregorianDateTime = thisDateObj->gregorianDateTime(exec); if (!gregorianDateTime) - return jsNaN(exec); - return jsNumber(exec, gregorianDateTime->hour); + return JSValue::encode(jsNaN(exec)); + return JSValue::encode(jsNumber(exec, gregorianDateTime->hour)); } -JSValue JSC_HOST_CALL dateProtoFuncGetUTCHours(ExecState* exec) +EncodedJSValue JSC_HOST_CALL dateProtoFuncGetUTCHours(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); if (!thisValue.inherits(&DateInstance::info)) - return throwError(exec, TypeError); + return throwVMTypeError(exec); DateInstance* thisDateObj = asDateInstance(thisValue); const GregorianDateTime* gregorianDateTime = thisDateObj->gregorianDateTimeUTC(exec); if (!gregorianDateTime) - return jsNaN(exec); - return jsNumber(exec, gregorianDateTime->hour); + return JSValue::encode(jsNaN(exec)); + return JSValue::encode(jsNumber(exec, gregorianDateTime->hour)); } -JSValue JSC_HOST_CALL dateProtoFuncGetMinutes(ExecState* exec) +EncodedJSValue JSC_HOST_CALL dateProtoFuncGetMinutes(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); if (!thisValue.inherits(&DateInstance::info)) - return throwError(exec, TypeError); + return throwVMTypeError(exec); DateInstance* thisDateObj = asDateInstance(thisValue); const GregorianDateTime* gregorianDateTime = thisDateObj->gregorianDateTime(exec); if (!gregorianDateTime) - return jsNaN(exec); - return jsNumber(exec, gregorianDateTime->minute); + return JSValue::encode(jsNaN(exec)); + return JSValue::encode(jsNumber(exec, gregorianDateTime->minute)); } -JSValue JSC_HOST_CALL dateProtoFuncGetUTCMinutes(ExecState* exec) +EncodedJSValue JSC_HOST_CALL dateProtoFuncGetUTCMinutes(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); if (!thisValue.inherits(&DateInstance::info)) - return throwError(exec, TypeError); + return throwVMTypeError(exec); DateInstance* thisDateObj = asDateInstance(thisValue); const GregorianDateTime* gregorianDateTime = thisDateObj->gregorianDateTimeUTC(exec); if (!gregorianDateTime) - return jsNaN(exec); - return jsNumber(exec, gregorianDateTime->minute); + return JSValue::encode(jsNaN(exec)); + return JSValue::encode(jsNumber(exec, gregorianDateTime->minute)); } -JSValue JSC_HOST_CALL dateProtoFuncGetSeconds(ExecState* exec) +EncodedJSValue JSC_HOST_CALL dateProtoFuncGetSeconds(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); if (!thisValue.inherits(&DateInstance::info)) - return throwError(exec, TypeError); + return throwVMTypeError(exec); DateInstance* thisDateObj = asDateInstance(thisValue); const GregorianDateTime* gregorianDateTime = thisDateObj->gregorianDateTime(exec); if (!gregorianDateTime) - return jsNaN(exec); - return jsNumber(exec, gregorianDateTime->second); + return JSValue::encode(jsNaN(exec)); + return JSValue::encode(jsNumber(exec, gregorianDateTime->second)); } -JSValue JSC_HOST_CALL dateProtoFuncGetUTCSeconds(ExecState* exec) +EncodedJSValue JSC_HOST_CALL dateProtoFuncGetUTCSeconds(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); if (!thisValue.inherits(&DateInstance::info)) - return throwError(exec, TypeError); + return throwVMTypeError(exec); DateInstance* thisDateObj = asDateInstance(thisValue); const GregorianDateTime* gregorianDateTime = thisDateObj->gregorianDateTimeUTC(exec); if (!gregorianDateTime) - return jsNaN(exec); - return jsNumber(exec, gregorianDateTime->second); + return JSValue::encode(jsNaN(exec)); + return JSValue::encode(jsNumber(exec, gregorianDateTime->second)); } -JSValue JSC_HOST_CALL dateProtoFuncGetMilliSeconds(ExecState* exec) +EncodedJSValue JSC_HOST_CALL dateProtoFuncGetMilliSeconds(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); if (!thisValue.inherits(&DateInstance::info)) - return throwError(exec, TypeError); + return throwVMTypeError(exec); DateInstance* thisDateObj = asDateInstance(thisValue); double milli = thisDateObj->internalNumber(); if (isnan(milli)) - return jsNaN(exec); + return JSValue::encode(jsNaN(exec)); double secs = floor(milli / msPerSecond); double ms = milli - secs * msPerSecond; - return jsNumber(exec, ms); + return JSValue::encode(jsNumber(exec, ms)); } -JSValue JSC_HOST_CALL dateProtoFuncGetUTCMilliseconds(ExecState* exec) +EncodedJSValue JSC_HOST_CALL dateProtoFuncGetUTCMilliseconds(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); if (!thisValue.inherits(&DateInstance::info)) - return throwError(exec, TypeError); + return throwVMTypeError(exec); DateInstance* thisDateObj = asDateInstance(thisValue); double milli = thisDateObj->internalNumber(); if (isnan(milli)) - return jsNaN(exec); + return JSValue::encode(jsNaN(exec)); double secs = floor(milli / msPerSecond); double ms = milli - secs * msPerSecond; - return jsNumber(exec, ms); + return JSValue::encode(jsNumber(exec, ms)); } -JSValue JSC_HOST_CALL dateProtoFuncGetTimezoneOffset(ExecState* exec) +EncodedJSValue JSC_HOST_CALL dateProtoFuncGetTimezoneOffset(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); if (!thisValue.inherits(&DateInstance::info)) - return throwError(exec, TypeError); + return throwVMTypeError(exec); DateInstance* thisDateObj = asDateInstance(thisValue); const GregorianDateTime* gregorianDateTime = thisDateObj->gregorianDateTime(exec); if (!gregorianDateTime) - return jsNaN(exec); - return jsNumber(exec, -gregorianDateTime->utcOffset / minutesPerHour); + return JSValue::encode(jsNaN(exec)); + return JSValue::encode(jsNumber(exec, -gregorianDateTime->utcOffset / minutesPerHour)); } -JSValue JSC_HOST_CALL dateProtoFuncSetTime(ExecState* exec) +EncodedJSValue JSC_HOST_CALL dateProtoFuncSetTime(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); if (!thisValue.inherits(&DateInstance::info)) - return throwError(exec, TypeError); + return throwVMTypeError(exec); DateInstance* thisDateObj = asDateInstance(thisValue); double milli = timeClip(exec->argument(0).toNumber(exec)); JSValue result = jsNumber(exec, milli); thisDateObj->setInternalValue(result); - return result; + return JSValue::encode(result); } -static JSValue setNewValueFromTimeArgs(ExecState* exec, int numArgsToUse, bool inputIsUTC) +static EncodedJSValue setNewValueFromTimeArgs(ExecState* exec, int numArgsToUse, bool inputIsUTC) { JSValue thisValue = exec->hostThisValue(); if (!thisValue.inherits(&DateInstance::info)) - return throwError(exec, TypeError); + return throwVMTypeError(exec); DateInstance* thisDateObj = asDateInstance(thisValue); double milli = thisDateObj->internalNumber(); @@ -849,7 +849,7 @@ static JSValue setNewValueFromTimeArgs(ExecState* exec, int numArgsToUse, bool i if (!exec->argumentCount() || isnan(milli)) { JSValue result = jsNaN(exec); thisDateObj->setInternalValue(result); - return result; + return JSValue::encode(result); } double secs = floor(milli / msPerSecond); @@ -859,32 +859,32 @@ static JSValue setNewValueFromTimeArgs(ExecState* exec, int numArgsToUse, bool i ? thisDateObj->gregorianDateTimeUTC(exec) : thisDateObj->gregorianDateTime(exec); if (!other) - return jsNaN(exec); + return JSValue::encode(jsNaN(exec)); GregorianDateTime gregorianDateTime; gregorianDateTime.copyFrom(*other); if (!fillStructuresUsingTimeArgs(exec, numArgsToUse, &ms, &gregorianDateTime)) { JSValue result = jsNaN(exec); thisDateObj->setInternalValue(result); - return result; + return JSValue::encode(result); } JSValue result = jsNumber(exec, gregorianDateTimeToMS(exec, gregorianDateTime, ms, inputIsUTC)); thisDateObj->setInternalValue(result); - return result; + return JSValue::encode(result); } -static JSValue setNewValueFromDateArgs(ExecState* exec, int numArgsToUse, bool inputIsUTC) +static EncodedJSValue setNewValueFromDateArgs(ExecState* exec, int numArgsToUse, bool inputIsUTC) { JSValue thisValue = exec->hostThisValue(); if (!thisValue.inherits(&DateInstance::info)) - return throwError(exec, TypeError); + return throwVMTypeError(exec); DateInstance* thisDateObj = asDateInstance(thisValue); if (!exec->argumentCount()) { JSValue result = jsNaN(exec); thisDateObj->setInternalValue(result); - return result; + return JSValue::encode(result); } double milli = thisDateObj->internalNumber(); @@ -899,116 +899,116 @@ static JSValue setNewValueFromDateArgs(ExecState* exec, int numArgsToUse, bool i ? thisDateObj->gregorianDateTimeUTC(exec) : thisDateObj->gregorianDateTime(exec); if (!other) - return jsNaN(exec); + return JSValue::encode(jsNaN(exec)); gregorianDateTime.copyFrom(*other); } if (!fillStructuresUsingDateArgs(exec, numArgsToUse, &ms, &gregorianDateTime)) { JSValue result = jsNaN(exec); thisDateObj->setInternalValue(result); - return result; + return JSValue::encode(result); } JSValue result = jsNumber(exec, gregorianDateTimeToMS(exec, gregorianDateTime, ms, inputIsUTC)); thisDateObj->setInternalValue(result); - return result; + return JSValue::encode(result); } -JSValue JSC_HOST_CALL dateProtoFuncSetMilliSeconds(ExecState* exec) +EncodedJSValue JSC_HOST_CALL dateProtoFuncSetMilliSeconds(ExecState* exec) { const bool inputIsUTC = false; return setNewValueFromTimeArgs(exec, 1, inputIsUTC); } -JSValue JSC_HOST_CALL dateProtoFuncSetUTCMilliseconds(ExecState* exec) +EncodedJSValue JSC_HOST_CALL dateProtoFuncSetUTCMilliseconds(ExecState* exec) { const bool inputIsUTC = true; return setNewValueFromTimeArgs(exec, 1, inputIsUTC); } -JSValue JSC_HOST_CALL dateProtoFuncSetSeconds(ExecState* exec) +EncodedJSValue JSC_HOST_CALL dateProtoFuncSetSeconds(ExecState* exec) { const bool inputIsUTC = false; return setNewValueFromTimeArgs(exec, 2, inputIsUTC); } -JSValue JSC_HOST_CALL dateProtoFuncSetUTCSeconds(ExecState* exec) +EncodedJSValue JSC_HOST_CALL dateProtoFuncSetUTCSeconds(ExecState* exec) { const bool inputIsUTC = true; return setNewValueFromTimeArgs(exec, 2, inputIsUTC); } -JSValue JSC_HOST_CALL dateProtoFuncSetMinutes(ExecState* exec) +EncodedJSValue JSC_HOST_CALL dateProtoFuncSetMinutes(ExecState* exec) { const bool inputIsUTC = false; return setNewValueFromTimeArgs(exec, 3, inputIsUTC); } -JSValue JSC_HOST_CALL dateProtoFuncSetUTCMinutes(ExecState* exec) +EncodedJSValue JSC_HOST_CALL dateProtoFuncSetUTCMinutes(ExecState* exec) { const bool inputIsUTC = true; return setNewValueFromTimeArgs(exec, 3, inputIsUTC); } -JSValue JSC_HOST_CALL dateProtoFuncSetHours(ExecState* exec) +EncodedJSValue JSC_HOST_CALL dateProtoFuncSetHours(ExecState* exec) { const bool inputIsUTC = false; return setNewValueFromTimeArgs(exec, 4, inputIsUTC); } -JSValue JSC_HOST_CALL dateProtoFuncSetUTCHours(ExecState* exec) +EncodedJSValue JSC_HOST_CALL dateProtoFuncSetUTCHours(ExecState* exec) { const bool inputIsUTC = true; return setNewValueFromTimeArgs(exec, 4, inputIsUTC); } -JSValue JSC_HOST_CALL dateProtoFuncSetDate(ExecState* exec) +EncodedJSValue JSC_HOST_CALL dateProtoFuncSetDate(ExecState* exec) { const bool inputIsUTC = false; return setNewValueFromDateArgs(exec, 1, inputIsUTC); } -JSValue JSC_HOST_CALL dateProtoFuncSetUTCDate(ExecState* exec) +EncodedJSValue JSC_HOST_CALL dateProtoFuncSetUTCDate(ExecState* exec) { const bool inputIsUTC = true; return setNewValueFromDateArgs(exec, 1, inputIsUTC); } -JSValue JSC_HOST_CALL dateProtoFuncSetMonth(ExecState* exec) +EncodedJSValue JSC_HOST_CALL dateProtoFuncSetMonth(ExecState* exec) { const bool inputIsUTC = false; return setNewValueFromDateArgs(exec, 2, inputIsUTC); } -JSValue JSC_HOST_CALL dateProtoFuncSetUTCMonth(ExecState* exec) +EncodedJSValue JSC_HOST_CALL dateProtoFuncSetUTCMonth(ExecState* exec) { const bool inputIsUTC = true; return setNewValueFromDateArgs(exec, 2, inputIsUTC); } -JSValue JSC_HOST_CALL dateProtoFuncSetFullYear(ExecState* exec) +EncodedJSValue JSC_HOST_CALL dateProtoFuncSetFullYear(ExecState* exec) { const bool inputIsUTC = false; return setNewValueFromDateArgs(exec, 3, inputIsUTC); } -JSValue JSC_HOST_CALL dateProtoFuncSetUTCFullYear(ExecState* exec) +EncodedJSValue JSC_HOST_CALL dateProtoFuncSetUTCFullYear(ExecState* exec) { const bool inputIsUTC = true; return setNewValueFromDateArgs(exec, 3, inputIsUTC); } -JSValue JSC_HOST_CALL dateProtoFuncSetYear(ExecState* exec) +EncodedJSValue JSC_HOST_CALL dateProtoFuncSetYear(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); if (!thisValue.inherits(&DateInstance::info)) - return throwError(exec, TypeError); + return throwVMTypeError(exec); DateInstance* thisDateObj = asDateInstance(thisValue); if (!exec->argumentCount()) { JSValue result = jsNaN(exec); thisDateObj->setInternalValue(result); - return result; + return JSValue::encode(result); } double milli = thisDateObj->internalNumber(); @@ -1031,53 +1031,53 @@ JSValue JSC_HOST_CALL dateProtoFuncSetYear(ExecState* exec) if (!ok) { JSValue result = jsNaN(exec); thisDateObj->setInternalValue(result); - return result; + return JSValue::encode(result); } gregorianDateTime.year = (year > 99 || year < 0) ? year - 1900 : year; JSValue result = jsNumber(exec, gregorianDateTimeToMS(exec, gregorianDateTime, ms, false)); thisDateObj->setInternalValue(result); - return result; + return JSValue::encode(result); } -JSValue JSC_HOST_CALL dateProtoFuncGetYear(ExecState* exec) +EncodedJSValue JSC_HOST_CALL dateProtoFuncGetYear(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); if (!thisValue.inherits(&DateInstance::info)) - return throwError(exec, TypeError); + return throwVMTypeError(exec); DateInstance* thisDateObj = asDateInstance(thisValue); const GregorianDateTime* gregorianDateTime = thisDateObj->gregorianDateTime(exec); if (!gregorianDateTime) - return jsNaN(exec); + return JSValue::encode(jsNaN(exec)); // NOTE: IE returns the full year even in getYear. - return jsNumber(exec, gregorianDateTime->year); + return JSValue::encode(jsNumber(exec, gregorianDateTime->year)); } -JSValue JSC_HOST_CALL dateProtoFuncToJSON(ExecState* exec) +EncodedJSValue JSC_HOST_CALL dateProtoFuncToJSON(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); JSObject* object = thisValue.toThisObject(exec); if (exec->hadException()) - return jsNull(); + return JSValue::encode(jsNull()); JSValue toISOValue = object->get(exec, exec->globalData().propertyNames->toISOString); if (exec->hadException()) - return jsNull(); + return JSValue::encode(jsNull()); CallData callData; - CallType callType = toISOValue.getCallData(callData); + CallType callType = getCallData(toISOValue, callData); if (callType == CallTypeNone) - return throwError(exec, TypeError, "toISOString is not a function"); + return throwVMError(exec, createTypeError(exec, "toISOString is not a function")); JSValue result = call(exec, asObject(toISOValue), callType, callData, object, exec->emptyList()); if (exec->hadException()) - return jsNull(); + return JSValue::encode(jsNull()); if (result.isObject()) - return throwError(exec, TypeError, "toISOString did not return a primitive value"); - return result; + return throwVMError(exec, createTypeError(exec, "toISOString did not return a primitive value")); + return JSValue::encode(result); } } // namespace JSC diff --git a/JavaScriptCore/runtime/Error.cpp b/JavaScriptCore/runtime/Error.cpp index 69464b7..a2be473 100644 --- a/JavaScriptCore/runtime/Error.cpp +++ b/JavaScriptCore/runtime/Error.cpp @@ -31,104 +31,168 @@ #include "JSObject.h" #include "JSString.h" #include "NativeErrorConstructor.h" +#include "SourceCode.h" namespace JSC { -const char* expressionBeginOffsetPropertyName = "expressionBeginOffset"; -const char* expressionCaretOffsetPropertyName = "expressionCaretOffset"; -const char* expressionEndOffsetPropertyName = "expressionEndOffset"; - -JSObject* Error::create(ExecState* exec, ErrorType type, const UString& message, int lineNumber, intptr_t sourceID, const UString& sourceURL) -{ - JSObject* constructor; - const char* name; - switch (type) { - case EvalError: - constructor = exec->lexicalGlobalObject()->evalErrorConstructor(); - name = "Evaluation error"; - break; - case RangeError: - constructor = exec->lexicalGlobalObject()->rangeErrorConstructor(); - name = "Range error"; - break; - case ReferenceError: - constructor = exec->lexicalGlobalObject()->referenceErrorConstructor(); - name = "Reference error"; - break; - case SyntaxError: - constructor = exec->lexicalGlobalObject()->syntaxErrorConstructor(); - name = "Syntax error"; - break; - case TypeError: - constructor = exec->lexicalGlobalObject()->typeErrorConstructor(); - name = "Type error"; - break; - case URIError: - constructor = exec->lexicalGlobalObject()->URIErrorConstructor(); - name = "URI error"; - break; - default: - constructor = exec->lexicalGlobalObject()->errorConstructor(); - name = "Error"; - break; - } - - MarkedArgumentBuffer args; - if (message.isEmpty()) - args.append(jsString(exec, name)); - else - args.append(jsString(exec, message)); - ConstructData constructData; - ConstructType constructType = constructor->getConstructData(constructData); - JSObject* error = construct(exec, constructor, constructType, constructData, args); - - if (lineNumber != -1) - error->putWithAttributes(exec, Identifier(exec, "line"), jsNumber(exec, lineNumber), ReadOnly | DontDelete); +static const char* linePropertyName = "line"; +static const char* sourceIdPropertyName = "sourceId"; +static const char* sourceURLPropertyName = "sourceURL"; +static const char* expressionBeginOffsetPropertyName = "expressionBeginOffset"; +static const char* expressionCaretOffsetPropertyName = "expressionCaretOffset"; +static const char* expressionEndOffsetPropertyName = "expressionEndOffset"; + +JSObject* createError(JSGlobalObject* globalObject, const UString& message) +{ + ASSERT(!message.isEmpty()); + return ErrorInstance::create(globalObject->globalData(), globalObject->errorStructure(), message); +} + +JSObject* createEvalError(JSGlobalObject* globalObject, const UString& message) +{ + ASSERT(!message.isEmpty()); + return ErrorInstance::create(globalObject->globalData(), globalObject->evalErrorConstructor()->errorStructure(), message); +} + +JSObject* createRangeError(JSGlobalObject* globalObject, const UString& message) +{ + ASSERT(!message.isEmpty()); + return ErrorInstance::create(globalObject->globalData(), globalObject->rangeErrorConstructor()->errorStructure(), message); +} + +JSObject* createReferenceError(JSGlobalObject* globalObject, const UString& message) +{ + ASSERT(!message.isEmpty()); + return ErrorInstance::create(globalObject->globalData(), globalObject->referenceErrorConstructor()->errorStructure(), message); +} + +JSObject* createSyntaxError(JSGlobalObject* globalObject, const UString& message) +{ + ASSERT(!message.isEmpty()); + return ErrorInstance::create(globalObject->globalData(), globalObject->syntaxErrorConstructor()->errorStructure(), message); +} + +JSObject* createTypeError(JSGlobalObject* globalObject, const UString& message) +{ + ASSERT(!message.isEmpty()); + return ErrorInstance::create(globalObject->globalData(), globalObject->typeErrorConstructor()->errorStructure(), message); +} + +JSObject* createURIError(JSGlobalObject* globalObject, const UString& message) +{ + ASSERT(!message.isEmpty()); + return ErrorInstance::create(globalObject->globalData(), globalObject->URIErrorConstructor()->errorStructure(), message); +} + +JSObject* createError(ExecState* exec, const UString& message) +{ + return createError(exec->lexicalGlobalObject(), message); +} + +JSObject* createEvalError(ExecState* exec, const UString& message) +{ + return createEvalError(exec->lexicalGlobalObject(), message); +} + +JSObject* createRangeError(ExecState* exec, const UString& message) +{ + return createRangeError(exec->lexicalGlobalObject(), message); +} + +JSObject* createReferenceError(ExecState* exec, const UString& message) +{ + return createReferenceError(exec->lexicalGlobalObject(), message); +} + +JSObject* createSyntaxError(ExecState* exec, const UString& message) +{ + return createSyntaxError(exec->lexicalGlobalObject(), message); +} + +JSObject* createTypeError(ExecState* exec, const UString& message) +{ + return createTypeError(exec->lexicalGlobalObject(), message); +} + +JSObject* createURIError(ExecState* exec, const UString& message) +{ + return createURIError(exec->lexicalGlobalObject(), message); +} + +static void addErrorSourceInfo(JSGlobalData* globalData, JSObject* error, int line, const SourceCode& source) +{ + intptr_t sourceID = source.provider()->asID(); + const UString& sourceURL = source.provider()->url(); + + if (line != -1) + error->putWithAttributes(globalData, Identifier(globalData, linePropertyName), jsNumber(globalData, line), ReadOnly | DontDelete); if (sourceID != -1) - error->putWithAttributes(exec, Identifier(exec, "sourceId"), jsNumber(exec, sourceID), ReadOnly | DontDelete); + error->putWithAttributes(globalData, Identifier(globalData, sourceIdPropertyName), jsNumber(globalData, (double)sourceID), ReadOnly | DontDelete); if (!sourceURL.isNull()) - error->putWithAttributes(exec, Identifier(exec, "sourceURL"), jsString(exec, sourceURL), ReadOnly | DontDelete); - - return error; + error->putWithAttributes(globalData, Identifier(globalData, sourceURLPropertyName), jsString(globalData, sourceURL), ReadOnly | DontDelete); } -JSObject* Error::create(ExecState* exec, ErrorType type, const char* message) +static void addErrorDivotInfo(JSGlobalData* globalData, JSObject* error, int divotPoint, int startOffset, int endOffset, bool withCaret) { - return create(exec, type, message, -1, -1, UString()); + error->putWithAttributes(globalData, Identifier(globalData, expressionBeginOffsetPropertyName), jsNumber(globalData, divotPoint - startOffset), ReadOnly | DontDelete); + error->putWithAttributes(globalData, Identifier(globalData, expressionEndOffsetPropertyName), jsNumber(globalData, divotPoint + endOffset), ReadOnly | DontDelete); + if (withCaret) + error->putWithAttributes(globalData, Identifier(globalData, expressionCaretOffsetPropertyName), jsNumber(globalData, divotPoint), ReadOnly | DontDelete); } -JSObject* throwError(ExecState* exec, JSObject* error) +JSObject* addErrorInfo(JSGlobalData* globalData, JSObject* error, int line, const SourceCode& source) { - exec->setException(error); + addErrorSourceInfo(globalData, error, line, source); return error; } -JSObject* throwError(ExecState* exec, ErrorType type) +JSObject* addErrorInfo(JSGlobalData* globalData, JSObject* error, int line, const SourceCode& source, int divotPoint, int startOffset, int endOffset, bool withCaret) { - JSObject* error = Error::create(exec, type, UString(), -1, -1, UString()); - exec->setException(error); + addErrorSourceInfo(globalData, error, line, source); + addErrorDivotInfo(globalData, error, divotPoint, startOffset, endOffset, withCaret); return error; } -JSObject* throwError(ExecState* exec, ErrorType type, const UString& message) +JSObject* addErrorInfo(ExecState* exec, JSObject* error, int line, const SourceCode& source) { - JSObject* error = Error::create(exec, type, message, -1, -1, UString()); - exec->setException(error); - return error; + return addErrorInfo(&exec->globalData(), error, line, source); +} + +JSObject* addErrorInfo(ExecState* exec, JSObject* error, int line, const SourceCode& source, int divotPoint, int startOffset, int endOffset, bool withCaret) +{ + return addErrorInfo(&exec->globalData(), error, line, source, divotPoint, startOffset, endOffset, withCaret); +} + +bool hasErrorInfo(ExecState* exec, JSObject* error) +{ + return error->hasProperty(exec, Identifier(exec, linePropertyName)) + || error->hasProperty(exec, Identifier(exec, sourceIdPropertyName)) + || error->hasProperty(exec, Identifier(exec, sourceURLPropertyName)) + || error->hasProperty(exec, Identifier(exec, expressionBeginOffsetPropertyName)) + || error->hasProperty(exec, Identifier(exec, expressionCaretOffsetPropertyName)) + || error->hasProperty(exec, Identifier(exec, expressionEndOffsetPropertyName)); } -JSObject* throwError(ExecState* exec, ErrorType type, const char* message) +JSValue throwError(ExecState* exec, JSValue error) { - JSObject* error = Error::create(exec, type, message, -1, -1, UString()); - exec->setException(error); + exec->globalData().exception = error; return error; } -JSObject* throwError(ExecState* exec, ErrorType type, const UString& message, int line, intptr_t sourceID, const UString& sourceURL) +JSObject* throwError(ExecState* exec, JSObject* error) { - JSObject* error = Error::create(exec, type, message, line, sourceID, sourceURL); - exec->setException(error); + exec->globalData().exception = error; return error; } +JSObject* throwTypeError(ExecState* exec) +{ + return throwError(exec, createTypeError(exec, "Type error")); +} + +JSObject* throwSyntaxError(ExecState* exec) +{ + return throwError(exec, createSyntaxError(exec, "Syntax error")); +} + } // namespace JSC diff --git a/JavaScriptCore/runtime/Error.h b/JavaScriptCore/runtime/Error.h index e959cff..1a0ece5 100644 --- a/JavaScriptCore/runtime/Error.h +++ b/JavaScriptCore/runtime/Error.h @@ -23,44 +23,56 @@ #ifndef Error_h #define Error_h +#include "JSObject.h" #include <stdint.h> namespace JSC { class ExecState; + class JSGlobalData; + class JSGlobalObject; class JSObject; + class SourceCode; + class Structure; class UString; - /** - * Types of Native Errors available. For custom errors, GeneralError - * should be used. - */ - enum ErrorType { - GeneralError = 0, - EvalError = 1, - RangeError = 2, - ReferenceError = 3, - SyntaxError = 4, - TypeError = 5, - URIError = 6 - }; - - extern const char* expressionBeginOffsetPropertyName; - extern const char* expressionCaretOffsetPropertyName; - extern const char* expressionEndOffsetPropertyName; - - class Error { - public: - static JSObject* create(ExecState*, ErrorType, const UString& message, int lineNumber, intptr_t sourceID, const UString& sourceURL); - static JSObject* create(ExecState*, ErrorType, const char* message); - }; + // Methods to create a range of internal errors. + JSObject* createError(JSGlobalObject*, const UString&); + JSObject* createEvalError(JSGlobalObject*, const UString&); + JSObject* createRangeError(JSGlobalObject*, const UString&); + JSObject* createReferenceError(JSGlobalObject*, const UString&); + JSObject* createSyntaxError(JSGlobalObject*, const UString&); + JSObject* createTypeError(JSGlobalObject*, const UString&); + JSObject* createURIError(JSGlobalObject*, const UString&); + // ExecState wrappers. + JSObject* createError(ExecState*, const UString&); + JSObject* createEvalError(ExecState*, const UString&); + JSObject* createRangeError(ExecState*, const UString&); + JSObject* createReferenceError(ExecState*, const UString&); + JSObject* createSyntaxError(ExecState*, const UString&); + JSObject* createTypeError(ExecState*, const UString&); + JSObject* createURIError(ExecState*, const UString&); - JSObject* throwError(ExecState*, ErrorType, const UString& message, int lineNumber, intptr_t sourceID, const UString& sourceURL); - JSObject* throwError(ExecState*, ErrorType, const UString& message); - JSObject* throwError(ExecState*, ErrorType, const char* message); - JSObject* throwError(ExecState*, ErrorType); + // Methods to add + bool hasErrorInfo(ExecState*, JSObject* error); + JSObject* addErrorInfo(JSGlobalData*, JSObject* error, int line, const SourceCode&); + JSObject* addErrorInfo(JSGlobalData*, JSObject* error, int line, const SourceCode&, int divotPoint, int startOffset, int endOffset, bool withCaret = true); + // ExecState wrappers. + JSObject* addErrorInfo(ExecState*, JSObject* error, int line, const SourceCode&); + JSObject* addErrorInfo(ExecState*, JSObject* error, int line, const SourceCode&, int divotPoint, int startOffset, int endOffset, bool withCaret = true); + + // Methods to throw Errors. + JSValue throwError(ExecState*, JSValue); JSObject* throwError(ExecState*, JSObject*); + // Convenience wrappers, create an throw an exception with a default message. + JSObject* throwTypeError(ExecState*); + JSObject* throwSyntaxError(ExecState*); + + // Convenience wrappers, wrap result as an EncodedJSValue. + inline EncodedJSValue throwVMError(ExecState* exec, JSValue error) { return JSValue::encode(throwError(exec, error)); } + inline EncodedJSValue throwVMTypeError(ExecState* exec) { return JSValue::encode(throwTypeError(exec)); } + } // namespace JSC #endif // Error_h diff --git a/JavaScriptCore/runtime/ErrorConstructor.cpp b/JavaScriptCore/runtime/ErrorConstructor.cpp index b4b0ba2..a0874d4 100644 --- a/JavaScriptCore/runtime/ErrorConstructor.cpp +++ b/JavaScriptCore/runtime/ErrorConstructor.cpp @@ -38,17 +38,12 @@ ErrorConstructor::ErrorConstructor(ExecState* exec, JSGlobalObject* globalObject } // ECMA 15.9.3 -ErrorInstance* constructError(ExecState* exec, const ArgList& args) -{ - ErrorInstance* obj = new (exec) ErrorInstance(exec->lexicalGlobalObject()->errorStructure()); - if (!args.at(0).isUndefined()) - obj->putDirect(exec->propertyNames().message, jsString(exec, args.at(0).toString(exec))); - return obj; -} -static JSObject* constructWithErrorConstructor(ExecState* exec, JSObject*, const ArgList& args) +static EncodedJSValue JSC_HOST_CALL constructWithErrorConstructor(ExecState* exec) { - return constructError(exec, args); + JSValue message = exec->argumentCount() ? exec->argument(0) : jsUndefined(); + Structure* errorStructure = exec->lexicalGlobalObject()->errorStructure(); + return JSValue::encode(ErrorInstance::create(exec, errorStructure, message)); } ConstructType ErrorConstructor::getConstructData(ConstructData& constructData) @@ -57,10 +52,11 @@ ConstructType ErrorConstructor::getConstructData(ConstructData& constructData) return ConstructTypeHost; } -static JSValue JSC_HOST_CALL callErrorConstructor(ExecState* exec) +static EncodedJSValue JSC_HOST_CALL callErrorConstructor(ExecState* exec) { - ArgList args(exec); - return constructError(exec, args); + JSValue message = exec->argumentCount() ? exec->argument(0) : jsUndefined(); + Structure* errorStructure = exec->lexicalGlobalObject()->errorStructure(); + return JSValue::encode(ErrorInstance::create(exec, errorStructure, message)); } CallType ErrorConstructor::getCallData(CallData& callData) diff --git a/JavaScriptCore/runtime/ErrorConstructor.h b/JavaScriptCore/runtime/ErrorConstructor.h index c0e3323..3d0d706 100644 --- a/JavaScriptCore/runtime/ErrorConstructor.h +++ b/JavaScriptCore/runtime/ErrorConstructor.h @@ -37,8 +37,6 @@ namespace JSC { virtual CallType getCallData(CallData&); }; - ErrorInstance* constructError(ExecState*, const ArgList&); - } // namespace JSC #endif // ErrorConstructor_h diff --git a/JavaScriptCore/runtime/ErrorInstance.cpp b/JavaScriptCore/runtime/ErrorInstance.cpp index 1cdb87a..be6d0fb 100644 --- a/JavaScriptCore/runtime/ErrorInstance.cpp +++ b/JavaScriptCore/runtime/ErrorInstance.cpp @@ -30,4 +30,22 @@ ErrorInstance::ErrorInstance(NonNullPassRefPtr<Structure> structure) { } +ErrorInstance::ErrorInstance(JSGlobalData* globalData, NonNullPassRefPtr<Structure> structure, const UString& message) + : JSObject(structure) +{ + putDirect(globalData->propertyNames->message, jsString(globalData, message)); +} + +ErrorInstance* ErrorInstance::create(JSGlobalData* globalData, NonNullPassRefPtr<Structure> structure, const UString& message) +{ + return new (globalData) ErrorInstance(globalData, structure, message); +} + +ErrorInstance* ErrorInstance::create(ExecState* exec, NonNullPassRefPtr<Structure> structure, JSValue message) +{ + if (message.isUndefined()) + return new (exec) ErrorInstance(structure); + return new (exec) ErrorInstance(&exec->globalData(), structure, message.toString(exec)); +} + } // namespace JSC diff --git a/JavaScriptCore/runtime/ErrorInstance.h b/JavaScriptCore/runtime/ErrorInstance.h index 9f53b51..35edcb0 100644 --- a/JavaScriptCore/runtime/ErrorInstance.h +++ b/JavaScriptCore/runtime/ErrorInstance.h @@ -27,10 +27,16 @@ namespace JSC { class ErrorInstance : public JSObject { public: - explicit ErrorInstance(NonNullPassRefPtr<Structure>); virtual const ClassInfo* classInfo() const { return &info; } static const ClassInfo info; + + static ErrorInstance* create(JSGlobalData*, NonNullPassRefPtr<Structure>, const UString&); + static ErrorInstance* create(ExecState* exec, NonNullPassRefPtr<Structure>, JSValue message); + + protected: + explicit ErrorInstance(NonNullPassRefPtr<Structure>); + explicit ErrorInstance(JSGlobalData*, NonNullPassRefPtr<Structure>, const UString&); }; } // namespace JSC diff --git a/JavaScriptCore/runtime/ErrorPrototype.cpp b/JavaScriptCore/runtime/ErrorPrototype.cpp index 4c895fa..0e14a30 100644 --- a/JavaScriptCore/runtime/ErrorPrototype.cpp +++ b/JavaScriptCore/runtime/ErrorPrototype.cpp @@ -32,21 +32,19 @@ namespace JSC { ASSERT_CLASS_FITS_IN_CELL(ErrorPrototype); -static JSValue JSC_HOST_CALL errorProtoFuncToString(ExecState*); +static EncodedJSValue JSC_HOST_CALL errorProtoFuncToString(ExecState*); // ECMA 15.9.4 ErrorPrototype::ErrorPrototype(ExecState* exec, JSGlobalObject* globalObject, NonNullPassRefPtr<Structure> structure, Structure* prototypeFunctionStructure) - : ErrorInstance(structure) + : ErrorInstance(&exec->globalData(), structure, "Unknown error") { // The constructor will be added later in ErrorConstructor's constructor putDirectWithoutTransition(exec->propertyNames().name, jsNontrivialString(exec, "Error"), DontEnum); - putDirectWithoutTransition(exec->propertyNames().message, jsNontrivialString(exec, "Unknown error"), DontEnum); - putDirectFunctionWithoutTransition(exec, new (exec) NativeFunctionWrapper(exec, globalObject, prototypeFunctionStructure, 0, exec->propertyNames().toString, errorProtoFuncToString), DontEnum); } -JSValue JSC_HOST_CALL errorProtoFuncToString(ExecState* exec) +EncodedJSValue JSC_HOST_CALL errorProtoFuncToString(ExecState* exec) { JSObject* thisObj = exec->hostThisValue().toThisObject(exec); JSValue name = thisObj->get(exec, exec->propertyNames().name); @@ -56,12 +54,12 @@ JSValue JSC_HOST_CALL errorProtoFuncToString(ExecState* exec) if (!name.isUndefined()) { if (!message.isUndefined()) - return jsMakeNontrivialString(exec, name.toString(exec), ": ", message.toString(exec)); - return jsNontrivialString(exec, name.toString(exec)); + return JSValue::encode(jsMakeNontrivialString(exec, name.toString(exec), ": ", message.toString(exec))); + return JSValue::encode(jsNontrivialString(exec, name.toString(exec))); } if (!message.isUndefined()) - return jsMakeNontrivialString(exec, "Error: ", message.toString(exec)); - return jsNontrivialString(exec, "Error"); + return JSValue::encode(jsMakeNontrivialString(exec, "Error: ", message.toString(exec))); + return JSValue::encode(jsNontrivialString(exec, "Error")); } } // namespace JSC diff --git a/JavaScriptCore/runtime/ExceptionHelpers.cpp b/JavaScriptCore/runtime/ExceptionHelpers.cpp index b76c226..0647e81 100644 --- a/JavaScriptCore/runtime/ExceptionHelpers.cpp +++ b/JavaScriptCore/runtime/ExceptionHelpers.cpp @@ -73,19 +73,9 @@ JSValue createTerminatedExecutionException(JSGlobalData* globalData) return new (globalData) TerminatedExecutionError(globalData); } -static JSValue createError(ExecState* exec, ErrorType e, const char* msg) +JSObject* createStackOverflowError(ExecState* exec) { - return Error::create(exec, e, msg, -1, -1, UString()); -} - -JSValue createStackOverflowError(ExecState* exec) -{ - return createError(exec, RangeError, "Maximum call stack size exceeded."); -} - -JSValue createTypeError(ExecState* exec, const char* message) -{ - return createError(exec, TypeError, message); + return createRangeError(exec, "Maximum call stack size exceeded."); } JSValue createUndefinedVariableError(ExecState* exec, const Identifier& ident, unsigned bytecodeOffset, CodeBlock* codeBlock) @@ -94,10 +84,8 @@ JSValue createUndefinedVariableError(ExecState* exec, const Identifier& ident, u int endOffset = 0; int divotPoint = 0; int line = codeBlock->expressionRangeForBytecodeOffset(exec, bytecodeOffset, divotPoint, startOffset, endOffset); - JSObject* exception = Error::create(exec, ReferenceError, makeString("Can't find variable: ", ident.ustring()), line, codeBlock->ownerExecutable()->sourceID(), codeBlock->ownerExecutable()->sourceURL()); - exception->putWithAttributes(exec, Identifier(exec, expressionBeginOffsetPropertyName), jsNumber(exec, divotPoint - startOffset), ReadOnly | DontDelete); - exception->putWithAttributes(exec, Identifier(exec, expressionCaretOffsetPropertyName), jsNumber(exec, divotPoint), ReadOnly | DontDelete); - exception->putWithAttributes(exec, Identifier(exec, expressionEndOffsetPropertyName), jsNumber(exec, divotPoint + endOffset), ReadOnly | DontDelete); + UString message(makeString("Can't find variable: ", ident.ustring())); + JSObject* exception = addErrorInfo(exec, createReferenceError(exec, message), line, codeBlock->ownerExecutable()->source(), divotPoint, startOffset, endOffset); return exception; } @@ -133,10 +121,7 @@ JSObject* createInvalidParamError(ExecState* exec, const char* op, JSValue value int divotPoint = 0; int line = codeBlock->expressionRangeForBytecodeOffset(exec, bytecodeOffset, divotPoint, startOffset, endOffset); UString errorMessage = createErrorMessage(exec, codeBlock, line, divotPoint, divotPoint + endOffset, value, makeString("not a valid argument for '", op, "'")); - JSObject* exception = Error::create(exec, TypeError, errorMessage, line, codeBlock->ownerExecutable()->sourceID(), codeBlock->ownerExecutable()->sourceURL()); - exception->putWithAttributes(exec, Identifier(exec, expressionBeginOffsetPropertyName), jsNumber(exec, divotPoint - startOffset), ReadOnly | DontDelete); - exception->putWithAttributes(exec, Identifier(exec, expressionCaretOffsetPropertyName), jsNumber(exec, divotPoint), ReadOnly | DontDelete); - exception->putWithAttributes(exec, Identifier(exec, expressionEndOffsetPropertyName), jsNumber(exec, divotPoint + endOffset), ReadOnly | DontDelete); + JSObject* exception = addErrorInfo(exec, createTypeError(exec, errorMessage), line, codeBlock->ownerExecutable()->source(), divotPoint, startOffset, endOffset); return exception; } @@ -154,10 +139,7 @@ JSObject* createNotAConstructorError(ExecState* exec, JSValue value, unsigned by startPoint++; UString errorMessage = createErrorMessage(exec, codeBlock, line, startPoint, divotPoint, value, "not a constructor"); - JSObject* exception = Error::create(exec, TypeError, errorMessage, line, codeBlock->ownerExecutable()->sourceID(), codeBlock->ownerExecutable()->sourceURL()); - exception->putWithAttributes(exec, Identifier(exec, expressionBeginOffsetPropertyName), jsNumber(exec, divotPoint - startOffset), ReadOnly | DontDelete); - exception->putWithAttributes(exec, Identifier(exec, expressionCaretOffsetPropertyName), jsNumber(exec, divotPoint), ReadOnly | DontDelete); - exception->putWithAttributes(exec, Identifier(exec, expressionEndOffsetPropertyName), jsNumber(exec, divotPoint + endOffset), ReadOnly | DontDelete); + JSObject* exception = addErrorInfo(exec, createTypeError(exec, errorMessage), line, codeBlock->ownerExecutable()->source(), divotPoint, startOffset, endOffset); return exception; } @@ -168,10 +150,7 @@ JSValue createNotAFunctionError(ExecState* exec, JSValue value, unsigned bytecod int divotPoint = 0; int line = codeBlock->expressionRangeForBytecodeOffset(exec, bytecodeOffset, divotPoint, startOffset, endOffset); UString errorMessage = createErrorMessage(exec, codeBlock, line, divotPoint - startOffset, divotPoint, value, "not a function"); - JSObject* exception = Error::create(exec, TypeError, errorMessage, line, codeBlock->ownerExecutable()->sourceID(), codeBlock->ownerExecutable()->sourceURL()); - exception->putWithAttributes(exec, Identifier(exec, expressionBeginOffsetPropertyName), jsNumber(exec, divotPoint - startOffset), ReadOnly | DontDelete); - exception->putWithAttributes(exec, Identifier(exec, expressionCaretOffsetPropertyName), jsNumber(exec, divotPoint), ReadOnly | DontDelete); - exception->putWithAttributes(exec, Identifier(exec, expressionEndOffsetPropertyName), jsNumber(exec, divotPoint + endOffset), ReadOnly | DontDelete); + JSObject* exception = addErrorInfo(exec, createTypeError(exec, errorMessage), line, codeBlock->ownerExecutable()->source(), divotPoint, startOffset, endOffset); return exception; } @@ -198,16 +177,13 @@ JSObject* createNotAnObjectError(ExecState* exec, JSNotAnObjectErrorStub* error, int divotPoint = 0; int line = codeBlock->expressionRangeForBytecodeOffset(exec, bytecodeOffset, divotPoint, startOffset, endOffset); UString errorMessage = createErrorMessage(exec, codeBlock, line, divotPoint - startOffset, divotPoint, error->isNull() ? jsNull() : jsUndefined(), "not an object"); - JSObject* exception = Error::create(exec, TypeError, errorMessage, line, codeBlock->ownerExecutable()->sourceID(), codeBlock->ownerExecutable()->sourceURL()); - exception->putWithAttributes(exec, Identifier(exec, expressionBeginOffsetPropertyName), jsNumber(exec, divotPoint - startOffset), ReadOnly | DontDelete); - exception->putWithAttributes(exec, Identifier(exec, expressionCaretOffsetPropertyName), jsNumber(exec, divotPoint), ReadOnly | DontDelete); - exception->putWithAttributes(exec, Identifier(exec, expressionEndOffsetPropertyName), jsNumber(exec, divotPoint + endOffset), ReadOnly | DontDelete); + JSObject* exception = addErrorInfo(exec, createTypeError(exec, errorMessage), line, codeBlock->ownerExecutable()->source(), divotPoint, startOffset, endOffset); return exception; } JSValue throwOutOfMemoryError(ExecState* exec) { - return throwError(exec, GeneralError, "Out of memory"); + return throwError(exec, createError(exec, "Out of memory")); } } // namespace JSC diff --git a/JavaScriptCore/runtime/ExceptionHelpers.h b/JavaScriptCore/runtime/ExceptionHelpers.h index b152439..906465f 100644 --- a/JavaScriptCore/runtime/ExceptionHelpers.h +++ b/JavaScriptCore/runtime/ExceptionHelpers.h @@ -29,6 +29,7 @@ #ifndef ExceptionHelpers_h #define ExceptionHelpers_h +#include "JSValue.h" namespace JSC { @@ -38,14 +39,12 @@ namespace JSC { class JSGlobalData; class JSNotAnObjectErrorStub; class JSObject; - class JSValue; class Node; struct Instruction; JSValue createInterruptedExecutionException(JSGlobalData*); JSValue createTerminatedExecutionException(JSGlobalData*); - JSValue createStackOverflowError(ExecState*); - JSValue createTypeError(ExecState*, const char* message); + JSObject* createStackOverflowError(ExecState*); JSValue createUndefinedVariableError(ExecState*, const Identifier&, unsigned bytecodeOffset, CodeBlock*); JSNotAnObjectErrorStub* createNotAnObjectErrorStub(ExecState*, bool isNull); JSObject* createInvalidParamError(ExecState*, const char* op, JSValue, unsigned bytecodeOffset, CodeBlock*); diff --git a/JavaScriptCore/runtime/Executable.cpp b/JavaScriptCore/runtime/Executable.cpp index 2176e36..a18e80c 100644 --- a/JavaScriptCore/runtime/Executable.cpp +++ b/JavaScriptCore/runtime/Executable.cpp @@ -65,9 +65,11 @@ JSObject* EvalExecutable::compile(ExecState* exec, ScopeChainNode* scopeChainNod { int errLine; UString errMsg; - RefPtr<EvalNode> evalNode = exec->globalData().parser->parse<EvalNode>(&exec->globalData(), exec->lexicalGlobalObject()->debugger(), exec, m_source, &errLine, &errMsg); + JSGlobalData* globalData = &exec->globalData(); + JSGlobalObject* lexicalGlobalObject = exec->lexicalGlobalObject(); + RefPtr<EvalNode> evalNode = globalData->parser->parse<EvalNode>(globalData, lexicalGlobalObject->debugger(), exec, m_source, &errLine, &errMsg); if (!evalNode) - return Error::create(exec, SyntaxError, errMsg, errLine, m_source.provider()->asID(), m_source.provider()->url()); + return addErrorInfo(globalData, createSyntaxError(lexicalGlobalObject, errMsg), errLine, m_source); recordParse(evalNode->features(), evalNode->lineNo(), evalNode->lastLine()); ScopeChain scopeChain(scopeChainNode); @@ -86,9 +88,11 @@ JSObject* ProgramExecutable::checkSyntax(ExecState* exec) { int errLine; UString errMsg; - RefPtr<ProgramNode> programNode = exec->globalData().parser->parse<ProgramNode>(&exec->globalData(), exec->lexicalGlobalObject()->debugger(), exec, m_source, &errLine, &errMsg); + JSGlobalData* globalData = &exec->globalData(); + JSGlobalObject* lexicalGlobalObject = exec->lexicalGlobalObject(); + RefPtr<ProgramNode> programNode = globalData->parser->parse<ProgramNode>(globalData, lexicalGlobalObject->debugger(), exec, m_source, &errLine, &errMsg); if (!programNode) - return Error::create(exec, SyntaxError, errMsg, errLine, m_source.provider()->asID(), m_source.provider()->url()); + return addErrorInfo(globalData, createSyntaxError(lexicalGlobalObject, errMsg), errLine, m_source); return 0; } @@ -96,9 +100,11 @@ JSObject* ProgramExecutable::compile(ExecState* exec, ScopeChainNode* scopeChain { int errLine; UString errMsg; - RefPtr<ProgramNode> programNode = exec->globalData().parser->parse<ProgramNode>(&exec->globalData(), exec->lexicalGlobalObject()->debugger(), exec, m_source, &errLine, &errMsg); + JSGlobalData* globalData = &exec->globalData(); + JSGlobalObject* lexicalGlobalObject = exec->lexicalGlobalObject(); + RefPtr<ProgramNode> programNode = globalData->parser->parse<ProgramNode>(globalData, lexicalGlobalObject->debugger(), exec, m_source, &errLine, &errMsg); if (!programNode) - return Error::create(exec, SyntaxError, errMsg, errLine, m_source.provider()->asID(), m_source.provider()->url()); + return addErrorInfo(globalData, createSyntaxError(lexicalGlobalObject, errMsg), errLine, m_source); recordParse(programNode->features(), programNode->lineNo(), programNode->lastLine()); ScopeChain scopeChain(scopeChainNode); diff --git a/JavaScriptCore/runtime/FunctionConstructor.cpp b/JavaScriptCore/runtime/FunctionConstructor.cpp index de9fff1..a5ff28c 100644 --- a/JavaScriptCore/runtime/FunctionConstructor.cpp +++ b/JavaScriptCore/runtime/FunctionConstructor.cpp @@ -22,6 +22,7 @@ #include "FunctionConstructor.h" #include "Debugger.h" +#include "ExceptionHelpers.h" #include "FunctionPrototype.h" #include "JSFunction.h" #include "JSGlobalObject.h" @@ -44,9 +45,10 @@ FunctionConstructor::FunctionConstructor(ExecState* exec, JSGlobalObject* global putDirectWithoutTransition(exec->propertyNames().length, jsNumber(exec, 1), ReadOnly | DontDelete | DontEnum); } -static JSObject* constructWithFunctionConstructor(ExecState* exec, JSObject*, const ArgList& args) +static EncodedJSValue JSC_HOST_CALL constructWithFunctionConstructor(ExecState* exec) { - return constructFunction(exec, args); + ArgList args(exec); + return JSValue::encode(constructFunction(exec, args)); } ConstructType FunctionConstructor::getConstructData(ConstructData& constructData) @@ -55,10 +57,10 @@ ConstructType FunctionConstructor::getConstructData(ConstructData& constructData return ConstructTypeHost; } -static JSValue JSC_HOST_CALL callFunctionConstructor(ExecState* exec) +static EncodedJSValue JSC_HOST_CALL callFunctionConstructor(ExecState* exec) { ArgList args(exec); - return constructFunction(exec, args); + return JSValue::encode(constructFunction(exec, args)); } // ECMA 15.3.1 The Function Constructor Called as a Function @@ -95,13 +97,14 @@ JSObject* constructFunction(ExecState* exec, const ArgList& args, const Identifi int errLine; UString errMsg; + JSGlobalObject* globalObject = exec->lexicalGlobalObject(); + JSGlobalData* globalData = globalObject->globalData(); SourceCode source = makeSource(program, sourceURL, lineNumber); RefPtr<FunctionExecutable> function = FunctionExecutable::fromGlobalCode(functionName, exec, exec->dynamicGlobalObject()->debugger(), source, &errLine, &errMsg); if (!function) - return throwError(exec, SyntaxError, errMsg, errLine, source.provider()->asID(), source.provider()->url()); + return throwError(exec, addErrorInfo(globalData, createSyntaxError(globalObject, errMsg), errLine, source)); - JSGlobalObject* globalObject = exec->lexicalGlobalObject(); - ScopeChain scopeChain(globalObject, globalObject->globalData(), globalObject, exec->globalThisValue()); + ScopeChain scopeChain(globalObject, globalData, globalObject, exec->globalThisValue()); return new (exec) JSFunction(exec, function, scopeChain.node()); } diff --git a/JavaScriptCore/runtime/FunctionPrototype.cpp b/JavaScriptCore/runtime/FunctionPrototype.cpp index 15392cf..fb2f627 100644 --- a/JavaScriptCore/runtime/FunctionPrototype.cpp +++ b/JavaScriptCore/runtime/FunctionPrototype.cpp @@ -34,9 +34,9 @@ namespace JSC { ASSERT_CLASS_FITS_IN_CELL(FunctionPrototype); -static JSValue JSC_HOST_CALL functionProtoFuncToString(ExecState*); -static JSValue JSC_HOST_CALL functionProtoFuncApply(ExecState*); -static JSValue JSC_HOST_CALL functionProtoFuncCall(ExecState*); +static EncodedJSValue JSC_HOST_CALL functionProtoFuncToString(ExecState*); +static EncodedJSValue JSC_HOST_CALL functionProtoFuncApply(ExecState*); +static EncodedJSValue JSC_HOST_CALL functionProtoFuncCall(ExecState*); FunctionPrototype::FunctionPrototype(ExecState* exec, JSGlobalObject* globalObject, NonNullPassRefPtr<Structure> structure) : InternalFunction(&exec->globalData(), globalObject, structure, exec->propertyNames().nullIdentifier) @@ -53,9 +53,9 @@ void FunctionPrototype::addFunctionProperties(ExecState* exec, JSGlobalObject* g putDirectFunctionWithoutTransition(exec, *callFunction, DontEnum); } -static JSValue JSC_HOST_CALL callFunctionPrototype(ExecState*) +static EncodedJSValue JSC_HOST_CALL callFunctionPrototype(ExecState*) { - return jsUndefined(); + return JSValue::encode(jsUndefined()); } // ECMA 15.3.4 @@ -83,41 +83,41 @@ static inline void insertSemicolonIfNeeded(UString& functionBody) } } -JSValue JSC_HOST_CALL functionProtoFuncToString(ExecState* exec) +EncodedJSValue JSC_HOST_CALL functionProtoFuncToString(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); if (thisValue.inherits(&JSFunction::info)) { JSFunction* function = asFunction(thisValue); if (function->isHostFunction()) - return jsMakeNontrivialString(exec, "function ", function->name(exec), "() {\n [native code]\n}"); + return JSValue::encode(jsMakeNontrivialString(exec, "function ", function->name(exec), "() {\n [native code]\n}")); FunctionExecutable* executable = function->jsExecutable(); UString sourceString = executable->source().toString(); insertSemicolonIfNeeded(sourceString); - return jsMakeNontrivialString(exec, "function ", function->name(exec), "(", executable->paramString(), ") ", sourceString); + return JSValue::encode(jsMakeNontrivialString(exec, "function ", function->name(exec), "(", executable->paramString(), ") ", sourceString)); } if (thisValue.inherits(&InternalFunction::info)) { InternalFunction* function = asInternalFunction(thisValue); - return jsMakeNontrivialString(exec, "function ", function->name(exec), "() {\n [native code]\n}"); + return JSValue::encode(jsMakeNontrivialString(exec, "function ", function->name(exec), "() {\n [native code]\n}")); } - return throwError(exec, TypeError); + return throwVMTypeError(exec); } -JSValue JSC_HOST_CALL functionProtoFuncApply(ExecState* exec) +EncodedJSValue JSC_HOST_CALL functionProtoFuncApply(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); CallData callData; - CallType callType = thisValue.getCallData(callData); + CallType callType = getCallData(thisValue, callData); if (callType == CallTypeNone) - return throwError(exec, TypeError); + return throwVMTypeError(exec); JSValue array = exec->argument(1); MarkedArgumentBuffer applyArgs; if (!array.isUndefinedOrNull()) { if (!array.isObject()) - return throwError(exec, TypeError); + return throwVMTypeError(exec); if (asObject(array)->classInfo() == &Arguments::info) asArguments(array)->fillArgList(exec, applyArgs); else if (isJSArray(&exec->globalData(), array)) @@ -127,24 +127,24 @@ JSValue JSC_HOST_CALL functionProtoFuncApply(ExecState* exec) for (unsigned i = 0; i < length; ++i) applyArgs.append(asArray(array)->get(exec, i)); } else - return throwError(exec, TypeError); + return throwVMTypeError(exec); } - return call(exec, thisValue, callType, callData, exec->argument(0), applyArgs); + return JSValue::encode(call(exec, thisValue, callType, callData, exec->argument(0), applyArgs)); } -JSValue JSC_HOST_CALL functionProtoFuncCall(ExecState* exec) +EncodedJSValue JSC_HOST_CALL functionProtoFuncCall(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); CallData callData; - CallType callType = thisValue.getCallData(callData); + CallType callType = getCallData(thisValue, callData); if (callType == CallTypeNone) - return throwError(exec, TypeError); + return throwVMTypeError(exec); ArgList args(exec); ArgList callArgs; args.getSlice(1, callArgs); - return call(exec, thisValue, callType, callData, exec->argument(0), callArgs); + return JSValue::encode(call(exec, thisValue, callType, callData, exec->argument(0), callArgs)); } } // namespace JSC diff --git a/JavaScriptCore/runtime/Identifier.cpp b/JavaScriptCore/runtime/Identifier.cpp index f2642a9..46772d0 100644 --- a/JavaScriptCore/runtime/Identifier.cpp +++ b/JavaScriptCore/runtime/Identifier.cpp @@ -228,6 +228,21 @@ Identifier Identifier::from(ExecState* exec, double value) return Identifier(exec, exec->globalData().numericStrings.add(value)); } +Identifier Identifier::from(JSGlobalData* globalData, unsigned value) +{ + return Identifier(globalData, globalData->numericStrings.add(value)); +} + +Identifier Identifier::from(JSGlobalData* globalData, int value) +{ + return Identifier(globalData, globalData->numericStrings.add(value)); +} + +Identifier Identifier::from(JSGlobalData* globalData, double value) +{ + return Identifier(globalData, globalData->numericStrings.add(value)); +} + #ifndef NDEBUG void Identifier::checkCurrentIdentifierTable(JSGlobalData* globalData) diff --git a/JavaScriptCore/runtime/Identifier.h b/JavaScriptCore/runtime/Identifier.h index 2f16bbf..2db0716 100644 --- a/JavaScriptCore/runtime/Identifier.h +++ b/JavaScriptCore/runtime/Identifier.h @@ -57,6 +57,9 @@ namespace JSC { static Identifier from(ExecState* exec, unsigned y); static Identifier from(ExecState* exec, int y); static Identifier from(ExecState* exec, double y); + static Identifier from(JSGlobalData*, unsigned y); + static Identifier from(JSGlobalData*, int y); + static Identifier from(JSGlobalData*, double y); bool isNull() const { return _ustring.isNull(); } bool isEmpty() const { return _ustring.isEmpty(); } diff --git a/JavaScriptCore/runtime/JSArray.cpp b/JavaScriptCore/runtime/JSArray.cpp index cf32e07..05623f5 100644 --- a/JavaScriptCore/runtime/JSArray.cpp +++ b/JavaScriptCore/runtime/JSArray.cpp @@ -283,7 +283,7 @@ void JSArray::put(ExecState* exec, const Identifier& propertyName, JSValue value if (propertyName == exec->propertyNames().length) { unsigned newLength = value.toUInt32(exec); if (value.toNumber(exec) != static_cast<double>(newLength)) { - throwError(exec, RangeError, "Invalid array length."); + throwError(exec, createRangeError(exec, "Invalid array length.")); return; } setLength(newLength); diff --git a/JavaScriptCore/runtime/JSCell.h b/JavaScriptCore/runtime/JSCell.h index c083825..72f81df 100644 --- a/JavaScriptCore/runtime/JSCell.h +++ b/JavaScriptCore/runtime/JSCell.h @@ -23,6 +23,8 @@ #ifndef JSCell_h #define JSCell_h +#include "CallData.h" +#include "ConstructData.h" #include "Collector.h" #include "JSImmediate.h" #include "JSValue.h" @@ -205,17 +207,17 @@ namespace JSC { return isCell() ? asCell()->getObject() : 0; } - inline CallType JSValue::getCallData(CallData& callData) + inline CallType getCallData(JSValue value, CallData& callData) { - CallType result = isCell() ? asCell()->getCallData(callData) : CallTypeNone; - ASSERT(result == CallTypeNone || isValidCallee()); + CallType result = value.isCell() ? asCell(value)->getCallData(callData) : CallTypeNone; + ASSERT(result == CallTypeNone || value.isValidCallee()); return result; } - inline ConstructType JSValue::getConstructData(ConstructData& constructData) + inline ConstructType getConstructData(JSValue value, ConstructData& constructData) { - ConstructType result = isCell() ? asCell()->getConstructData(constructData) : ConstructTypeNone; - ASSERT(result == ConstructTypeNone || isValidCallee()); + ConstructType result = value.isCell() ? asCell(value)->getConstructData(constructData) : ConstructTypeNone; + ASSERT(result == ConstructTypeNone || value.isValidCallee()); return result; } diff --git a/JavaScriptCore/runtime/JSFunction.cpp b/JavaScriptCore/runtime/JSFunction.cpp index f44ca2f..7fcd037 100644 --- a/JavaScriptCore/runtime/JSFunction.cpp +++ b/JavaScriptCore/runtime/JSFunction.cpp @@ -43,12 +43,11 @@ using namespace Unicode; namespace JSC { -JSValue JSC_HOST_CALL callHostFunctionAsConstructor(ExecState* exec) +EncodedJSValue JSC_HOST_CALL callHostFunctionAsConstructor(ExecState* exec) { CodeBlock* codeBlock = exec->callerFrame()->codeBlock(); unsigned vPCIndex = codeBlock->bytecodeOffset(exec, exec->returnPC()); - exec->setException(createNotAConstructorError(exec, exec->callee(), vPCIndex, codeBlock)); - return JSValue(); + return throwVMError(exec, createNotAConstructorError(exec, exec->callee(), vPCIndex, codeBlock)); } ASSERT_CLASS_FITS_IN_CELL(JSFunction); diff --git a/JavaScriptCore/runtime/JSFunction.h b/JavaScriptCore/runtime/JSFunction.h index a906b2e..3a2fe30 100644 --- a/JavaScriptCore/runtime/JSFunction.h +++ b/JavaScriptCore/runtime/JSFunction.h @@ -35,7 +35,7 @@ namespace JSC { class JSGlobalObject; class NativeExecutable; - JSValue JSC_HOST_CALL callHostFunctionAsConstructor(ExecState*); + EncodedJSValue JSC_HOST_CALL callHostFunctionAsConstructor(ExecState*); class JSFunction : public JSObjectWithGlobalObject { friend class JIT; diff --git a/JavaScriptCore/runtime/JSGlobalObjectFunctions.cpp b/JavaScriptCore/runtime/JSGlobalObjectFunctions.cpp index 21d06b7..04cb7cf 100644 --- a/JavaScriptCore/runtime/JSGlobalObjectFunctions.cpp +++ b/JavaScriptCore/runtime/JSGlobalObjectFunctions.cpp @@ -56,7 +56,7 @@ static JSValue encode(ExecState* exec, const char* doNotEscape) UString str = exec->argument(0).toString(exec); CString cstr = str.UTF8String(true); if (!cstr.data()) - return throwError(exec, URIError, "String contained an illegal UTF-16 sequence."); + return throwError(exec, createURIError(exec, "String contained an illegal UTF-16 sequence.")); JSStringBuilder builder; const char* p = cstr.data(); @@ -118,7 +118,7 @@ static JSValue decode(ExecState* exec, const char* doNotUnescape, bool strict) } if (charLen == 0) { if (strict) - return throwError(exec, URIError); + return throwError(exec, createURIError(exec, "URI error")); // The only case where we don't use "strict" mode is the "unescape" function. // For that, it's good to support the wonky "%u" syntax for compatibility with WinIE. if (k <= len - 6 && p[1] == 'u' @@ -272,84 +272,84 @@ static double parseFloat(const UString& s) return s.toDouble(true /*tolerant*/, false /* NaN for empty string */); } -JSValue JSC_HOST_CALL globalFuncEval(ExecState* exec) +EncodedJSValue JSC_HOST_CALL globalFuncEval(ExecState* exec) { JSObject* thisObject = exec->hostThisValue().toThisObject(exec); JSObject* unwrappedObject = thisObject->unwrappedObject(); if (!unwrappedObject->isGlobalObject() || static_cast<JSGlobalObject*>(unwrappedObject)->evalFunction() != exec->callee()) - return throwError(exec, EvalError, "The \"this\" value passed to eval must be the global object from which eval originated"); + return throwVMError(exec, createEvalError(exec, "The \"this\" value passed to eval must be the global object from which eval originated")); JSValue x = exec->argument(0); if (!x.isString()) - return x; + return JSValue::encode(x); UString s = x.toString(exec); LiteralParser preparser(exec, s, LiteralParser::NonStrictJSON); if (JSValue parsedObject = preparser.tryLiteralParse()) - return parsedObject; + return JSValue::encode(parsedObject); RefPtr<EvalExecutable> eval = EvalExecutable::create(exec, makeSource(s)); JSObject* error = eval->compile(exec, static_cast<JSGlobalObject*>(unwrappedObject)->globalScopeChain().node()); if (error) - return throwError(exec, error); + return throwVMError(exec, error); - return exec->interpreter()->execute(eval.get(), exec, thisObject, static_cast<JSGlobalObject*>(unwrappedObject)->globalScopeChain().node(), exec->exceptionSlot()); + return JSValue::encode(exec->interpreter()->execute(eval.get(), exec, thisObject, static_cast<JSGlobalObject*>(unwrappedObject)->globalScopeChain().node(), exec->exceptionSlot())); } -JSValue JSC_HOST_CALL globalFuncParseInt(ExecState* exec) +EncodedJSValue JSC_HOST_CALL globalFuncParseInt(ExecState* exec) { JSValue value = exec->argument(0); int32_t radix = exec->argument(1).toInt32(exec); if (radix != 0 && radix != 10) - return jsNumber(exec, parseInt(value.toString(exec), radix)); + return JSValue::encode(jsNumber(exec, parseInt(value.toString(exec), radix))); if (value.isInt32()) - return value; + return JSValue::encode(value); if (value.isDouble()) { double d = value.asDouble(); if (isfinite(d)) - return jsNumber(exec, (d > 0) ? floor(d) : ceil(d)); + return JSValue::encode(jsNumber(exec, (d > 0) ? floor(d) : ceil(d))); if (isnan(d) || isinf(d)) - return jsNaN(exec); - return jsNumber(exec, 0); + return JSValue::encode(jsNaN(exec)); + return JSValue::encode(jsNumber(exec, 0)); } - return jsNumber(exec, parseInt(value.toString(exec), radix)); + return JSValue::encode(jsNumber(exec, parseInt(value.toString(exec), radix))); } -JSValue JSC_HOST_CALL globalFuncParseFloat(ExecState* exec) +EncodedJSValue JSC_HOST_CALL globalFuncParseFloat(ExecState* exec) { - return jsNumber(exec, parseFloat(exec->argument(0).toString(exec))); + return JSValue::encode(jsNumber(exec, parseFloat(exec->argument(0).toString(exec)))); } -JSValue JSC_HOST_CALL globalFuncIsNaN(ExecState* exec) +EncodedJSValue JSC_HOST_CALL globalFuncIsNaN(ExecState* exec) { - return jsBoolean(isnan(exec->argument(0).toNumber(exec))); + return JSValue::encode(jsBoolean(isnan(exec->argument(0).toNumber(exec)))); } -JSValue JSC_HOST_CALL globalFuncIsFinite(ExecState* exec) +EncodedJSValue JSC_HOST_CALL globalFuncIsFinite(ExecState* exec) { double n = exec->argument(0).toNumber(exec); - return jsBoolean(!isnan(n) && !isinf(n)); + return JSValue::encode(jsBoolean(!isnan(n) && !isinf(n))); } -JSValue JSC_HOST_CALL globalFuncDecodeURI(ExecState* exec) +EncodedJSValue JSC_HOST_CALL globalFuncDecodeURI(ExecState* exec) { static const char do_not_unescape_when_decoding_URI[] = "#$&+,/:;=?@"; - return decode(exec, do_not_unescape_when_decoding_URI, true); + return JSValue::encode(decode(exec, do_not_unescape_when_decoding_URI, true)); } -JSValue JSC_HOST_CALL globalFuncDecodeURIComponent(ExecState* exec) +EncodedJSValue JSC_HOST_CALL globalFuncDecodeURIComponent(ExecState* exec) { - return decode(exec, "", true); + return JSValue::encode(decode(exec, "", true)); } -JSValue JSC_HOST_CALL globalFuncEncodeURI(ExecState* exec) +EncodedJSValue JSC_HOST_CALL globalFuncEncodeURI(ExecState* exec) { static const char do_not_escape_when_encoding_URI[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" @@ -357,10 +357,10 @@ JSValue JSC_HOST_CALL globalFuncEncodeURI(ExecState* exec) "0123456789" "!#$&'()*+,-./:;=?@_~"; - return encode(exec, do_not_escape_when_encoding_URI); + return JSValue::encode(encode(exec, do_not_escape_when_encoding_URI)); } -JSValue JSC_HOST_CALL globalFuncEncodeURIComponent(ExecState* exec) +EncodedJSValue JSC_HOST_CALL globalFuncEncodeURIComponent(ExecState* exec) { static const char do_not_escape_when_encoding_URI_component[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" @@ -368,10 +368,10 @@ JSValue JSC_HOST_CALL globalFuncEncodeURIComponent(ExecState* exec) "0123456789" "!'()*-._~"; - return encode(exec, do_not_escape_when_encoding_URI_component); + return JSValue::encode(encode(exec, do_not_escape_when_encoding_URI_component)); } -JSValue JSC_HOST_CALL globalFuncEscape(ExecState* exec) +EncodedJSValue JSC_HOST_CALL globalFuncEscape(ExecState* exec) { static const char do_not_escape[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" @@ -397,10 +397,10 @@ JSValue JSC_HOST_CALL globalFuncEscape(ExecState* exec) } } - return builder.build(exec); + return JSValue::encode(builder.build(exec)); } -JSValue JSC_HOST_CALL globalFuncUnescape(ExecState* exec) +EncodedJSValue JSC_HOST_CALL globalFuncUnescape(ExecState* exec) { StringBuilder builder; UString str = exec->argument(0).toString(exec); @@ -424,15 +424,15 @@ JSValue JSC_HOST_CALL globalFuncUnescape(ExecState* exec) builder.append(*c); } - return jsString(exec, builder.build()); + return JSValue::encode(jsString(exec, builder.build())); } #ifndef NDEBUG -JSValue JSC_HOST_CALL globalFuncJSCPrint(ExecState* exec) +EncodedJSValue JSC_HOST_CALL globalFuncJSCPrint(ExecState* exec) { CString string = exec->argument(0).toString(exec).UTF8String(); puts(string.data()); - return jsUndefined(); + return JSValue::encode(jsUndefined()); } #endif diff --git a/JavaScriptCore/runtime/JSGlobalObjectFunctions.h b/JavaScriptCore/runtime/JSGlobalObjectFunctions.h index b1dada4..91dfca8 100644 --- a/JavaScriptCore/runtime/JSGlobalObjectFunctions.h +++ b/JavaScriptCore/runtime/JSGlobalObjectFunctions.h @@ -24,6 +24,7 @@ #ifndef JSGlobalObjectFunctions_h #define JSGlobalObjectFunctions_h +#include "JSValue.h" #include <wtf/unicode/Unicode.h> namespace JSC { @@ -31,24 +32,23 @@ namespace JSC { class ArgList; class ExecState; class JSObject; - class JSValue; // FIXME: These functions should really be in JSGlobalObject.cpp, but putting them there // is a 0.5% reduction. - JSValue JSC_HOST_CALL globalFuncEval(ExecState*); - JSValue JSC_HOST_CALL globalFuncParseInt(ExecState*); - JSValue JSC_HOST_CALL globalFuncParseFloat(ExecState*); - JSValue JSC_HOST_CALL globalFuncIsNaN(ExecState*); - JSValue JSC_HOST_CALL globalFuncIsFinite(ExecState*); - JSValue JSC_HOST_CALL globalFuncDecodeURI(ExecState*); - JSValue JSC_HOST_CALL globalFuncDecodeURIComponent(ExecState*); - JSValue JSC_HOST_CALL globalFuncEncodeURI(ExecState*); - JSValue JSC_HOST_CALL globalFuncEncodeURIComponent(ExecState*); - JSValue JSC_HOST_CALL globalFuncEscape(ExecState*); - JSValue JSC_HOST_CALL globalFuncUnescape(ExecState*); + EncodedJSValue JSC_HOST_CALL globalFuncEval(ExecState*); + EncodedJSValue JSC_HOST_CALL globalFuncParseInt(ExecState*); + EncodedJSValue JSC_HOST_CALL globalFuncParseFloat(ExecState*); + EncodedJSValue JSC_HOST_CALL globalFuncIsNaN(ExecState*); + EncodedJSValue JSC_HOST_CALL globalFuncIsFinite(ExecState*); + EncodedJSValue JSC_HOST_CALL globalFuncDecodeURI(ExecState*); + EncodedJSValue JSC_HOST_CALL globalFuncDecodeURIComponent(ExecState*); + EncodedJSValue JSC_HOST_CALL globalFuncEncodeURI(ExecState*); + EncodedJSValue JSC_HOST_CALL globalFuncEncodeURIComponent(ExecState*); + EncodedJSValue JSC_HOST_CALL globalFuncEscape(ExecState*); + EncodedJSValue JSC_HOST_CALL globalFuncUnescape(ExecState*); #ifndef NDEBUG - JSValue JSC_HOST_CALL globalFuncJSCPrint(ExecState*); + EncodedJSValue JSC_HOST_CALL globalFuncJSCPrint(ExecState*); #endif static const double mantissaOverflowLowerBound = 9007199254740992.0; diff --git a/JavaScriptCore/runtime/JSONObject.cpp b/JavaScriptCore/runtime/JSONObject.cpp index 86604d8..ccfd43a 100644 --- a/JavaScriptCore/runtime/JSONObject.cpp +++ b/JavaScriptCore/runtime/JSONObject.cpp @@ -41,8 +41,8 @@ namespace JSC { ASSERT_CLASS_FITS_IN_CELL(JSONObject); -static JSValue JSC_HOST_CALL JSONProtoFuncParse(ExecState*); -static JSValue JSC_HOST_CALL JSONProtoFuncStringify(ExecState*); +static EncodedJSValue JSC_HOST_CALL JSONProtoFuncParse(ExecState*); +static EncodedJSValue JSC_HOST_CALL JSONProtoFuncStringify(ExecState*); } @@ -425,7 +425,7 @@ Stringifier::StringifyResult Stringifier::appendStringifiedValue(StringBuilder& // Handle cycle detection, and put the holder on the stack. if (!m_holderCycleDetector.add(object).second) { - throwError(m_exec, TypeError, "JSON.stringify cannot serialize cyclic structures."); + throwError(m_exec, createTypeError(m_exec, "JSON.stringify cannot serialize cyclic structures.")); return StringifyFailed; } bool holderStackWasEmpty = m_holderStack.isEmpty(); @@ -443,7 +443,7 @@ Stringifier::StringifyResult Stringifier::appendStringifiedValue(StringBuilder& return StringifyFailed; if (!--tickCount) { if (localTimeoutChecker.didTimeOut(m_exec)) { - m_exec->setException(createInterruptedExecutionException(&m_exec->globalData())); + throwError(m_exec, createInterruptedExecutionException(&m_exec->globalData())); return StringifyFailed; } tickCount = localTimeoutChecker.ticksUntilNextCheck(); @@ -679,10 +679,8 @@ NEVER_INLINE JSValue Walker::walk(JSValue unfiltered) case ArrayStartState: { ASSERT(inValue.isObject()); ASSERT(isJSArray(&m_exec->globalData(), asObject(inValue)) || asObject(inValue)->inherits(&JSArray::info)); - if (objectStack.size() + arrayStack.size() > maximumFilterRecursion) { - m_exec->setException(createStackOverflowError(m_exec)); - return jsUndefined(); - } + if (objectStack.size() + arrayStack.size() > maximumFilterRecursion) + return throwError(m_exec, createStackOverflowError(m_exec)); JSArray* array = asArray(inValue); arrayStack.append(array); @@ -692,10 +690,8 @@ NEVER_INLINE JSValue Walker::walk(JSValue unfiltered) arrayStartVisitMember: case ArrayStartVisitMember: { if (!--tickCount) { - if (localTimeoutChecker.didTimeOut(m_exec)) { - m_exec->setException(createInterruptedExecutionException(&m_exec->globalData())); - return jsUndefined(); - } + if (localTimeoutChecker.didTimeOut(m_exec)) + return throwError(m_exec, createInterruptedExecutionException(&m_exec->globalData())); tickCount = localTimeoutChecker.ticksUntilNextCheck(); } @@ -744,10 +740,8 @@ NEVER_INLINE JSValue Walker::walk(JSValue unfiltered) case ObjectStartState: { ASSERT(inValue.isObject()); ASSERT(!isJSArray(&m_exec->globalData(), asObject(inValue)) && !asObject(inValue)->inherits(&JSArray::info)); - if (objectStack.size() + arrayStack.size() > maximumFilterRecursion) { - m_exec->setException(createStackOverflowError(m_exec)); - return jsUndefined(); - } + if (objectStack.size() + arrayStack.size() > maximumFilterRecursion) + return throwError(m_exec, createStackOverflowError(m_exec)); JSObject* object = asObject(inValue); objectStack.append(object); @@ -759,10 +753,8 @@ NEVER_INLINE JSValue Walker::walk(JSValue unfiltered) objectStartVisitMember: case ObjectStartVisitMember: { if (!--tickCount) { - if (localTimeoutChecker.didTimeOut(m_exec)) { - m_exec->setException(createInterruptedExecutionException(&m_exec->globalData())); - return jsUndefined(); - } + if (localTimeoutChecker.didTimeOut(m_exec)) + return throwError(m_exec, createInterruptedExecutionException(&m_exec->globalData())); tickCount = localTimeoutChecker.ticksUntilNextCheck(); } @@ -825,10 +817,8 @@ NEVER_INLINE JSValue Walker::walk(JSValue unfiltered) stateStack.removeLast(); if (!--tickCount) { - if (localTimeoutChecker.didTimeOut(m_exec)) { - m_exec->setException(createInterruptedExecutionException(&m_exec->globalData())); - return jsUndefined(); - } + if (localTimeoutChecker.didTimeOut(m_exec)) + return throwError(m_exec, createInterruptedExecutionException(&m_exec->globalData())); tickCount = localTimeoutChecker.ticksUntilNextCheck(); } } @@ -839,40 +829,40 @@ NEVER_INLINE JSValue Walker::walk(JSValue unfiltered) } // ECMA-262 v5 15.12.2 -JSValue JSC_HOST_CALL JSONProtoFuncParse(ExecState* exec) +EncodedJSValue JSC_HOST_CALL JSONProtoFuncParse(ExecState* exec) { if (!exec->argumentCount()) - return throwError(exec, GeneralError, "JSON.parse requires at least one parameter"); + return throwVMError(exec, createError(exec, "JSON.parse requires at least one parameter")); JSValue value = exec->argument(0); UString source = value.toString(exec); if (exec->hadException()) - return jsNull(); + return JSValue::encode(jsNull()); LiteralParser jsonParser(exec, source, LiteralParser::StrictJSON); JSValue unfiltered = jsonParser.tryLiteralParse(); if (!unfiltered) - return throwError(exec, SyntaxError, "Unable to parse JSON string"); + return throwVMError(exec, createSyntaxError(exec, "Unable to parse JSON string")); if (exec->argumentCount() < 2) - return unfiltered; + return JSValue::encode(unfiltered); JSValue function = exec->argument(1); CallData callData; - CallType callType = function.getCallData(callData); + CallType callType = getCallData(function, callData); if (callType == CallTypeNone) - return unfiltered; - return Walker(exec, asObject(function), callType, callData).walk(unfiltered); + return JSValue::encode(unfiltered); + return JSValue::encode(Walker(exec, asObject(function), callType, callData).walk(unfiltered)); } // ECMA-262 v5 15.12.3 -JSValue JSC_HOST_CALL JSONProtoFuncStringify(ExecState* exec) +EncodedJSValue JSC_HOST_CALL JSONProtoFuncStringify(ExecState* exec) { if (!exec->argumentCount()) - return throwError(exec, GeneralError, "No input to stringify"); + return throwVMError(exec, createError(exec, "No input to stringify")); JSValue value = exec->argument(0); JSValue replacer = exec->argument(1); JSValue space = exec->argument(2); - return Stringifier(exec, replacer, space).stringify(value); + return JSValue::encode(Stringifier(exec, replacer, space).stringify(value)); } UString JSONStringify(ExecState* exec, JSValue value, unsigned indent) diff --git a/JavaScriptCore/runtime/JSObject.cpp b/JavaScriptCore/runtime/JSObject.cpp index 5cff4fa..cabc428 100644 --- a/JavaScriptCore/runtime/JSObject.cpp +++ b/JavaScriptCore/runtime/JSObject.cpp @@ -91,7 +91,7 @@ bool JSObject::getOwnPropertySlot(ExecState* exec, unsigned propertyName, Proper static void throwSetterError(ExecState* exec) { - throwError(exec, TypeError, "setting a property that has only a getter"); + throwError(exec, createTypeError(exec, "setting a property that has only a getter")); } // ECMA 8.6.2.2 @@ -105,7 +105,7 @@ void JSObject::put(ExecState* exec, const Identifier& propertyName, JSValue valu if (!value.isObject() && !value.isNull()) return; if (!setPrototypeWithCycleCheck(value)) - throwError(exec, GeneralError, "cyclic __proto__ value"); + throwError(exec, createError(exec, "cyclic __proto__ value")); return; } @@ -161,6 +161,21 @@ void JSObject::put(ExecState* exec, unsigned propertyName, JSValue value) put(exec, Identifier::from(exec, propertyName), value, slot); } +void JSObject::putWithAttributes(JSGlobalData* globalData, const Identifier& propertyName, JSValue value, unsigned attributes, bool checkReadOnly, PutPropertySlot& slot) +{ + putDirectInternal(*globalData, propertyName, value, attributes, checkReadOnly, slot); +} + +void JSObject::putWithAttributes(JSGlobalData* globalData, const Identifier& propertyName, JSValue value, unsigned attributes) +{ + putDirectInternal(*globalData, propertyName, value, attributes); +} + +void JSObject::putWithAttributes(JSGlobalData* globalData, unsigned propertyName, JSValue value, unsigned attributes) +{ + putWithAttributes(globalData, Identifier::from(globalData, propertyName), value, attributes); +} + void JSObject::putWithAttributes(ExecState* exec, const Identifier& propertyName, JSValue value, unsigned attributes, bool checkReadOnly, PutPropertySlot& slot) { putDirectInternal(exec->globalData(), propertyName, value, attributes, checkReadOnly, slot); @@ -224,7 +239,7 @@ static ALWAYS_INLINE JSValue callDefaultValueFunction(ExecState* exec, const JSO { JSValue function = object->get(exec, propertyName); CallData callData; - CallType callType = function.getCallData(callData); + CallType callType = getCallData(function, callData); if (callType == CallTypeNone) return exec->exception(); @@ -271,7 +286,7 @@ JSValue JSObject::defaultValue(ExecState* exec, PreferredPrimitiveType hint) con ASSERT(!exec->hadException()); - return throwError(exec, TypeError, "No default value"); + return throwError(exec, createTypeError(exec, "No default value")); } const HashEntry* JSObject::findPropertyHashEntry(ExecState* exec, const Identifier& propertyName) const @@ -383,7 +398,7 @@ bool JSObject::hasInstance(ExecState* exec, JSValue value, JSValue proto) return false; if (!proto.isObject()) { - throwError(exec, TypeError, "instanceof called on an object with an invalid prototype property."); + throwError(exec, createTypeError(exec, "instanceof called on an object with an invalid prototype property.")); return false; } @@ -594,12 +609,12 @@ bool JSObject::defineOwnProperty(ExecState* exec, const Identifier& propertyName if (!current.configurable()) { if (descriptor.configurable()) { if (throwException) - throwError(exec, TypeError, "Attempting to configurable attribute of unconfigurable property."); + throwError(exec, createTypeError(exec, "Attempting to configurable attribute of unconfigurable property.")); return false; } if (descriptor.enumerablePresent() && descriptor.enumerable() != current.enumerable()) { if (throwException) - throwError(exec, TypeError, "Attempting to change enumerable attribute of unconfigurable property."); + throwError(exec, createTypeError(exec, "Attempting to change enumerable attribute of unconfigurable property.")); return false; } } @@ -617,7 +632,7 @@ bool JSObject::defineOwnProperty(ExecState* exec, const Identifier& propertyName if (descriptor.isDataDescriptor() != current.isDataDescriptor()) { if (!current.configurable()) { if (throwException) - throwError(exec, TypeError, "Attempting to change access mechanism for an unconfigurable property."); + throwError(exec, createTypeError(exec, "Attempting to change access mechanism for an unconfigurable property.")); return false; } deleteProperty(exec, propertyName); @@ -629,13 +644,13 @@ bool JSObject::defineOwnProperty(ExecState* exec, const Identifier& propertyName if (!current.configurable()) { if (!current.writable() && descriptor.writable()) { if (throwException) - throwError(exec, TypeError, "Attempting to change writable attribute of unconfigurable property."); + throwError(exec, createTypeError(exec, "Attempting to change writable attribute of unconfigurable property.")); return false; } if (!current.writable()) { if (descriptor.value() || !JSValue::strictEqual(exec, current.value(), descriptor.value())) { if (throwException) - throwError(exec, TypeError, "Attempting to change value of a readonly property."); + throwError(exec, createTypeError(exec, "Attempting to change value of a readonly property.")); return false; } } @@ -657,12 +672,12 @@ bool JSObject::defineOwnProperty(ExecState* exec, const Identifier& propertyName if (!current.configurable()) { if (descriptor.setterPresent() && !(current.setter() && JSValue::strictEqual(exec, current.setter(), descriptor.setter()))) { if (throwException) - throwError(exec, TypeError, "Attempting to change the setter of an unconfigurable property."); + throwError(exec, createTypeError(exec, "Attempting to change the setter of an unconfigurable property.")); return false; } if (descriptor.getterPresent() && !(current.getter() && JSValue::strictEqual(exec, current.getter(), descriptor.getter()))) { if (throwException) - throwError(exec, TypeError, "Attempting to change the getter of an unconfigurable property."); + throwError(exec, createTypeError(exec, "Attempting to change the getter of an unconfigurable property.")); return false; } } diff --git a/JavaScriptCore/runtime/JSObject.h b/JavaScriptCore/runtime/JSObject.h index 0738d60..edd376c 100644 --- a/JavaScriptCore/runtime/JSObject.h +++ b/JavaScriptCore/runtime/JSObject.h @@ -109,6 +109,9 @@ namespace JSC { virtual void put(ExecState*, const Identifier& propertyName, JSValue value, PutPropertySlot&); virtual void put(ExecState*, unsigned propertyName, JSValue value); + virtual void putWithAttributes(JSGlobalData*, const Identifier& propertyName, JSValue value, unsigned attributes, bool checkReadOnly, PutPropertySlot& slot); + virtual void putWithAttributes(JSGlobalData*, const Identifier& propertyName, JSValue value, unsigned attributes); + virtual void putWithAttributes(JSGlobalData*, unsigned propertyName, JSValue value, unsigned attributes); virtual void putWithAttributes(ExecState*, const Identifier& propertyName, JSValue value, unsigned attributes, bool checkReadOnly, PutPropertySlot& slot); virtual void putWithAttributes(ExecState*, const Identifier& propertyName, JSValue value, unsigned attributes); virtual void putWithAttributes(ExecState*, unsigned propertyName, JSValue value, unsigned attributes); diff --git a/JavaScriptCore/runtime/JSValue.cpp b/JavaScriptCore/runtime/JSValue.cpp index 3a2d713..728cbcf 100644 --- a/JavaScriptCore/runtime/JSValue.cpp +++ b/JavaScriptCore/runtime/JSValue.cpp @@ -25,6 +25,7 @@ #include "BooleanConstructor.h" #include "BooleanPrototype.h" +#include "Error.h" #include "ExceptionHelpers.h" #include "JSGlobalObject.h" #include "JSFunction.h" @@ -63,7 +64,7 @@ JSObject* JSValue::toObjectSlowCase(ExecState* exec) const return constructBooleanFromImmediateBoolean(exec, asValue()); ASSERT(isUndefinedOrNull()); JSNotAnObjectErrorStub* exception = createNotAnObjectErrorStub(exec, isNull()); - exec->setException(exception); + throwError(exec, exception); return new (exec) JSNotAnObject(exec, exception); } @@ -88,7 +89,7 @@ JSObject* JSValue::synthesizeObject(ExecState* exec) const return constructBooleanFromImmediateBoolean(exec, asValue()); JSNotAnObjectErrorStub* exception = createNotAnObjectErrorStub(exec, isNull()); - exec->setException(exception); + throwError(exec, exception); return new (exec) JSNotAnObject(exec, exception); } @@ -101,7 +102,7 @@ JSObject* JSValue::synthesizePrototype(ExecState* exec) const return exec->lexicalGlobalObject()->booleanPrototype(); JSNotAnObjectErrorStub* exception = createNotAnObjectErrorStub(exec, isNull()); - exec->setException(exception); + throwError(exec, exception); return new (exec) JSNotAnObject(exec, exception); } diff --git a/JavaScriptCore/runtime/JSValue.h b/JavaScriptCore/runtime/JSValue.h index 914e2d5..9190f70 100644 --- a/JavaScriptCore/runtime/JSValue.h +++ b/JavaScriptCore/runtime/JSValue.h @@ -23,8 +23,6 @@ #ifndef JSValue_h #define JSValue_h -#include "CallData.h" -#include "ConstructData.h" #include <math.h> #include <stddef.h> // for size_t #include <stdint.h> @@ -35,6 +33,7 @@ namespace JSC { + class ExecState; class Identifier; class JSCell; class JSGlobalData; @@ -143,9 +142,6 @@ namespace JSC { UString getString(ExecState* exec) const; // null string if not a string JSObject* getObject() const; // 0 if not an object - CallType getCallData(CallData&); - ConstructType getConstructData(ConstructData&); - // Extracting integer values. bool getUInt32(uint32_t&) const; diff --git a/JavaScriptCore/runtime/MathObject.cpp b/JavaScriptCore/runtime/MathObject.cpp index 28997db..cfbaab2 100644 --- a/JavaScriptCore/runtime/MathObject.cpp +++ b/JavaScriptCore/runtime/MathObject.cpp @@ -34,24 +34,24 @@ namespace JSC { ASSERT_CLASS_FITS_IN_CELL(MathObject); -static JSValue JSC_HOST_CALL mathProtoFuncAbs(ExecState*); -static JSValue JSC_HOST_CALL mathProtoFuncACos(ExecState*); -static JSValue JSC_HOST_CALL mathProtoFuncASin(ExecState*); -static JSValue JSC_HOST_CALL mathProtoFuncATan(ExecState*); -static JSValue JSC_HOST_CALL mathProtoFuncATan2(ExecState*); -static JSValue JSC_HOST_CALL mathProtoFuncCeil(ExecState*); -static JSValue JSC_HOST_CALL mathProtoFuncCos(ExecState*); -static JSValue JSC_HOST_CALL mathProtoFuncExp(ExecState*); -static JSValue JSC_HOST_CALL mathProtoFuncFloor(ExecState*); -static JSValue JSC_HOST_CALL mathProtoFuncLog(ExecState*); -static JSValue JSC_HOST_CALL mathProtoFuncMax(ExecState*); -static JSValue JSC_HOST_CALL mathProtoFuncMin(ExecState*); -static JSValue JSC_HOST_CALL mathProtoFuncPow(ExecState*); -static JSValue JSC_HOST_CALL mathProtoFuncRandom(ExecState*); -static JSValue JSC_HOST_CALL mathProtoFuncRound(ExecState*); -static JSValue JSC_HOST_CALL mathProtoFuncSin(ExecState*); -static JSValue JSC_HOST_CALL mathProtoFuncSqrt(ExecState*); -static JSValue JSC_HOST_CALL mathProtoFuncTan(ExecState*); +static EncodedJSValue JSC_HOST_CALL mathProtoFuncAbs(ExecState*); +static EncodedJSValue JSC_HOST_CALL mathProtoFuncACos(ExecState*); +static EncodedJSValue JSC_HOST_CALL mathProtoFuncASin(ExecState*); +static EncodedJSValue JSC_HOST_CALL mathProtoFuncATan(ExecState*); +static EncodedJSValue JSC_HOST_CALL mathProtoFuncATan2(ExecState*); +static EncodedJSValue JSC_HOST_CALL mathProtoFuncCeil(ExecState*); +static EncodedJSValue JSC_HOST_CALL mathProtoFuncCos(ExecState*); +static EncodedJSValue JSC_HOST_CALL mathProtoFuncExp(ExecState*); +static EncodedJSValue JSC_HOST_CALL mathProtoFuncFloor(ExecState*); +static EncodedJSValue JSC_HOST_CALL mathProtoFuncLog(ExecState*); +static EncodedJSValue JSC_HOST_CALL mathProtoFuncMax(ExecState*); +static EncodedJSValue JSC_HOST_CALL mathProtoFuncMin(ExecState*); +static EncodedJSValue JSC_HOST_CALL mathProtoFuncPow(ExecState*); +static EncodedJSValue JSC_HOST_CALL mathProtoFuncRandom(ExecState*); +static EncodedJSValue JSC_HOST_CALL mathProtoFuncRound(ExecState*); +static EncodedJSValue JSC_HOST_CALL mathProtoFuncSin(ExecState*); +static EncodedJSValue JSC_HOST_CALL mathProtoFuncSqrt(ExecState*); +static EncodedJSValue JSC_HOST_CALL mathProtoFuncTan(ExecState*); } @@ -113,57 +113,57 @@ bool MathObject::getOwnPropertyDescriptor(ExecState* exec, const Identifier& pro // ------------------------------ Functions -------------------------------- -JSValue JSC_HOST_CALL mathProtoFuncAbs(ExecState* exec) +EncodedJSValue JSC_HOST_CALL mathProtoFuncAbs(ExecState* exec) { - return jsNumber(exec, fabs(exec->argument(0).toNumber(exec))); + return JSValue::encode(jsNumber(exec, fabs(exec->argument(0).toNumber(exec)))); } -JSValue JSC_HOST_CALL mathProtoFuncACos(ExecState* exec) +EncodedJSValue JSC_HOST_CALL mathProtoFuncACos(ExecState* exec) { - return jsDoubleNumber(exec, acos(exec->argument(0).toNumber(exec))); + return JSValue::encode(jsDoubleNumber(exec, acos(exec->argument(0).toNumber(exec)))); } -JSValue JSC_HOST_CALL mathProtoFuncASin(ExecState* exec) +EncodedJSValue JSC_HOST_CALL mathProtoFuncASin(ExecState* exec) { - return jsDoubleNumber(exec, asin(exec->argument(0).toNumber(exec))); + return JSValue::encode(jsDoubleNumber(exec, asin(exec->argument(0).toNumber(exec)))); } -JSValue JSC_HOST_CALL mathProtoFuncATan(ExecState* exec) +EncodedJSValue JSC_HOST_CALL mathProtoFuncATan(ExecState* exec) { - return jsDoubleNumber(exec, atan(exec->argument(0).toNumber(exec))); + return JSValue::encode(jsDoubleNumber(exec, atan(exec->argument(0).toNumber(exec)))); } -JSValue JSC_HOST_CALL mathProtoFuncATan2(ExecState* exec) +EncodedJSValue JSC_HOST_CALL mathProtoFuncATan2(ExecState* exec) { - return jsDoubleNumber(exec, atan2(exec->argument(0).toNumber(exec), exec->argument(1).toNumber(exec))); + return JSValue::encode(jsDoubleNumber(exec, atan2(exec->argument(0).toNumber(exec), exec->argument(1).toNumber(exec)))); } -JSValue JSC_HOST_CALL mathProtoFuncCeil(ExecState* exec) +EncodedJSValue JSC_HOST_CALL mathProtoFuncCeil(ExecState* exec) { - return jsNumber(exec, ceil(exec->argument(0).toNumber(exec))); + return JSValue::encode(jsNumber(exec, ceil(exec->argument(0).toNumber(exec)))); } -JSValue JSC_HOST_CALL mathProtoFuncCos(ExecState* exec) +EncodedJSValue JSC_HOST_CALL mathProtoFuncCos(ExecState* exec) { - return jsDoubleNumber(exec, cos(exec->argument(0).toNumber(exec))); + return JSValue::encode(jsDoubleNumber(exec, cos(exec->argument(0).toNumber(exec)))); } -JSValue JSC_HOST_CALL mathProtoFuncExp(ExecState* exec) +EncodedJSValue JSC_HOST_CALL mathProtoFuncExp(ExecState* exec) { - return jsDoubleNumber(exec, exp(exec->argument(0).toNumber(exec))); + return JSValue::encode(jsDoubleNumber(exec, exp(exec->argument(0).toNumber(exec)))); } -JSValue JSC_HOST_CALL mathProtoFuncFloor(ExecState* exec) +EncodedJSValue JSC_HOST_CALL mathProtoFuncFloor(ExecState* exec) { - return jsNumber(exec, floor(exec->argument(0).toNumber(exec))); + return JSValue::encode(jsNumber(exec, floor(exec->argument(0).toNumber(exec)))); } -JSValue JSC_HOST_CALL mathProtoFuncLog(ExecState* exec) +EncodedJSValue JSC_HOST_CALL mathProtoFuncLog(ExecState* exec) { - return jsDoubleNumber(exec, log(exec->argument(0).toNumber(exec))); + return JSValue::encode(jsDoubleNumber(exec, log(exec->argument(0).toNumber(exec)))); } -JSValue JSC_HOST_CALL mathProtoFuncMax(ExecState* exec) +EncodedJSValue JSC_HOST_CALL mathProtoFuncMax(ExecState* exec) { unsigned argsCount = exec->argumentCount(); double result = -Inf; @@ -176,10 +176,10 @@ JSValue JSC_HOST_CALL mathProtoFuncMax(ExecState* exec) if (val > result || (val == 0 && result == 0 && !signbit(val))) result = val; } - return jsNumber(exec, result); + return JSValue::encode(jsNumber(exec, result)); } -JSValue JSC_HOST_CALL mathProtoFuncMin(ExecState* exec) +EncodedJSValue JSC_HOST_CALL mathProtoFuncMin(ExecState* exec) { unsigned argsCount = exec->argumentCount(); double result = +Inf; @@ -192,10 +192,10 @@ JSValue JSC_HOST_CALL mathProtoFuncMin(ExecState* exec) if (val < result || (val == 0 && result == 0 && signbit(val))) result = val; } - return jsNumber(exec, result); + return JSValue::encode(jsNumber(exec, result)); } -JSValue JSC_HOST_CALL mathProtoFuncPow(ExecState* exec) +EncodedJSValue JSC_HOST_CALL mathProtoFuncPow(ExecState* exec) { // ECMA 15.8.2.1.13 @@ -203,37 +203,37 @@ JSValue JSC_HOST_CALL mathProtoFuncPow(ExecState* exec) double arg2 = exec->argument(1).toNumber(exec); if (isnan(arg2)) - return jsNaN(exec); + return JSValue::encode(jsNaN(exec)); if (isinf(arg2) && fabs(arg) == 1) - return jsNaN(exec); - return jsNumber(exec, pow(arg, arg2)); + return JSValue::encode(jsNaN(exec)); + return JSValue::encode(jsNumber(exec, pow(arg, arg2))); } -JSValue JSC_HOST_CALL mathProtoFuncRandom(ExecState* exec) +EncodedJSValue JSC_HOST_CALL mathProtoFuncRandom(ExecState* exec) { - return jsDoubleNumber(exec, exec->globalData().weakRandom.get()); + return JSValue::encode(jsDoubleNumber(exec, exec->globalData().weakRandom.get())); } -JSValue JSC_HOST_CALL mathProtoFuncRound(ExecState* exec) +EncodedJSValue JSC_HOST_CALL mathProtoFuncRound(ExecState* exec) { double arg = exec->argument(0).toNumber(exec); double integer = ceil(arg); - return jsNumber(exec, integer - (integer - arg > 0.5)); + return JSValue::encode(jsNumber(exec, integer - (integer - arg > 0.5))); } -JSValue JSC_HOST_CALL mathProtoFuncSin(ExecState* exec) +EncodedJSValue JSC_HOST_CALL mathProtoFuncSin(ExecState* exec) { - return exec->globalData().cachedSin(exec, exec->argument(0).toNumber(exec)); + return JSValue::encode(exec->globalData().cachedSin(exec, exec->argument(0).toNumber(exec))); } -JSValue JSC_HOST_CALL mathProtoFuncSqrt(ExecState* exec) +EncodedJSValue JSC_HOST_CALL mathProtoFuncSqrt(ExecState* exec) { - return jsDoubleNumber(exec, sqrt(exec->argument(0).toNumber(exec))); + return JSValue::encode(jsDoubleNumber(exec, sqrt(exec->argument(0).toNumber(exec)))); } -JSValue JSC_HOST_CALL mathProtoFuncTan(ExecState* exec) +EncodedJSValue JSC_HOST_CALL mathProtoFuncTan(ExecState* exec) { - return jsDoubleNumber(exec, tan(exec->argument(0).toNumber(exec))); + return JSValue::encode(jsDoubleNumber(exec, tan(exec->argument(0).toNumber(exec)))); } } // namespace JSC diff --git a/JavaScriptCore/runtime/NativeErrorConstructor.cpp b/JavaScriptCore/runtime/NativeErrorConstructor.cpp index 32ae6b8..31f9bc3 100644 --- a/JavaScriptCore/runtime/NativeErrorConstructor.cpp +++ b/JavaScriptCore/runtime/NativeErrorConstructor.cpp @@ -42,18 +42,11 @@ NativeErrorConstructor::NativeErrorConstructor(ExecState* exec, JSGlobalObject* m_errorStructure = ErrorInstance::createStructure(prototype); } - -ErrorInstance* NativeErrorConstructor::construct(ExecState* exec, const ArgList& args) -{ - ErrorInstance* object = new (exec) ErrorInstance(m_errorStructure); - if (!args.at(0).isUndefined()) - object->putDirect(exec->propertyNames().message, jsString(exec, args.at(0).toString(exec))); - return object; -} - -static JSObject* constructWithNativeErrorConstructor(ExecState* exec, JSObject* constructor, const ArgList& args) +static EncodedJSValue JSC_HOST_CALL constructWithNativeErrorConstructor(ExecState* exec) { - return static_cast<NativeErrorConstructor*>(constructor)->construct(exec, args); + JSValue message = exec->argumentCount() ? exec->argument(0) : jsUndefined(); + Structure* errorStructure = static_cast<NativeErrorConstructor*>(exec->callee())->errorStructure(); + return JSValue::encode(ErrorInstance::create(exec, errorStructure, message)); } ConstructType NativeErrorConstructor::getConstructData(ConstructData& constructData) @@ -62,10 +55,11 @@ ConstructType NativeErrorConstructor::getConstructData(ConstructData& constructD return ConstructTypeHost; } -static JSValue JSC_HOST_CALL callNativeErrorConstructor(ExecState* exec) +static EncodedJSValue JSC_HOST_CALL callNativeErrorConstructor(ExecState* exec) { - ArgList args(exec); - return static_cast<NativeErrorConstructor*>(exec->callee())->construct(exec, args); + JSValue message = exec->argumentCount() ? exec->argument(0) : jsUndefined(); + Structure* errorStructure = static_cast<NativeErrorConstructor*>(exec->callee())->errorStructure(); + return JSValue::encode(ErrorInstance::create(exec, errorStructure, message)); } CallType NativeErrorConstructor::getCallData(CallData& callData) diff --git a/JavaScriptCore/runtime/NativeErrorConstructor.h b/JavaScriptCore/runtime/NativeErrorConstructor.h index 0153309..1ff8207 100644 --- a/JavaScriptCore/runtime/NativeErrorConstructor.h +++ b/JavaScriptCore/runtime/NativeErrorConstructor.h @@ -35,7 +35,7 @@ namespace JSC { static const ClassInfo info; - ErrorInstance* construct(ExecState*, const ArgList&); + Structure* errorStructure() { return m_errorStructure.get(); } private: virtual ConstructType getConstructData(ConstructData&); diff --git a/JavaScriptCore/runtime/NumberConstructor.cpp b/JavaScriptCore/runtime/NumberConstructor.cpp index fe91f2e..a197952 100644 --- a/JavaScriptCore/runtime/NumberConstructor.cpp +++ b/JavaScriptCore/runtime/NumberConstructor.cpp @@ -100,12 +100,12 @@ static JSValue numberConstructorMinValue(ExecState* exec, JSValue, const Identif } // ECMA 15.7.1 -static JSObject* constructWithNumberConstructor(ExecState* exec, JSObject*, const ArgList& args) +static EncodedJSValue JSC_HOST_CALL constructWithNumberConstructor(ExecState* exec) { NumberObject* object = new (exec) NumberObject(exec->lexicalGlobalObject()->numberObjectStructure()); - double n = args.isEmpty() ? 0 : args.at(0).toNumber(exec); + double n = exec->argumentCount() ? exec->argument(0).toNumber(exec) : 0; object->setInternalValue(jsNumber(exec, n)); - return object; + return JSValue::encode(object); } ConstructType NumberConstructor::getConstructData(ConstructData& constructData) @@ -115,9 +115,9 @@ ConstructType NumberConstructor::getConstructData(ConstructData& constructData) } // ECMA 15.7.2 -static JSValue JSC_HOST_CALL callNumberConstructor(ExecState* exec) +static EncodedJSValue JSC_HOST_CALL callNumberConstructor(ExecState* exec) { - return jsNumber(exec, !exec->argumentCount() ? 0 : exec->argument(0).toNumber(exec)); + return JSValue::encode(jsNumber(exec, !exec->argumentCount() ? 0 : exec->argument(0).toNumber(exec))); } CallType NumberConstructor::getCallData(CallData& callData) diff --git a/JavaScriptCore/runtime/NumberPrototype.cpp b/JavaScriptCore/runtime/NumberPrototype.cpp index 0f1590c..e338d7c 100644 --- a/JavaScriptCore/runtime/NumberPrototype.cpp +++ b/JavaScriptCore/runtime/NumberPrototype.cpp @@ -38,12 +38,12 @@ namespace JSC { ASSERT_CLASS_FITS_IN_CELL(NumberPrototype); -static JSValue JSC_HOST_CALL numberProtoFuncToString(ExecState*); -static JSValue JSC_HOST_CALL numberProtoFuncToLocaleString(ExecState*); -static JSValue JSC_HOST_CALL numberProtoFuncValueOf(ExecState*); -static JSValue JSC_HOST_CALL numberProtoFuncToFixed(ExecState*); -static JSValue JSC_HOST_CALL numberProtoFuncToExponential(ExecState*); -static JSValue JSC_HOST_CALL numberProtoFuncToPrecision(ExecState*); +static EncodedJSValue JSC_HOST_CALL numberProtoFuncToString(ExecState*); +static EncodedJSValue JSC_HOST_CALL numberProtoFuncToLocaleString(ExecState*); +static EncodedJSValue JSC_HOST_CALL numberProtoFuncValueOf(ExecState*); +static EncodedJSValue JSC_HOST_CALL numberProtoFuncToFixed(ExecState*); +static EncodedJSValue JSC_HOST_CALL numberProtoFuncToExponential(ExecState*); +static EncodedJSValue JSC_HOST_CALL numberProtoFuncToPrecision(ExecState*); // ECMA 15.7.4 @@ -137,12 +137,12 @@ static double intPow10(int e) return static_cast<double>(result); } -JSValue JSC_HOST_CALL numberProtoFuncToString(ExecState* exec) +EncodedJSValue JSC_HOST_CALL numberProtoFuncToString(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); JSValue v = thisValue.getJSNumber(); if (!v) - return throwError(exec, TypeError); + return throwVMTypeError(exec); JSValue radixValue = exec->argument(0); int radix; @@ -154,7 +154,7 @@ JSValue JSC_HOST_CALL numberProtoFuncToString(ExecState* exec) radix = static_cast<int>(radixValue.toInteger(exec)); // nan -> 0 if (radix == 10) - return jsString(exec, v.toString(exec)); + return JSValue::encode(jsString(exec, v.toString(exec))); static const char* const digits = "0123456789abcdefghijklmnopqrstuvwxyz"; @@ -164,13 +164,13 @@ JSValue JSC_HOST_CALL numberProtoFuncToString(ExecState* exec) int x = v.asInt32(); if (static_cast<unsigned>(x) < 36) { // Exclude negatives JSGlobalData* globalData = &exec->globalData(); - return globalData->smallStrings.singleCharacterString(globalData, digits[x]); + return JSValue::encode(globalData->smallStrings.singleCharacterString(globalData, digits[x])); } } } if (radix < 2 || radix > 36) - return throwError(exec, RangeError, "toString() radix argument must be between 2 and 36"); + return throwVMError(exec, createRangeError(exec, "toString() radix argument must be between 2 and 36")); // INT_MAX results in 1024 characters left of the dot with radix 2 // give the same space on the right side. safety checks are in place @@ -179,7 +179,7 @@ JSValue JSC_HOST_CALL numberProtoFuncToString(ExecState* exec) const char* lastCharInString = s + sizeof(s) - 1; double x = v.uncheckedGetNumber(); if (isnan(x) || isinf(x)) - return jsString(exec, UString::from(x)); + return JSValue::encode(jsString(exec, UString::from(x))); bool isNegative = x < 0.0; if (isNegative) @@ -218,47 +218,47 @@ JSValue JSC_HOST_CALL numberProtoFuncToString(ExecState* exec) *p = '\0'; ASSERT(p < s + sizeof(s)); - return jsString(exec, startOfResultString); + return JSValue::encode(jsString(exec, startOfResultString)); } -JSValue JSC_HOST_CALL numberProtoFuncToLocaleString(ExecState* exec) +EncodedJSValue JSC_HOST_CALL numberProtoFuncToLocaleString(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); // FIXME: Not implemented yet. JSValue v = thisValue.getJSNumber(); if (!v) - return throwError(exec, TypeError); + return throwVMTypeError(exec); - return jsString(exec, v.toString(exec)); + return JSValue::encode(jsString(exec, v.toString(exec))); } -JSValue JSC_HOST_CALL numberProtoFuncValueOf(ExecState* exec) +EncodedJSValue JSC_HOST_CALL numberProtoFuncValueOf(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); JSValue v = thisValue.getJSNumber(); if (!v) - return throwError(exec, TypeError); + return throwVMTypeError(exec); - return v; + return JSValue::encode(v); } -JSValue JSC_HOST_CALL numberProtoFuncToFixed(ExecState* exec) +EncodedJSValue JSC_HOST_CALL numberProtoFuncToFixed(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); JSValue v = thisValue.getJSNumber(); if (!v) - return throwError(exec, TypeError); + return throwVMTypeError(exec); JSValue fractionDigits = exec->argument(0); double df = fractionDigits.toInteger(exec); if (!(df >= 0 && df <= 20)) - return throwError(exec, RangeError, "toFixed() digits argument must be between 0 and 20"); + return throwVMError(exec, createRangeError(exec, "toFixed() digits argument must be between 0 and 20")); int f = static_cast<int>(df); double x = v.uncheckedGetNumber(); if (isnan(x)) - return jsNontrivialString(exec, "NaN"); + return JSValue::encode(jsNontrivialString(exec, "NaN")); UString s; if (x < 0) { @@ -271,7 +271,7 @@ JSValue JSC_HOST_CALL numberProtoFuncToFixed(ExecState* exec) } if (x >= pow(10.0, 21.0)) - return jsString(exec, makeString(s, UString::from(x))); + return JSValue::encode(jsString(exec, makeString(s, UString::from(x)))); const double tenToTheF = pow(10.0, f); double n = floor(x * tenToTheF); @@ -293,8 +293,8 @@ JSValue JSC_HOST_CALL numberProtoFuncToFixed(ExecState* exec) int kMinusf = k - f; if (kMinusf < static_cast<int>(m.size())) - return jsString(exec, makeString(s, m.substr(0, kMinusf), ".", m.substr(kMinusf))); - return jsString(exec, makeString(s, m.substr(0, kMinusf))); + return JSValue::encode(jsString(exec, makeString(s, m.substr(0, kMinusf), ".", m.substr(kMinusf)))); + return JSValue::encode(jsString(exec, makeString(s, m.substr(0, kMinusf)))); } static void fractionalPartToString(char* buf, int& i, const char* result, int resultLength, int fractionalDigits) @@ -335,22 +335,22 @@ static void exponentialPartToString(char* buf, int& i, int decimalPoint) buf[i++] = static_cast<char>('0' + exponential % 10); } -JSValue JSC_HOST_CALL numberProtoFuncToExponential(ExecState* exec) +EncodedJSValue JSC_HOST_CALL numberProtoFuncToExponential(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); JSValue v = thisValue.getJSNumber(); if (!v) - return throwError(exec, TypeError); + return throwVMTypeError(exec); double x = v.uncheckedGetNumber(); if (isnan(x) || isinf(x)) - return jsString(exec, UString::from(x)); + return JSValue::encode(jsString(exec, UString::from(x))); JSValue fractionalDigitsValue = exec->argument(0); double df = fractionalDigitsValue.toInteger(exec); if (!(df >= 0 && df <= 20)) - return throwError(exec, RangeError, "toExponential() argument must between 0 and 20"); + return throwVMError(exec, createRangeError(exec, "toExponential() argument must between 0 and 20")); int fractionalDigits = static_cast<int>(df); bool includeAllDigits = fractionalDigitsValue.isUndefined(); @@ -371,7 +371,7 @@ JSValue JSC_HOST_CALL numberProtoFuncToExponential(ExecState* exec) } if (isnan(x)) - return jsNontrivialString(exec, "NaN"); + return JSValue::encode(jsNontrivialString(exec, "NaN")); if (x == -0.0) // (-0.0).toExponential() should print as 0 instead of -0 x = 0; @@ -405,20 +405,20 @@ JSValue JSC_HOST_CALL numberProtoFuncToExponential(ExecState* exec) } ASSERT(i <= 80); - return jsString(exec, buf); + return JSValue::encode(jsString(exec, buf)); } -JSValue JSC_HOST_CALL numberProtoFuncToPrecision(ExecState* exec) +EncodedJSValue JSC_HOST_CALL numberProtoFuncToPrecision(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); JSValue v = thisValue.getJSNumber(); if (!v) - return throwError(exec, TypeError); + return throwVMTypeError(exec); double doublePrecision = exec->argument(0).toIntegerPreserveNaN(exec); double x = v.uncheckedGetNumber(); if (exec->argument(0).isUndefined() || isnan(x) || isinf(x)) - return jsString(exec, v.toString(exec)); + return JSValue::encode(jsString(exec, v.toString(exec))); UString s; if (x < 0) { @@ -428,7 +428,7 @@ JSValue JSC_HOST_CALL numberProtoFuncToPrecision(ExecState* exec) s = ""; if (!(doublePrecision >= 1 && doublePrecision <= 21)) // true for NaN - return throwError(exec, RangeError, "toPrecision() argument must be between 1 and 21"); + return throwVMError(exec, createRangeError(exec, "toPrecision() argument must be between 1 and 21")); int precision = static_cast<int>(doublePrecision); int e = 0; @@ -458,8 +458,8 @@ JSValue JSC_HOST_CALL numberProtoFuncToPrecision(ExecState* exec) if (m.size() > 1) m = makeString(m.substr(0, 1), ".", m.substr(1)); if (e >= 0) - return jsMakeNontrivialString(exec, s, m, "e+", UString::from(e)); - return jsMakeNontrivialString(exec, s, m, "e-", UString::from(-e)); + return JSValue::encode(jsMakeNontrivialString(exec, s, m, "e+", UString::from(e))); + return JSValue::encode(jsMakeNontrivialString(exec, s, m, "e-", UString::from(-e))); } } else { m = charSequence('0', precision); @@ -467,13 +467,13 @@ JSValue JSC_HOST_CALL numberProtoFuncToPrecision(ExecState* exec) } if (e == precision - 1) - return jsString(exec, makeString(s, m)); + return JSValue::encode(jsString(exec, makeString(s, m))); if (e >= 0) { if (e + 1 < static_cast<int>(m.size())) - return jsString(exec, makeString(s, m.substr(0, e + 1), ".", m.substr(e + 1))); - return jsString(exec, makeString(s, m)); + return JSValue::encode(jsString(exec, makeString(s, m.substr(0, e + 1), ".", m.substr(e + 1)))); + return JSValue::encode(jsString(exec, makeString(s, m))); } - return jsMakeNontrivialString(exec, s, "0.", charSequence('0', -(e + 1)), m); + return JSValue::encode(jsMakeNontrivialString(exec, s, "0.", charSequence('0', -(e + 1)), m)); } } // namespace JSC diff --git a/JavaScriptCore/runtime/ObjectConstructor.cpp b/JavaScriptCore/runtime/ObjectConstructor.cpp index c373f87..b1f9d70 100644 --- a/JavaScriptCore/runtime/ObjectConstructor.cpp +++ b/JavaScriptCore/runtime/ObjectConstructor.cpp @@ -22,6 +22,7 @@ #include "ObjectConstructor.h" #include "Error.h" +#include "ExceptionHelpers.h" #include "JSFunction.h" #include "JSArray.h" #include "JSGlobalObject.h" @@ -34,13 +35,13 @@ namespace JSC { ASSERT_CLASS_FITS_IN_CELL(ObjectConstructor); -static JSValue JSC_HOST_CALL objectConstructorGetPrototypeOf(ExecState*); -static JSValue JSC_HOST_CALL objectConstructorGetOwnPropertyDescriptor(ExecState*); -static JSValue JSC_HOST_CALL objectConstructorGetOwnPropertyNames(ExecState*); -static JSValue JSC_HOST_CALL objectConstructorKeys(ExecState*); -static JSValue JSC_HOST_CALL objectConstructorDefineProperty(ExecState*); -static JSValue JSC_HOST_CALL objectConstructorDefineProperties(ExecState*); -static JSValue JSC_HOST_CALL objectConstructorCreate(ExecState*); +static EncodedJSValue JSC_HOST_CALL objectConstructorGetPrototypeOf(ExecState*); +static EncodedJSValue JSC_HOST_CALL objectConstructorGetOwnPropertyDescriptor(ExecState*); +static EncodedJSValue JSC_HOST_CALL objectConstructorGetOwnPropertyNames(ExecState*); +static EncodedJSValue JSC_HOST_CALL objectConstructorKeys(ExecState*); +static EncodedJSValue JSC_HOST_CALL objectConstructorDefineProperty(ExecState*); +static EncodedJSValue JSC_HOST_CALL objectConstructorDefineProperties(ExecState*); +static EncodedJSValue JSC_HOST_CALL objectConstructorCreate(ExecState*); ObjectConstructor::ObjectConstructor(ExecState* exec, JSGlobalObject* globalObject, NonNullPassRefPtr<Structure> structure, ObjectPrototype* objectPrototype, Structure* prototypeFunctionStructure) : InternalFunction(&exec->globalData(), globalObject, structure, Identifier(exec, "Object")) @@ -69,9 +70,10 @@ static ALWAYS_INLINE JSObject* constructObject(ExecState* exec, const ArgList& a return arg.toObject(exec); } -static JSObject* constructWithObjectConstructor(ExecState* exec, JSObject*, const ArgList& args) +static EncodedJSValue JSC_HOST_CALL constructWithObjectConstructor(ExecState* exec) { - return constructObject(exec, args); + ArgList args(exec); + return JSValue::encode(constructObject(exec, args)); } ConstructType ObjectConstructor::getConstructData(ConstructData& constructData) @@ -80,10 +82,10 @@ ConstructType ObjectConstructor::getConstructData(ConstructData& constructData) return ConstructTypeHost; } -static JSValue JSC_HOST_CALL callObjectConstructor(ExecState* exec) +static EncodedJSValue JSC_HOST_CALL callObjectConstructor(ExecState* exec) { ArgList args(exec); - return constructObject(exec, args); + return JSValue::encode(constructObject(exec, args)); } CallType ObjectConstructor::getCallData(CallData& callData) @@ -92,26 +94,26 @@ CallType ObjectConstructor::getCallData(CallData& callData) return CallTypeHost; } -JSValue JSC_HOST_CALL objectConstructorGetPrototypeOf(ExecState* exec) +EncodedJSValue JSC_HOST_CALL objectConstructorGetPrototypeOf(ExecState* exec) { if (!exec->argument(0).isObject()) - return throwError(exec, TypeError, "Requested prototype of a value that is not an object."); - return asObject(exec->argument(0))->prototype(); + return throwVMError(exec, createTypeError(exec, "Requested prototype of a value that is not an object.")); + return JSValue::encode(asObject(exec->argument(0))->prototype()); } -JSValue JSC_HOST_CALL objectConstructorGetOwnPropertyDescriptor(ExecState* exec) +EncodedJSValue JSC_HOST_CALL objectConstructorGetOwnPropertyDescriptor(ExecState* exec) { if (!exec->argument(0).isObject()) - return throwError(exec, TypeError, "Requested property descriptor of a value that is not an object."); + return throwVMError(exec, createTypeError(exec, "Requested property descriptor of a value that is not an object.")); UString propertyName = exec->argument(1).toString(exec); if (exec->hadException()) - return jsNull(); + return JSValue::encode(jsNull()); JSObject* object = asObject(exec->argument(0)); PropertyDescriptor descriptor; if (!object->getOwnPropertyDescriptor(exec, Identifier(exec, propertyName), descriptor)) - return jsUndefined(); + return JSValue::encode(jsUndefined()); if (exec->hadException()) - return jsUndefined(); + return JSValue::encode(jsUndefined()); JSObject* description = constructEmptyObject(exec); if (!descriptor.isAccessorDescriptor()) { @@ -125,42 +127,42 @@ JSValue JSC_HOST_CALL objectConstructorGetOwnPropertyDescriptor(ExecState* exec) description->putDirect(exec->propertyNames().enumerable, jsBoolean(descriptor.enumerable()), 0); description->putDirect(exec->propertyNames().configurable, jsBoolean(descriptor.configurable()), 0); - return description; + return JSValue::encode(description); } // FIXME: Use the enumeration cache. -JSValue JSC_HOST_CALL objectConstructorGetOwnPropertyNames(ExecState* exec) +EncodedJSValue JSC_HOST_CALL objectConstructorGetOwnPropertyNames(ExecState* exec) { if (!exec->argument(0).isObject()) - return throwError(exec, TypeError, "Requested property names of a value that is not an object."); + return throwVMError(exec, createTypeError(exec, "Requested property names of a value that is not an object.")); PropertyNameArray properties(exec); asObject(exec->argument(0))->getOwnPropertyNames(exec, properties, IncludeDontEnumProperties); JSArray* names = constructEmptyArray(exec); size_t numProperties = properties.size(); for (size_t i = 0; i < numProperties; i++) names->push(exec, jsOwnedString(exec, properties[i].ustring())); - return names; + return JSValue::encode(names); } // FIXME: Use the enumeration cache. -JSValue JSC_HOST_CALL objectConstructorKeys(ExecState* exec) +EncodedJSValue JSC_HOST_CALL objectConstructorKeys(ExecState* exec) { if (!exec->argument(0).isObject()) - return throwError(exec, TypeError, "Requested keys of a value that is not an object."); + return throwVMError(exec, createTypeError(exec, "Requested keys of a value that is not an object.")); PropertyNameArray properties(exec); asObject(exec->argument(0))->getOwnPropertyNames(exec, properties); JSArray* keys = constructEmptyArray(exec); size_t numProperties = properties.size(); for (size_t i = 0; i < numProperties; i++) keys->push(exec, jsOwnedString(exec, properties[i].ustring())); - return keys; + return JSValue::encode(keys); } // ES5 8.10.5 ToPropertyDescriptor static bool toPropertyDescriptor(ExecState* exec, JSValue in, PropertyDescriptor& desc) { if (!in.isObject()) { - throwError(exec, TypeError, "Property description must be an object."); + throwError(exec, createTypeError(exec, "Property description must be an object.")); return false; } JSObject* description = asObject(in); @@ -201,8 +203,8 @@ static bool toPropertyDescriptor(ExecState* exec, JSValue in, PropertyDescriptor return false; if (!get.isUndefined()) { CallData callData; - if (get.getCallData(callData) == CallTypeNone) { - throwError(exec, TypeError, "Getter must be a function."); + if (getCallData(get, callData) == CallTypeNone) { + throwError(exec, createTypeError(exec, "Getter must be a function.")); return false; } } else @@ -217,8 +219,8 @@ static bool toPropertyDescriptor(ExecState* exec, JSValue in, PropertyDescriptor return false; if (!set.isUndefined()) { CallData callData; - if (set.getCallData(callData) == CallTypeNone) { - throwError(exec, TypeError, "Setter must be a function."); + if (getCallData(set, callData) == CallTypeNone) { + throwError(exec, createTypeError(exec, "Setter must be a function.")); return false; } } else @@ -231,32 +233,32 @@ static bool toPropertyDescriptor(ExecState* exec, JSValue in, PropertyDescriptor return true; if (desc.value()) { - throwError(exec, TypeError, "Invalid property. 'value' present on property with getter or setter."); + throwError(exec, createTypeError(exec, "Invalid property. 'value' present on property with getter or setter.")); return false; } if (desc.writablePresent()) { - throwError(exec, TypeError, "Invalid property. 'writable' present on property with getter or setter."); + throwError(exec, createTypeError(exec, "Invalid property. 'writable' present on property with getter or setter.")); return false; } return true; } -JSValue JSC_HOST_CALL objectConstructorDefineProperty(ExecState* exec) +EncodedJSValue JSC_HOST_CALL objectConstructorDefineProperty(ExecState* exec) { if (!exec->argument(0).isObject()) - return throwError(exec, TypeError, "Properties can only be defined on Objects."); + return throwVMError(exec, createTypeError(exec, "Properties can only be defined on Objects.")); JSObject* O = asObject(exec->argument(0)); UString propertyName = exec->argument(1).toString(exec); if (exec->hadException()) - return jsNull(); + return JSValue::encode(jsNull()); PropertyDescriptor descriptor; if (!toPropertyDescriptor(exec, exec->argument(2), descriptor)) - return jsNull(); + return JSValue::encode(jsNull()); ASSERT((descriptor.attributes() & (Getter | Setter)) || (!descriptor.isAccessorDescriptor())); ASSERT(!exec->hadException()); O->defineOwnProperty(exec, Identifier(exec, propertyName), descriptor, true); - return O; + return JSValue::encode(O); } static JSValue defineProperties(ExecState* exec, JSObject* object, JSObject* properties) @@ -293,26 +295,26 @@ static JSValue defineProperties(ExecState* exec, JSObject* object, JSObject* pro return object; } -JSValue JSC_HOST_CALL objectConstructorDefineProperties(ExecState* exec) +EncodedJSValue JSC_HOST_CALL objectConstructorDefineProperties(ExecState* exec) { if (!exec->argument(0).isObject()) - return throwError(exec, TypeError, "Properties can only be defined on Objects."); + return throwVMError(exec, createTypeError(exec, "Properties can only be defined on Objects.")); if (!exec->argument(1).isObject()) - return throwError(exec, TypeError, "Property descriptor list must be an Object."); - return defineProperties(exec, asObject(exec->argument(0)), asObject(exec->argument(1))); + return throwVMError(exec, createTypeError(exec, "Property descriptor list must be an Object.")); + return JSValue::encode(defineProperties(exec, asObject(exec->argument(0)), asObject(exec->argument(1)))); } -JSValue JSC_HOST_CALL objectConstructorCreate(ExecState* exec) +EncodedJSValue JSC_HOST_CALL objectConstructorCreate(ExecState* exec) { if (!exec->argument(0).isObject() && !exec->argument(0).isNull()) - return throwError(exec, TypeError, "Object prototype may only be an Object or null."); + return throwVMError(exec, createTypeError(exec, "Object prototype may only be an Object or null.")); JSObject* newObject = constructEmptyObject(exec); newObject->setPrototype(exec->argument(0)); if (exec->argument(1).isUndefined()) - return newObject; + return JSValue::encode(newObject); if (!exec->argument(1).isObject()) - return throwError(exec, TypeError, "Property descriptor list must be an Object."); - return defineProperties(exec, newObject, asObject(exec->argument(1))); + return throwVMError(exec, createTypeError(exec, "Property descriptor list must be an Object.")); + return JSValue::encode(defineProperties(exec, newObject, asObject(exec->argument(1)))); } } // namespace JSC diff --git a/JavaScriptCore/runtime/ObjectPrototype.cpp b/JavaScriptCore/runtime/ObjectPrototype.cpp index 87212da..6197f75 100644 --- a/JavaScriptCore/runtime/ObjectPrototype.cpp +++ b/JavaScriptCore/runtime/ObjectPrototype.cpp @@ -31,15 +31,15 @@ namespace JSC { ASSERT_CLASS_FITS_IN_CELL(ObjectPrototype); -static JSValue JSC_HOST_CALL objectProtoFuncValueOf(ExecState*); -static JSValue JSC_HOST_CALL objectProtoFuncHasOwnProperty(ExecState*); -static JSValue JSC_HOST_CALL objectProtoFuncIsPrototypeOf(ExecState*); -static JSValue JSC_HOST_CALL objectProtoFuncDefineGetter(ExecState*); -static JSValue JSC_HOST_CALL objectProtoFuncDefineSetter(ExecState*); -static JSValue JSC_HOST_CALL objectProtoFuncLookupGetter(ExecState*); -static JSValue JSC_HOST_CALL objectProtoFuncLookupSetter(ExecState*); -static JSValue JSC_HOST_CALL objectProtoFuncPropertyIsEnumerable(ExecState*); -static JSValue JSC_HOST_CALL objectProtoFuncToLocaleString(ExecState*); +static EncodedJSValue JSC_HOST_CALL objectProtoFuncValueOf(ExecState*); +static EncodedJSValue JSC_HOST_CALL objectProtoFuncHasOwnProperty(ExecState*); +static EncodedJSValue JSC_HOST_CALL objectProtoFuncIsPrototypeOf(ExecState*); +static EncodedJSValue JSC_HOST_CALL objectProtoFuncDefineGetter(ExecState*); +static EncodedJSValue JSC_HOST_CALL objectProtoFuncDefineSetter(ExecState*); +static EncodedJSValue JSC_HOST_CALL objectProtoFuncLookupGetter(ExecState*); +static EncodedJSValue JSC_HOST_CALL objectProtoFuncLookupSetter(ExecState*); +static EncodedJSValue JSC_HOST_CALL objectProtoFuncPropertyIsEnumerable(ExecState*); +static EncodedJSValue JSC_HOST_CALL objectProtoFuncToLocaleString(ExecState*); ObjectPrototype::ObjectPrototype(ExecState* exec, JSGlobalObject* globalObject, NonNullPassRefPtr<Structure> stucture, Structure* prototypeFunctionStructure) : JSObject(stucture) @@ -81,85 +81,85 @@ bool ObjectPrototype::getOwnPropertySlot(ExecState* exec, unsigned propertyName, // ECMA 15.2.4.2, 15.2.4.4, 15.2.4.5, 15.2.4.7 -JSValue JSC_HOST_CALL objectProtoFuncValueOf(ExecState* exec) +EncodedJSValue JSC_HOST_CALL objectProtoFuncValueOf(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); - return thisValue.toThisObject(exec); + return JSValue::encode(thisValue.toThisObject(exec)); } -JSValue JSC_HOST_CALL objectProtoFuncHasOwnProperty(ExecState* exec) +EncodedJSValue JSC_HOST_CALL objectProtoFuncHasOwnProperty(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); - return jsBoolean(thisValue.toThisObject(exec)->hasOwnProperty(exec, Identifier(exec, exec->argument(0).toString(exec)))); + return JSValue::encode(jsBoolean(thisValue.toThisObject(exec)->hasOwnProperty(exec, Identifier(exec, exec->argument(0).toString(exec))))); } -JSValue JSC_HOST_CALL objectProtoFuncIsPrototypeOf(ExecState* exec) +EncodedJSValue JSC_HOST_CALL objectProtoFuncIsPrototypeOf(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); JSObject* thisObj = thisValue.toThisObject(exec); if (!exec->argument(0).isObject()) - return jsBoolean(false); + return JSValue::encode(jsBoolean(false)); JSValue v = asObject(exec->argument(0))->prototype(); while (true) { if (!v.isObject()) - return jsBoolean(false); + return JSValue::encode(jsBoolean(false)); if (v == thisObj) - return jsBoolean(true); + return JSValue::encode(jsBoolean(true)); v = asObject(v)->prototype(); } } -JSValue JSC_HOST_CALL objectProtoFuncDefineGetter(ExecState* exec) +EncodedJSValue JSC_HOST_CALL objectProtoFuncDefineGetter(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); CallData callData; - if (exec->argument(1).getCallData(callData) == CallTypeNone) - return throwError(exec, SyntaxError, "invalid getter usage"); + if (getCallData(exec->argument(1), callData) == CallTypeNone) + return throwVMError(exec, createSyntaxError(exec, "invalid getter usage")); thisValue.toThisObject(exec)->defineGetter(exec, Identifier(exec, exec->argument(0).toString(exec)), asObject(exec->argument(1))); - return jsUndefined(); + return JSValue::encode(jsUndefined()); } -JSValue JSC_HOST_CALL objectProtoFuncDefineSetter(ExecState* exec) +EncodedJSValue JSC_HOST_CALL objectProtoFuncDefineSetter(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); CallData callData; - if (exec->argument(1).getCallData(callData) == CallTypeNone) - return throwError(exec, SyntaxError, "invalid setter usage"); + if (getCallData(exec->argument(1), callData) == CallTypeNone) + return throwVMError(exec, createSyntaxError(exec, "invalid setter usage")); thisValue.toThisObject(exec)->defineSetter(exec, Identifier(exec, exec->argument(0).toString(exec)), asObject(exec->argument(1))); - return jsUndefined(); + return JSValue::encode(jsUndefined()); } -JSValue JSC_HOST_CALL objectProtoFuncLookupGetter(ExecState* exec) +EncodedJSValue JSC_HOST_CALL objectProtoFuncLookupGetter(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); - return thisValue.toThisObject(exec)->lookupGetter(exec, Identifier(exec, exec->argument(0).toString(exec))); + return JSValue::encode(thisValue.toThisObject(exec)->lookupGetter(exec, Identifier(exec, exec->argument(0).toString(exec)))); } -JSValue JSC_HOST_CALL objectProtoFuncLookupSetter(ExecState* exec) +EncodedJSValue JSC_HOST_CALL objectProtoFuncLookupSetter(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); - return thisValue.toThisObject(exec)->lookupSetter(exec, Identifier(exec, exec->argument(0).toString(exec))); + return JSValue::encode(thisValue.toThisObject(exec)->lookupSetter(exec, Identifier(exec, exec->argument(0).toString(exec)))); } -JSValue JSC_HOST_CALL objectProtoFuncPropertyIsEnumerable(ExecState* exec) +EncodedJSValue JSC_HOST_CALL objectProtoFuncPropertyIsEnumerable(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); - return jsBoolean(thisValue.toThisObject(exec)->propertyIsEnumerable(exec, Identifier(exec, exec->argument(0).toString(exec)))); + return JSValue::encode(jsBoolean(thisValue.toThisObject(exec)->propertyIsEnumerable(exec, Identifier(exec, exec->argument(0).toString(exec))))); } -JSValue JSC_HOST_CALL objectProtoFuncToLocaleString(ExecState* exec) +EncodedJSValue JSC_HOST_CALL objectProtoFuncToLocaleString(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); - return thisValue.toThisJSString(exec); + return JSValue::encode(thisValue.toThisJSString(exec)); } -JSValue JSC_HOST_CALL objectProtoFuncToString(ExecState* exec) +EncodedJSValue JSC_HOST_CALL objectProtoFuncToString(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); - return jsMakeNontrivialString(exec, "[object ", thisValue.toThisObject(exec)->className(), "]"); + return JSValue::encode(jsMakeNontrivialString(exec, "[object ", thisValue.toThisObject(exec)->className(), "]")); } } // namespace JSC diff --git a/JavaScriptCore/runtime/ObjectPrototype.h b/JavaScriptCore/runtime/ObjectPrototype.h index 8865d6b..0382ae4 100644 --- a/JavaScriptCore/runtime/ObjectPrototype.h +++ b/JavaScriptCore/runtime/ObjectPrototype.h @@ -36,7 +36,7 @@ namespace JSC { bool m_hasNoPropertiesWithUInt32Names; }; - JSValue JSC_HOST_CALL objectProtoFuncToString(ExecState*); + EncodedJSValue JSC_HOST_CALL objectProtoFuncToString(ExecState*); } // namespace JSC diff --git a/JavaScriptCore/runtime/RegExpConstructor.cpp b/JavaScriptCore/runtime/RegExpConstructor.cpp index c79d5f8..24476d6 100644 --- a/JavaScriptCore/runtime/RegExpConstructor.cpp +++ b/JavaScriptCore/runtime/RegExpConstructor.cpp @@ -24,6 +24,7 @@ #include "ArrayPrototype.h" #include "Error.h" +#include "ExceptionHelpers.h" #include "JSArray.h" #include "JSFunction.h" #include "JSString.h" @@ -294,7 +295,7 @@ JSObject* constructRegExp(ExecState* exec, const ArgList& args) if (arg0.inherits(&RegExpObject::info)) { if (!arg1.isUndefined()) - return throwError(exec, TypeError, "Cannot supply flags when constructing one RegExp from another."); + return throwError(exec, createTypeError(exec, "Cannot supply flags when constructing one RegExp from another.")); return asObject(arg0); } @@ -303,13 +304,14 @@ JSObject* constructRegExp(ExecState* exec, const ArgList& args) RefPtr<RegExp> regExp = RegExp::create(&exec->globalData(), pattern, flags); if (!regExp->isValid()) - return throwError(exec, SyntaxError, makeString("Invalid regular expression: ", regExp->errorMessage())); + return throwError(exec, createSyntaxError(exec, makeString("Invalid regular expression: ", regExp->errorMessage()))); return new (exec) RegExpObject(exec->lexicalGlobalObject(), exec->lexicalGlobalObject()->regExpStructure(), regExp.release()); } -static JSObject* constructWithRegExpConstructor(ExecState* exec, JSObject*, const ArgList& args) +static EncodedJSValue JSC_HOST_CALL constructWithRegExpConstructor(ExecState* exec) { - return constructRegExp(exec, args); + ArgList args(exec); + return JSValue::encode(constructRegExp(exec, args)); } ConstructType RegExpConstructor::getConstructData(ConstructData& constructData) @@ -319,10 +321,10 @@ ConstructType RegExpConstructor::getConstructData(ConstructData& constructData) } // ECMA 15.10.3 -static JSValue JSC_HOST_CALL callRegExpConstructor(ExecState* exec) +static EncodedJSValue JSC_HOST_CALL callRegExpConstructor(ExecState* exec) { ArgList args(exec); - return constructRegExp(exec, args); + return JSValue::encode(constructRegExp(exec, args)); } CallType RegExpConstructor::getCallData(CallData& callData) diff --git a/JavaScriptCore/runtime/RegExpObject.cpp b/JavaScriptCore/runtime/RegExpObject.cpp index acec966..4824944 100644 --- a/JavaScriptCore/runtime/RegExpObject.cpp +++ b/JavaScriptCore/runtime/RegExpObject.cpp @@ -22,6 +22,7 @@ #include "RegExpObject.h" #include "Error.h" +#include "ExceptionHelpers.h" #include "JSArray.h" #include "JSGlobalObject.h" #include "JSString.h" @@ -125,9 +126,9 @@ JSValue RegExpObject::exec(ExecState* exec) return jsNull(); } -static JSValue JSC_HOST_CALL callRegExpObject(ExecState* exec) +static EncodedJSValue JSC_HOST_CALL callRegExpObject(ExecState* exec) { - return asRegExpObject(exec->callee())->exec(exec); + return JSValue::encode(asRegExpObject(exec->callee())->exec(exec)); } CallType RegExpObject::getCallData(CallData& callData) @@ -143,7 +144,7 @@ bool RegExpObject::match(ExecState* exec) UString input = !exec->argumentCount() ? regExpConstructor->input() : exec->argument(0).toString(exec); if (input.isNull()) { - throwError(exec, GeneralError, makeString("No input to ", toString(exec), ".")); + throwError(exec, createError(exec, makeString("No input to ", toString(exec), "."))); return false; } diff --git a/JavaScriptCore/runtime/RegExpPrototype.cpp b/JavaScriptCore/runtime/RegExpPrototype.cpp index 0a531ac..9d78f59 100644 --- a/JavaScriptCore/runtime/RegExpPrototype.cpp +++ b/JavaScriptCore/runtime/RegExpPrototype.cpp @@ -38,10 +38,10 @@ namespace JSC { ASSERT_CLASS_FITS_IN_CELL(RegExpPrototype); -static JSValue JSC_HOST_CALL regExpProtoFuncTest(ExecState*); -static JSValue JSC_HOST_CALL regExpProtoFuncExec(ExecState*); -static JSValue JSC_HOST_CALL regExpProtoFuncCompile(ExecState*); -static JSValue JSC_HOST_CALL regExpProtoFuncToString(ExecState*); +static EncodedJSValue JSC_HOST_CALL regExpProtoFuncTest(ExecState*); +static EncodedJSValue JSC_HOST_CALL regExpProtoFuncExec(ExecState*); +static EncodedJSValue JSC_HOST_CALL regExpProtoFuncCompile(ExecState*); +static EncodedJSValue JSC_HOST_CALL regExpProtoFuncToString(ExecState*); // ECMA 15.10.5 @@ -57,28 +57,28 @@ RegExpPrototype::RegExpPrototype(ExecState* exec, JSGlobalObject* globalObject, } // ------------------------------ Functions --------------------------- - -JSValue JSC_HOST_CALL regExpProtoFuncTest(ExecState* exec) + +EncodedJSValue JSC_HOST_CALL regExpProtoFuncTest(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); if (!thisValue.inherits(&RegExpObject::info)) - return throwError(exec, TypeError); - return asRegExpObject(thisValue)->test(exec); + return throwVMTypeError(exec); + return JSValue::encode(asRegExpObject(thisValue)->test(exec)); } -JSValue JSC_HOST_CALL regExpProtoFuncExec(ExecState* exec) +EncodedJSValue JSC_HOST_CALL regExpProtoFuncExec(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); if (!thisValue.inherits(&RegExpObject::info)) - return throwError(exec, TypeError); - return asRegExpObject(thisValue)->exec(exec); + return throwVMTypeError(exec); + return JSValue::encode(asRegExpObject(thisValue)->exec(exec)); } -JSValue JSC_HOST_CALL regExpProtoFuncCompile(ExecState* exec) +EncodedJSValue JSC_HOST_CALL regExpProtoFuncCompile(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); if (!thisValue.inherits(&RegExpObject::info)) - return throwError(exec, TypeError); + return throwVMTypeError(exec); RefPtr<RegExp> regExp; JSValue arg0 = exec->argument(0); @@ -86,7 +86,7 @@ JSValue JSC_HOST_CALL regExpProtoFuncCompile(ExecState* exec) if (arg0.inherits(&RegExpObject::info)) { if (!arg1.isUndefined()) - return throwError(exec, TypeError, "Cannot supply flags when constructing one RegExp from another."); + return throwVMError(exec, createTypeError(exec, "Cannot supply flags when constructing one RegExp from another.")); regExp = asRegExpObject(arg0)->regExp(); } else { UString pattern = !exec->argumentCount() ? UString("") : arg0.toString(exec); @@ -95,20 +95,20 @@ JSValue JSC_HOST_CALL regExpProtoFuncCompile(ExecState* exec) } if (!regExp->isValid()) - return throwError(exec, SyntaxError, makeString("Invalid regular expression: ", regExp->errorMessage())); + return throwVMError(exec, createSyntaxError(exec, makeString("Invalid regular expression: ", regExp->errorMessage()))); asRegExpObject(thisValue)->setRegExp(regExp.release()); asRegExpObject(thisValue)->setLastIndex(0); - return jsUndefined(); + return JSValue::encode(jsUndefined()); } -JSValue JSC_HOST_CALL regExpProtoFuncToString(ExecState* exec) +EncodedJSValue JSC_HOST_CALL regExpProtoFuncToString(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); if (!thisValue.inherits(&RegExpObject::info)) { if (thisValue.inherits(&RegExpPrototype::info)) - return jsNontrivialString(exec, "//"); - return throwError(exec, TypeError); + return JSValue::encode(jsNontrivialString(exec, "//")); + return throwVMTypeError(exec); } char postfix[5] = { '/', 0, 0, 0, 0 }; @@ -121,7 +121,7 @@ JSValue JSC_HOST_CALL regExpProtoFuncToString(ExecState* exec) postfix[index] = 'm'; UString source = asRegExpObject(thisValue)->get(exec, exec->propertyNames().source).toString(exec); // If source is empty, use "/(?:)/" to avoid colliding with comment syntax - return jsMakeNontrivialString(exec, "/", source.size() ? source : UString("(?:)"), postfix); + return JSValue::encode(jsMakeNontrivialString(exec, "/", source.size() ? source : UString("(?:)"), postfix)); } } // namespace JSC diff --git a/JavaScriptCore/runtime/StringConstructor.cpp b/JavaScriptCore/runtime/StringConstructor.cpp index c1484c5..f02ab09 100644 --- a/JavaScriptCore/runtime/StringConstructor.cpp +++ b/JavaScriptCore/runtime/StringConstructor.cpp @@ -40,11 +40,11 @@ static NEVER_INLINE JSValue stringFromCharCodeSlowCase(ExecState* exec) return jsString(exec, impl); } -static JSValue JSC_HOST_CALL stringFromCharCode(ExecState* exec) +static EncodedJSValue JSC_HOST_CALL stringFromCharCode(ExecState* exec) { if (LIKELY(exec->argumentCount() == 1)) - return jsSingleCharacterString(exec, exec->argument(0).toUInt32(exec)); - return stringFromCharCodeSlowCase(exec); + return JSValue::encode(jsSingleCharacterString(exec, exec->argument(0).toUInt32(exec))); + return JSValue::encode(stringFromCharCodeSlowCase(exec)); } ASSERT_CLASS_FITS_IN_CELL(StringConstructor); @@ -66,11 +66,11 @@ StringConstructor::StringConstructor(ExecState* exec, JSGlobalObject* globalObje } // ECMA 15.5.2 -static JSObject* constructWithStringConstructor(ExecState* exec, JSObject*, const ArgList& args) +static EncodedJSValue JSC_HOST_CALL constructWithStringConstructor(ExecState* exec) { - if (args.isEmpty()) - return new (exec) StringObject(exec, exec->lexicalGlobalObject()->stringObjectStructure()); - return new (exec) StringObject(exec, exec->lexicalGlobalObject()->stringObjectStructure(), args.at(0).toString(exec)); + if (!exec->argumentCount()) + return JSValue::encode(new (exec) StringObject(exec, exec->lexicalGlobalObject()->stringObjectStructure())); + return JSValue::encode(new (exec) StringObject(exec, exec->lexicalGlobalObject()->stringObjectStructure(), exec->argument(0).toString(exec))); } ConstructType StringConstructor::getConstructData(ConstructData& constructData) @@ -80,11 +80,11 @@ ConstructType StringConstructor::getConstructData(ConstructData& constructData) } // ECMA 15.5.1 -static JSValue JSC_HOST_CALL callStringConstructor(ExecState* exec) +static EncodedJSValue JSC_HOST_CALL callStringConstructor(ExecState* exec) { if (!exec->argumentCount()) - return jsEmptyString(exec); - return jsString(exec, exec->argument(0).toString(exec)); + return JSValue::encode(jsEmptyString(exec)); + return JSValue::encode(jsString(exec, exec->argument(0).toString(exec))); } CallType StringConstructor::getCallData(CallData& callData) diff --git a/JavaScriptCore/runtime/StringPrototype.cpp b/JavaScriptCore/runtime/StringPrototype.cpp index f90d908..5b90456 100644 --- a/JavaScriptCore/runtime/StringPrototype.cpp +++ b/JavaScriptCore/runtime/StringPrototype.cpp @@ -45,38 +45,38 @@ namespace JSC { ASSERT_CLASS_FITS_IN_CELL(StringPrototype); -static JSValue JSC_HOST_CALL stringProtoFuncToString(ExecState*); -static JSValue JSC_HOST_CALL stringProtoFuncCharAt(ExecState*); -static JSValue JSC_HOST_CALL stringProtoFuncCharCodeAt(ExecState*); -static JSValue JSC_HOST_CALL stringProtoFuncConcat(ExecState*); -static JSValue JSC_HOST_CALL stringProtoFuncIndexOf(ExecState*); -static JSValue JSC_HOST_CALL stringProtoFuncLastIndexOf(ExecState*); -static JSValue JSC_HOST_CALL stringProtoFuncMatch(ExecState*); -static JSValue JSC_HOST_CALL stringProtoFuncReplace(ExecState*); -static JSValue JSC_HOST_CALL stringProtoFuncSearch(ExecState*); -static JSValue JSC_HOST_CALL stringProtoFuncSlice(ExecState*); -static JSValue JSC_HOST_CALL stringProtoFuncSplit(ExecState*); -static JSValue JSC_HOST_CALL stringProtoFuncSubstr(ExecState*); -static JSValue JSC_HOST_CALL stringProtoFuncSubstring(ExecState*); -static JSValue JSC_HOST_CALL stringProtoFuncToLowerCase(ExecState*); -static JSValue JSC_HOST_CALL stringProtoFuncToUpperCase(ExecState*); -static JSValue JSC_HOST_CALL stringProtoFuncLocaleCompare(ExecState*); -static JSValue JSC_HOST_CALL stringProtoFuncBig(ExecState*); -static JSValue JSC_HOST_CALL stringProtoFuncSmall(ExecState*); -static JSValue JSC_HOST_CALL stringProtoFuncBlink(ExecState*); -static JSValue JSC_HOST_CALL stringProtoFuncBold(ExecState*); -static JSValue JSC_HOST_CALL stringProtoFuncFixed(ExecState*); -static JSValue JSC_HOST_CALL stringProtoFuncItalics(ExecState*); -static JSValue JSC_HOST_CALL stringProtoFuncStrike(ExecState*); -static JSValue JSC_HOST_CALL stringProtoFuncSub(ExecState*); -static JSValue JSC_HOST_CALL stringProtoFuncSup(ExecState*); -static JSValue JSC_HOST_CALL stringProtoFuncFontcolor(ExecState*); -static JSValue JSC_HOST_CALL stringProtoFuncFontsize(ExecState*); -static JSValue JSC_HOST_CALL stringProtoFuncAnchor(ExecState*); -static JSValue JSC_HOST_CALL stringProtoFuncLink(ExecState*); -static JSValue JSC_HOST_CALL stringProtoFuncTrim(ExecState*); -static JSValue JSC_HOST_CALL stringProtoFuncTrimLeft(ExecState*); -static JSValue JSC_HOST_CALL stringProtoFuncTrimRight(ExecState*); +static EncodedJSValue JSC_HOST_CALL stringProtoFuncToString(ExecState*); +static EncodedJSValue JSC_HOST_CALL stringProtoFuncCharAt(ExecState*); +static EncodedJSValue JSC_HOST_CALL stringProtoFuncCharCodeAt(ExecState*); +static EncodedJSValue JSC_HOST_CALL stringProtoFuncConcat(ExecState*); +static EncodedJSValue JSC_HOST_CALL stringProtoFuncIndexOf(ExecState*); +static EncodedJSValue JSC_HOST_CALL stringProtoFuncLastIndexOf(ExecState*); +static EncodedJSValue JSC_HOST_CALL stringProtoFuncMatch(ExecState*); +static EncodedJSValue JSC_HOST_CALL stringProtoFuncReplace(ExecState*); +static EncodedJSValue JSC_HOST_CALL stringProtoFuncSearch(ExecState*); +static EncodedJSValue JSC_HOST_CALL stringProtoFuncSlice(ExecState*); +static EncodedJSValue JSC_HOST_CALL stringProtoFuncSplit(ExecState*); +static EncodedJSValue JSC_HOST_CALL stringProtoFuncSubstr(ExecState*); +static EncodedJSValue JSC_HOST_CALL stringProtoFuncSubstring(ExecState*); +static EncodedJSValue JSC_HOST_CALL stringProtoFuncToLowerCase(ExecState*); +static EncodedJSValue JSC_HOST_CALL stringProtoFuncToUpperCase(ExecState*); +static EncodedJSValue JSC_HOST_CALL stringProtoFuncLocaleCompare(ExecState*); +static EncodedJSValue JSC_HOST_CALL stringProtoFuncBig(ExecState*); +static EncodedJSValue JSC_HOST_CALL stringProtoFuncSmall(ExecState*); +static EncodedJSValue JSC_HOST_CALL stringProtoFuncBlink(ExecState*); +static EncodedJSValue JSC_HOST_CALL stringProtoFuncBold(ExecState*); +static EncodedJSValue JSC_HOST_CALL stringProtoFuncFixed(ExecState*); +static EncodedJSValue JSC_HOST_CALL stringProtoFuncItalics(ExecState*); +static EncodedJSValue JSC_HOST_CALL stringProtoFuncStrike(ExecState*); +static EncodedJSValue JSC_HOST_CALL stringProtoFuncSub(ExecState*); +static EncodedJSValue JSC_HOST_CALL stringProtoFuncSup(ExecState*); +static EncodedJSValue JSC_HOST_CALL stringProtoFuncFontcolor(ExecState*); +static EncodedJSValue JSC_HOST_CALL stringProtoFuncFontsize(ExecState*); +static EncodedJSValue JSC_HOST_CALL stringProtoFuncAnchor(ExecState*); +static EncodedJSValue JSC_HOST_CALL stringProtoFuncLink(ExecState*); +static EncodedJSValue JSC_HOST_CALL stringProtoFuncTrim(ExecState*); +static EncodedJSValue JSC_HOST_CALL stringProtoFuncTrimLeft(ExecState*); +static EncodedJSValue JSC_HOST_CALL stringProtoFuncTrimRight(ExecState*); } @@ -286,7 +286,7 @@ static ALWAYS_INLINE JSValue jsSpliceSubstringsWithSeparators(ExecState* exec, J return jsString(exec, impl); } -JSValue JSC_HOST_CALL stringProtoFuncReplace(ExecState* exec) +EncodedJSValue JSC_HOST_CALL stringProtoFuncReplace(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); JSString* sourceVal = thisValue.toThisJSString(exec); @@ -295,14 +295,14 @@ JSValue JSC_HOST_CALL stringProtoFuncReplace(ExecState* exec) UString replacementString; CallData callData; - CallType callType = replacement.getCallData(callData); + CallType callType = getCallData(replacement, callData); if (callType == CallTypeNone) replacementString = replacement.toString(exec); if (pattern.inherits(&RegExpObject::info)) { const UString& source = sourceVal->value(exec); if (exec->hadException()) - return JSValue(); + return JSValue::encode(JSValue()); RegExp* reg = asRegExpObject(pattern)->regExp(); bool global = reg->global(); @@ -321,7 +321,7 @@ JSValue JSC_HOST_CALL stringProtoFuncReplace(ExecState* exec) JSFunction* func = asFunction(replacement); CachedCall cachedCall(exec, func, argCount, exec->exceptionSlot()); if (exec->hadException()) - return jsNull(); + return JSValue::encode(jsNull()); while (true) { int matchIndex; int matchLen = 0; @@ -413,25 +413,25 @@ JSValue JSC_HOST_CALL stringProtoFuncReplace(ExecState* exec) } if (!lastIndex && replacements.isEmpty()) - return sourceVal; + return JSValue::encode(sourceVal); if (static_cast<unsigned>(lastIndex) < source.size()) sourceRanges.append(StringRange(lastIndex, source.size() - lastIndex)); - return jsSpliceSubstringsWithSeparators(exec, sourceVal, source, sourceRanges.data(), sourceRanges.size(), replacements.data(), replacements.size()); + return JSValue::encode(jsSpliceSubstringsWithSeparators(exec, sourceVal, source, sourceRanges.data(), sourceRanges.size(), replacements.data(), replacements.size())); } // Not a regular expression, so treat the pattern as a string. UString patternString = pattern.toString(exec); if (patternString.size() == 1 && callType == CallTypeNone) - return sourceVal->replaceCharacter(exec, patternString[0], replacementString); + return JSValue::encode(sourceVal->replaceCharacter(exec, patternString[0], replacementString)); const UString& source = sourceVal->value(exec); unsigned matchPos = source.find(patternString); if (matchPos == UString::NotFound) - return sourceVal; + return JSValue::encode(sourceVal); int matchLen = patternString.size(); if (callType != CallTypeNone) { @@ -445,24 +445,24 @@ JSValue JSC_HOST_CALL stringProtoFuncReplace(ExecState* exec) size_t matchEnd = matchPos + matchLen; int ovector[2] = { matchPos, matchEnd }; - return jsString(exec, source.substr(0, matchPos), substituteBackreferences(replacementString, source, ovector, 0), source.substr(matchEnd)); + return JSValue::encode(jsString(exec, source.substr(0, matchPos), substituteBackreferences(replacementString, source, ovector, 0), source.substr(matchEnd))); } -JSValue JSC_HOST_CALL stringProtoFuncToString(ExecState* exec) +EncodedJSValue JSC_HOST_CALL stringProtoFuncToString(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); // Also used for valueOf. if (thisValue.isString()) - return thisValue; + return JSValue::encode(thisValue); if (thisValue.inherits(&StringObject::info)) - return asStringObject(thisValue)->internalValue(); + return JSValue::encode(asStringObject(thisValue)->internalValue()); - return throwError(exec, TypeError); + return throwVMTypeError(exec); } -JSValue JSC_HOST_CALL stringProtoFuncCharAt(ExecState* exec) +EncodedJSValue JSC_HOST_CALL stringProtoFuncCharAt(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); UString s = thisValue.toThisString(exec); @@ -471,16 +471,16 @@ JSValue JSC_HOST_CALL stringProtoFuncCharAt(ExecState* exec) if (a0.isUInt32()) { uint32_t i = a0.asUInt32(); if (i < len) - return jsSingleCharacterSubstring(exec, s, i); - return jsEmptyString(exec); + return JSValue::encode(jsSingleCharacterSubstring(exec, s, i)); + return JSValue::encode(jsEmptyString(exec)); } double dpos = a0.toInteger(exec); if (dpos >= 0 && dpos < len) - return jsSingleCharacterSubstring(exec, s, static_cast<unsigned>(dpos)); - return jsEmptyString(exec); + return JSValue::encode(jsSingleCharacterSubstring(exec, s, static_cast<unsigned>(dpos))); + return JSValue::encode(jsEmptyString(exec)); } -JSValue JSC_HOST_CALL stringProtoFuncCharCodeAt(ExecState* exec) +EncodedJSValue JSC_HOST_CALL stringProtoFuncCharCodeAt(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); UString s = thisValue.toThisString(exec); @@ -489,29 +489,29 @@ JSValue JSC_HOST_CALL stringProtoFuncCharCodeAt(ExecState* exec) if (a0.isUInt32()) { uint32_t i = a0.asUInt32(); if (i < len) - return jsNumber(exec, s.data()[i]); - return jsNaN(exec); + return JSValue::encode(jsNumber(exec, s.data()[i])); + return JSValue::encode(jsNaN(exec)); } double dpos = a0.toInteger(exec); if (dpos >= 0 && dpos < len) - return jsNumber(exec, s[static_cast<int>(dpos)]); - return jsNaN(exec); + return JSValue::encode(jsNumber(exec, s[static_cast<int>(dpos)])); + return JSValue::encode(jsNaN(exec)); } -JSValue JSC_HOST_CALL stringProtoFuncConcat(ExecState* exec) +EncodedJSValue JSC_HOST_CALL stringProtoFuncConcat(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); if (thisValue.isString() && (exec->argumentCount() == 1)) { JSValue v = exec->argument(0); - return v.isString() + return JSValue::encode(v.isString() ? jsString(exec, asString(thisValue), asString(v)) - : jsString(exec, asString(thisValue), v.toString(exec)); + : jsString(exec, asString(thisValue), v.toString(exec))); } - return jsString(exec, thisValue); + return JSValue::encode(jsString(exec, thisValue)); } -JSValue JSC_HOST_CALL stringProtoFuncIndexOf(ExecState* exec) +EncodedJSValue JSC_HOST_CALL stringProtoFuncIndexOf(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); UString s = thisValue.toThisString(exec); @@ -536,11 +536,11 @@ JSValue JSC_HOST_CALL stringProtoFuncIndexOf(ExecState* exec) unsigned result = s.find(u2, pos); if (result == UString::NotFound) - return jsNumber(exec, -1); - return jsNumber(exec, result); + return JSValue::encode(jsNumber(exec, -1)); + return JSValue::encode(jsNumber(exec, result)); } -JSValue JSC_HOST_CALL stringProtoFuncLastIndexOf(ExecState* exec) +EncodedJSValue JSC_HOST_CALL stringProtoFuncLastIndexOf(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); UString s = thisValue.toThisString(exec); @@ -563,11 +563,11 @@ JSValue JSC_HOST_CALL stringProtoFuncLastIndexOf(ExecState* exec) unsigned result = s.rfind(u2, static_cast<unsigned>(dpos)); if (result == UString::NotFound) - return jsNumber(exec, -1); - return jsNumber(exec, result); + return JSValue::encode(jsNumber(exec, -1)); + return JSValue::encode(jsNumber(exec, result)); } -JSValue JSC_HOST_CALL stringProtoFuncMatch(ExecState* exec) +EncodedJSValue JSC_HOST_CALL stringProtoFuncMatch(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); UString s = thisValue.toThisString(exec); @@ -594,8 +594,8 @@ JSValue JSC_HOST_CALL stringProtoFuncMatch(ExecState* exec) if (!(reg->global())) { // case without 'g' flag is handled like RegExp.prototype.exec if (pos < 0) - return jsNull(); - return regExpConstructor->arrayOfMatches(exec); + return JSValue::encode(jsNull()); + return JSValue::encode(regExpConstructor->arrayOfMatches(exec)); } // return array of matches @@ -613,13 +613,13 @@ JSValue JSC_HOST_CALL stringProtoFuncMatch(ExecState* exec) // if there are no matches at all, it's important to return // Null instead of an empty array, because this matches // other browsers and because Null is a false value. - return jsNull(); + return JSValue::encode(jsNull()); } - return constructArray(exec, list); + return JSValue::encode(constructArray(exec, list)); } -JSValue JSC_HOST_CALL stringProtoFuncSearch(ExecState* exec) +EncodedJSValue JSC_HOST_CALL stringProtoFuncSearch(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); UString s = thisValue.toThisString(exec); @@ -642,10 +642,10 @@ JSValue JSC_HOST_CALL stringProtoFuncSearch(ExecState* exec) int pos; int matchLength = 0; regExpConstructor->performMatch(reg.get(), u, 0, pos, matchLength); - return jsNumber(exec, pos); + return JSValue::encode(jsNumber(exec, pos)); } -JSValue JSC_HOST_CALL stringProtoFuncSlice(ExecState* exec) +EncodedJSValue JSC_HOST_CALL stringProtoFuncSlice(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); UString s = thisValue.toThisString(exec); @@ -664,13 +664,13 @@ JSValue JSC_HOST_CALL stringProtoFuncSlice(ExecState* exec) from = 0; if (to > len) to = len; - return jsSubstring(exec, s, static_cast<unsigned>(from), static_cast<unsigned>(to) - static_cast<unsigned>(from)); + return JSValue::encode(jsSubstring(exec, s, static_cast<unsigned>(from), static_cast<unsigned>(to) - static_cast<unsigned>(from))); } - return jsEmptyString(exec); + return JSValue::encode(jsEmptyString(exec)); } -JSValue JSC_HOST_CALL stringProtoFuncSplit(ExecState* exec) +EncodedJSValue JSC_HOST_CALL stringProtoFuncSplit(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); UString s = thisValue.toThisString(exec); @@ -686,7 +686,7 @@ JSValue JSC_HOST_CALL stringProtoFuncSplit(ExecState* exec) RegExp* reg = asRegExpObject(a0)->regExp(); if (s.isEmpty() && reg->match(s, 0) >= 0) { // empty string matched by regexp -> empty array - return result; + return JSValue::encode(result); } unsigned pos = 0; while (i != limit && pos < s.size()) { @@ -713,7 +713,7 @@ JSValue JSC_HOST_CALL stringProtoFuncSplit(ExecState* exec) if (u2.isEmpty()) { if (s.isEmpty()) { // empty separator matches empty string -> empty array - return result; + return JSValue::encode(result); } while (i != limit && p0 < s.size() - 1) result->put(exec, i++, jsSingleCharacterSubstring(exec, s, p0++)); @@ -731,10 +731,10 @@ JSValue JSC_HOST_CALL stringProtoFuncSplit(ExecState* exec) if (i != limit) result->put(exec, i++, jsSubstring(exec, s, p0, s.size() - p0)); - return result; + return JSValue::encode(result); } -JSValue JSC_HOST_CALL stringProtoFuncSubstr(ExecState* exec) +EncodedJSValue JSC_HOST_CALL stringProtoFuncSubstr(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); UString s = thisValue.toThisString(exec); @@ -746,7 +746,7 @@ JSValue JSC_HOST_CALL stringProtoFuncSubstr(ExecState* exec) double start = a0.toInteger(exec); double length = a1.isUndefined() ? len : a1.toInteger(exec); if (start >= len || length <= 0) - return jsEmptyString(exec); + return JSValue::encode(jsEmptyString(exec)); if (start < 0) { start += len; if (start < 0) @@ -754,10 +754,10 @@ JSValue JSC_HOST_CALL stringProtoFuncSubstr(ExecState* exec) } if (start + length > len) length = len - start; - return jsSubstring(exec, s, static_cast<unsigned>(start), static_cast<unsigned>(length)); + return JSValue::encode(jsSubstring(exec, s, static_cast<unsigned>(start), static_cast<unsigned>(length))); } -JSValue JSC_HOST_CALL stringProtoFuncSubstring(ExecState* exec) +EncodedJSValue JSC_HOST_CALL stringProtoFuncSubstring(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); UString s = thisValue.toThisString(exec); @@ -786,10 +786,10 @@ JSValue JSC_HOST_CALL stringProtoFuncSubstring(ExecState* exec) end = start; start = temp; } - return jsSubstring(exec, s, static_cast<unsigned>(start), static_cast<unsigned>(end) - static_cast<unsigned>(start)); + return JSValue::encode(jsSubstring(exec, s, static_cast<unsigned>(start), static_cast<unsigned>(end) - static_cast<unsigned>(start))); } -JSValue JSC_HOST_CALL stringProtoFuncToLowerCase(ExecState* exec) +EncodedJSValue JSC_HOST_CALL stringProtoFuncToLowerCase(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); JSString* sVal = thisValue.toThisJSString(exec); @@ -797,7 +797,7 @@ JSValue JSC_HOST_CALL stringProtoFuncToLowerCase(ExecState* exec) int sSize = s.size(); if (!sSize) - return sVal; + return JSValue::encode(sVal); const UChar* sData = s.data(); Vector<UChar> buffer(sSize); @@ -809,7 +809,7 @@ JSValue JSC_HOST_CALL stringProtoFuncToLowerCase(ExecState* exec) buffer[i] = toASCIILower(c); } if (!(ored & ~0x7f)) - return jsString(exec, UString::adopt(buffer)); + return JSValue::encode(jsString(exec, UString::adopt(buffer))); bool error; int length = Unicode::toLower(buffer.data(), sSize, sData, sSize, &error); @@ -817,17 +817,17 @@ JSValue JSC_HOST_CALL stringProtoFuncToLowerCase(ExecState* exec) buffer.resize(length); length = Unicode::toLower(buffer.data(), length, sData, sSize, &error); if (error) - return sVal; + return JSValue::encode(sVal); } if (length == sSize) { if (memcmp(buffer.data(), sData, length * sizeof(UChar)) == 0) - return sVal; + return JSValue::encode(sVal); } else buffer.resize(length); - return jsString(exec, UString::adopt(buffer)); + return JSValue::encode(jsString(exec, UString::adopt(buffer))); } -JSValue JSC_HOST_CALL stringProtoFuncToUpperCase(ExecState* exec) +EncodedJSValue JSC_HOST_CALL stringProtoFuncToUpperCase(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); JSString* sVal = thisValue.toThisJSString(exec); @@ -835,7 +835,7 @@ JSValue JSC_HOST_CALL stringProtoFuncToUpperCase(ExecState* exec) int sSize = s.size(); if (!sSize) - return sVal; + return JSValue::encode(sVal); const UChar* sData = s.data(); Vector<UChar> buffer(sSize); @@ -847,7 +847,7 @@ JSValue JSC_HOST_CALL stringProtoFuncToUpperCase(ExecState* exec) buffer[i] = toASCIIUpper(c); } if (!(ored & ~0x7f)) - return jsString(exec, UString::adopt(buffer)); + return JSValue::encode(jsString(exec, UString::adopt(buffer))); bool error; int length = Unicode::toUpper(buffer.data(), sSize, sData, sSize, &error); @@ -855,99 +855,99 @@ JSValue JSC_HOST_CALL stringProtoFuncToUpperCase(ExecState* exec) buffer.resize(length); length = Unicode::toUpper(buffer.data(), length, sData, sSize, &error); if (error) - return sVal; + return JSValue::encode(sVal); } if (length == sSize) { if (memcmp(buffer.data(), sData, length * sizeof(UChar)) == 0) - return sVal; + return JSValue::encode(sVal); } else buffer.resize(length); - return jsString(exec, UString::adopt(buffer)); + return JSValue::encode(jsString(exec, UString::adopt(buffer))); } -JSValue JSC_HOST_CALL stringProtoFuncLocaleCompare(ExecState* exec) +EncodedJSValue JSC_HOST_CALL stringProtoFuncLocaleCompare(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); if (exec->argumentCount() < 1) - return jsNumber(exec, 0); + return JSValue::encode(jsNumber(exec, 0)); UString s = thisValue.toThisString(exec); JSValue a0 = exec->argument(0); - return jsNumber(exec, localeCompare(s, a0.toString(exec))); + return JSValue::encode(jsNumber(exec, localeCompare(s, a0.toString(exec)))); } -JSValue JSC_HOST_CALL stringProtoFuncBig(ExecState* exec) +EncodedJSValue JSC_HOST_CALL stringProtoFuncBig(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); UString s = thisValue.toThisString(exec); - return jsMakeNontrivialString(exec, "<big>", s, "</big>"); + return JSValue::encode(jsMakeNontrivialString(exec, "<big>", s, "</big>")); } -JSValue JSC_HOST_CALL stringProtoFuncSmall(ExecState* exec) +EncodedJSValue JSC_HOST_CALL stringProtoFuncSmall(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); UString s = thisValue.toThisString(exec); - return jsMakeNontrivialString(exec, "<small>", s, "</small>"); + return JSValue::encode(jsMakeNontrivialString(exec, "<small>", s, "</small>")); } -JSValue JSC_HOST_CALL stringProtoFuncBlink(ExecState* exec) +EncodedJSValue JSC_HOST_CALL stringProtoFuncBlink(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); UString s = thisValue.toThisString(exec); - return jsMakeNontrivialString(exec, "<blink>", s, "</blink>"); + return JSValue::encode(jsMakeNontrivialString(exec, "<blink>", s, "</blink>")); } -JSValue JSC_HOST_CALL stringProtoFuncBold(ExecState* exec) +EncodedJSValue JSC_HOST_CALL stringProtoFuncBold(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); UString s = thisValue.toThisString(exec); - return jsMakeNontrivialString(exec, "<b>", s, "</b>"); + return JSValue::encode(jsMakeNontrivialString(exec, "<b>", s, "</b>")); } -JSValue JSC_HOST_CALL stringProtoFuncFixed(ExecState* exec) +EncodedJSValue JSC_HOST_CALL stringProtoFuncFixed(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); UString s = thisValue.toThisString(exec); - return jsMakeNontrivialString(exec, "<tt>", s, "</tt>"); + return JSValue::encode(jsMakeNontrivialString(exec, "<tt>", s, "</tt>")); } -JSValue JSC_HOST_CALL stringProtoFuncItalics(ExecState* exec) +EncodedJSValue JSC_HOST_CALL stringProtoFuncItalics(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); UString s = thisValue.toThisString(exec); - return jsMakeNontrivialString(exec, "<i>", s, "</i>"); + return JSValue::encode(jsMakeNontrivialString(exec, "<i>", s, "</i>")); } -JSValue JSC_HOST_CALL stringProtoFuncStrike(ExecState* exec) +EncodedJSValue JSC_HOST_CALL stringProtoFuncStrike(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); UString s = thisValue.toThisString(exec); - return jsMakeNontrivialString(exec, "<strike>", s, "</strike>"); + return JSValue::encode(jsMakeNontrivialString(exec, "<strike>", s, "</strike>")); } -JSValue JSC_HOST_CALL stringProtoFuncSub(ExecState* exec) +EncodedJSValue JSC_HOST_CALL stringProtoFuncSub(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); UString s = thisValue.toThisString(exec); - return jsMakeNontrivialString(exec, "<sub>", s, "</sub>"); + return JSValue::encode(jsMakeNontrivialString(exec, "<sub>", s, "</sub>")); } -JSValue JSC_HOST_CALL stringProtoFuncSup(ExecState* exec) +EncodedJSValue JSC_HOST_CALL stringProtoFuncSup(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); UString s = thisValue.toThisString(exec); - return jsMakeNontrivialString(exec, "<sup>", s, "</sup>"); + return JSValue::encode(jsMakeNontrivialString(exec, "<sup>", s, "</sup>")); } -JSValue JSC_HOST_CALL stringProtoFuncFontcolor(ExecState* exec) +EncodedJSValue JSC_HOST_CALL stringProtoFuncFontcolor(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); UString s = thisValue.toThisString(exec); JSValue a0 = exec->argument(0); - return jsMakeNontrivialString(exec, "<font color=\"", a0.toString(exec), "\">", s, "</font>"); + return JSValue::encode(jsMakeNontrivialString(exec, "<font color=\"", a0.toString(exec), "\">", s, "</font>")); } -JSValue JSC_HOST_CALL stringProtoFuncFontsize(ExecState* exec) +EncodedJSValue JSC_HOST_CALL stringProtoFuncFontsize(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); UString s = thisValue.toThisString(exec); @@ -960,7 +960,7 @@ JSValue JSC_HOST_CALL stringProtoFuncFontsize(ExecState* exec) UChar* buffer; PassRefPtr<UStringImpl> impl = UStringImpl::tryCreateUninitialized(bufferSize, buffer); if (!impl) - return jsUndefined(); + return JSValue::encode(jsUndefined()); buffer[0] = '<'; buffer[1] = 'f'; buffer[2] = 'o'; @@ -984,21 +984,21 @@ JSValue JSC_HOST_CALL stringProtoFuncFontsize(ExecState* exec) buffer[19 + stringSize] = 'n'; buffer[20 + stringSize] = 't'; buffer[21 + stringSize] = '>'; - return jsNontrivialString(exec, impl); + return JSValue::encode(jsNontrivialString(exec, impl)); } - return jsMakeNontrivialString(exec, "<font size=\"", a0.toString(exec), "\">", s, "</font>"); + return JSValue::encode(jsMakeNontrivialString(exec, "<font size=\"", a0.toString(exec), "\">", s, "</font>")); } -JSValue JSC_HOST_CALL stringProtoFuncAnchor(ExecState* exec) +EncodedJSValue JSC_HOST_CALL stringProtoFuncAnchor(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); UString s = thisValue.toThisString(exec); JSValue a0 = exec->argument(0); - return jsMakeNontrivialString(exec, "<a name=\"", a0.toString(exec), "\">", s, "</a>"); + return JSValue::encode(jsMakeNontrivialString(exec, "<a name=\"", a0.toString(exec), "\">", s, "</a>")); } -JSValue JSC_HOST_CALL stringProtoFuncLink(ExecState* exec) +EncodedJSValue JSC_HOST_CALL stringProtoFuncLink(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); UString s = thisValue.toThisString(exec); @@ -1011,7 +1011,7 @@ JSValue JSC_HOST_CALL stringProtoFuncLink(ExecState* exec) UChar* buffer; PassRefPtr<UStringImpl> impl = UStringImpl::tryCreateUninitialized(bufferSize, buffer); if (!impl) - return jsUndefined(); + return JSValue::encode(jsUndefined()); buffer[0] = '<'; buffer[1] = 'a'; buffer[2] = ' '; @@ -1029,7 +1029,7 @@ JSValue JSC_HOST_CALL stringProtoFuncLink(ExecState* exec) buffer[12 + linkTextSize + stringSize] = '/'; buffer[13 + linkTextSize + stringSize] = 'a'; buffer[14 + linkTextSize + stringSize] = '>'; - return jsNontrivialString(exec, impl); + return JSValue::encode(jsNontrivialString(exec, impl)); } enum { @@ -1063,22 +1063,22 @@ static inline JSValue trimString(ExecState* exec, JSValue thisValue, int trimKin return jsString(exec, str.substr(left, right - left)); } -JSValue JSC_HOST_CALL stringProtoFuncTrim(ExecState* exec) +EncodedJSValue JSC_HOST_CALL stringProtoFuncTrim(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); - return trimString(exec, thisValue, TrimLeft | TrimRight); + return JSValue::encode(trimString(exec, thisValue, TrimLeft | TrimRight)); } -JSValue JSC_HOST_CALL stringProtoFuncTrimLeft(ExecState* exec) +EncodedJSValue JSC_HOST_CALL stringProtoFuncTrimLeft(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); - return trimString(exec, thisValue, TrimLeft); + return JSValue::encode(trimString(exec, thisValue, TrimLeft)); } -JSValue JSC_HOST_CALL stringProtoFuncTrimRight(ExecState* exec) +EncodedJSValue JSC_HOST_CALL stringProtoFuncTrimRight(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); - return trimString(exec, thisValue, TrimRight); + return JSValue::encode(trimString(exec, thisValue, TrimRight)); } |