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

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

Issue 2810743003: Move ScriptState::GetExecutionContext (Part 3) (Closed)
Patch Set: Rebase Created 3 years, 8 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/ScriptCustomElementDefinition.h" 5 #include "bindings/core/v8/ScriptCustomElementDefinition.h"
6 6
7 #include "bindings/core/v8/ScriptState.h" 7 #include "bindings/core/v8/ScriptState.h"
8 #include "bindings/core/v8/V8Binding.h" 8 #include "bindings/core/v8/V8Binding.h"
9 #include "bindings/core/v8/V8BindingMacros.h" 9 #include "bindings/core/v8/V8BindingMacros.h"
10 #include "bindings/core/v8/V8CustomElementRegistry.h" 10 #include "bindings/core/v8/V8CustomElementRegistry.h"
11 #include "bindings/core/v8/V8Element.h" 11 #include "bindings/core/v8/V8Element.h"
12 #include "bindings/core/v8/V8ErrorHandler.h" 12 #include "bindings/core/v8/V8ErrorHandler.h"
13 #include "bindings/core/v8/V8PrivateProperty.h" 13 #include "bindings/core/v8/V8PrivateProperty.h"
14 #include "bindings/core/v8/V8ScriptRunner.h" 14 #include "bindings/core/v8/V8ScriptRunner.h"
15 #include "bindings/core/v8/V8ThrowException.h" 15 #include "bindings/core/v8/V8ThrowException.h"
16 #include "core/dom/ExceptionCode.h" 16 #include "core/dom/ExceptionCode.h"
17 #include "core/dom/ExecutionContext.h"
17 #include "core/dom/custom/CustomElement.h" 18 #include "core/dom/custom/CustomElement.h"
18 #include "core/events/ErrorEvent.h" 19 #include "core/events/ErrorEvent.h"
19 #include "core/html/HTMLElement.h" 20 #include "core/html/HTMLElement.h"
20 #include "core/html/imports/HTMLImportsController.h" 21 #include "core/html/imports/HTMLImportsController.h"
21 #include "platform/wtf/Allocator.h" 22 #include "platform/wtf/Allocator.h"
22 #include "v8.h" 23 #include "v8.h"
23 24
24 namespace blink { 25 namespace blink {
25 26
26 // Retrieves the custom elements constructor -> name map, creating it 27 // Retrieves the custom elements constructor -> name map, creating it
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 DispatchErrorEvent(isolate, exception, Constructor()); 264 DispatchErrorEvent(isolate, exception, Constructor());
264 return false; 265 return false;
265 } 266 }
266 267
267 return true; 268 return true;
268 } 269 }
269 270
270 Element* ScriptCustomElementDefinition::CallConstructor() { 271 Element* ScriptCustomElementDefinition::CallConstructor() {
271 v8::Isolate* isolate = script_state_->GetIsolate(); 272 v8::Isolate* isolate = script_state_->GetIsolate();
272 DCHECK(ScriptState::Current(isolate) == script_state_); 273 DCHECK(ScriptState::Current(isolate) == script_state_);
273 ExecutionContext* execution_context = script_state_->GetExecutionContext(); 274 ExecutionContext* execution_context =
275 ExecutionContext::From(script_state_.Get());
274 v8::Local<v8::Value> result; 276 v8::Local<v8::Value> result;
275 if (!V8Call(V8ScriptRunner::CallAsConstructor(isolate, Constructor(), 277 if (!V8Call(V8ScriptRunner::CallAsConstructor(isolate, Constructor(),
276 execution_context, 0, nullptr), 278 execution_context, 0, nullptr),
277 result)) { 279 result)) {
278 return nullptr; 280 return nullptr;
279 } 281 }
280 return V8Element::toImplWithTypeCheck(isolate, result); 282 return V8Element::toImplWithTypeCheck(isolate, result);
281 } 283 }
282 284
283 v8::Local<v8::Object> ScriptCustomElementDefinition::Constructor() const { 285 v8::Local<v8::Object> ScriptCustomElementDefinition::Constructor() const {
(...skipping 25 matching lines...) Expand all
309 v8::Local<v8::Value> argv[]) { 311 v8::Local<v8::Value> argv[]) {
310 DCHECK(ScriptState::Current(script_state_->GetIsolate()) == script_state_); 312 DCHECK(ScriptState::Current(script_state_->GetIsolate()) == script_state_);
311 v8::Isolate* isolate = script_state_->GetIsolate(); 313 v8::Isolate* isolate = script_state_->GetIsolate();
312 314
313 // Invoke custom element reactions 315 // Invoke custom element reactions
314 // https://html.spec.whatwg.org/multipage/scripting.html#invoke-custom-element -reactions 316 // https://html.spec.whatwg.org/multipage/scripting.html#invoke-custom-element -reactions
315 // If this throws any exception, then report the exception. 317 // If this throws any exception, then report the exception.
316 v8::TryCatch try_catch(isolate); 318 v8::TryCatch try_catch(isolate);
317 try_catch.SetVerbose(true); 319 try_catch.SetVerbose(true);
318 320
319 ExecutionContext* execution_context = script_state_->GetExecutionContext(); 321 ExecutionContext* execution_context =
322 ExecutionContext::From(script_state_.Get());
320 v8::Local<v8::Value> element_handle = 323 v8::Local<v8::Value> element_handle =
321 ToV8(element, script_state_->GetContext()->Global(), isolate); 324 ToV8(element, script_state_->GetContext()->Global(), isolate);
322 V8ScriptRunner::CallFunction(callback, execution_context, element_handle, 325 V8ScriptRunner::CallFunction(callback, execution_context, element_handle,
323 argc, argv, isolate); 326 argc, argv, isolate);
324 } 327 }
325 328
326 void ScriptCustomElementDefinition::RunConnectedCallback(Element* element) { 329 void ScriptCustomElementDefinition::RunConnectedCallback(Element* element) {
327 if (!script_state_->ContextIsValid()) 330 if (!script_state_->ContextIsValid())
328 return; 331 return;
329 ScriptState::Scope scope(script_state_.Get()); 332 ScriptState::Scope scope(script_state_.Get());
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 v8::Local<v8::Value> argv[] = { 368 v8::Local<v8::Value> argv[] = {
366 V8String(isolate, name.LocalName()), V8StringOrNull(isolate, old_value), 369 V8String(isolate, name.LocalName()), V8StringOrNull(isolate, old_value),
367 V8StringOrNull(isolate, new_value), 370 V8StringOrNull(isolate, new_value),
368 V8StringOrNull(isolate, name.NamespaceURI()), 371 V8StringOrNull(isolate, name.NamespaceURI()),
369 }; 372 };
370 RunCallback(attribute_changed_callback_.NewLocal(isolate), element, 373 RunCallback(attribute_changed_callback_.NewLocal(isolate), element,
371 WTF_ARRAY_LENGTH(argv), argv); 374 WTF_ARRAY_LENGTH(argv), argv);
372 } 375 }
373 376
374 } // namespace blink 377 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698