source: webkit/trunk/JavaScriptCore/VM/ExceptionHelpers.cpp@ 37891

Last change on this file since 37891 was 37845, checked in by Darin Adler, 17 years ago

JavaScriptCore:

2008-10-24 Darin Adler <Darin Adler>

  • API/APICast.h:
  • API/JSCallbackConstructor.h:
  • API/JSCallbackFunction.cpp:
  • API/JSCallbackFunction.h:
  • API/JSCallbackObject.h:
  • API/JSCallbackObjectFunctions.h:
  • API/JSContextRef.cpp:
  • API/JSObjectRef.cpp:
  • API/JSValueRef.cpp:
  • VM/CTI.cpp:
  • VM/CTI.h:
  • VM/CodeBlock.cpp:
  • VM/CodeBlock.h:
  • VM/CodeGenerator.cpp:
  • VM/CodeGenerator.h:
  • VM/ExceptionHelpers.cpp:
  • VM/ExceptionHelpers.h:
  • VM/JSPropertyNameIterator.cpp:
  • VM/JSPropertyNameIterator.h:
  • VM/Machine.cpp:
  • VM/Machine.h:
  • VM/Register.h:
  • kjs/ArgList.cpp:
  • kjs/ArgList.h:
  • kjs/Arguments.cpp:
  • kjs/Arguments.h:
  • kjs/ArrayConstructor.cpp:
  • kjs/ArrayPrototype.cpp:
  • kjs/BooleanConstructor.cpp:
  • kjs/BooleanConstructor.h:
  • kjs/BooleanObject.h:
  • kjs/BooleanPrototype.cpp:
  • kjs/CallData.cpp:
  • kjs/CallData.h:
  • kjs/ConstructData.cpp:
  • kjs/ConstructData.h:
  • kjs/DateConstructor.cpp:
  • kjs/DateInstance.h:
  • kjs/DatePrototype.cpp:
  • kjs/DatePrototype.h:
  • kjs/DebuggerCallFrame.cpp:
  • kjs/DebuggerCallFrame.h:
  • kjs/ErrorConstructor.cpp:
  • kjs/ErrorPrototype.cpp:
  • kjs/ExecState.cpp:
  • kjs/ExecState.h:
  • kjs/FunctionConstructor.cpp:
  • kjs/FunctionPrototype.cpp:
  • kjs/FunctionPrototype.h:
  • kjs/GetterSetter.cpp:
  • kjs/GetterSetter.h:
  • kjs/InternalFunction.h:
  • kjs/JSActivation.cpp:
  • kjs/JSActivation.h:
  • kjs/JSArray.cpp:
  • kjs/JSArray.h:
  • kjs/JSCell.cpp:
  • kjs/JSCell.h:
  • kjs/JSFunction.cpp:
  • kjs/JSFunction.h:
  • kjs/JSGlobalData.h:
  • kjs/JSGlobalObject.cpp:
  • kjs/JSGlobalObject.h:
  • kjs/JSGlobalObjectFunctions.cpp:
  • kjs/JSGlobalObjectFunctions.h:
  • kjs/JSImmediate.cpp:
  • kjs/JSImmediate.h:
  • kjs/JSNotAnObject.cpp:
  • kjs/JSNotAnObject.h:
  • kjs/JSNumberCell.cpp:
  • kjs/JSNumberCell.h:
  • kjs/JSObject.cpp:
  • kjs/JSObject.h:
  • kjs/JSStaticScopeObject.cpp:
  • kjs/JSStaticScopeObject.h:
  • kjs/JSString.cpp:
  • kjs/JSString.h:
  • kjs/JSValue.h:
  • kjs/JSVariableObject.h:
  • kjs/JSWrapperObject.h:
  • kjs/MathObject.cpp:
  • kjs/MathObject.h:
  • kjs/NativeErrorConstructor.cpp:
  • kjs/NumberConstructor.cpp:
  • kjs/NumberConstructor.h:
  • kjs/NumberObject.cpp:
  • kjs/NumberObject.h:
  • kjs/NumberPrototype.cpp:
  • kjs/ObjectConstructor.cpp:
  • kjs/ObjectPrototype.cpp:
  • kjs/ObjectPrototype.h:
  • kjs/PropertyMap.h:
  • kjs/PropertySlot.cpp:
  • kjs/PropertySlot.h:
  • kjs/RegExpConstructor.cpp:
  • kjs/RegExpConstructor.h:
  • kjs/RegExpMatchesArray.h:
  • kjs/RegExpObject.cpp:
  • kjs/RegExpObject.h:
  • kjs/RegExpPrototype.cpp:
  • kjs/Shell.cpp:
  • kjs/StringConstructor.cpp:
  • kjs/StringObject.cpp:
  • kjs/StringObject.h:
  • kjs/StringObjectThatMasqueradesAsUndefined.h:
  • kjs/StringPrototype.cpp:
  • kjs/StructureID.cpp:
  • kjs/StructureID.h:
  • kjs/collector.cpp:
  • kjs/collector.h:
  • kjs/completion.h:
  • kjs/grammar.y:
  • kjs/interpreter.cpp:
  • kjs/interpreter.h:
  • kjs/lookup.cpp:
  • kjs/lookup.h:
  • kjs/nodes.h:
  • kjs/operations.cpp:
  • kjs/operations.h:
  • kjs/protect.h:
  • profiler/ProfileGenerator.cpp:
  • profiler/Profiler.cpp:
  • profiler/Profiler.h: Use JSValue* instead of JSValuePtr.

