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

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

Issue 394493003: Revert of 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 if (index == WTF_ARRAY_LENGTH(kPrivateScriptSources)) { 40 RELEASE_ASSERT(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;
46 String source(reinterpret_cast<const char*>(kPrivateScriptSources[index].sou rce), kPrivateScriptSources[index].size); 41 String source(reinterpret_cast<const char*>(kPrivateScriptSources[index].sou rce), kPrivateScriptSources[index].size);
47 v8::Handle<v8::Value> result = V8ScriptRunner::compileAndRunInternalScript(v 8String(isolate, source), isolate); 42 return V8ScriptRunner::compileAndRunInternalScript(v8String(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;
55 } 43 }
56 44
57 static v8::Handle<v8::Object> classObjectOfPrivateScript(ScriptState* scriptStat e, String className) 45 static v8::Handle<v8::Object> classObjectOfPrivateScript(ScriptState* scriptStat e, String className)
58 { 46 {
59 ASSERT(scriptState->perContextData()); 47 ASSERT(scriptState->perContextData());
60 ASSERT(scriptState->executionContext()); 48 ASSERT(scriptState->executionContext());
61 v8::Isolate* isolate = scriptState->isolate(); 49 v8::Isolate* isolate = scriptState->isolate();
62 v8::Handle<v8::Value> compiledClass = scriptState->perContextData()->compile dPrivateScript(className); 50 v8::Handle<v8::Value> compiledClass = scriptState->perContextData()->compile dPrivateScript(className);
63 if (compiledClass.IsEmpty()) { 51 if (compiledClass.IsEmpty()) {
64 v8::Handle<v8::Value> installedClasses = scriptState->perContextData()-> compiledPrivateScript("PrivateScriptRunner"); 52 v8::Handle<v8::Value> installedClasses = scriptState->perContextData()-> compiledPrivateScript("PrivateScriptRunner");
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 static void initializeHolderIfNeeded(ScriptState* scriptState, v8::Handle<v8::Ob ject> classObject, v8::Handle<v8::Value> holder) 86 static void initializeHolderIfNeeded(ScriptState* scriptState, v8::Handle<v8::Ob ject> classObject, v8::Handle<v8::Value> holder)
99 { 87 {
100 RELEASE_ASSERT(!holder.IsEmpty()); 88 RELEASE_ASSERT(!holder.IsEmpty());
101 RELEASE_ASSERT(holder->IsObject()); 89 RELEASE_ASSERT(holder->IsObject());
102 v8::Handle<v8::Object> holderObject = v8::Handle<v8::Object>::Cast(holder); 90 v8::Handle<v8::Object> holderObject = v8::Handle<v8::Object>::Cast(holder);
103 v8::Isolate* isolate = scriptState->isolate(); 91 v8::Isolate* isolate = scriptState->isolate();
104 v8::Handle<v8::Value> isInitialized = V8HiddenValue::getHiddenValue(isolate, holderObject, V8HiddenValue::privateScriptObjectIsInitialized(isolate)); 92 v8::Handle<v8::Value> isInitialized = V8HiddenValue::getHiddenValue(isolate, holderObject, V8HiddenValue::privateScriptObjectIsInitialized(isolate));
105 if (isInitialized.IsEmpty()) { 93 if (isInitialized.IsEmpty()) {
106 v8::Handle<v8::Value> initializeFunction = classObject->Get(v8String(iso late, "constructor")); 94 v8::Handle<v8::Value> initializeFunction = classObject->Get(v8String(iso late, "constructor"));
107 if (!initializeFunction.IsEmpty() && initializeFunction->IsFunction()) { 95 if (!initializeFunction.IsEmpty() && initializeFunction->IsFunction()) {
108 v8::TryCatch block;
109 V8ScriptRunner::callFunction(v8::Handle<v8::Function>::Cast(initiali zeFunction), scriptState->executionContext(), holder, 0, 0, isolate); 96 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 }
116 } 97 }
117 isInitialized = v8Boolean(true, isolate); 98 isInitialized = v8Boolean(true, isolate);
118 V8HiddenValue::setHiddenValue(isolate, holderObject, V8HiddenValue::priv ateScriptObjectIsInitialized(isolate), isInitialized); 99 V8HiddenValue::setHiddenValue(isolate, holderObject, V8HiddenValue::priv ateScriptObjectIsInitialized(isolate), isInitialized);
119 } 100 }
120 } 101 }
121 102
122 v8::Handle<v8::Value> PrivateScriptRunner::installClass(LocalFrame* frame, Strin g className) 103 v8::Handle<v8::Value> PrivateScriptRunner::installClass(LocalFrame* frame, Strin g className)
123 { 104 {
124 if (!frame) 105 if (!frame)
125 return v8::Handle<v8::Value>(); 106 return v8::Handle<v8::Value>();
126 v8::Handle<v8::Context> context = toV8Context(frame, DOMWrapperWorld::privat eScriptIsolatedWorld()); 107 v8::Handle<v8::Context> context = toV8Context(frame, DOMWrapperWorld::privat eScriptIsolatedWorld());
127 if (context.IsEmpty()) 108 if (context.IsEmpty())
128 return v8::Handle<v8::Value>(); 109 return v8::Handle<v8::Value>();
129 ScriptState* scriptState = ScriptState::from(context); 110 ScriptState* scriptState = ScriptState::from(context);
130 if (!scriptState->executionContext()) 111 if (!scriptState->executionContext())
131 return v8::Handle<v8::Value>(); 112 return v8::Handle<v8::Value>();
132 113
133 ScriptState::Scope scope(scriptState); 114 ScriptState::Scope scope(scriptState);
134 return classObjectOfPrivateScript(scriptState, className); 115 return classObjectOfPrivateScript(scriptState, className);
135 } 116 }
136 117
137 v8::Handle<v8::Value> PrivateScriptRunner::runDOMAttributeGetter(ScriptState* sc riptState, String className, String attributeName, v8::Handle<v8::Value> holder) 118 v8::Handle<v8::Value> PrivateScriptRunner::runDOMAttributeGetter(ScriptState* sc riptState, String className, String attributeName, v8::Handle<v8::Value> holder)
138 { 119 {
139 v8::Handle<v8::Object> classObject = classObjectOfPrivateScript(scriptState, className); 120 v8::Handle<v8::Object> classObject = classObjectOfPrivateScript(scriptState, className);
140 v8::Handle<v8::Object> descriptor = getOwnPropertyDescriptor(scriptState, cl assObject, attributeName); 121 v8::Handle<v8::Object> descriptor = getOwnPropertyDescriptor(scriptState, cl assObject, attributeName);
141 v8::Handle<v8::Value> getter = descriptor->Get(v8String(scriptState->isolate (), "get")); 122 v8::Handle<v8::Value> getter = descriptor->Get(v8String(scriptState->isolate (), "get"));
142 if (getter.IsEmpty() || !getter->IsFunction()) { 123 RELEASE_ASSERT(!getter.IsEmpty());
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()); 124 RELEASE_ASSERT(getter->IsFunction());
144 RELEASE_ASSERT_NOT_REACHED();
145 }
146 initializeHolderIfNeeded(scriptState, classObject, holder); 125 initializeHolderIfNeeded(scriptState, classObject, holder);
147 return V8ScriptRunner::callFunction(v8::Handle<v8::Function>::Cast(getter), scriptState->executionContext(), holder, 0, 0, scriptState->isolate()); 126 return V8ScriptRunner::callFunction(v8::Handle<v8::Function>::Cast(getter), scriptState->executionContext(), holder, 0, 0, scriptState->isolate());
148 } 127 }
149 128
150 void PrivateScriptRunner::runDOMAttributeSetter(ScriptState* scriptState, String className, String attributeName, v8::Handle<v8::Value> holder, v8::Handle<v8::V alue> v8Value) 129 void PrivateScriptRunner::runDOMAttributeSetter(ScriptState* scriptState, String className, String attributeName, v8::Handle<v8::Value> holder, v8::Handle<v8::V alue> v8Value)
151 { 130 {
152 v8::Handle<v8::Object> classObject = classObjectOfPrivateScript(scriptState, className); 131 v8::Handle<v8::Object> classObject = classObjectOfPrivateScript(scriptState, className);
153 v8::Handle<v8::Object> descriptor = getOwnPropertyDescriptor(scriptState, cl assObject, attributeName); 132 v8::Handle<v8::Object> descriptor = getOwnPropertyDescriptor(scriptState, cl assObject, attributeName);
154 v8::Handle<v8::Value> setter = descriptor->Get(v8String(scriptState->isolate (), "set")); 133 v8::Handle<v8::Value> setter = descriptor->Get(v8String(scriptState->isolate (), "set"));
155 if (setter.IsEmpty() || !setter->IsFunction()) { 134 RELEASE_ASSERT(!setter.IsEmpty());
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()); 135 RELEASE_ASSERT(setter->IsFunction());
157 RELEASE_ASSERT_NOT_REACHED();
158 }
159 initializeHolderIfNeeded(scriptState, classObject, holder); 136 initializeHolderIfNeeded(scriptState, classObject, holder);
160 v8::Handle<v8::Value> argv[] = { v8Value }; 137 v8::Handle<v8::Value> argv[] = { v8Value };
161 V8ScriptRunner::callFunction(v8::Handle<v8::Function>::Cast(setter), scriptS tate->executionContext(), holder, WTF_ARRAY_LENGTH(argv), argv, scriptState->iso late()); 138 V8ScriptRunner::callFunction(v8::Handle<v8::Function>::Cast(setter), scriptS tate->executionContext(), holder, WTF_ARRAY_LENGTH(argv), argv, scriptState->iso late());
162 } 139 }
163 140
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[]) 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[])
165 { 142 {
166 v8::Handle<v8::Object> classObject = classObjectOfPrivateScript(scriptState, className); 143 v8::Handle<v8::Object> classObject = classObjectOfPrivateScript(scriptState, className);
167 v8::Handle<v8::Value> method = classObject->Get(v8String(scriptState->isolat e(), methodName)); 144 v8::Handle<v8::Value> method = classObject->Get(v8String(scriptState->isolat e(), methodName));
168 if (method.IsEmpty() || !method->IsFunction()) { 145 RELEASE_ASSERT(!method.IsEmpty());
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()) ; 146 RELEASE_ASSERT(method->IsFunction());
170 RELEASE_ASSERT_NOT_REACHED();
171 }
172 initializeHolderIfNeeded(scriptState, classObject, holder); 147 initializeHolderIfNeeded(scriptState, classObject, holder);
173 return V8ScriptRunner::callFunction(v8::Handle<v8::Function>::Cast(method), scriptState->executionContext(), holder, argc, argv, scriptState->isolate()); 148 return V8ScriptRunner::callFunction(v8::Handle<v8::Function>::Cast(method), scriptState->executionContext(), holder, argc, argv, scriptState->isolate());
174 } 149 }
175 150
176 bool PrivateScriptRunner::throwDOMExceptionInPrivateScriptIfNeeded(v8::Isolate* isolate, ExceptionState& exceptionState, v8::Handle<v8::Value> exception) 151 bool PrivateScriptRunner::throwDOMExceptionInPrivateScriptIfNeeded(v8::Isolate* isolate, ExceptionState& exceptionState, v8::Handle<v8::Value> exception)
177 { 152 {
178 if (exception.IsEmpty() || !exception->IsObject()) 153 if (exception.IsEmpty() || !exception->IsObject())
179 return false; 154 return false;
180 155
181 v8::Handle<v8::Object> exceptionObject = v8::Handle<v8::Object>::Cast(except ion); 156 v8::Handle<v8::Object> exceptionObject = v8::Handle<v8::Object>::Cast(except ion);
182 v8::Handle<v8::Value> type = exceptionObject->Get(v8String(isolate, "type")) ; 157 v8::Handle<v8::Value> type = exceptionObject->Get(v8String(isolate, "type")) ;
183 if (type.IsEmpty() || !type->IsString()) 158 if (type.IsEmpty() || !type->IsString())
184 return false; 159 return false;
185 if (toCoreString(v8::Handle<v8::String>::Cast(type)) != "DOMExceptionInPriva teScript") 160 if (toCoreString(v8::Handle<v8::String>::Cast(type)) != "DOMExceptionInPriva teScript")
186 return false; 161 return false;
187 162
188 v8::Handle<v8::Value> message = exceptionObject->Get(v8String(isolate, "mess age")); 163 v8::Handle<v8::Value> message = exceptionObject->Get(v8String(isolate, "mess age"));
189 RELEASE_ASSERT(!message.IsEmpty() && message->IsString()); 164 RELEASE_ASSERT(!message.IsEmpty() && message->IsString());
190 v8::Handle<v8::Value> code = exceptionObject->Get(v8String(isolate, "code")) ; 165 v8::Handle<v8::Value> code = exceptionObject->Get(v8String(isolate, "code")) ;
191 RELEASE_ASSERT(!code.IsEmpty() && code->IsInt32()); 166 RELEASE_ASSERT(!code.IsEmpty() && code->IsInt32());
192 // FIXME: Support JavaScript errors such as TypeError, RangeError and Securi tyError. 167 // FIXME: Support JavaScript errors such as TypeError, RangeError and Securi tyError.
193 exceptionState.throwDOMException(toInt32(code), toCoreString(v8::Handle<v8:: String>::Cast(message))); 168 exceptionState.throwDOMException(toInt32(code), toCoreString(v8::Handle<v8:: String>::Cast(message)));
194 exceptionState.throwIfNeeded(); 169 exceptionState.throwIfNeeded();
195 return true; 170 return true;
196 } 171 }
197 172
198 } // namespace WebCore 173 } // 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