diff options
Diffstat (limited to 'JavaScriptCore/runtime')
| -rw-r--r-- | JavaScriptCore/runtime/Error.cpp | 34 | ||||
| -rw-r--r-- | JavaScriptCore/runtime/Error.h | 2 | ||||
| -rw-r--r-- | JavaScriptCore/runtime/ErrorInstance.cpp | 2 | ||||
| -rw-r--r-- | JavaScriptCore/runtime/ErrorInstance.h | 9 | ||||
| -rw-r--r-- | JavaScriptCore/runtime/ExceptionHelpers.cpp | 110 | ||||
| -rw-r--r-- | JavaScriptCore/runtime/ExceptionHelpers.h | 15 | ||||
| -rw-r--r-- | JavaScriptCore/runtime/JSFunction.cpp | 14 | ||||
| -rw-r--r-- | JavaScriptCore/runtime/JSGlobalData.cpp | 1 | ||||
| -rw-r--r-- | JavaScriptCore/runtime/JSGlobalData.h | 1 | ||||
| -rw-r--r-- | JavaScriptCore/runtime/JSNotAnObject.cpp | 39 | ||||
| -rw-r--r-- | JavaScriptCore/runtime/JSNotAnObject.h | 26 | ||||
| -rw-r--r-- | JavaScriptCore/runtime/JSObject.h | 2 | ||||
| -rw-r--r-- | JavaScriptCore/runtime/JSValue.cpp | 20 |
13 files changed, 85 insertions, 190 deletions
diff --git a/JavaScriptCore/runtime/Error.cpp b/JavaScriptCore/runtime/Error.cpp index fd97beb..227e9ec 100644 --- a/JavaScriptCore/runtime/Error.cpp +++ b/JavaScriptCore/runtime/Error.cpp @@ -38,9 +38,6 @@ namespace JSC { 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) { @@ -119,7 +116,7 @@ JSObject* createURIError(ExecState* exec, const UString& message) return createURIError(exec->lexicalGlobalObject(), message); } -static void addErrorSourceInfo(JSGlobalData* globalData, JSObject* error, int line, const SourceCode& source) +JSObject* addErrorInfo(JSGlobalData* globalData, JSObject* error, int line, const SourceCode& source) { intptr_t sourceID = source.provider()->asID(); const UString& sourceURL = source.provider()->url(); @@ -130,26 +127,7 @@ static void addErrorSourceInfo(JSGlobalData* globalData, JSObject* error, int li error->putWithAttributes(globalData, Identifier(globalData, sourceIdPropertyName), jsNumber((double)sourceID), ReadOnly | DontDelete); if (!sourceURL.isNull()) error->putWithAttributes(globalData, Identifier(globalData, sourceURLPropertyName), jsString(globalData, sourceURL), ReadOnly | DontDelete); -} - -static void addErrorDivotInfo(JSGlobalData* globalData, JSObject* error, int divotPoint, int startOffset, int endOffset, bool withCaret) -{ - error->putWithAttributes(globalData, Identifier(globalData, expressionBeginOffsetPropertyName), jsNumber(divotPoint - startOffset), ReadOnly | DontDelete); - error->putWithAttributes(globalData, Identifier(globalData, expressionEndOffsetPropertyName), jsNumber(divotPoint + endOffset), ReadOnly | DontDelete); - if (withCaret) - error->putWithAttributes(globalData, Identifier(globalData, expressionCaretOffsetPropertyName), jsNumber(divotPoint), ReadOnly | DontDelete); -} - -JSObject* addErrorInfo(JSGlobalData* globalData, JSObject* error, int line, const SourceCode& source) -{ - addErrorSourceInfo(globalData, error, line, source); - return error; -} -JSObject* addErrorInfo(JSGlobalData* globalData, JSObject* error, int line, const SourceCode& source, int divotPoint, int startOffset, int endOffset, bool withCaret) -{ - addErrorSourceInfo(globalData, error, line, source); - addErrorDivotInfo(globalData, error, divotPoint, startOffset, endOffset, withCaret); return error; } @@ -158,19 +136,11 @@ JSObject* addErrorInfo(ExecState* exec, JSObject* error, int line, const SourceC 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)); + || error->hasProperty(exec, Identifier(exec, sourceURLPropertyName)); } JSValue throwError(ExecState* exec, JSValue error) diff --git a/JavaScriptCore/runtime/Error.h b/JavaScriptCore/runtime/Error.h index bfde7dc..c0f9d32 100644 --- a/JavaScriptCore/runtime/Error.h +++ b/JavaScriptCore/runtime/Error.h @@ -56,10 +56,8 @@ namespace JSC { // 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); diff --git a/JavaScriptCore/runtime/ErrorInstance.cpp b/JavaScriptCore/runtime/ErrorInstance.cpp index 740e20e..0f3153c 100644 --- a/JavaScriptCore/runtime/ErrorInstance.cpp +++ b/JavaScriptCore/runtime/ErrorInstance.cpp @@ -27,12 +27,14 @@ const ClassInfo ErrorInstance::info = { "Error", 0, 0, 0 }; ErrorInstance::ErrorInstance(JSGlobalData* globalData, NonNullPassRefPtr<Structure> structure) : JSObject(structure) + , m_appendSourceToMessage(false) { putDirect(globalData->propertyNames->message, jsString(globalData, "")); } ErrorInstance::ErrorInstance(JSGlobalData* globalData, NonNullPassRefPtr<Structure> structure, const UString& message) : JSObject(structure) + , m_appendSourceToMessage(false) { putDirect(globalData->propertyNames->message, jsString(globalData, message)); } diff --git a/JavaScriptCore/runtime/ErrorInstance.h b/JavaScriptCore/runtime/ErrorInstance.h index a49cc3c..b3bebec 100644 --- a/JavaScriptCore/runtime/ErrorInstance.h +++ b/JavaScriptCore/runtime/ErrorInstance.h @@ -34,9 +34,18 @@ namespace JSC { static ErrorInstance* create(JSGlobalData*, NonNullPassRefPtr<Structure>, const UString&); static ErrorInstance* create(ExecState* exec, NonNullPassRefPtr<Structure>, JSValue message); + + bool appendSourceToMessage() { return m_appendSourceToMessage; } + void setAppendSourceToMessage() { m_appendSourceToMessage = true; } + void clearAppendSourceToMessage() { m_appendSourceToMessage = false; } + + virtual bool isErrorInstance() const { return true; } + protected: explicit ErrorInstance(JSGlobalData*, NonNullPassRefPtr<Structure>); explicit ErrorInstance(JSGlobalData*, NonNullPassRefPtr<Structure>, const UString&); + + bool m_appendSourceToMessage; }; } // namespace JSC diff --git a/JavaScriptCore/runtime/ExceptionHelpers.cpp b/JavaScriptCore/runtime/ExceptionHelpers.cpp index 5fbaa18..1ef264c 100644 --- a/JavaScriptCore/runtime/ExceptionHelpers.cpp +++ b/JavaScriptCore/runtime/ExceptionHelpers.cpp @@ -31,6 +31,7 @@ #include "CodeBlock.h" #include "CallFrame.h" +#include "ErrorInstance.h" #include "JSGlobalObjectFunctions.h" #include "JSObject.h" #include "JSNotAnObject.h" @@ -52,7 +53,7 @@ public: virtual UString toString(ExecState*) const { return "JavaScript execution exceeded timeout."; } }; -JSValue createInterruptedExecutionException(JSGlobalData* globalData) +JSObject* createInterruptedExecutionException(JSGlobalData* globalData) { return new (globalData) InterruptedExecutionError(globalData); } @@ -69,7 +70,7 @@ public: virtual UString toString(ExecState*) const { return "JavaScript execution terminated."; } }; -JSValue createTerminatedExecutionException(JSGlobalData* globalData) +JSObject* createTerminatedExecutionException(JSGlobalData* globalData) { return new (globalData) TerminatedExecutionError(globalData); } @@ -84,106 +85,45 @@ JSObject* createStackOverflowError(JSGlobalObject* globalObject) return createRangeError(globalObject, "Maximum call stack size exceeded."); } -JSValue createUndefinedVariableError(ExecState* exec, const Identifier& ident, unsigned bytecodeOffset, CodeBlock* codeBlock) +JSObject* createUndefinedVariableError(ExecState* exec, const Identifier& ident) { - int startOffset = 0; - int endOffset = 0; - int divotPoint = 0; - int line = codeBlock->expressionRangeForBytecodeOffset(exec, bytecodeOffset, divotPoint, startOffset, endOffset); UString message(makeUString("Can't find variable: ", ident.ustring())); - JSObject* exception = addErrorInfo(exec, createReferenceError(exec, message), line, codeBlock->ownerExecutable()->source(), divotPoint, startOffset, endOffset); - return exception; + return createReferenceError(exec, message); } -static UString createErrorMessage(ExecState* exec, CodeBlock* codeBlock, int, int expressionStart, int expressionStop, JSValue value, UString error) +JSObject* createInvalidParamError(ExecState* exec, const char* op, JSValue value) { - if (!expressionStop || expressionStart > codeBlock->source()->length()) - return makeUString(value.toString(exec), " is ", error); - if (expressionStart < expressionStop) - return makeUString("Result of expression '", codeBlock->source()->getRange(expressionStart, expressionStop), "' [", value.toString(exec), "] is ", error, "."); - - // No range information, so give a few characters of context - const UChar* data = codeBlock->source()->data(); - int dataLength = codeBlock->source()->length(); - int start = expressionStart; - int stop = expressionStart; - // Get up to 20 characters of context to the left and right of the divot, clamping to the line. - // then strip whitespace. - while (start > 0 && (expressionStart - start < 20) && data[start - 1] != '\n') - start--; - while (start < (expressionStart - 1) && isStrWhiteSpace(data[start])) - start++; - while (stop < dataLength && (stop - expressionStart < 20) && data[stop] != '\n') - stop++; - while (stop > expressionStart && isStrWhiteSpace(data[stop])) - stop--; - return makeUString("Result of expression near '...", codeBlock->source()->getRange(start, stop), "...' [", value.toString(exec), "] is ", error, "."); -} - -JSObject* createInvalidParamError(ExecState* exec, const char* op, JSValue value, unsigned bytecodeOffset, CodeBlock* codeBlock) -{ - int startOffset = 0; - int endOffset = 0; - int divotPoint = 0; - int line = codeBlock->expressionRangeForBytecodeOffset(exec, bytecodeOffset, divotPoint, startOffset, endOffset); - UString errorMessage = createErrorMessage(exec, codeBlock, line, divotPoint, divotPoint + endOffset, value, makeUString("not a valid argument for '", op, "'")); - JSObject* exception = addErrorInfo(exec, createTypeError(exec, errorMessage), line, codeBlock->ownerExecutable()->source(), divotPoint, startOffset, endOffset); + UString errorMessage = makeUString("'", value.toString(exec), "' is not a valid argument for '", op, "'"); + JSObject* exception = createTypeError(exec, errorMessage); + ASSERT(exception->isErrorInstance()); + static_cast<ErrorInstance*>(exception)->setAppendSourceToMessage(); return exception; } -JSObject* createNotAConstructorError(ExecState* exec, JSValue value, unsigned bytecodeOffset, CodeBlock* codeBlock) +JSObject* createNotAConstructorError(ExecState* exec, JSValue value) { - int startOffset = 0; - int endOffset = 0; - int divotPoint = 0; - int line = codeBlock->expressionRangeForBytecodeOffset(exec, bytecodeOffset, divotPoint, startOffset, endOffset); - - // We're in a "new" expression, so we need to skip over the "new.." part - int startPoint = divotPoint - (startOffset ? startOffset - 4 : 0); // -4 for "new " - const UChar* data = codeBlock->source()->data(); - while (startPoint < divotPoint && isStrWhiteSpace(data[startPoint])) - startPoint++; - - UString errorMessage = createErrorMessage(exec, codeBlock, line, startPoint, divotPoint, value, "not a constructor"); - JSObject* exception = addErrorInfo(exec, createTypeError(exec, errorMessage), line, codeBlock->ownerExecutable()->source(), divotPoint, startOffset, endOffset); + UString errorMessage = makeUString("'", value.toString(exec), "' is not a constructor"); + JSObject* exception = createTypeError(exec, errorMessage); + ASSERT(exception->isErrorInstance()); + static_cast<ErrorInstance*>(exception)->setAppendSourceToMessage(); return exception; } -JSValue createNotAFunctionError(ExecState* exec, JSValue value, unsigned bytecodeOffset, CodeBlock* codeBlock) +JSObject* createNotAFunctionError(ExecState* exec, JSValue value) { - int startOffset = 0; - int endOffset = 0; - 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 = addErrorInfo(exec, createTypeError(exec, errorMessage), line, codeBlock->ownerExecutable()->source(), divotPoint, startOffset, endOffset); + UString errorMessage = makeUString("'", value.toString(exec), "' is not a function"); + JSObject* exception = createTypeError(exec, errorMessage); + ASSERT(exception->isErrorInstance()); + static_cast<ErrorInstance*>(exception)->setAppendSourceToMessage(); return exception; } -JSNotAnObjectErrorStub* createNotAnObjectErrorStub(ExecState* exec, bool isNull) +JSObject* createNotAnObjectError(ExecState* exec, JSValue value) { - return new (exec) JSNotAnObjectErrorStub(exec, isNull); -} - -JSObject* createNotAnObjectError(ExecState* exec, JSNotAnObjectErrorStub* error, unsigned bytecodeOffset, CodeBlock* codeBlock) -{ - // Both op_create_this and op_instanceof require a use of op_get_by_id to get - // the prototype property from an object. The exception messages for exceptions - // thrown by these instances op_get_by_id need to reflect this. - OpcodeID followingOpcodeID; - if (codeBlock->getByIdExceptionInfoForBytecodeOffset(exec, bytecodeOffset, followingOpcodeID)) { - ASSERT(followingOpcodeID == op_create_this || followingOpcodeID == op_instanceof); - if (followingOpcodeID == op_create_this) - return createNotAConstructorError(exec, error->isNull() ? jsNull() : jsUndefined(), bytecodeOffset, codeBlock); - return createInvalidParamError(exec, "instanceof", error->isNull() ? jsNull() : jsUndefined(), bytecodeOffset, codeBlock); - } - - int startOffset = 0; - int endOffset = 0; - 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 = addErrorInfo(exec, createTypeError(exec, errorMessage), line, codeBlock->ownerExecutable()->source(), divotPoint, startOffset, endOffset); + UString errorMessage = makeUString("'", value.toString(exec), "' is not an object"); + JSObject* exception = createTypeError(exec, errorMessage); + ASSERT(exception->isErrorInstance()); + static_cast<ErrorInstance*>(exception)->setAppendSourceToMessage(); return exception; } diff --git a/JavaScriptCore/runtime/ExceptionHelpers.h b/JavaScriptCore/runtime/ExceptionHelpers.h index a7b2ca7..7edffad 100644 --- a/JavaScriptCore/runtime/ExceptionHelpers.h +++ b/JavaScriptCore/runtime/ExceptionHelpers.h @@ -43,16 +43,15 @@ namespace JSC { class Node; struct Instruction; - JSValue createInterruptedExecutionException(JSGlobalData*); - JSValue createTerminatedExecutionException(JSGlobalData*); + JSObject* createInterruptedExecutionException(JSGlobalData*); + JSObject* createTerminatedExecutionException(JSGlobalData*); JSObject* createStackOverflowError(ExecState*); JSObject* createStackOverflowError(JSGlobalObject*); - JSValue createUndefinedVariableError(ExecState*, const Identifier&, unsigned bytecodeOffset, CodeBlock*); - JSNotAnObjectErrorStub* createNotAnObjectErrorStub(ExecState*, bool isNull); - JSObject* createInvalidParamError(ExecState*, const char* op, JSValue, unsigned bytecodeOffset, CodeBlock*); - JSObject* createNotAConstructorError(ExecState*, JSValue, unsigned bytecodeOffset, CodeBlock*); - JSValue createNotAFunctionError(ExecState*, JSValue, unsigned bytecodeOffset, CodeBlock*); - JSObject* createNotAnObjectError(ExecState*, JSNotAnObjectErrorStub*, unsigned bytecodeOffset, CodeBlock*); + JSObject* createUndefinedVariableError(ExecState*, const Identifier&); + JSObject* createNotAnObjectError(ExecState*, JSValue); + JSObject* createInvalidParamError(ExecState*, const char* op, JSValue); + JSObject* createNotAConstructorError(ExecState*, JSValue); + JSObject* createNotAFunctionError(ExecState*, JSValue); JSObject* createErrorForInvalidGlobalAssignment(ExecState*, const UString&); JSObject* throwOutOfMemoryError(ExecState*); diff --git a/JavaScriptCore/runtime/JSFunction.cpp b/JavaScriptCore/runtime/JSFunction.cpp index 0697fc3..ba89d04 100644 --- a/JavaScriptCore/runtime/JSFunction.cpp +++ b/JavaScriptCore/runtime/JSFunction.cpp @@ -45,9 +45,7 @@ namespace JSC { #if ENABLE(JIT) EncodedJSValue JSC_HOST_CALL callHostFunctionAsConstructor(ExecState* exec) { - CodeBlock* codeBlock = exec->callerFrame()->codeBlock(); - unsigned vPCIndex = codeBlock->bytecodeOffset(exec, exec->returnPC()); - return throwVMError(exec, createNotAConstructorError(exec, exec->callee(), vPCIndex, codeBlock)); + return throwVMError(exec, createNotAConstructorError(exec, exec->callee())); } #endif @@ -284,6 +282,10 @@ bool JSFunction::getOwnPropertyDescriptor(ExecState* exec, const Identifier& pro void JSFunction::getOwnPropertyNames(ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode) { if (!isHostFunction() && (mode == IncludeDontEnumProperties)) { + // Make sure prototype has been reified. + PropertySlot slot; + getOwnPropertySlot(exec, exec->propertyNames().prototype, slot); + propertyNames.add(exec->propertyNames().arguments); propertyNames.add(exec->propertyNames().callee); propertyNames.add(exec->propertyNames().caller); @@ -298,6 +300,12 @@ void JSFunction::put(ExecState* exec, const Identifier& propertyName, JSValue va Base::put(exec, propertyName, value, slot); return; } + if (propertyName == exec->propertyNames().prototype) { + // Make sure prototype has been reified, such that it can only be overwritten + // following the rules set out in ECMA-262 8.12.9. + PropertySlot slot; + getOwnPropertySlot(exec, propertyName, slot); + } if (jsExecutable()->isStrictMode()) { if (propertyName == exec->propertyNames().arguments) { throwTypeError(exec, StrictModeArgumentsAccessError); diff --git a/JavaScriptCore/runtime/JSGlobalData.cpp b/JavaScriptCore/runtime/JSGlobalData.cpp index 1404ddf..58b844c 100644 --- a/JavaScriptCore/runtime/JSGlobalData.cpp +++ b/JavaScriptCore/runtime/JSGlobalData.cpp @@ -127,7 +127,6 @@ JSGlobalData::JSGlobalData(GlobalDataType globalDataType, ThreadStackType thread , staticScopeStructure(JSStaticScopeObject::createStructure(jsNull())) , strictEvalActivationStructure(StrictEvalActivation::createStructure(jsNull())) , stringStructure(JSString::createStructure(jsNull())) - , notAnObjectErrorStubStructure(JSNotAnObjectErrorStub::createStructure(jsNull())) , notAnObjectStructure(JSNotAnObject::createStructure(jsNull())) , propertyNameIteratorStructure(JSPropertyNameIterator::createStructure(jsNull())) , getterSetterStructure(GetterSetter::createStructure(jsNull())) diff --git a/JavaScriptCore/runtime/JSGlobalData.h b/JavaScriptCore/runtime/JSGlobalData.h index 775d026..153a4e5 100644 --- a/JavaScriptCore/runtime/JSGlobalData.h +++ b/JavaScriptCore/runtime/JSGlobalData.h @@ -147,7 +147,6 @@ namespace JSC { RefPtr<Structure> staticScopeStructure; RefPtr<Structure> strictEvalActivationStructure; RefPtr<Structure> stringStructure; - RefPtr<Structure> notAnObjectErrorStubStructure; RefPtr<Structure> notAnObjectStructure; RefPtr<Structure> propertyNameIteratorStructure; RefPtr<Structure> getterSetterStructure; diff --git a/JavaScriptCore/runtime/JSNotAnObject.cpp b/JavaScriptCore/runtime/JSNotAnObject.cpp index f4764e2..e01b401 100644 --- a/JavaScriptCore/runtime/JSNotAnObject.cpp +++ b/JavaScriptCore/runtime/JSNotAnObject.cpp @@ -39,91 +39,84 @@ ASSERT_CLASS_FITS_IN_CELL(JSNotAnObject); // JSValue methods JSValue JSNotAnObject::toPrimitive(ExecState* exec, PreferredPrimitiveType) const { - ASSERT_UNUSED(exec, exec->hadException() && exec->exception() == m_exception); - return m_exception; + ASSERT_UNUSED(exec, exec->hadException()); + return jsNumber(0); } bool JSNotAnObject::getPrimitiveNumber(ExecState* exec, double&, JSValue&) { - ASSERT_UNUSED(exec, exec->hadException() && exec->exception() == m_exception); + ASSERT_UNUSED(exec, exec->hadException()); return false; } bool JSNotAnObject::toBoolean(ExecState* exec) const { - ASSERT_UNUSED(exec, exec->hadException() && exec->exception() == m_exception); + ASSERT_UNUSED(exec, exec->hadException()); return false; } double JSNotAnObject::toNumber(ExecState* exec) const { - ASSERT_UNUSED(exec, exec->hadException() && exec->exception() == m_exception); + ASSERT_UNUSED(exec, exec->hadException()); return NaN; } UString JSNotAnObject::toString(ExecState* exec) const { - ASSERT_UNUSED(exec, exec->hadException() && exec->exception() == m_exception); + ASSERT_UNUSED(exec, exec->hadException()); return ""; } JSObject* JSNotAnObject::toObject(ExecState* exec) const { - ASSERT_UNUSED(exec, exec->hadException() && exec->exception() == m_exception); - return m_exception; -} - -// Marking -void JSNotAnObject::markChildren(MarkStack& markStack) -{ - JSObject::markChildren(markStack); - markStack.append(m_exception); + ASSERT_UNUSED(exec, exec->hadException()); + return const_cast<JSNotAnObject*>(this); } // JSObject methods bool JSNotAnObject::getOwnPropertySlot(ExecState* exec, const Identifier&, PropertySlot&) { - ASSERT_UNUSED(exec, exec->hadException() && exec->exception() == m_exception); + ASSERT_UNUSED(exec, exec->hadException()); return false; } bool JSNotAnObject::getOwnPropertySlot(ExecState* exec, unsigned, PropertySlot&) { - ASSERT_UNUSED(exec, exec->hadException() && exec->exception() == m_exception); + ASSERT_UNUSED(exec, exec->hadException()); return false; } bool JSNotAnObject::getOwnPropertyDescriptor(ExecState* exec, const Identifier&, PropertyDescriptor&) { - ASSERT_UNUSED(exec, exec->hadException() && exec->exception() == m_exception); + ASSERT_UNUSED(exec, exec->hadException()); return false; } void JSNotAnObject::put(ExecState* exec, const Identifier& , JSValue, PutPropertySlot&) { - ASSERT_UNUSED(exec, exec->hadException() && exec->exception() == m_exception); + ASSERT_UNUSED(exec, exec->hadException()); } void JSNotAnObject::put(ExecState* exec, unsigned, JSValue) { - ASSERT_UNUSED(exec, exec->hadException() && exec->exception() == m_exception); + ASSERT_UNUSED(exec, exec->hadException()); } bool JSNotAnObject::deleteProperty(ExecState* exec, const Identifier&) { - ASSERT_UNUSED(exec, exec->hadException() && exec->exception() == m_exception); + ASSERT_UNUSED(exec, exec->hadException()); return false; } bool JSNotAnObject::deleteProperty(ExecState* exec, unsigned) { - ASSERT_UNUSED(exec, exec->hadException() && exec->exception() == m_exception); + ASSERT_UNUSED(exec, exec->hadException()); return false; } void JSNotAnObject::getOwnPropertyNames(ExecState* exec, PropertyNameArray&, EnumerationMode) { - ASSERT_UNUSED(exec, exec->hadException() && exec->exception() == m_exception); + ASSERT_UNUSED(exec, exec->hadException()); } } // namespace JSC diff --git a/JavaScriptCore/runtime/JSNotAnObject.h b/JavaScriptCore/runtime/JSNotAnObject.h index 339d41f..9f527cf 100644 --- a/JavaScriptCore/runtime/JSNotAnObject.h +++ b/JavaScriptCore/runtime/JSNotAnObject.h @@ -33,30 +33,13 @@ namespace JSC { - class JSNotAnObjectErrorStub : public JSObject { - public: - JSNotAnObjectErrorStub(ExecState* exec, bool isNull) - : JSObject(exec->globalData().notAnObjectErrorStubStructure) - , m_isNull(isNull) - { - } - - bool isNull() const { return m_isNull; } - - private: - virtual bool isNotAnObjectErrorStub() const { return true; } - - bool m_isNull; - }; - // This unholy class is used to allow us to avoid multiple exception checks // in certain SquirrelFish bytecodes -- effectively it just silently consumes // any operations performed on the result of a failed toObject call. class JSNotAnObject : public JSObject { public: - JSNotAnObject(ExecState* exec, JSNotAnObjectErrorStub* exception) + JSNotAnObject(ExecState* exec) : JSObject(exec->globalData().notAnObjectStructure) - , m_exception(exception) { } @@ -67,7 +50,7 @@ namespace JSC { private: - static const unsigned StructureFlags = OverridesGetOwnPropertySlot | OverridesMarkChildren | OverridesGetPropertyNames | JSObject::StructureFlags; + static const unsigned StructureFlags = OverridesGetOwnPropertySlot | OverridesGetPropertyNames | JSObject::StructureFlags; // JSValue methods virtual JSValue toPrimitive(ExecState*, PreferredPrimitiveType) const; @@ -77,9 +60,6 @@ namespace JSC { virtual UString toString(ExecState*) const; virtual JSObject* toObject(ExecState*) const; - // Marking - virtual void markChildren(MarkStack&); - // JSObject methods virtual bool getOwnPropertySlot(ExecState*, const Identifier& propertyName, PropertySlot&); virtual bool getOwnPropertySlot(ExecState*, unsigned propertyName, PropertySlot&); @@ -92,8 +72,6 @@ namespace JSC { virtual bool deleteProperty(ExecState*, unsigned propertyName); virtual void getOwnPropertyNames(ExecState*, PropertyNameArray&, EnumerationMode mode = ExcludeDontEnumProperties); - - JSNotAnObjectErrorStub* m_exception; }; } // namespace JSC diff --git a/JavaScriptCore/runtime/JSObject.h b/JavaScriptCore/runtime/JSObject.h index f484ce4..803abfd 100644 --- a/JavaScriptCore/runtime/JSObject.h +++ b/JavaScriptCore/runtime/JSObject.h @@ -208,8 +208,8 @@ namespace JSC { virtual bool isGlobalObject() const { return false; } virtual bool isVariableObject() const { return false; } virtual bool isActivationObject() const { return false; } - virtual bool isNotAnObjectErrorStub() const { return false; } virtual bool isStrictModeFunction() const { return false; } + virtual bool isErrorInstance() const { return false; } virtual ComplType exceptionType() const { return Throw; } diff --git a/JavaScriptCore/runtime/JSValue.cpp b/JavaScriptCore/runtime/JSValue.cpp index 2a23a79..f4662db 100644 --- a/JavaScriptCore/runtime/JSValue.cpp +++ b/JavaScriptCore/runtime/JSValue.cpp @@ -62,10 +62,10 @@ JSObject* JSValue::toObjectSlowCase(ExecState* exec) const return constructNumber(exec, asValue()); if (isTrue() || isFalse()) return constructBooleanFromImmediateBoolean(exec, asValue()); + ASSERT(isUndefinedOrNull()); - JSNotAnObjectErrorStub* exception = createNotAnObjectErrorStub(exec, isNull()); - throwError(exec, exception); - return new (exec) JSNotAnObject(exec, exception); + throwError(exec, createNotAnObjectError(exec, *this)); + return new (exec) JSNotAnObject(exec); } JSObject* JSValue::toThisObjectSlowCase(ExecState* exec) const @@ -87,10 +87,10 @@ JSObject* JSValue::synthesizeObject(ExecState* exec) const return constructNumber(exec, asValue()); if (isBoolean()) return constructBooleanFromImmediateBoolean(exec, asValue()); - - JSNotAnObjectErrorStub* exception = createNotAnObjectErrorStub(exec, isNull()); - throwError(exec, exception); - return new (exec) JSNotAnObject(exec, exception); + + ASSERT(isUndefinedOrNull()); + throwError(exec, createNotAnObjectError(exec, *this)); + return new (exec) JSNotAnObject(exec); } JSObject* JSValue::synthesizePrototype(ExecState* exec) const @@ -101,9 +101,9 @@ JSObject* JSValue::synthesizePrototype(ExecState* exec) const if (isBoolean()) return exec->lexicalGlobalObject()->booleanPrototype(); - JSNotAnObjectErrorStub* exception = createNotAnObjectErrorStub(exec, isNull()); - throwError(exec, exception); - return new (exec) JSNotAnObject(exec, exception); + ASSERT(isUndefinedOrNull()); + throwError(exec, createNotAnObjectError(exec, *this)); + return new (exec) JSNotAnObject(exec); } #ifndef NDEBUG |