JavaScriptGlue:

2008-10-24 Darin Adler <Darin Adler>

  • JSObject.cpp: (nativeCallFunction):
  • JSUtils.cpp: (KJSValueToJSObject): (JSObjectKJSValue): (KJSValueToCFTypeInternal): (KJSValueToCFType):
  • JSUtils.h:
  • JSValueWrapper.cpp: (JSValueWrapper::JSValueWrapper): (JSValueWrapper::GetValue): (JSValueWrapper::JSObjectCopyProperty): (JSValueWrapper::JSObjectSetProperty): (JSValueWrapper::JSObjectCallFunction):
  • JSValueWrapper.h:
  • UserObjectImp.cpp: (UserObjectImp::callAsFunction): (UserObjectImp::userObjectGetter): (UserObjectImp::getOwnPropertySlot): (UserObjectImp::put): (UserObjectImp::toPrimitive):
  • UserObjectImp.h: (UserObjectImp::createStructureID): Use JSValue* instead of JSValuePtr.

WebCore:

2008-10-24 Darin Adler <Darin Adler>

  • bindings/js/JSAttrCustom.cpp:
  • bindings/js/JSCSSRuleCustom.cpp:
  • bindings/js/JSCSSStyleDeclarationCustom.cpp:
  • bindings/js/JSCSSValueCustom.cpp:
  • bindings/js/JSCanvasPixelArrayCustom.h:
  • bindings/js/JSCanvasRenderingContext2DCustom.cpp:
  • bindings/js/JSClipboardCustom.cpp:
  • bindings/js/JSConsoleCustom.cpp:
  • bindings/js/JSCustomSQLStatementCallback.cpp:
  • bindings/js/JSCustomSQLStatementErrorCallback.cpp:
  • bindings/js/JSCustomSQLTransactionCallback.cpp:
  • bindings/js/JSCustomSQLTransactionErrorCallback.cpp:
  • bindings/js/JSCustomVoidCallback.cpp:
  • bindings/js/JSCustomVoidCallback.h:
  • bindings/js/JSCustomXPathNSResolver.cpp:
  • bindings/js/JSCustomXPathNSResolver.h:
  • bindings/js/JSDOMApplicationCacheCustom.cpp:
  • bindings/js/JSDOMBinding.cpp:
  • bindings/js/JSDOMBinding.h:
  • bindings/js/JSDOMWindowBase.cpp:
  • bindings/js/JSDOMWindowBase.h:
  • bindings/js/JSDOMWindowCustom.cpp:
  • bindings/js/JSDOMWindowCustom.h:
  • bindings/js/JSDOMWindowShell.cpp:
  • bindings/js/JSDOMWindowShell.h:
  • bindings/js/JSDatabaseCustom.cpp:
  • bindings/js/JSDedicatedWorkerCustom.cpp:
  • bindings/js/JSDocumentCustom.cpp:
  • bindings/js/JSElementCustom.cpp:
  • bindings/js/JSEventCustom.cpp:
  • bindings/js/JSEventListener.cpp:
  • bindings/js/JSEventTarget.cpp:
  • bindings/js/JSEventTarget.h:
  • bindings/js/JSEventTargetBase.h:
  • bindings/js/JSEventTargetNodeCustom.cpp:
  • bindings/js/JSHTMLAllCollection.h:
  • bindings/js/JSHTMLAppletElementCustom.cpp:
  • bindings/js/JSHTMLCollectionCustom.cpp:
  • bindings/js/JSHTMLDocumentCustom.cpp:
  • bindings/js/JSHTMLEmbedElementCustom.cpp:
  • bindings/js/JSHTMLFormElementCustom.cpp:
  • bindings/js/JSHTMLFrameElementCustom.cpp:
  • bindings/js/JSHTMLFrameSetElementCustom.cpp:
  • bindings/js/JSHTMLIFrameElementCustom.cpp:
  • bindings/js/JSHTMLInputElementCustom.cpp:
  • bindings/js/JSHTMLObjectElementCustom.cpp:
  • bindings/js/JSHTMLOptionsCollectionCustom.cpp:
  • bindings/js/JSHTMLSelectElementCustom.cpp:
  • bindings/js/JSHTMLSelectElementCustom.h:
  • bindings/js/JSHistoryCustom.cpp:
  • bindings/js/JSImageDataCustom.cpp:
  • bindings/js/JSInspectedObjectWrapper.cpp:
  • bindings/js/JSInspectedObjectWrapper.h:
  • bindings/js/JSInspectorCallbackWrapper.cpp:
  • bindings/js/JSInspectorCallbackWrapper.h:
  • bindings/js/JSJavaScriptCallFrameCustom.cpp:
  • bindings/js/JSLocationCustom.cpp:
  • bindings/js/JSMessagePortCustom.cpp:
  • bindings/js/JSMimeTypeArrayCustom.cpp:
  • bindings/js/JSNamedNodeMapCustom.cpp:
  • bindings/js/JSNamedNodesCollection.cpp:
  • bindings/js/JSNamedNodesCollection.h:
  • bindings/js/JSNavigatorCustom.cpp:
  • bindings/js/JSNodeCustom.cpp:
  • bindings/js/JSNodeFilterCondition.cpp:
  • bindings/js/JSNodeFilterCondition.h:
  • bindings/js/JSNodeFilterCustom.cpp:
  • bindings/js/JSNodeIteratorCustom.cpp:
  • bindings/js/JSNodeListCustom.cpp:
  • bindings/js/JSPluginArrayCustom.cpp:
  • bindings/js/JSPluginCustom.cpp:
  • bindings/js/JSPluginElementFunctions.cpp:
  • bindings/js/JSPluginElementFunctions.h:
  • bindings/js/JSQuarantinedObjectWrapper.cpp:
  • bindings/js/JSQuarantinedObjectWrapper.h:
  • bindings/js/JSRGBColor.cpp:
  • bindings/js/JSRGBColor.h:
  • bindings/js/JSSQLResultSetRowListCustom.cpp:
  • bindings/js/JSSQLTransactionCustom.cpp:
  • bindings/js/JSSVGElementInstanceCustom.cpp:
  • bindings/js/JSSVGLengthCustom.cpp:
  • bindings/js/JSSVGMatrixCustom.cpp:
  • bindings/js/JSSVGPathSegCustom.cpp:
  • bindings/js/JSSVGPathSegListCustom.cpp:
  • bindings/js/JSSVGPointListCustom.cpp:
  • bindings/js/JSSVGTransformListCustom.cpp:
  • bindings/js/JSStorageCustom.cpp:
  • bindings/js/JSStyleSheetCustom.cpp:
  • bindings/js/JSStyleSheetListCustom.cpp:
  • bindings/js/JSTextCustom.cpp:
  • bindings/js/JSTreeWalkerCustom.cpp:
  • bindings/js/JSXMLHttpRequestCustom.cpp:
  • bindings/js/JSXMLHttpRequestUploadCustom.cpp:
  • bindings/js/JSXSLTProcessorCustom.cpp:
  • bindings/js/ScheduledAction.cpp:
  • bindings/js/ScheduledAction.h:
  • bindings/js/ScriptController.cpp:
  • bindings/js/ScriptController.h:
  • bindings/objc/WebScriptObject.mm:
  • bindings/objc/WebScriptObjectPrivate.h:
  • bindings/scripts/CodeGeneratorJS.pm:
  • bridge/NP_jsobject.cpp:
  • bridge/c/c_instance.cpp:
  • bridge/c/c_instance.h:
  • bridge/c/c_runtime.cpp:
  • bridge/c/c_runtime.h:
  • bridge/c/c_utility.cpp:
  • bridge/c/c_utility.h:
  • bridge/jni/jni_instance.cpp:
  • bridge/jni/jni_instance.h:
  • bridge/jni/jni_jsobject.h:
  • bridge/jni/jni_jsobject.mm:
  • bridge/jni/jni_objc.mm:
  • bridge/jni/jni_runtime.cpp:
  • bridge/jni/jni_runtime.h:
  • bridge/jni/jni_utility.cpp:
  • bridge/jni/jni_utility.h:
  • bridge/objc/WebScriptObject.h:
  • bridge/objc/objc_class.h:
  • bridge/objc/objc_class.mm:
  • bridge/objc/objc_instance.h:
  • bridge/objc/objc_instance.mm:
  • bridge/objc/objc_runtime.h:
  • bridge/objc/objc_runtime.mm:
  • bridge/objc/objc_utility.h:
  • bridge/objc/objc_utility.mm:
  • bridge/qt/qt_class.cpp:
  • bridge/qt/qt_class.h:
  • bridge/qt/qt_instance.cpp:
  • bridge/qt/qt_instance.h:
  • bridge/qt/qt_runtime.cpp:
  • bridge/qt/qt_runtime.h:
  • bridge/runtime.cpp:
  • bridge/runtime.h:
  • bridge/runtime_array.cpp:
  • bridge/runtime_array.h:
  • bridge/runtime_method.cpp:
  • bridge/runtime_method.h:
  • bridge/runtime_object.cpp:
  • bridge/runtime_object.h:
  • bridge/testqtbindings.cpp:
  • inspector/JavaScriptCallFrame.cpp:
  • inspector/JavaScriptCallFrame.h:
  • inspector/JavaScriptProfile.cpp:
  • inspector/JavaScriptProfile.h:
  • inspector/JavaScriptProfileNode.cpp:
  • inspector/JavaScriptProfileNode.h:
  • loader/FrameLoader.cpp:
  • loader/FrameLoader.h:
  • page/Console.cpp:
  • page/Console.h:
  • plugins/MimeTypeArray.h:
  • plugins/Plugin.h:
  • plugins/PluginArray.h:
  • plugins/PluginView.cpp:
  • xml/XMLHttpRequest.cpp: Use JSValue* instead of JSValuePtr.

