mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 1 | /* |
weinig@apple.com | af0231a | 2009-01-08 01:46:14 +0000 | [diff] [blame] | 2 | * Copyright (C) 2008, 2009 Apple Inc. All rights reserved. |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * |
| 8 | * 1. Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer in the |
| 12 | * documentation and/or other materials provided with the distribution. |
| 13 | * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of |
| 14 | * its contributors may be used to endorse or promote products derived |
| 15 | * from this software without specific prior written permission. |
| 16 | * |
| 17 | * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY |
| 18 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 19 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 20 | * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
| 21 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 22 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 23 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 24 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | */ |
| 28 | |
| 29 | #include "config.h" |
| 30 | #include "ExceptionHelpers.h" |
| 31 | |
oliver@apple.com | 90b88ae | 2008-07-19 01:44:24 +0000 | [diff] [blame] | 32 | #include "CodeBlock.h" |
ggaren@apple.com | 5169fc9 | 2008-11-17 22:11:26 +0000 | [diff] [blame] | 33 | #include "CallFrame.h" |
barraclough@apple.com | e979a65 | 2010-11-16 01:30:25 +0000 | [diff] [blame] | 34 | #include "ErrorInstance.h" |
andersca@apple.com | 8c52c94 | 2009-01-23 19:40:56 +0000 | [diff] [blame] | 35 | #include "JSGlobalObjectFunctions.h" |
darin@apple.com | 3dcb636 | 2008-06-16 04:00:19 +0000 | [diff] [blame] | 36 | #include "JSObject.h" |
oliver@apple.com | 90b88ae | 2008-07-19 01:44:24 +0000 | [diff] [blame] | 37 | #include "JSNotAnObject.h" |
ggaren@apple.com | 901a8a2 | 2008-11-17 20:57:18 +0000 | [diff] [blame] | 38 | #include "Interpreter.h" |
cwzwarich@webkit.org | 3ff0e6a | 2008-11-07 00:18:07 +0000 | [diff] [blame] | 39 | #include "Nodes.h" |
fpizlo@apple.com | a4b4cbe | 2013-01-12 04:47:03 +0000 | [diff] [blame] | 40 | #include "Operations.h" |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 41 | |
cwzwarich@webkit.org | 3f782f6 | 2008-09-08 01:28:33 +0000 | [diff] [blame] | 42 | namespace JSC { |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 43 | |
mhahnenberg@apple.com | c58d54d | 2011-12-16 19:06:44 +0000 | [diff] [blame] | 44 | ASSERT_HAS_TRIVIAL_DESTRUCTOR(InterruptedExecutionError); |
| 45 | |
mhahnenberg@apple.com | 3e08466 | 2011-09-26 07:05:28 +0000 | [diff] [blame] | 46 | const ClassInfo InterruptedExecutionError::s_info = { "InterruptedExecutionError", &Base::s_info, 0, 0, CREATE_METHOD_TABLE(InterruptedExecutionError) }; |
weinig@apple.com | 3412bb4 | 2008-09-01 21:22:54 +0000 | [diff] [blame] | 47 | |
mhahnenberg@apple.com | 6e506e6 | 2011-11-01 01:15:06 +0000 | [diff] [blame] | 48 | JSValue InterruptedExecutionError::defaultValue(const JSObject*, ExecState* exec, PreferredPrimitiveType hint) |
weinig@apple.com | f41a7da | 2011-09-08 22:38:44 +0000 | [diff] [blame] | 49 | { |
mhahnenberg@apple.com | 7b72b79 | 2011-10-12 20:23:08 +0000 | [diff] [blame] | 50 | if (hint == PreferString) |
benjamin@webkit.org | 762e2c6 | 2012-09-04 21:19:25 +0000 | [diff] [blame] | 51 | return jsNontrivialString(exec, String(ASCIILiteral("JavaScript execution exceeded timeout."))); |
fpizlo@apple.com | 3494d02 | 2012-11-05 18:15:23 +0000 | [diff] [blame] | 52 | return JSValue(QNaN); |
weinig@apple.com | f41a7da | 2011-09-08 22:38:44 +0000 | [diff] [blame] | 53 | } |
commit-queue@webkit.org | 6c25c52 | 2011-08-09 20:46:17 +0000 | [diff] [blame] | 54 | |
weinig@apple.com | 76c1146 | 2011-09-11 05:16:09 +0000 | [diff] [blame] | 55 | JSObject* createInterruptedExecutionException(JSGlobalData* globalData) |
| 56 | { |
| 57 | return InterruptedExecutionError::create(*globalData); |
| 58 | } |
| 59 | |
| 60 | bool isInterruptedExecutionException(JSObject* object) |
| 61 | { |
| 62 | return object->inherits(&InterruptedExecutionError::s_info); |
| 63 | } |
| 64 | |
| 65 | bool isInterruptedExecutionException(JSValue value) |
| 66 | { |
| 67 | return value.inherits(&InterruptedExecutionError::s_info); |
| 68 | } |
| 69 | |
| 70 | |
mhahnenberg@apple.com | c58d54d | 2011-12-16 19:06:44 +0000 | [diff] [blame] | 71 | ASSERT_HAS_TRIVIAL_DESTRUCTOR(TerminatedExecutionError); |
| 72 | |
mhahnenberg@apple.com | 3e08466 | 2011-09-26 07:05:28 +0000 | [diff] [blame] | 73 | const ClassInfo TerminatedExecutionError::s_info = { "TerminatedExecutionError", &Base::s_info, 0, 0, CREATE_METHOD_TABLE(TerminatedExecutionError) }; |
oliver@apple.com | fcacd3c | 2011-07-18 17:47:13 +0000 | [diff] [blame] | 74 | |
mhahnenberg@apple.com | 6e506e6 | 2011-11-01 01:15:06 +0000 | [diff] [blame] | 75 | JSValue TerminatedExecutionError::defaultValue(const JSObject*, ExecState* exec, PreferredPrimitiveType hint) |
weinig@apple.com | f41a7da | 2011-09-08 22:38:44 +0000 | [diff] [blame] | 76 | { |
mhahnenberg@apple.com | 7b72b79 | 2011-10-12 20:23:08 +0000 | [diff] [blame] | 77 | if (hint == PreferString) |
benjamin@webkit.org | 762e2c6 | 2012-09-04 21:19:25 +0000 | [diff] [blame] | 78 | return jsNontrivialString(exec, String(ASCIILiteral("JavaScript execution terminated."))); |
fpizlo@apple.com | 3494d02 | 2012-11-05 18:15:23 +0000 | [diff] [blame] | 79 | return JSValue(QNaN); |
weinig@apple.com | f41a7da | 2011-09-08 22:38:44 +0000 | [diff] [blame] | 80 | } |
ddkilzer@apple.com | 69637d4 | 2009-03-23 18:27:22 +0000 | [diff] [blame] | 81 | |
barraclough@apple.com | 8da6d97 | 2010-11-16 21:11:26 +0000 | [diff] [blame] | 82 | JSObject* createTerminatedExecutionException(JSGlobalData* globalData) |
eric@webkit.org | 5d91a8d | 2010-04-07 04:38:23 +0000 | [diff] [blame] | 83 | { |
oliver@apple.com | fcacd3c | 2011-07-18 17:47:13 +0000 | [diff] [blame] | 84 | return TerminatedExecutionError::create(*globalData); |
eric@webkit.org | 5d91a8d | 2010-04-07 04:38:23 +0000 | [diff] [blame] | 85 | } |
| 86 | |
weinig@apple.com | 76c1146 | 2011-09-11 05:16:09 +0000 | [diff] [blame] | 87 | bool isTerminatedExecutionException(JSObject* object) |
| 88 | { |
| 89 | return object->inherits(&TerminatedExecutionError::s_info); |
| 90 | } |
| 91 | |
| 92 | bool isTerminatedExecutionException(JSValue value) |
| 93 | { |
| 94 | return value.inherits(&TerminatedExecutionError::s_info); |
| 95 | } |
| 96 | |
| 97 | |
barraclough@apple.com | 9c099f9 | 2010-06-06 23:34:36 +0000 | [diff] [blame] | 98 | JSObject* createStackOverflowError(ExecState* exec) |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 99 | { |
benjamin@webkit.org | 762e2c6 | 2012-09-04 21:19:25 +0000 | [diff] [blame] | 100 | return createRangeError(exec, ASCIILiteral("Maximum call stack size exceeded.")); |
oliver@apple.com | 0ef2c5b | 2009-10-07 02:06:03 +0000 | [diff] [blame] | 101 | } |
| 102 | |
barraclough@apple.com | 40b4ad3 | 2010-07-14 00:27:13 +0000 | [diff] [blame] | 103 | JSObject* createStackOverflowError(JSGlobalObject* globalObject) |
| 104 | { |
benjamin@webkit.org | 762e2c6 | 2012-09-04 21:19:25 +0000 | [diff] [blame] | 105 | return createRangeError(globalObject, ASCIILiteral("Maximum call stack size exceeded.")); |
barraclough@apple.com | 40b4ad3 | 2010-07-14 00:27:13 +0000 | [diff] [blame] | 106 | } |
| 107 | |
barraclough@apple.com | 8da6d97 | 2010-11-16 21:11:26 +0000 | [diff] [blame] | 108 | JSObject* createUndefinedVariableError(ExecState* exec, const Identifier& ident) |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 109 | { |
benjamin@webkit.org | c9b7a20 | 2012-09-08 05:46:29 +0000 | [diff] [blame] | 110 | String message(makeString("Can't find variable: ", ident.string())); |
barraclough@apple.com | e979a65 | 2010-11-16 01:30:25 +0000 | [diff] [blame] | 111 | return createReferenceError(exec, message); |
oliver@apple.com | 90b88ae | 2008-07-19 01:44:24 +0000 | [diff] [blame] | 112 | } |
| 113 | |
barraclough@apple.com | e979a65 | 2010-11-16 01:30:25 +0000 | [diff] [blame] | 114 | JSObject* createInvalidParamError(ExecState* exec, const char* op, JSValue value) |
oliver@apple.com | 90b88ae | 2008-07-19 01:44:24 +0000 | [diff] [blame] | 115 | { |
benjamin@webkit.org | cff06e4 | 2012-08-30 21:23:51 +0000 | [diff] [blame] | 116 | String errorMessage = makeString("'", value.toString(exec)->value(exec), "' is not a valid argument for '", op, "'"); |
barraclough@apple.com | e979a65 | 2010-11-16 01:30:25 +0000 | [diff] [blame] | 117 | JSObject* exception = createTypeError(exec, errorMessage); |
| 118 | ASSERT(exception->isErrorInstance()); |
| 119 | static_cast<ErrorInstance*>(exception)->setAppendSourceToMessage(); |
oliver@apple.com | 90b88ae | 2008-07-19 01:44:24 +0000 | [diff] [blame] | 120 | return exception; |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 121 | } |
| 122 | |
barraclough@apple.com | e979a65 | 2010-11-16 01:30:25 +0000 | [diff] [blame] | 123 | JSObject* createNotAConstructorError(ExecState* exec, JSValue value) |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 124 | { |
benjamin@webkit.org | cff06e4 | 2012-08-30 21:23:51 +0000 | [diff] [blame] | 125 | String errorMessage = makeString("'", value.toString(exec)->value(exec), "' is not a constructor"); |
barraclough@apple.com | e979a65 | 2010-11-16 01:30:25 +0000 | [diff] [blame] | 126 | JSObject* exception = createTypeError(exec, errorMessage); |
| 127 | ASSERT(exception->isErrorInstance()); |
| 128 | static_cast<ErrorInstance*>(exception)->setAppendSourceToMessage(); |
oliver@apple.com | 90b88ae | 2008-07-19 01:44:24 +0000 | [diff] [blame] | 129 | return exception; |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 130 | } |
| 131 | |
barraclough@apple.com | 8da6d97 | 2010-11-16 21:11:26 +0000 | [diff] [blame] | 132 | JSObject* createNotAFunctionError(ExecState* exec, JSValue value) |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 133 | { |
benjamin@webkit.org | cff06e4 | 2012-08-30 21:23:51 +0000 | [diff] [blame] | 134 | String errorMessage = makeString("'", value.toString(exec)->value(exec), "' is not a function"); |
barraclough@apple.com | e979a65 | 2010-11-16 01:30:25 +0000 | [diff] [blame] | 135 | JSObject* exception = createTypeError(exec, errorMessage); |
| 136 | ASSERT(exception->isErrorInstance()); |
| 137 | static_cast<ErrorInstance*>(exception)->setAppendSourceToMessage(); |
oliver@apple.com | 90b88ae | 2008-07-19 01:44:24 +0000 | [diff] [blame] | 138 | return exception; |
| 139 | } |
| 140 | |
barraclough@apple.com | 8da6d97 | 2010-11-16 21:11:26 +0000 | [diff] [blame] | 141 | JSObject* createNotAnObjectError(ExecState* exec, JSValue value) |
oliver@apple.com | 90b88ae | 2008-07-19 01:44:24 +0000 | [diff] [blame] | 142 | { |
benjamin@webkit.org | cff06e4 | 2012-08-30 21:23:51 +0000 | [diff] [blame] | 143 | String errorMessage = makeString("'", value.toString(exec)->value(exec), "' is not an object"); |
barraclough@apple.com | e979a65 | 2010-11-16 01:30:25 +0000 | [diff] [blame] | 144 | JSObject* exception = createTypeError(exec, errorMessage); |
| 145 | ASSERT(exception->isErrorInstance()); |
| 146 | static_cast<ErrorInstance*>(exception)->setAppendSourceToMessage(); |
oliver@apple.com | 90b88ae | 2008-07-19 01:44:24 +0000 | [diff] [blame] | 147 | return exception; |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 148 | } |
| 149 | |
benjamin@webkit.org | cff06e4 | 2012-08-30 21:23:51 +0000 | [diff] [blame] | 150 | JSObject* createErrorForInvalidGlobalAssignment(ExecState* exec, const String& propertyName) |
oliver@apple.com | aad311c | 2010-10-18 04:08:37 +0000 | [diff] [blame] | 151 | { |
benjamin@webkit.org | cff06e4 | 2012-08-30 21:23:51 +0000 | [diff] [blame] | 152 | return createReferenceError(exec, makeString("Strict mode forbids implicit creation of global property '", propertyName, "'")); |
barraclough@apple.com | 7e6bd6d | 2011-01-10 20:20:15 +0000 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | JSObject* createOutOfMemoryError(JSGlobalObject* globalObject) |
| 156 | { |
benjamin@webkit.org | 762e2c6 | 2012-09-04 21:19:25 +0000 | [diff] [blame] | 157 | return createError(globalObject, ASCIILiteral("Out of memory")); |
barraclough@apple.com | 7e6bd6d | 2011-01-10 20:20:15 +0000 | [diff] [blame] | 158 | } |
oliver@apple.com | aad311c | 2010-10-18 04:08:37 +0000 | [diff] [blame] | 159 | |
barraclough@apple.com | 2607dd0 | 2010-10-27 20:46:09 +0000 | [diff] [blame] | 160 | JSObject* throwOutOfMemoryError(ExecState* exec) |
| 161 | { |
barraclough@apple.com | 7e6bd6d | 2011-01-10 20:20:15 +0000 | [diff] [blame] | 162 | return throwError(exec, createOutOfMemoryError(exec->lexicalGlobalObject())); |
barraclough@apple.com | 2607dd0 | 2010-10-27 20:46:09 +0000 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | JSObject* throwStackOverflowError(ExecState* exec) |
| 166 | { |
mark.lam@apple.com | 8b97fde | 2012-10-22 22:09:58 +0000 | [diff] [blame] | 167 | Interpreter::ErrorHandlingMode mode(exec); |
barraclough@apple.com | 2607dd0 | 2010-10-27 20:46:09 +0000 | [diff] [blame] | 168 | return throwError(exec, createStackOverflowError(exec)); |
| 169 | } |
| 170 | |
cwzwarich@webkit.org | 3f782f6 | 2008-09-08 01:28:33 +0000 | [diff] [blame] | 171 | } // namespace JSC |