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

Side by Side Diff: Source/bindings/core/v8/V8DOMConfiguration.cpp

Issue 1202683002: bindings: Supports per-member [Exposed] for attributes on prototype. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Addressed a review comment. Created 5 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 55
56 ASSERT(attribute.propertyLocationConfiguration); 56 ASSERT(attribute.propertyLocationConfiguration);
57 if (attribute.propertyLocationConfiguration & V8DOMConfiguration::OnInstance ) 57 if (attribute.propertyLocationConfiguration & V8DOMConfiguration::OnInstance )
58 instanceTemplate->SetAccessor(name, getter, setter, data, attribute.sett ings, attribute.attribute); 58 instanceTemplate->SetAccessor(name, getter, setter, data, attribute.sett ings, attribute.attribute);
59 if (attribute.propertyLocationConfiguration & V8DOMConfiguration::OnPrototyp e) 59 if (attribute.propertyLocationConfiguration & V8DOMConfiguration::OnPrototyp e)
60 prototypeTemplate->SetAccessor(name, getter, setter, data, attribute.set tings, attribute.attribute); 60 prototypeTemplate->SetAccessor(name, getter, setter, data, attribute.set tings, attribute.attribute);
61 if (attribute.propertyLocationConfiguration & V8DOMConfiguration::OnInterfac e) 61 if (attribute.propertyLocationConfiguration & V8DOMConfiguration::OnInterfac e)
62 ASSERT_NOT_REACHED(); 62 ASSERT_NOT_REACHED();
63 } 63 }
64 64
65 v8::Local<v8::FunctionTemplate> createAccessorFunctionTemplate(v8::Isolate* isol ate, v8::FunctionCallback callback, v8::Local<v8::Value> data, v8::Local<v8::Sig nature> signature, int length) 65 template<class FunctionOrTemplate>
66 v8::Local<FunctionOrTemplate> createAccessorFunctionOrTemplate(v8::Isolate*, v8: :FunctionCallback, v8::Local<v8::Value> data, v8::Local<v8::Signature>, int leng th);
67
68 template<>
69 v8::Local<v8::FunctionTemplate> createAccessorFunctionOrTemplate<v8::FunctionTem plate>(v8::Isolate* isolate, v8::FunctionCallback callback, v8::Local<v8::Value> data, v8::Local<v8::Signature> signature, int length)
66 { 70 {
67 v8::Local<v8::FunctionTemplate> functionTemplate; 71 v8::Local<v8::FunctionTemplate> functionTemplate;
68 if (callback) { 72 if (callback) {
69 functionTemplate = v8::FunctionTemplate::New(isolate, callback, data, si gnature, length); 73 functionTemplate = v8::FunctionTemplate::New(isolate, callback, data, si gnature, length);
70 if (!functionTemplate.IsEmpty()) { 74 if (!functionTemplate.IsEmpty()) {
71 functionTemplate->RemovePrototype(); 75 functionTemplate->RemovePrototype();
72 functionTemplate->SetAcceptAnyReceiver(false); 76 functionTemplate->SetAcceptAnyReceiver(false);
73 } 77 }
74 } 78 }
75 return functionTemplate; 79 return functionTemplate;
76 } 80 }
77 81
78 void installAccessorInternal(v8::Isolate* isolate, v8::Local<v8::ObjectTemplate> instanceTemplate, v8::Local<v8::ObjectTemplate> prototypeTemplate, v8::Local<v8 ::FunctionTemplate> interfaceTemplate, v8::Local<v8::Signature> signature, const V8DOMConfiguration::AccessorConfiguration& accessor, const DOMWrapperWorld& wor ld) 82 template<>
83 v8::Local<v8::Function> createAccessorFunctionOrTemplate<v8::Function>(v8::Isola te* isolate, v8::FunctionCallback callback, v8::Local<v8::Value> data, v8::Local <v8::Signature> signature, int length)
84 {
85 if (!callback)
86 return v8::Local<v8::Function>();
87
88 v8::Local<v8::FunctionTemplate> functionTemplate = createAccessorFunctionOrT emplate<v8::FunctionTemplate>(isolate, callback, data, signature, length);
89 if (functionTemplate.IsEmpty())
90 return v8::Local<v8::Function>();
91
92 v8::Local<v8::Context> context = isolate->GetCurrentContext();
93 v8::Local<v8::Function> function;
94 if (!functionTemplate->GetFunction(context).ToLocal(&function))
95 return v8::Local<v8::Function>();
96 return function;
97 }
98
99 template<class ObjectOrTemplate, class FunctionOrTemplate>
100 void installAccessorInternal(v8::Isolate* isolate, v8::Local<ObjectOrTemplate> i nstanceOrTemplate, v8::Local<ObjectOrTemplate> prototypeOrTemplate, v8::Local<Fu nctionOrTemplate> interfaceOrTemplate, v8::Local<v8::Signature> signature, const V8DOMConfiguration::AccessorConfiguration& accessor, const DOMWrapperWorld& wor ld)
79 { 101 {
80 if (accessor.exposeConfiguration == V8DOMConfiguration::OnlyExposedToPrivate Script 102 if (accessor.exposeConfiguration == V8DOMConfiguration::OnlyExposedToPrivate Script
81 && !world.isPrivateScriptIsolatedWorld()) 103 && !world.isPrivateScriptIsolatedWorld())
82 return; 104 return;
83 105
84 v8::Local<v8::Name> name = v8AtomicString(isolate, accessor.name); 106 v8::Local<v8::Name> name = v8AtomicString(isolate, accessor.name);
85 v8::FunctionCallback getterCallback = accessor.getter; 107 v8::FunctionCallback getterCallback = accessor.getter;
86 v8::FunctionCallback setterCallback = accessor.setter; 108 v8::FunctionCallback setterCallback = accessor.setter;
87 if (world.isMainWorld()) { 109 if (world.isMainWorld()) {
88 if (accessor.getterForMainWorld) 110 if (accessor.getterForMainWorld)
89 getterCallback = accessor.getterForMainWorld; 111 getterCallback = accessor.getterForMainWorld;
90 if (accessor.setterForMainWorld) 112 if (accessor.setterForMainWorld)
91 setterCallback = accessor.setterForMainWorld; 113 setterCallback = accessor.setterForMainWorld;
92 } 114 }
93 // Support [LenientThis] by not specifying the signature. V8 does not do 115 // Support [LenientThis] by not specifying the signature. V8 does not do
94 // the type checking against holder if no signature is specified. Note that 116 // the type checking against holder if no signature is specified. Note that
95 // info.Holder() passed to callbacks will be *unsafe*. 117 // info.Holder() passed to callbacks will be *unsafe*.
96 if (accessor.holderCheckConfiguration == V8DOMConfiguration::DoNotCheckHolde r) 118 if (accessor.holderCheckConfiguration == V8DOMConfiguration::DoNotCheckHolde r)
97 signature = v8::Local<v8::Signature>(); 119 signature = v8::Local<v8::Signature>();
98 v8::Local<v8::Value> data = v8::External::New(isolate, const_cast<WrapperTyp eInfo*>(accessor.data)); 120 v8::Local<v8::Value> data = v8::External::New(isolate, const_cast<WrapperTyp eInfo*>(accessor.data));
99 v8::Local<v8::FunctionTemplate> getter = createAccessorFunctionTemplate(isol ate, getterCallback, data, signature, 0);
100 v8::Local<v8::FunctionTemplate> setter = createAccessorFunctionTemplate(isol ate, setterCallback, data, signature, 1);
101 121
102 ASSERT(accessor.propertyLocationConfiguration); 122 ASSERT(accessor.propertyLocationConfiguration);
103 if (accessor.propertyLocationConfiguration & V8DOMConfiguration::OnInstance) 123 if (accessor.propertyLocationConfiguration &
104 instanceTemplate->SetAccessorProperty(name, getter, setter, accessor.att ribute, accessor.settings); 124 (V8DOMConfiguration::OnInstance | V8DOMConfiguration::OnPrototype)) {
105 if (accessor.propertyLocationConfiguration & V8DOMConfiguration::OnPrototype ) 125 v8::Local<FunctionOrTemplate> getter = createAccessorFunctionOrTemplate< FunctionOrTemplate>(isolate, getterCallback, data, signature, 0);
106 prototypeTemplate->SetAccessorProperty(name, getter, setter, accessor.at tribute, accessor.settings); 126 v8::Local<FunctionOrTemplate> setter = createAccessorFunctionOrTemplate< FunctionOrTemplate>(isolate, setterCallback, data, signature, 1);
107 if (accessor.propertyLocationConfiguration & V8DOMConfiguration::OnInterface ) 127 if (accessor.propertyLocationConfiguration & V8DOMConfiguration::OnInsta nce)
108 interfaceTemplate->SetAccessorProperty(name, getter, setter, accessor.at tribute, accessor.settings); 128 instanceOrTemplate->SetAccessorProperty(name, getter, setter, access or.attribute, accessor.settings);
129 if (accessor.propertyLocationConfiguration & V8DOMConfiguration::OnProto type)
130 prototypeOrTemplate->SetAccessorProperty(name, getter, setter, acces sor.attribute, accessor.settings);
131 }
132 if (accessor.propertyLocationConfiguration & V8DOMConfiguration::OnInterface ) {
133 v8::Local<FunctionOrTemplate> getter = createAccessorFunctionOrTemplate< FunctionOrTemplate>(isolate, getterCallback, data, v8::Local<v8::Signature>(), 0 );
134 v8::Local<FunctionOrTemplate> setter = createAccessorFunctionOrTemplate< FunctionOrTemplate>(isolate, setterCallback, data, v8::Local<v8::Signature>(), 1 );
135 interfaceOrTemplate->SetAccessorProperty(name, getter, setter, accessor. attribute, accessor.settings);
136 }
109 } 137 }
110 138
111 void installConstantInternal(v8::Isolate* isolate, v8::Local<v8::FunctionTemplat e> functionDescriptor, v8::Local<v8::ObjectTemplate> prototypeTemplate, const V8 DOMConfiguration::ConstantConfiguration& constant) 139 void installConstantInternal(v8::Isolate* isolate, v8::Local<v8::FunctionTemplat e> functionDescriptor, v8::Local<v8::ObjectTemplate> prototypeTemplate, const V8 DOMConfiguration::ConstantConfiguration& constant)
112 { 140 {
113 v8::Local<v8::String> constantName = v8AtomicString(isolate, constant.name); 141 v8::Local<v8::String> constantName = v8AtomicString(isolate, constant.name);
114 v8::PropertyAttribute attributes = 142 v8::PropertyAttribute attributes =
115 static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete); 143 static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete);
116 v8::Local<v8::Primitive> value; 144 v8::Local<v8::Primitive> value;
117 switch (constant.type) { 145 switch (constant.type) {
118 case V8DOMConfiguration::ConstantTypeShort: 146 case V8DOMConfiguration::ConstantTypeShort:
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 for (size_t i = 0; i < accessorCount; ++i) 208 for (size_t i = 0; i < accessorCount; ++i)
181 installAccessorInternal(isolate, instanceTemplate, prototypeTemplate, in terfaceTemplate, signature, accessors[i], world); 209 installAccessorInternal(isolate, instanceTemplate, prototypeTemplate, in terfaceTemplate, signature, accessors[i], world);
182 } 210 }
183 211
184 void V8DOMConfiguration::installAccessor(v8::Isolate* isolate, v8::Local<v8::Obj ectTemplate> instanceTemplate, v8::Local<v8::ObjectTemplate> prototypeTemplate, v8::Local<v8::FunctionTemplate> interfaceTemplate, v8::Local<v8::Signature> sign ature, const AccessorConfiguration& accessor) 212 void V8DOMConfiguration::installAccessor(v8::Isolate* isolate, v8::Local<v8::Obj ectTemplate> instanceTemplate, v8::Local<v8::ObjectTemplate> prototypeTemplate, v8::Local<v8::FunctionTemplate> interfaceTemplate, v8::Local<v8::Signature> sign ature, const AccessorConfiguration& accessor)
185 { 213 {
186 const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate); 214 const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate);
187 installAccessorInternal(isolate, instanceTemplate, prototypeTemplate, interf aceTemplate, signature, accessor, world); 215 installAccessorInternal(isolate, instanceTemplate, prototypeTemplate, interf aceTemplate, signature, accessor, world);
188 } 216 }
189 217
218 void V8DOMConfiguration::installAccessor(v8::Isolate* isolate, v8::Local<v8::Obj ect> instance, v8::Local<v8::Object> prototype, v8::Local<v8::Function> interfac e, v8::Local<v8::Signature> signature, const AccessorConfiguration& accessor)
219 {
220 const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate);
221 installAccessorInternal(isolate, instance, prototype, interface, signature, accessor, world);
222 }
223
190 void V8DOMConfiguration::installConstants(v8::Isolate* isolate, v8::Local<v8::Fu nctionTemplate> functionDescriptor, v8::Local<v8::ObjectTemplate> prototypeTempl ate, const ConstantConfiguration* constants, size_t constantCount) 224 void V8DOMConfiguration::installConstants(v8::Isolate* isolate, v8::Local<v8::Fu nctionTemplate> functionDescriptor, v8::Local<v8::ObjectTemplate> prototypeTempl ate, const ConstantConfiguration* constants, size_t constantCount)
191 { 225 {
192 for (size_t i = 0; i < constantCount; ++i) 226 for (size_t i = 0; i < constantCount; ++i)
193 installConstantInternal(isolate, functionDescriptor, prototypeTemplate, constants[i]); 227 installConstantInternal(isolate, functionDescriptor, prototypeTemplate, constants[i]);
194 } 228 }
195 229
196 void V8DOMConfiguration::installConstant(v8::Isolate* isolate, v8::Local<v8::Fun ctionTemplate> functionDescriptor, v8::Local<v8::ObjectTemplate> prototypeTempla te, const ConstantConfiguration& constant) 230 void V8DOMConfiguration::installConstant(v8::Isolate* isolate, v8::Local<v8::Fun ctionTemplate> functionDescriptor, v8::Local<v8::ObjectTemplate> prototypeTempla te, const ConstantConfiguration& constant)
197 { 231 {
198 installConstantInternal(isolate, functionDescriptor, prototypeTemplate, cons tant); 232 installConstantInternal(isolate, functionDescriptor, prototypeTemplate, cons tant);
199 } 233 }
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 return result; 301 return result;
268 302
269 TRACE_EVENT_SCOPED_SAMPLING_STATE("blink", "BuildDOMTemplate"); 303 TRACE_EVENT_SCOPED_SAMPLING_STATE("blink", "BuildDOMTemplate");
270 result = v8::FunctionTemplate::New(isolate, V8ObjectConstructor::isValidCons tructorMode); 304 result = v8::FunctionTemplate::New(isolate, V8ObjectConstructor::isValidCons tructorMode);
271 configureDOMClassTemplate(result, isolate); 305 configureDOMClassTemplate(result, isolate);
272 data->setDOMTemplate(wrapperTypeInfo, result); 306 data->setDOMTemplate(wrapperTypeInfo, result);
273 return result; 307 return result;
274 } 308 }
275 309
276 } // namespace blink 310 } // namespace blink
OLDNEW
« no previous file with comments | « Source/bindings/core/v8/V8DOMConfiguration.h ('k') | Source/bindings/core/v8/V8PerContextData.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698