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

Side by Side Diff: Source/bindings/v8/V8CustomElementLifecycleCallbacks.cpp

Issue 18258003: Pow __proto__, sock :unresolved, and clunk the created callback at once. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Try to be nicer to MSVC. Created 7 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 14 matching lines...) Expand all
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "config.h" 31 #include "config.h"
32 #include "bindings/v8/V8CustomElementLifecycleCallbacks.h" 32 #include "bindings/v8/V8CustomElementLifecycleCallbacks.h"
33 33
34 #include "V8Element.h" 34 #include "V8Element.h"
35 #include "bindings/v8/CustomElementHelpers.h"
36 #include "bindings/v8/DOMDataStore.h"
35 #include "bindings/v8/ScriptController.h" 37 #include "bindings/v8/ScriptController.h"
36 #include "bindings/v8/V8Binding.h" 38 #include "bindings/v8/V8Binding.h"
37 #include "bindings/v8/V8HiddenPropertyName.h" 39 #include "bindings/v8/V8HiddenPropertyName.h"
38 #include "core/dom/ScriptExecutionContext.h" 40 #include "core/dom/ScriptExecutionContext.h"
39 #include "wtf/PassRefPtr.h" 41 #include "wtf/PassRefPtr.h"
40 42
41 namespace WebCore { 43 namespace WebCore {
42 44
43 PassRefPtr<V8CustomElementLifecycleCallbacks> V8CustomElementLifecycleCallbacks: :create(ScriptExecutionContext* scriptExecutionContext, v8::Handle<v8::Object> o wner, v8::Handle<v8::Function> created) 45 PassRefPtr<V8CustomElementLifecycleCallbacks> V8CustomElementLifecycleCallbacks: :create(ScriptExecutionContext* scriptExecutionContext, v8::Handle<v8::Object> p rototype, v8::Handle<v8::Function> created)
44 { 46 {
47 // A given object can only be used as a Custom Element prototype once, see i sCustomElementInterfacePrototypeObject
48 ASSERT(prototype->GetHiddenValue(V8HiddenPropertyName::customElementCreated( )).IsEmpty());
45 if (!created.IsEmpty()) 49 if (!created.IsEmpty())
46 owner->SetHiddenValue(V8HiddenPropertyName::customElementCreated(), crea ted); 50 prototype->SetHiddenValue(V8HiddenPropertyName::customElementCreated(), created);
47 return adoptRef(new V8CustomElementLifecycleCallbacks(scriptExecutionContext , created)); 51 return adoptRef(new V8CustomElementLifecycleCallbacks(scriptExecutionContext , prototype, created));
48 } 52 }
49 53
50 static void weakCallback(v8::Isolate*, v8::Persistent<v8::Function>*, ScopedPers istent<v8::Function>* handle) 54 template <typename T>
55 static void weakCallback(v8::Isolate*, v8::Persistent<T>*, ScopedPersistent<T>* handle)
51 { 56 {
52 handle->clear(); 57 handle->clear();
53 } 58 }
54 59
55 V8CustomElementLifecycleCallbacks::V8CustomElementLifecycleCallbacks(ScriptExecu tionContext* scriptExecutionContext, v8::Handle<v8::Function> created) 60 V8CustomElementLifecycleCallbacks::V8CustomElementLifecycleCallbacks(ScriptExecu tionContext* scriptExecutionContext, v8::Handle<v8::Object> prototype, v8::Handl e<v8::Function> created)
56 : CustomElementLifecycleCallbacks(created.IsEmpty() ? None : Created) 61 : CustomElementLifecycleCallbacks(Created)
57 , ActiveDOMCallback(scriptExecutionContext) 62 , ActiveDOMCallback(scriptExecutionContext)
58 , m_world(DOMWrapperWorld::current()) 63 , m_world(DOMWrapperWorld::current())
64 , m_prototype(prototype)
59 , m_created(created) 65 , m_created(created)
60 { 66 {
67 m_prototype.makeWeak(&m_prototype, weakCallback<v8::Object>);
61 if (!m_created.isEmpty()) 68 if (!m_created.isEmpty())
62 m_created.makeWeak(&m_created, weakCallback); 69 m_created.makeWeak(&m_created, weakCallback<v8::Function>);
63 } 70 }
64 71
65 void V8CustomElementLifecycleCallbacks::created(Element* element) 72 void V8CustomElementLifecycleCallbacks::created(Element* element)
66 { 73 {
67 if (!canInvokeCallback()) 74 if (!canInvokeCallback())
68 return; 75 return;
69 76
77 element->setIsUpgradedCustomElement();
78
70 v8::HandleScope handleScope; 79 v8::HandleScope handleScope;
71
72 v8::Handle<v8::Context> context = toV8Context(scriptExecutionContext(), m_wo rld.get()); 80 v8::Handle<v8::Context> context = toV8Context(scriptExecutionContext(), m_wo rld.get());
73 if (context.IsEmpty()) 81 if (context.IsEmpty())
74 return; 82 return;
75 83
76 v8::Context::Scope scope(context); 84 v8::Context::Scope scope(context);
77 v8::Isolate* isolate = context->GetIsolate(); 85 v8::Isolate* isolate = context->GetIsolate();
78 86
87 v8::Handle<v8::Object> receiver = DOMDataStore::current(isolate)->get(elemen t);
88 if (!receiver.IsEmpty()) {
89 // Swizzle the prototype of the existing wrapper. We don't need to
90 // worry about non-existent wrappers; they will get the right
91 // prototype when wrapped.
92 v8::Handle<v8::Object> prototype = m_prototype.newLocal(isolate);
93 if (prototype.IsEmpty())
94 return;
95 receiver->SetPrototype(prototype);
96 }
97
79 v8::Handle<v8::Function> callback = m_created.newLocal(isolate); 98 v8::Handle<v8::Function> callback = m_created.newLocal(isolate);
80 if (callback.IsEmpty()) 99 if (callback.IsEmpty())
81 return; 100 return;
82 101
83 v8::Handle<v8::Value> elementHandle = toV8(element, context->Global(), isola te); 102 if (receiver.IsEmpty())
84 if (elementHandle.IsEmpty()) { 103 receiver = toV8(element, context->Global(), isolate).As<v8::Object>();
85 if (!isScriptControllerTerminating())
86 CRASH();
87 return;
88 }
89 104
90 ASSERT(elementHandle->IsObject()); 105 ASSERT(!receiver.IsEmpty());
91 v8::Handle<v8::Object> receiver = v8::Handle<v8::Object>::Cast(elementHandle );
92 106
93 v8::TryCatch exceptionCatcher; 107 v8::TryCatch exceptionCatcher;
94 exceptionCatcher.SetVerbose(true); 108 exceptionCatcher.SetVerbose(true);
95 ScriptController::callFunctionWithInstrumentation(scriptExecutionContext(), callback, receiver, 0, 0); 109 ScriptController::callFunctionWithInstrumentation(scriptExecutionContext(), callback, receiver, 0, 0);
96 } 110 }
97 111
98 } // namespace WebCore 112 } // namespace WebCore
99
OLDNEW
« no previous file with comments | « Source/bindings/v8/V8CustomElementLifecycleCallbacks.h ('k') | Source/core/dom/CustomElementCallbackDispatcher.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698