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

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

Issue 297513008: Decrease call sites of ScriptState::current() (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 7 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 #include "wtf/PassOwnPtr.h" 43 #include "wtf/PassOwnPtr.h"
44 44
45 namespace WebCore { 45 namespace WebCore {
46 46
47 #define CALLBACK_LIST(V) \ 47 #define CALLBACK_LIST(V) \
48 V(created, Created) \ 48 V(created, Created) \
49 V(attached, Attached) \ 49 V(attached, Attached) \
50 V(detached, Detached) \ 50 V(detached, Detached) \
51 V(attributeChanged, AttributeChanged) 51 V(attributeChanged, AttributeChanged)
52 52
53 PassRefPtr<V8CustomElementLifecycleCallbacks> V8CustomElementLifecycleCallbacks: :create(ExecutionContext* executionContext, v8::Handle<v8::Object> prototype, v8 ::Handle<v8::Function> created, v8::Handle<v8::Function> attached, v8::Handle<v8 ::Function> detached, v8::Handle<v8::Function> attributeChanged) 53 PassRefPtr<V8CustomElementLifecycleCallbacks> V8CustomElementLifecycleCallbacks: :create(ScriptState* scriptState, v8::Handle<v8::Object> prototype, v8::Handle<v 8::Function> created, v8::Handle<v8::Function> attached, v8::Handle<v8::Function > detached, v8::Handle<v8::Function> attributeChanged)
54 { 54 {
55 v8::Isolate* isolate = toIsolate(executionContext); 55 v8::Isolate* isolate = scriptState->isolate();
56 // A given object can only be used as a Custom Element prototype 56 // A given object can only be used as a Custom Element prototype
57 // once; see customElementIsInterfacePrototypeObject 57 // once; see customElementIsInterfacePrototypeObject
58 #define SET_HIDDEN_VALUE(Value, Name) \ 58 #define SET_HIDDEN_VALUE(Value, Name) \
59 ASSERT(V8HiddenValue::getHiddenValue(isolate, prototype, V8HiddenValue::cust omElement##Name(isolate)).IsEmpty()); \ 59 ASSERT(V8HiddenValue::getHiddenValue(isolate, prototype, V8HiddenValue::cust omElement##Name(isolate)).IsEmpty()); \
60 if (!Value.IsEmpty()) \ 60 if (!Value.IsEmpty()) \
61 V8HiddenValue::setHiddenValue(isolate, prototype, V8HiddenValue::customE lement##Name(isolate), Value); 61 V8HiddenValue::setHiddenValue(isolate, prototype, V8HiddenValue::customE lement##Name(isolate), Value);
62 62
63 CALLBACK_LIST(SET_HIDDEN_VALUE) 63 CALLBACK_LIST(SET_HIDDEN_VALUE)
64 #undef SET_HIDDEN_VALUE 64 #undef SET_HIDDEN_VALUE
65 65
66 return adoptRef(new V8CustomElementLifecycleCallbacks(executionContext, prot otype, created, attached, detached, attributeChanged)); 66 return adoptRef(new V8CustomElementLifecycleCallbacks(scriptState, prototype , created, attached, detached, attributeChanged));
67 } 67 }
68 68
69 static CustomElementLifecycleCallbacks::CallbackType flagSet(v8::Handle<v8::Func tion> attached, v8::Handle<v8::Function> detached, v8::Handle<v8::Function> attr ibuteChanged) 69 static CustomElementLifecycleCallbacks::CallbackType flagSet(v8::Handle<v8::Func tion> attached, v8::Handle<v8::Function> detached, v8::Handle<v8::Function> attr ibuteChanged)
70 { 70 {
71 // V8 Custom Elements always run created to swizzle prototypes. 71 // V8 Custom Elements always run created to swizzle prototypes.
72 int flags = CustomElementLifecycleCallbacks::Created; 72 int flags = CustomElementLifecycleCallbacks::Created;
73 73
74 if (!attached.IsEmpty()) 74 if (!attached.IsEmpty())
75 flags |= CustomElementLifecycleCallbacks::Attached; 75 flags |= CustomElementLifecycleCallbacks::Attached;
76 76
77 if (!detached.IsEmpty()) 77 if (!detached.IsEmpty())
78 flags |= CustomElementLifecycleCallbacks::Detached; 78 flags |= CustomElementLifecycleCallbacks::Detached;
79 79
80 if (!attributeChanged.IsEmpty()) 80 if (!attributeChanged.IsEmpty())
81 flags |= CustomElementLifecycleCallbacks::AttributeChanged; 81 flags |= CustomElementLifecycleCallbacks::AttributeChanged;
82 82
83 return CustomElementLifecycleCallbacks::CallbackType(flags); 83 return CustomElementLifecycleCallbacks::CallbackType(flags);
84 } 84 }
85 85
86 template <typename T> 86 template <typename T>
87 static void weakCallback(const v8::WeakCallbackData<T, ScopedPersistent<T> >& da ta) 87 static void weakCallback(const v8::WeakCallbackData<T, ScopedPersistent<T> >& da ta)
88 { 88 {
89 data.GetParameter()->clear(); 89 data.GetParameter()->clear();
90 } 90 }
91 91
92 V8CustomElementLifecycleCallbacks::V8CustomElementLifecycleCallbacks(ExecutionCo ntext* executionContext, v8::Handle<v8::Object> prototype, v8::Handle<v8::Functi on> created, v8::Handle<v8::Function> attached, v8::Handle<v8::Function> detache d, v8::Handle<v8::Function> attributeChanged) 92 V8CustomElementLifecycleCallbacks::V8CustomElementLifecycleCallbacks(ScriptState * scriptState, v8::Handle<v8::Object> prototype, v8::Handle<v8::Function> create d, v8::Handle<v8::Function> attached, v8::Handle<v8::Function> detached, v8::Han dle<v8::Function> attributeChanged)
93 : CustomElementLifecycleCallbacks(flagSet(attached, detached, attributeChang ed)) 93 : CustomElementLifecycleCallbacks(flagSet(attached, detached, attributeChang ed))
94 , ContextLifecycleObserver(executionContext) 94 , ContextLifecycleObserver(scriptState->executionContext())
95 , m_owner(0) 95 , m_owner(0)
96 , m_scriptState(ScriptState::current(toIsolate(executionContext))) 96 , m_scriptState(scriptState)
97 , m_prototype(m_scriptState->isolate(), prototype) 97 , m_prototype(scriptState->isolate(), prototype)
98 , m_created(m_scriptState->isolate(), created) 98 , m_created(scriptState->isolate(), created)
99 , m_attached(m_scriptState->isolate(), attached) 99 , m_attached(scriptState->isolate(), attached)
100 , m_detached(m_scriptState->isolate(), detached) 100 , m_detached(scriptState->isolate(), detached)
101 , m_attributeChanged(m_scriptState->isolate(), attributeChanged) 101 , m_attributeChanged(scriptState->isolate(), attributeChanged)
102 { 102 {
103 m_prototype.setWeak(&m_prototype, weakCallback<v8::Object>); 103 m_prototype.setWeak(&m_prototype, weakCallback<v8::Object>);
104 104
105 #define MAKE_WEAK(Var, _) \ 105 #define MAKE_WEAK(Var, _) \
106 if (!m_##Var.isEmpty()) \ 106 if (!m_##Var.isEmpty()) \
107 m_##Var.setWeak(&m_##Var, weakCallback<v8::Function>); 107 m_##Var.setWeak(&m_##Var, weakCallback<v8::Function>);
108 108
109 CALLBACK_LIST(MAKE_WEAK) 109 CALLBACK_LIST(MAKE_WEAK)
110 #undef MAKE_WEAK 110 #undef MAKE_WEAK
111 } 111 }
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 ASSERT(!receiver.IsEmpty()); 254 ASSERT(!receiver.IsEmpty());
255 255
256 InspectorInstrumentation::willExecuteCustomElementCallback(element); 256 InspectorInstrumentation::willExecuteCustomElementCallback(element);
257 257
258 v8::TryCatch exceptionCatcher; 258 v8::TryCatch exceptionCatcher;
259 exceptionCatcher.SetVerbose(true); 259 exceptionCatcher.SetVerbose(true);
260 ScriptController::callFunction(executionContext(), callback, receiver, 0, 0, isolate); 260 ScriptController::callFunction(executionContext(), callback, receiver, 0, 0, isolate);
261 } 261 }
262 262
263 } // namespace WebCore 263 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/bindings/v8/V8CustomElementLifecycleCallbacks.h ('k') | Source/bindings/v8/V8MutationCallback.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698