* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * 3. Neither the name of Apple Inc. ("Apple") nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
#include "CodeBlock.h"
#include "CallFrame.h"
+#include "ErrorHandlingScope.h"
#include "ErrorInstance.h"
#include "JSGlobalObjectFunctions.h"
#include "JSObject.h"
#include "JSNotAnObject.h"
#include "Interpreter.h"
#include "Nodes.h"
-#include "UStringConcatenate.h"
+#include "JSCInlines.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, "JavaScript execution exceeded timeout.");
- return JSValue(std::numeric_limits<double>::quiet_NaN());
-}
-
-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);
+STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(TerminatedExecutionError);
const ClassInfo TerminatedExecutionError::s_info = { "TerminatedExecutionError", &Base::s_info, 0, 0, CREATE_METHOD_TABLE(TerminatedExecutionError) };
JSValue TerminatedExecutionError::defaultValue(const JSObject*, ExecState* exec, PreferredPrimitiveType hint)
{
if (hint == PreferString)
- return jsNontrivialString(exec, "JavaScript execution terminated.");
- return JSValue(std::numeric_limits<double>::quiet_NaN());
+ return jsNontrivialString(exec, String(ASCIILiteral("JavaScript execution terminated.")));
+ return JSValue(PNaN);
}
-JSObject* createTerminatedExecutionException(JSGlobalData* globalData)
+JSObject* createTerminatedExecutionException(VM* vm)
{
- return TerminatedExecutionError::create(*globalData);
+ return TerminatedExecutionError::create(*vm);
}
bool isTerminatedExecutionException(JSObject* object)
{
- return object->inherits(&TerminatedExecutionError::s_info);
+ return object->inherits(TerminatedExecutionError::info());
}
bool isTerminatedExecutionException(JSValue value)
{
- return value.inherits(&TerminatedExecutionError::s_info);
+ return value.inherits(TerminatedExecutionError::info());
}
JSObject* createStackOverflowError(ExecState* exec)
{
- return createRangeError(exec, "Maximum call stack size exceeded.");
+ return createRangeError(exec, ASCIILiteral("Maximum call stack size exceeded."));
}
JSObject* createStackOverflowError(JSGlobalObject* globalObject)
{
- return createRangeError(globalObject, "Maximum call stack size exceeded.");
+ return createRangeError(globalObject, ASCIILiteral("Maximum call stack size exceeded."));
}
JSObject* createUndefinedVariableError(ExecState* exec, const Identifier& ident)
{
- UString message(makeUString("Can't find variable: ", ident.ustring()));
+
+ if (ident.impl()->isEmptyUnique()) {
+ String message(makeString("Can't find private variable: @", exec->propertyNames().getPublicName(ident).string()));
+ return createReferenceError(exec, message);
+ }
+ String message(makeString("Can't find variable: ", ident.string()));
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, object->methodTable()->className(object));
+ }
+
+ // The JSValue should never be empty, so this point in the code should never be reached.
+ ASSERT_NOT_REACHED();
+ return vm.smallStrings.emptyString();
+}
+
+JSObject* createError(ExecState* exec, ErrorFactory errorFactory, JSValue value, const String& message)
{
- UString errorMessage = makeUString("'", 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)
{
- UString errorMessage = makeUString("'", 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)
{
- UString errorMessage = makeUString("'", 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)
{
- UString errorMessage = makeUString("'", 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 UString& propertyName)
+JSObject* createErrorForInvalidGlobalAssignment(ExecState* exec, const String& propertyName)
{
- return createReferenceError(exec, makeUString("Strict mode forbids implicit creation of global property '", propertyName, "'"));
+ return createReferenceError(exec, makeString("Strict mode forbids implicit creation of global property '", propertyName, "'"));
}
JSObject* createOutOfMemoryError(JSGlobalObject* globalObject)
{
- return createError(globalObject, "Out of memory");
+ return createError(globalObject, ASCIILiteral("Out of memory"));
}
JSObject* throwOutOfMemoryError(ExecState* exec)
{
- return throwError(exec, createOutOfMemoryError(exec->lexicalGlobalObject()));
+ return exec->vm().throwException(exec, createOutOfMemoryError(exec->lexicalGlobalObject()));
}
JSObject* throwStackOverflowError(ExecState* exec)
{
- return throwError(exec, createStackOverflowError(exec));
+ VM& vm = exec->vm();
+ ErrorHandlingScope errorScope(vm);
+ return vm.throwException(exec, createStackOverflowError(exec));
+}
+
+JSObject* throwTerminatedExecutionException(ExecState* exec)
+{
+ VM& vm = exec->vm();
+ ErrorHandlingScope errorScope(vm);
+ return vm.throwException(exec, createTerminatedExecutionException(&vm));
}
} // namespace JSC