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

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

Issue 2027113003: binding: Makes PrivateScriptRunner use V8PrivateProperty instead of V8HiddenValue. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/bindings/core/v8/V8HiddenValue.h » ('j') | 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 "bindings/core/v8/PrivateScriptRunner.h" 5 #include "bindings/core/v8/PrivateScriptRunner.h"
6 6
7 #include "bindings/core/v8/DOMWrapperWorld.h" 7 #include "bindings/core/v8/DOMWrapperWorld.h"
8 #include "bindings/core/v8/ExceptionState.h" 8 #include "bindings/core/v8/ExceptionState.h"
9 #include "bindings/core/v8/V8Binding.h" 9 #include "bindings/core/v8/V8Binding.h"
10 #include "bindings/core/v8/V8PerContextData.h" 10 #include "bindings/core/v8/V8PerContextData.h"
11 #include "bindings/core/v8/V8PrivateProperty.h"
11 #include "bindings/core/v8/V8ScriptRunner.h" 12 #include "bindings/core/v8/V8ScriptRunner.h"
12 #include "core/PrivateScriptSources.h" 13 #include "core/PrivateScriptSources.h"
13 #ifndef NDEBUG 14 #ifndef NDEBUG
14 #include "core/PrivateScriptSourcesForTesting.h" 15 #include "core/PrivateScriptSourcesForTesting.h"
15 #endif 16 #endif
16 #include "core/dom/Document.h" 17 #include "core/dom/Document.h"
17 #include "core/dom/ExceptionCode.h" 18 #include "core/dom/ExceptionCode.h"
18 #include "platform/PlatformResourceLoader.h" 19 #include "platform/PlatformResourceLoader.h"
19 20
20 namespace blink { 21 namespace blink {
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 return v8::Local<v8::Object>::Cast(compiledClass); 183 return v8::Local<v8::Object>::Cast(compiledClass);
183 } 184 }
184 185
185 static void initializeHolderIfNeeded(ScriptState* scriptState, v8::Local<v8::Obj ect> classObject, v8::Local<v8::Value> holder) 186 static void initializeHolderIfNeeded(ScriptState* scriptState, v8::Local<v8::Obj ect> classObject, v8::Local<v8::Value> holder)
186 { 187 {
187 RELEASE_ASSERT(!holder.IsEmpty()); 188 RELEASE_ASSERT(!holder.IsEmpty());
188 RELEASE_ASSERT(holder->IsObject()); 189 RELEASE_ASSERT(holder->IsObject());
189 v8::Local<v8::Object> holderObject = v8::Local<v8::Object>::Cast(holder); 190 v8::Local<v8::Object> holderObject = v8::Local<v8::Object>::Cast(holder);
190 v8::Isolate* isolate = scriptState->isolate(); 191 v8::Isolate* isolate = scriptState->isolate();
191 v8::Local<v8::Context> context = scriptState->context(); 192 v8::Local<v8::Context> context = scriptState->context();
192 v8::Local<v8::Value> isInitialized = V8HiddenValue::getHiddenValue(scriptSta te, holderObject, V8HiddenValue::privateScriptObjectIsInitialized(isolate)); 193 auto privateIsInitialized = V8PrivateProperty::getPrivateScriptRunnerIsIniti alized(isolate);
193 if (isInitialized.IsEmpty()) { 194 if (privateIsInitialized.hasValue(context, holderObject))
195 return; // Already initialized.
196
197 v8::TryCatch block(isolate);
198 v8::Local<v8::Value> initializeFunction;
199 if (classObject->Get(scriptState->context(), v8String(isolate, "initialize") ).ToLocal(&initializeFunction) && initializeFunction->IsFunction()) {
194 v8::TryCatch block(isolate); 200 v8::TryCatch block(isolate);
195 v8::Local<v8::Value> initializeFunction; 201 v8::Local<v8::Value> result;
196 if (classObject->Get(scriptState->context(), v8String(isolate, "initiali ze")).ToLocal(&initializeFunction) && initializeFunction->IsFunction()) { 202 if (!V8ScriptRunner::callFunction(v8::Local<v8::Function>::Cast(initiali zeFunction), scriptState->getExecutionContext(), holder, 0, 0, isolate).ToLocal( &result)) {
197 v8::TryCatch block(isolate); 203 fprintf(stderr, "Private script error: Object constructor threw an e xception.\n");
198 v8::Local<v8::Value> result; 204 dumpV8Message(context, block.Message());
199 if (!V8ScriptRunner::callFunction(v8::Local<v8::Function>::Cast(init ializeFunction), scriptState->getExecutionContext(), holder, 0, 0, isolate).ToLo cal(&result)) { 205 RELEASE_NOTREACHED();
200 fprintf(stderr, "Private script error: Object constructor threw an exception.\n");
201 dumpV8Message(context, block.Message());
202 RELEASE_NOTREACHED();
203 }
204 } 206 }
207 }
205 208
206 // Inject the prototype object of the private script into the prototype chain of the holder object. 209 // Inject the prototype object of the private script into the prototype chai n of the holder object.
207 // This is necessary to let the holder object use properties defined on the prototype object 210 // This is necessary to let the holder object use properties defined on the prototype object
208 // of the private script. (e.g., if the prototype object has |foo|, the holder object should be able 211 // of the private script. (e.g., if the prototype object has |foo|, the hold er object should be able
209 // to use it with |this.foo|.) 212 // to use it with |this.foo|.)
210 if (classObject->GetPrototype() != holderObject->GetPrototype()) { 213 if (classObject->GetPrototype() != holderObject->GetPrototype()) {
211 if (!v8CallBoolean(classObject->SetPrototype(context, holderObject-> GetPrototype()))) { 214 if (!v8CallBoolean(classObject->SetPrototype(context, holderObject->GetP rototype()))) {
212 fprintf(stderr, "Private script error: SetPrototype failed.\n");
213 dumpV8Message(context, block.Message());
214 RELEASE_NOTREACHED();
215 }
216 }
217 if (!v8CallBoolean(holderObject->SetPrototype(context, classObject))) {
218 fprintf(stderr, "Private script error: SetPrototype failed.\n"); 215 fprintf(stderr, "Private script error: SetPrototype failed.\n");
219 dumpV8Message(context, block.Message()); 216 dumpV8Message(context, block.Message());
220 RELEASE_NOTREACHED(); 217 RELEASE_NOTREACHED();
221 } 218 }
219 }
220 if (!v8CallBoolean(holderObject->SetPrototype(context, classObject))) {
221 fprintf(stderr, "Private script error: SetPrototype failed.\n");
222 dumpV8Message(context, block.Message());
223 RELEASE_NOTREACHED();
224 }
222 225
223 isInitialized = v8Boolean(true, isolate); 226 privateIsInitialized.set(context, holderObject, v8Boolean(true, isolate));
224 V8HiddenValue::setHiddenValue(scriptState, holderObject, V8HiddenValue:: privateScriptObjectIsInitialized(isolate), isInitialized);
225 }
226 } 227 }
227 228
228 v8::Local<v8::Value> PrivateScriptRunner::installClassIfNeeded(Document* documen t, String className) 229 v8::Local<v8::Value> PrivateScriptRunner::installClassIfNeeded(Document* documen t, String className)
229 { 230 {
230 if (!document->contextDocument()->frame()) 231 if (!document->contextDocument()->frame())
231 return v8::Local<v8::Value>(); 232 return v8::Local<v8::Value>();
232 233
233 v8::HandleScope handleScope(toIsolate(document)); 234 v8::HandleScope handleScope(toIsolate(document));
234 ScriptState* scriptState = ScriptState::forWorld(document->contextDocument() ->frame(), DOMWrapperWorld::privateScriptIsolatedWorld()); 235 ScriptState* scriptState = ScriptState::forWorld(document->contextDocument() ->frame(), DOMWrapperWorld::privateScriptIsolatedWorld());
235 if (!scriptState) 236 if (!scriptState)
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 v8::Local<v8::Value> result; 353 v8::Local<v8::Value> result;
353 if (!V8ScriptRunner::callFunction(v8::Local<v8::Function>::Cast(method), scr iptState->getExecutionContext(), holder, argc, argv, scriptState->isolate()).ToL ocal(&result)) { 354 if (!V8ScriptRunner::callFunction(v8::Local<v8::Function>::Cast(method), scr iptState->getExecutionContext(), holder, argc, argv, scriptState->isolate()).ToL ocal(&result)) {
354 rethrowExceptionInPrivateScript(scriptState->isolate(), block, scriptSta teInUserScript, ExceptionState::ExecutionContext, methodName, className); 355 rethrowExceptionInPrivateScript(scriptState->isolate(), block, scriptSta teInUserScript, ExceptionState::ExecutionContext, methodName, className);
355 block.ReThrow(); 356 block.ReThrow();
356 return v8::Local<v8::Value>(); 357 return v8::Local<v8::Value>();
357 } 358 }
358 return result; 359 return result;
359 } 360 }
360 361
361 } // namespace blink 362 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/bindings/core/v8/V8HiddenValue.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698