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

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: Use a vector for upgrade candidates. 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 {
45 if (!created.IsEmpty()) 47 if (!created.IsEmpty())
46 owner->SetHiddenValue(V8HiddenPropertyName::customElementCreated(), crea ted); 48 prototype->SetHiddenValue(V8HiddenPropertyName::customElementCreated(), created);
esprehn 2013/07/04 01:29:01 I don't think this can work, what if I register th
47 return adoptRef(new V8CustomElementLifecycleCallbacks(scriptExecutionContext , created)); 49 return adoptRef(new V8CustomElementLifecycleCallbacks(scriptExecutionContext , prototype, created));
48 } 50 }
49 51
50 static void weakCallback(v8::Isolate*, v8::Persistent<v8::Function>*, ScopedPers istent<v8::Function>* handle) 52 template <typename T>
53 static void weakCallback(v8::Isolate*, v8::Persistent<T>*, ScopedPersistent<T>* handle)
51 { 54 {
52 handle->clear(); 55 handle->clear();
53 } 56 }
54 57
55 V8CustomElementLifecycleCallbacks::V8CustomElementLifecycleCallbacks(ScriptExecu tionContext* scriptExecutionContext, v8::Handle<v8::Function> created) 58 V8CustomElementLifecycleCallbacks::V8CustomElementLifecycleCallbacks(ScriptExecu tionContext* scriptExecutionContext, v8::Handle<v8::Object> prototype, v8::Handl e<v8::Function> created)
56 : CustomElementLifecycleCallbacks(created.IsEmpty() ? None : Created) 59 : CustomElementLifecycleCallbacks(Created)
57 , ActiveDOMCallback(scriptExecutionContext) 60 , ActiveDOMCallback(scriptExecutionContext)
58 , m_world(DOMWrapperWorld::current()) 61 , m_world(DOMWrapperWorld::current())
62 , m_prototype(prototype)
59 , m_created(created) 63 , m_created(created)
60 { 64 {
65 m_prototype.makeWeak(&m_prototype, weakCallback);
61 if (!m_created.isEmpty()) 66 if (!m_created.isEmpty())
62 m_created.makeWeak(&m_created, weakCallback); 67 m_created.makeWeak(&m_created, weakCallback);
63 } 68 }
64 69
65 void V8CustomElementLifecycleCallbacks::created(Element* element) 70 void V8CustomElementLifecycleCallbacks::created(Element* element)
66 { 71 {
67 if (!canInvokeCallback()) 72 if (!canInvokeCallback())
68 return; 73 return;
69 74
75 element->setIsUpgradedCustomElement();
76
70 v8::HandleScope handleScope; 77 v8::HandleScope handleScope;
71
72 v8::Handle<v8::Context> context = toV8Context(scriptExecutionContext(), m_wo rld.get()); 78 v8::Handle<v8::Context> context = toV8Context(scriptExecutionContext(), m_wo rld.get());
73 if (context.IsEmpty()) 79 if (context.IsEmpty())
74 return; 80 return;
75 81
76 v8::Context::Scope scope(context); 82 v8::Context::Scope scope(context);
77 v8::Isolate* isolate = context->GetIsolate(); 83 v8::Isolate* isolate = context->GetIsolate();
78 84
85 v8::Handle<v8::Object> receiver = DOMDataStore::current(isolate)->get(elemen t);
86 if (!receiver.IsEmpty()) {
87 // Swizzle the prototype of the existing wrapper. We don't need to
88 // worry about non-existent wrappers; they will get the right
89 // prototype when wrapped.
90 v8::Handle<v8::Object> prototype = m_prototype.newLocal(isolate);
91 if (prototype.IsEmpty())
92 return;
93 receiver->SetPrototype(prototype);
94 }
95
79 v8::Handle<v8::Function> callback = m_created.newLocal(isolate); 96 v8::Handle<v8::Function> callback = m_created.newLocal(isolate);
80 if (callback.IsEmpty()) 97 if (callback.IsEmpty())
81 return; 98 return;
82 99
83 v8::Handle<v8::Value> elementHandle = toV8(element, context->Global(), isola te); 100 if (receiver.IsEmpty())
84 if (elementHandle.IsEmpty()) { 101 receiver = toV8(element, context->Global(), isolate).As<v8::Object>();
85 if (!isScriptControllerTerminating())
86 CRASH();
87 return;
88 }
89 102
90 ASSERT(elementHandle->IsObject()); 103 ASSERT(!receiver.IsEmpty());
91 v8::Handle<v8::Object> receiver = v8::Handle<v8::Object>::Cast(elementHandle );
92 104
93 v8::TryCatch exceptionCatcher; 105 v8::TryCatch exceptionCatcher;
94 exceptionCatcher.SetVerbose(true); 106 exceptionCatcher.SetVerbose(true);
95 ScriptController::callFunctionWithInstrumentation(scriptExecutionContext(), callback, receiver, 0, 0); 107 ScriptController::callFunctionWithInstrumentation(scriptExecutionContext(), callback, receiver, 0, 0);
96 } 108 }
97 109
98 } // namespace WebCore 110 } // namespace WebCore
99
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698