WebKit/mac:

2008-10-24 Darin Adler <Darin Adler>

  • WebView/WebFrame.mm: (-[WebFrame _stringByEvaluatingJavaScriptFromString:forceUserGesture:]):
  • WebView/WebScriptDebugDelegate.mm: (-[WebScriptCallFrame _convertValueToObjcValue:]): (-[WebScriptCallFrame exception]): (-[WebScriptCallFrame evaluateWebScript:]):
  • WebView/WebView.mm: (aeDescFromJSValue): (-[WebView aeDescByEvaluatingJavaScriptFromString:]): Use JSValue* instead of JSValuePtr.

WebKit/qt:

2008-10-24 Darin Adler <Darin Adler>

  • Api/qwebframe.cpp: (QWebFrame::evaluateJavaScript): Use JSValue* instead of JSValuePtr.

WebKit/win:

2008-10-24 Darin Adler <Darin Adler>

  • WebScriptCallFrame.cpp: (WebScriptCallFrame::jsValueToString): (WebScriptCallFrame::stringByEvaluatingJavaScriptFromString): (WebScriptCallFrame::valueForVariable): (WebScriptCallFrame::valueByEvaluatingJavaScriptFromString):
  • WebScriptCallFrame.h:
  • WebView.cpp: (WebView::stringByEvaluatingJavaScriptFromString): Use JSValue* instead of JSValuePtr.

