Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(24)

Side by Side Diff: Source/bindings/core/v8/PrivateScriptRunner.cpp

Issue 389913003: Make error messages about private scripts more descriptive (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "config.h" 5 #include "config.h"
6 #include "bindings/core/v8/PrivateScriptRunner.h" 6 #include "bindings/core/v8/PrivateScriptRunner.h"
7 7
8 #include "bindings/core/v8/DOMWrapperWorld.h" 8 #include "bindings/core/v8/DOMWrapperWorld.h"
9 #include "bindings/core/v8/ExceptionState.h" 9 #include "bindings/core/v8/ExceptionState.h"
10 #include "bindings/core/v8/V8Binding.h" 10 #include "bindings/core/v8/V8Binding.h"
(...skipping 19 matching lines...) Expand all
30 return V8ScriptRunner::compileAndRunInternalScript(v8String(isolate, sou rce), isolate); 30 return V8ScriptRunner::compileAndRunInternalScript(v8String(isolate, sou rce), isolate);
31 } 31 }
32 #endif 32 #endif
33 33
34 // |kPrivateScriptSources| is defined in V8PrivateScriptSources.h, which is auto-generated 34 // |kPrivateScriptSources| is defined in V8PrivateScriptSources.h, which is auto-generated
35 // by make_private_script.py. 35 // by make_private_script.py.
36 for (index = 0; index < WTF_ARRAY_LENGTH(kPrivateScriptSources); index++) { 36 for (index = 0; index < WTF_ARRAY_LENGTH(kPrivateScriptSources); index++) {
37 if (className == kPrivateScriptSources[index].name) 37 if (className == kPrivateScriptSources[index].name)
38 break; 38 break;
39 } 39 }
40 RELEASE_ASSERT(index != WTF_ARRAY_LENGTH(kPrivateScriptSources)); 40 if (index == WTF_ARRAY_LENGTH(kPrivateScriptSources)) {
41 FATAL("Private script error: Target source code was not found. (Class na me = %s)\n", className.utf8().data());
42 RELEASE_ASSERT_NOT_REACHED();
43 }
44
45 v8::TryCatch block;
41 String source(reinterpret_cast<const char*>(kPrivateScriptSources[index].sou rce), kPrivateScriptSources[index].size); 46 String source(reinterpret_cast<const char*>(kPrivateScriptSources[index].sou rce), kPrivateScriptSources[index].size);
42 return V8ScriptRunner::compileAndRunInternalScript(v8String(isolate, source) , isolate); 47 v8::Handle<v8::Value> result = V8ScriptRunner::compileAndRunInternalScript(v 8String(isolate, source), isolate);
48 if (block.HasCaught()) {
49 FATAL("Private script error: Compile failed. (Class name = %s)\n", class Name.utf8().data());
50 if (!block.Message().IsEmpty())
51 FATAL("%s\n", toCoreString(block.Message()->Get()).utf8().data());
52 RELEASE_ASSERT_NOT_REACHED();
53 }
54 return result;
43 } 55 }
44 56
45 static v8::Handle<v8::Object> classObjectOfPrivateScript(ScriptState* scriptStat e, String className) 57 static v8::Handle<v8::Object> classObjectOfPrivateScript(ScriptState* scriptStat e, String className)
46 { 58 {
47 ASSERT(scriptState->perContextData()); 59 ASSERT(scriptState->perContextData());
48 ASSERT(scriptState->executionContext()); 60 ASSERT(scriptState->executionContext());
49 v8::Isolate* isolate = scriptState->isolate(); 61 v8::Isolate* isolate = scriptState->isolate();
50 v8::Handle<v8::Value> compiledClass = scriptState->perContextData()->compile dPrivateScript(className); 62 v8::Handle<v8::Value> compiledClass = scriptState->perContextData()->compile dPrivateScript(className);
51 if (compiledClass.IsEmpty()) { 63 if (compiledClass.IsEmpty()) {
52 v8::Handle<v8::Value> installedClasses = scriptState->perContextData()-> compiledPrivateScript("PrivateScriptRunner"); 64 v8::Handle<v8::Value> installedClasses = scriptState->perContextData()-> compiledPrivateScript("PrivateScriptRunner");
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 static void initializeHolderIfNeeded(ScriptState* scriptState, v8::Handle<v8::Ob ject> classObject, v8::Handle<v8::Value> holder) 98 static void initializeHolderIfNeeded(ScriptState* scriptState, v8::Handle<v8::Ob ject> classObject, v8::Handle<v8::Value> holder)
87 { 99 {
88 RELEASE_ASSERT(!holder.IsEmpty()); 100 RELEASE_ASSERT(!holder.IsEmpty());
89 RELEASE_ASSERT(holder->IsObject()); 101 RELEASE_ASSERT(holder->IsObject());
90 v8::Handle<v8::Object> holderObject = v8::Handle<v8::Object>::Cast(holder); 102 v8::Handle<v8::Object> holderObject = v8::Handle<v8::Object>::Cast(holder);
91 v8::Isolate* isolate = scriptState->isolate(); 103 v8::Isolate* isolate = scriptState->isolate();
92 v8::Handle<v8::Value> isInitialized = V8HiddenValue::getHiddenValue(isolate, holderObject, V8HiddenValue::privateScriptObjectIsInitialized(isolate)); 104 v8::Handle<v8::Value> isInitialized = V8HiddenValue::getHiddenValue(isolate, holderObject, V8HiddenValue::privateScriptObjectIsInitialized(isolate));
93 if (isInitialized.IsEmpty()) { 105 if (isInitialized.IsEmpty()) {
94 v8::Handle<v8::Value> initializeFunction = classObject->Get(v8String(iso late, "constructor")); 106 v8::Handle<v8::Value> initializeFunction = classObject->Get(v8String(iso late, "constructor"));
95 if (!initializeFunction.IsEmpty() && initializeFunction->IsFunction()) { 107 if (!initializeFunction.IsEmpty() && initializeFunction->IsFunction()) {
108 v8::TryCatch block;
96 V8ScriptRunner::callFunction(v8::Handle<v8::Function>::Cast(initiali zeFunction), scriptState->executionContext(), holder, 0, 0, isolate); 109 V8ScriptRunner::callFunction(v8::Handle<v8::Function>::Cast(initiali zeFunction), scriptState->executionContext(), holder, 0, 0, isolate);
110 if (block.HasCaught()) {
111 FATAL("Private script error: Object constructor threw an excepti on.\n");
112 if (!block.Message().IsEmpty())
113 FATAL("%s\n", toCoreString(block.Message()->Get()).utf8().da ta());
114 RELEASE_ASSERT_NOT_REACHED();
115 }
97 } 116 }
98 isInitialized = v8Boolean(true, isolate); 117 isInitialized = v8Boolean(true, isolate);
99 V8HiddenValue::setHiddenValue(isolate, holderObject, V8HiddenValue::priv ateScriptObjectIsInitialized(isolate), isInitialized); 118 V8HiddenValue::setHiddenValue(isolate, holderObject, V8HiddenValue::priv ateScriptObjectIsInitialized(isolate), isInitialized);
100 } 119 }
101 } 120 }
102 121
103 v8::Handle<v8::Value> PrivateScriptRunner::installClass(LocalFrame* frame, Strin g className) 122 v8::Handle<v8::Value> PrivateScriptRunner::installClass(LocalFrame* frame, Strin g className)
104 { 123 {
105 if (!frame) 124 if (!frame)
106 return v8::Handle<v8::Value>(); 125 return v8::Handle<v8::Value>();
107 v8::Handle<v8::Context> context = toV8Context(frame, DOMWrapperWorld::privat eScriptIsolatedWorld()); 126 v8::Handle<v8::Context> context = toV8Context(frame, DOMWrapperWorld::privat eScriptIsolatedWorld());
108 if (context.IsEmpty()) 127 if (context.IsEmpty())
109 return v8::Handle<v8::Value>(); 128 return v8::Handle<v8::Value>();
110 ScriptState* scriptState = ScriptState::from(context); 129 ScriptState* scriptState = ScriptState::from(context);
111 if (!scriptState->executionContext()) 130 if (!scriptState->executionContext())
112 return v8::Handle<v8::Value>(); 131 return v8::Handle<v8::Value>();
113 132
114 ScriptState::Scope scope(scriptState); 133 ScriptState::Scope scope(scriptState);
115 return classObjectOfPrivateScript(scriptState, className); 134 return classObjectOfPrivateScript(scriptState, className);
116 } 135 }
117 136
118 v8::Handle<v8::Value> PrivateScriptRunner::runDOMAttributeGetter(ScriptState* sc riptState, String className, String attributeName, v8::Handle<v8::Value> holder) 137 v8::Handle<v8::Value> PrivateScriptRunner::runDOMAttributeGetter(ScriptState* sc riptState, String className, String attributeName, v8::Handle<v8::Value> holder)
119 { 138 {
120 v8::Handle<v8::Object> classObject = classObjectOfPrivateScript(scriptState, className); 139 v8::Handle<v8::Object> classObject = classObjectOfPrivateScript(scriptState, className);
121 v8::Handle<v8::Object> descriptor = getOwnPropertyDescriptor(scriptState, cl assObject, attributeName); 140 v8::Handle<v8::Object> descriptor = getOwnPropertyDescriptor(scriptState, cl assObject, attributeName);
122 v8::Handle<v8::Value> getter = descriptor->Get(v8String(scriptState->isolate (), "get")); 141 v8::Handle<v8::Value> getter = descriptor->Get(v8String(scriptState->isolate (), "get"));
123 RELEASE_ASSERT(!getter.IsEmpty()); 142 if (getter.IsEmpty() || !getter->IsFunction()) {
124 RELEASE_ASSERT(getter->IsFunction()); 143 FATAL("Private script error: Target DOM attribute getter was not found. (Class name = %s, Attribute name = %s)\n", className.utf8().data(), attributeNam e.utf8().data());
144 RELEASE_ASSERT_NOT_REACHED();
145 }
125 initializeHolderIfNeeded(scriptState, classObject, holder); 146 initializeHolderIfNeeded(scriptState, classObject, holder);
126 return V8ScriptRunner::callFunction(v8::Handle<v8::Function>::Cast(getter), scriptState->executionContext(), holder, 0, 0, scriptState->isolate()); 147 return V8ScriptRunner::callFunction(v8::Handle<v8::Function>::Cast(getter), scriptState->executionContext(), holder, 0, 0, scriptState->isolate());
127 } 148 }
128 149
129 void PrivateScriptRunner::runDOMAttributeSetter(ScriptState* scriptState, String className, String attributeName, v8::Handle<v8::Value> holder, v8::Handle<v8::V alue> v8Value) 150 void PrivateScriptRunner::runDOMAttributeSetter(ScriptState* scriptState, String className, String attributeName, v8::Handle<v8::Value> holder, v8::Handle<v8::V alue> v8Value)
130 { 151 {
131 v8::Handle<v8::Object> classObject = classObjectOfPrivateScript(scriptState, className); 152 v8::Handle<v8::Object> classObject = classObjectOfPrivateScript(scriptState, className);
132 v8::Handle<v8::Object> descriptor = getOwnPropertyDescriptor(scriptState, cl assObject, attributeName); 153 v8::Handle<v8::Object> descriptor = getOwnPropertyDescriptor(scriptState, cl assObject, attributeName);
133 v8::Handle<v8::Value> setter = descriptor->Get(v8String(scriptState->isolate (), "set")); 154 v8::Handle<v8::Value> setter = descriptor->Get(v8String(scriptState->isolate (), "set"));
134 RELEASE_ASSERT(!setter.IsEmpty()); 155 if (setter.IsEmpty() || !setter->IsFunction()) {
135 RELEASE_ASSERT(setter->IsFunction()); 156 FATAL("Private script error: Target DOM attribute setter was not found. (Class name = %s, Attribute name = %s)\n", className.utf8().data(), attributeNam e.utf8().data());
157 RELEASE_ASSERT_NOT_REACHED();
158 }
136 initializeHolderIfNeeded(scriptState, classObject, holder); 159 initializeHolderIfNeeded(scriptState, classObject, holder);
137 v8::Handle<v8::Value> argv[] = { v8Value }; 160 v8::Handle<v8::Value> argv[] = { v8Value };
138 V8ScriptRunner::callFunction(v8::Handle<v8::Function>::Cast(setter), scriptS tate->executionContext(), holder, WTF_ARRAY_LENGTH(argv), argv, scriptState->iso late()); 161 V8ScriptRunner::callFunction(v8::Handle<v8::Function>::Cast(setter), scriptS tate->executionContext(), holder, WTF_ARRAY_LENGTH(argv), argv, scriptState->iso late());
139 } 162 }
140 163
141 v8::Handle<v8::Value> PrivateScriptRunner::runDOMMethod(ScriptState* scriptState , String className, String methodName, v8::Handle<v8::Value> holder, int argc, v 8::Handle<v8::Value> argv[]) 164 v8::Handle<v8::Value> PrivateScriptRunner::runDOMMethod(ScriptState* scriptState , String className, String methodName, v8::Handle<v8::Value> holder, int argc, v 8::Handle<v8::Value> argv[])
142 { 165 {
143 v8::Handle<v8::Object> classObject = classObjectOfPrivateScript(scriptState, className); 166 v8::Handle<v8::Object> classObject = classObjectOfPrivateScript(scriptState, className);
144 v8::Handle<v8::Value> method = classObject->Get(v8String(scriptState->isolat e(), methodName)); 167 v8::Handle<v8::Value> method = classObject->Get(v8String(scriptState->isolat e(), methodName));
145 RELEASE_ASSERT(!method.IsEmpty()); 168 if (method.IsEmpty() || !method->IsFunction()) {
146 RELEASE_ASSERT(method->IsFunction()); 169 FATAL("Private script error: Target DOM method was not found. (Class nam e = %s, Method name = %s)\n", className.utf8().data(), methodName.utf8().data()) ;
170 RELEASE_ASSERT_NOT_REACHED();
171 }
147 initializeHolderIfNeeded(scriptState, classObject, holder); 172 initializeHolderIfNeeded(scriptState, classObject, holder);
148 return V8ScriptRunner::callFunction(v8::Handle<v8::Function>::Cast(method), scriptState->executionContext(), holder, argc, argv, scriptState->isolate()); 173 return V8ScriptRunner::callFunction(v8::Handle<v8::Function>::Cast(method), scriptState->executionContext(), holder, argc, argv, scriptState->isolate());
149 } 174 }
150 175
151 bool PrivateScriptRunner::throwDOMExceptionInPrivateScriptIfNeeded(v8::Isolate* isolate, ExceptionState& exceptionState, v8::Handle<v8::Value> exception) 176 bool PrivateScriptRunner::throwDOMExceptionInPrivateScriptIfNeeded(v8::Isolate* isolate, ExceptionState& exceptionState, v8::Handle<v8::Value> exception)
152 { 177 {
153 if (exception.IsEmpty() || !exception->IsObject()) 178 if (exception.IsEmpty() || !exception->IsObject())
154 return false; 179 return false;
155 180
156 v8::Handle<v8::Object> exceptionObject = v8::Handle<v8::Object>::Cast(except ion); 181 v8::Handle<v8::Object> exceptionObject = v8::Handle<v8::Object>::Cast(except ion);
157 v8::Handle<v8::Value> type = exceptionObject->Get(v8String(isolate, "type")) ; 182 v8::Handle<v8::Value> type = exceptionObject->Get(v8String(isolate, "type")) ;
158 if (type.IsEmpty() || !type->IsString()) 183 if (type.IsEmpty() || !type->IsString())
159 return false; 184 return false;
160 if (toCoreString(v8::Handle<v8::String>::Cast(type)) != "DOMExceptionInPriva teScript") 185 if (toCoreString(v8::Handle<v8::String>::Cast(type)) != "DOMExceptionInPriva teScript")
161 return false; 186 return false;
162 187
163 v8::Handle<v8::Value> message = exceptionObject->Get(v8String(isolate, "mess age")); 188 v8::Handle<v8::Value> message = exceptionObject->Get(v8String(isolate, "mess age"));
164 RELEASE_ASSERT(!message.IsEmpty() && message->IsString()); 189 RELEASE_ASSERT(!message.IsEmpty() && message->IsString());
165 v8::Handle<v8::Value> code = exceptionObject->Get(v8String(isolate, "code")) ; 190 v8::Handle<v8::Value> code = exceptionObject->Get(v8String(isolate, "code")) ;
166 RELEASE_ASSERT(!code.IsEmpty() && code->IsInt32()); 191 RELEASE_ASSERT(!code.IsEmpty() && code->IsInt32());
167 // FIXME: Support JavaScript errors such as TypeError, RangeError and Securi tyError. 192 // FIXME: Support JavaScript errors such as TypeError, RangeError and Securi tyError.
168 exceptionState.throwDOMException(toInt32(code), toCoreString(v8::Handle<v8:: String>::Cast(message))); 193 exceptionState.throwDOMException(toInt32(code), toCoreString(v8::Handle<v8:: String>::Cast(message)));
169 exceptionState.throwIfNeeded(); 194 exceptionState.throwIfNeeded();
170 return true; 195 return true;
171 } 196 }
172 197
173 } // namespace WebCore 198 } // namespace WebCore
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698