summaryrefslogtreecommitdiff
path: root/Source/JavaScriptCore/runtime/ExceptionHelpers.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/JavaScriptCore/runtime/ExceptionHelpers.cpp')
-rw-r--r--Source/JavaScriptCore/runtime/ExceptionHelpers.cpp93
1 files changed, 46 insertions, 47 deletions
diff --git a/Source/JavaScriptCore/runtime/ExceptionHelpers.cpp b/Source/JavaScriptCore/runtime/ExceptionHelpers.cpp
index a4368a2bb..ccd7a02cb 100644
--- a/Source/JavaScriptCore/runtime/ExceptionHelpers.cpp
+++ b/Source/JavaScriptCore/runtime/ExceptionHelpers.cpp
@@ -37,36 +37,10 @@
#include "JSNotAnObject.h"
#include "Interpreter.h"
#include "Nodes.h"
+#include "Operations.h"
namespace JSC {
-ASSERT_HAS_TRIVIAL_DESTRUCTOR(InterruptedExecutionError);
-
-const ClassInfo InterruptedExecutionError::s_info = { "InterruptedExecutionError", &Base::s_info, 0, 0, CREATE_METHOD_TABLE(InterruptedExecutionError) };
-
-JSValue InterruptedExecutionError::defaultValue(const JSObject*, ExecState* exec, PreferredPrimitiveType hint)
-{
- if (hint == PreferString)
- return jsNontrivialString(exec, String(ASCIILiteral("JavaScript execution exceeded timeout.")));
- return JSValue(QNaN);
-}
-
-JSObject* createInterruptedExecutionException(JSGlobalData* globalData)
-{
- return InterruptedExecutionError::create(*globalData);
-}
-
-bool isInterruptedExecutionException(JSObject* object)
-{
- return object->inherits(&InterruptedExecutionError::s_info);
-}
-
-bool isInterruptedExecutionException(JSValue value)
-{
- return value.inherits(&InterruptedExecutionError::s_info);
-}
-
-
ASSERT_HAS_TRIVIAL_DESTRUCTOR(TerminatedExecutionError);
const ClassInfo TerminatedExecutionError::s_info = { "TerminatedExecutionError", &Base::s_info, 0, 0, CREATE_METHOD_TABLE(TerminatedExecutionError) };
@@ -78,9 +52,9 @@ JSValue TerminatedExecutionError::defaultValue(const JSObject*, ExecState* exec,
return JSValue(QNaN);
}
-JSObject* createTerminatedExecutionException(JSGlobalData* globalData)
+JSObject* createTerminatedExecutionException(VM* vm)
{
- return TerminatedExecutionError::create(*globalData);
+ return TerminatedExecutionError::create(*vm);
}
bool isTerminatedExecutionException(JSObject* object)
@@ -110,40 +84,59 @@ JSObject* createUndefinedVariableError(ExecState* exec, const Identifier& ident)
return createReferenceError(exec, message);
}
-JSObject* createInvalidParamError(ExecState* exec, const char* op, JSValue value)
+JSString* errorDescriptionForValue(ExecState* exec, JSValue v)
+{
+ VM& vm = exec->vm();
+ if (v.isNull())
+ return vm.smallStrings.nullString();
+ if (v.isUndefined())
+ return vm.smallStrings.undefinedString();
+ if (v.isInt32())
+ return jsString(&vm, vm.numericStrings.add(v.asInt32()));
+ if (v.isDouble())
+ return jsString(&vm, vm.numericStrings.add(v.asDouble()));
+ if (v.isTrue())
+ return vm.smallStrings.trueString();
+ if (v.isFalse())
+ return vm.smallStrings.falseString();
+ if (v.isString())
+ return jsCast<JSString*>(v.asCell());
+ if (v.isObject()) {
+ CallData callData;
+ JSObject* object = asObject(v);
+ if (object->methodTable()->getCallData(object, callData) != CallTypeNone)
+ return vm.smallStrings.functionString();
+ }
+ return jsString(exec, asObject(v)->methodTable()->className(asObject(v)));
+}
+
+JSObject* createError(ExecState* exec, ErrorFactory errorFactory, JSValue value, const String& message)
{
- String errorMessage = makeString("'", value.toString(exec)->value(exec), "' is not a valid argument for '", op, "'");
- JSObject* exception = createTypeError(exec, errorMessage);
+ String errorMessage = makeString(errorDescriptionForValue(exec, value)->value(exec), " ", message);
+ JSObject* exception = errorFactory(exec, errorMessage);
ASSERT(exception->isErrorInstance());
static_cast<ErrorInstance*>(exception)->setAppendSourceToMessage();
return exception;
}
+JSObject* createInvalidParameterError(ExecState* exec, const char* op, JSValue value)
+{
+ return createError(exec, createTypeError, value, makeString("is not a valid argument for '", op, "'"));
+}
+
JSObject* createNotAConstructorError(ExecState* exec, JSValue value)
{
- String errorMessage = makeString("'", value.toString(exec)->value(exec), "' is not a constructor");
- JSObject* exception = createTypeError(exec, errorMessage);
- ASSERT(exception->isErrorInstance());
- static_cast<ErrorInstance*>(exception)->setAppendSourceToMessage();
- return exception;
+ return createError(exec, createTypeError, value, "is not a constructor");
}
JSObject* createNotAFunctionError(ExecState* exec, JSValue value)
{
- String errorMessage = makeString("'", value.toString(exec)->value(exec), "' is not a function");
- JSObject* exception = createTypeError(exec, errorMessage);
- ASSERT(exception->isErrorInstance());
- static_cast<ErrorInstance*>(exception)->setAppendSourceToMessage();
- return exception;
+ return createError(exec, createTypeError, value, "is not a function");
}
JSObject* createNotAnObjectError(ExecState* exec, JSValue value)
{
- String errorMessage = makeString("'", value.toString(exec)->value(exec), "' is not an object");
- JSObject* exception = createTypeError(exec, errorMessage);
- ASSERT(exception->isErrorInstance());
- static_cast<ErrorInstance*>(exception)->setAppendSourceToMessage();
- return exception;
+ return createError(exec, createTypeError, value, "is not an object");
}
JSObject* createErrorForInvalidGlobalAssignment(ExecState* exec, const String& propertyName)
@@ -167,4 +160,10 @@ JSObject* throwStackOverflowError(ExecState* exec)
return throwError(exec, createStackOverflowError(exec));
}
+JSObject* throwTerminatedExecutionException(ExecState* exec)
+{
+ Interpreter::ErrorHandlingMode mode(exec);
+ return throwError(exec, createTerminatedExecutionException(&exec->vm()));
+}
+
} // namespace JSC