WebKit/wx:

2008-10-24 Darin Adler <Darin Adler>

  • WebFrame.cpp: (wxWebFrame::RunScript): Use JSValue* instead of JSValuePtr.
File size: 10.9 KB
Line 
1/*
2 * Copyright (C) 2008 Apple Inc. All rights reserved.
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
32#include "CodeBlock.h"
33#include "ExecState.h"
34#include "JSObject.h"
35#include "JSNotAnObject.h"
36#include "Machine.h"
37#include "nodes.h"
38
39namespace JSC {
40
41static void substitute(UString& string, const UString& substring)
42{
43 int position = string.find("%s");
44 ASSERT(position != -1);
45 UString newString = string.substr(0, position);
46 newString.append(substring);
47 newString.append(string.substr(position + 2));
48 string = newString;
49}
50
51class InterruptedExecutionError : public JSObject {
52public:
53 InterruptedExecutionError(JSGlobalData* globalData)
54 : JSObject(globalData->interruptedExecutionErrorStructure)
55 {
56 }
57
58 virtual bool isWatchdogException() const { return true; }
59};
60
61JSValue* createInterruptedExecutionException(JSGlobalData* globalData)
62{
63 return new (globalData) InterruptedExecutionError(globalData);
64}
65
66JSValue* createError(ExecState* exec, ErrorType e, const char* msg)
67{
68 return Error::create(exec, e, msg, -1, -1, 0);
69}
70
71JSValue* createError(ExecState* exec, ErrorType e, const char* msg, const Identifier& label)
72{
73 UString message = msg;
74 substitute(message, label.ustring());
75 return Error::create(exec, e, message, -1, -1, 0);
76}
77
78JSValue* createError(ExecState* exec, ErrorType e, const char* msg, JSValue* v)
79{
80 UString message = msg;
81 substitute(message, v->toString(exec));
82 return Error::create(exec, e, message, -1, -1, 0);
83}
84
85JSValue* createStackOverflowError(ExecState* exec)
86{
87 return createError(exec, RangeError, "Maximum call stack size exceeded.");
88}
89
90JSValue* createUndefinedVariableError(ExecState* exec, const Identifier& ident, const Instruction* vPC, CodeBlock* codeBlock)
91{
92 int startOffset = 0;
93 int endOffset = 0;
94 int divotPoint = 0;
95 int line = codeBlock->expressionRangeForVPC(vPC, divotPoint, startOffset, endOffset);
96 UString message = "Can't find variable: ";
97 message.append(ident.ustring());
98 JSObject* exception = Error::create(exec, ReferenceError, message, line, codeBlock->ownerNode->sourceID(), codeBlock->ownerNode->sourceURL());
99 exception->putWithAttributes(exec, Identifier(exec, expressionBeginOffsetPropertyName), jsNumber(exec, divotPoint - startOffset), ReadOnly | DontDelete);
100 exception->putWithAttributes(exec, Identifier(exec, expressionCaretOffsetPropertyName), jsNumber(exec, divotPoint), ReadOnly | DontDelete);
101 exception->putWithAttributes(exec, Identifier(exec, expressionEndOffsetPropertyName), jsNumber(exec, divotPoint + endOffset), ReadOnly | DontDelete);
102 return exception;
103}
104
105bool isStrWhiteSpace(UChar c);
106
107static UString createErrorMessage(ExecState* exec, CodeBlock* codeBlock, int, int expressionStart, int expressionStop, JSValue* value, UString error)
108{
109 if (!expressionStop || expressionStart > codeBlock->source->length()) {
110 UString errorText = value->toString(exec);
111 errorText.append(" is ");
112 errorText.append(error);
113 return errorText;
114 }
115
116 UString errorText = "Result of expression ";
117
118 if (expressionStart < expressionStop) {
119 errorText.append('\'');
120 errorText.append(codeBlock->source->getRange(expressionStart, expressionStop));
121 errorText.append("' [");
122 errorText.append(value->toString(exec));
123 errorText.append("] is ");
124 } else {
125 // No range information, so give a few characters of context
126 const UChar* data = codeBlock->source->data();
127 int dataLength = codeBlock->source->length();
128 int start = expressionStart;
129 int stop = expressionStart;
130 // Get up to 20 characters of context to the left and right of the divot, clamping to the line.
131 // then strip whitespace.
132 while (start > 0 && (expressionStart - start < 20) && data[start - 1] != '\n')
133 start--;
134 while (start < (expressionStart - 1) && isStrWhiteSpace(data[start]))
135 start++;
136 while (stop < dataLength && (stop - expressionStart < 20) && data[stop] != '\n')
137 stop++;
138 while (stop > expressionStart && isStrWhiteSpace(data[stop]))
139 stop--;
140 errorText.append("near '...");
141 errorText.append(codeBlock->source->getRange(start, stop));
142 errorText.append("...' [");
143 errorText.append(value->toString(exec));
144 errorText.append("] is ");
145 }
146 errorText.append(error);
147 errorText.append(".");
148 return errorText;
149}
150
151JSObject* createInvalidParamError(ExecState* exec, const char* op, JSValue* value, const Instruction* vPC, CodeBlock* codeBlock)
152{
153 UString message = "not a valid argument for '";
154 message.append(op);
155 message.append("'");
156
157 int startOffset = 0;
158 int endOffset = 0;
159 int divotPoint = 0;
160 int line = codeBlock->expressionRangeForVPC(vPC, divotPoint, startOffset, endOffset);
161 UString errorMessage = createErrorMessage(exec, codeBlock, line, divotPoint, divotPoint + endOffset, value, message);
162 JSObject* exception = Error::create(exec, TypeError, errorMessage, line, codeBlock->ownerNode->sourceID(), codeBlock->ownerNode->sourceURL());
163 exception->putWithAttributes(exec, Identifier(exec, expressionBeginOffsetPropertyName), jsNumber(exec, divotPoint - startOffset), ReadOnly | DontDelete);
164 exception->putWithAttributes(exec, Identifier(exec, expressionCaretOffsetPropertyName), jsNumber(exec, divotPoint), ReadOnly | DontDelete);
165 exception->putWithAttributes(exec, Identifier(exec, expressionEndOffsetPropertyName), jsNumber(exec, divotPoint + endOffset), ReadOnly | DontDelete);
166 return exception;
167}
168
169JSObject* createNotAConstructorError(ExecState* exec, JSValue* value, const Instruction* vPC, CodeBlock* codeBlock)
170{
171 int startOffset = 0;
172 int endOffset = 0;
173 int divotPoint = 0;
174 int line = codeBlock->expressionRangeForVPC(vPC, divotPoint, startOffset, endOffset);
175
176 // We're in a "new" expression, so we need to skip over the "new.." part
177 int startPoint = divotPoint - (startOffset ? startOffset - 4 : 0); // -4 for "new "
178 const UChar* data = codeBlock->source->data();
179 while (startPoint < divotPoint && isStrWhiteSpace(data[startPoint]))
180 startPoint++;
181
182 UString errorMessage = createErrorMessage(exec, codeBlock, line, startPoint, divotPoint, value, "not a constructor");
183 JSObject* exception = Error::create(exec, TypeError, errorMessage, line, codeBlock->ownerNode->sourceID(), codeBlock->ownerNode->sourceURL());
184 exception->putWithAttributes(exec, Identifier(exec, expressionBeginOffsetPropertyName), jsNumber(exec, divotPoint - startOffset), ReadOnly | DontDelete);
185 exception->putWithAttributes(exec, Identifier(exec, expressionCaretOffsetPropertyName), jsNumber(exec, divotPoint), ReadOnly | DontDelete);
186 exception->putWithAttributes(exec, Identifier(exec, expressionEndOffsetPropertyName), jsNumber(exec, divotPoint + endOffset), ReadOnly | DontDelete);
187 return exception;
188}
189
190JSValue* createNotAFunctionError(ExecState* exec, JSValue* value, const Instruction* vPC, CodeBlock* codeBlock)
191{
192 int startOffset = 0;
193 int endOffset = 0;
194 int divotPoint = 0;
195 int line = codeBlock->expressionRangeForVPC(vPC, divotPoint, startOffset, endOffset);
196 UString errorMessage = createErrorMessage(exec, codeBlock, line, divotPoint - startOffset, divotPoint, value, "not a function");
197 JSObject* exception = Error::create(exec, TypeError, errorMessage, line, codeBlock->ownerNode->sourceID(), codeBlock->ownerNode->sourceURL());
198 exception->putWithAttributes(exec, Identifier(exec, expressionBeginOffsetPropertyName), jsNumber(exec, divotPoint - startOffset), ReadOnly | DontDelete);
199 exception->putWithAttributes(exec, Identifier(exec, expressionCaretOffsetPropertyName), jsNumber(exec, divotPoint), ReadOnly | DontDelete);
200 exception->putWithAttributes(exec, Identifier(exec, expressionEndOffsetPropertyName), jsNumber(exec, divotPoint + endOffset), ReadOnly | DontDelete);
201 return exception;
202}
203
204JSNotAnObjectErrorStub* createNotAnObjectErrorStub(ExecState* exec, bool isNull)
205{
206 return new (exec) JSNotAnObjectErrorStub(exec, isNull);
207}
208
209JSObject* createNotAnObjectError(ExecState* exec, JSNotAnObjectErrorStub* error, const Instruction* vPC, CodeBlock* codeBlock)
210{
211 if (vPC[8].u.opcode == exec->machine()->getOpcode(op_instanceof))
212 return createInvalidParamError(exec, "instanceof", error->isNull() ? jsNull() : jsUndefined(), vPC, codeBlock);
213 if (vPC[8].u.opcode == exec->machine()->getOpcode(op_construct))
214 return createNotAConstructorError(exec, error->isNull() ? jsNull() : jsUndefined(), vPC, codeBlock);
215
216 int startOffset = 0;
217 int endOffset = 0;
218 int divotPoint = 0;
219 int line = codeBlock->expressionRangeForVPC(vPC, divotPoint, startOffset, endOffset);
220 UString errorMessage = createErrorMessage(exec, codeBlock, line, divotPoint - startOffset, divotPoint, error->isNull() ? jsNull() : jsUndefined(), "not an object");
221 JSObject* exception = Error::create(exec, TypeError, errorMessage, line, codeBlock->ownerNode->sourceID(), codeBlock->ownerNode->sourceURL());
222 exception->putWithAttributes(exec, Identifier(exec, expressionBeginOffsetPropertyName), jsNumber(exec, divotPoint - startOffset), ReadOnly | DontDelete);
223 exception->putWithAttributes(exec, Identifier(exec, expressionCaretOffsetPropertyName), jsNumber(exec, divotPoint), ReadOnly | DontDelete);
224 exception->putWithAttributes(exec, Identifier(exec, expressionEndOffsetPropertyName), jsNumber(exec, divotPoint + endOffset), ReadOnly | DontDelete);
225 return exception;
226}
227
228} // namespace JSC
Note: See TracBrowser for help on using the repository browser.