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

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

Issue 968583002: bindings: Supports conditionally-enabled accessors. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 9 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
« no previous file with comments | « Source/bindings/core/v8/V8DOMConfiguration.h ('k') | Source/bindings/templates/interface.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 19 matching lines...) Expand all
30 #include "bindings/core/v8/V8DOMConfiguration.h" 30 #include "bindings/core/v8/V8DOMConfiguration.h"
31 31
32 #include "bindings/core/v8/V8ObjectConstructor.h" 32 #include "bindings/core/v8/V8ObjectConstructor.h"
33 #include "platform/TraceEvent.h" 33 #include "platform/TraceEvent.h"
34 34
35 namespace blink { 35 namespace blink {
36 36
37 namespace { 37 namespace {
38 38
39 template<class ObjectOrTemplate> 39 template<class ObjectOrTemplate>
40 void installAttributeInternal(v8::Isolate* isolate, v8::Handle<ObjectOrTemplate> instanceTemplate, v8::Handle<ObjectOrTemplate> prototype, const V8DOMConfigurat ion::AttributeConfiguration& attribute, const DOMWrapperWorld& world) 40 void installAttributeInternal(v8::Isolate* isolate, v8::Handle<ObjectOrTemplate> instanceOrTemplate, v8::Handle<ObjectOrTemplate> prototypeOrTemplate, const V8D OMConfiguration::AttributeConfiguration& attribute, const DOMWrapperWorld& world )
haraken 2015/02/28 15:14:00 Not related to your CL, I'm not sure why we need t
Yuki 2015/03/03 07:11:46 Let me try if we can get rid of non-ObjectTemplate
41 { 41 {
42 if (attribute.exposeConfiguration == V8DOMConfiguration::OnlyExposedToPrivat eScript 42 if (attribute.exposeConfiguration == V8DOMConfiguration::OnlyExposedToPrivat eScript
43 && !world.isPrivateScriptIsolatedWorld()) 43 && !world.isPrivateScriptIsolatedWorld())
44 return; 44 return;
45 45
46 v8::AccessorGetterCallback getter = attribute.getter; 46 v8::AccessorGetterCallback getter = attribute.getter;
47 v8::AccessorSetterCallback setter = attribute.setter; 47 v8::AccessorSetterCallback setter = attribute.setter;
48 if (world.isMainWorld()) { 48 if (world.isMainWorld()) {
49 if (attribute.getterForMainWorld) 49 if (attribute.getterForMainWorld)
50 getter = attribute.getterForMainWorld; 50 getter = attribute.getterForMainWorld;
51 if (attribute.setterForMainWorld) 51 if (attribute.setterForMainWorld)
52 setter = attribute.setterForMainWorld; 52 setter = attribute.setterForMainWorld;
53 } 53 }
54 v8::Handle<ObjectOrTemplate> target = 54 v8::Handle<ObjectOrTemplate> target =
55 attribute.instanceOrPrototypeConfiguration == V8DOMConfiguration::OnProt otype ? 55 attribute.instanceOrPrototypeConfiguration == V8DOMConfiguration::OnProt otype ?
56 prototype : 56 prototypeOrTemplate :
57 instanceTemplate; 57 instanceOrTemplate;
58 target->SetAccessor( 58 target->SetAccessor(
59 v8AtomicString(isolate, attribute.name), 59 v8AtomicString(isolate, attribute.name),
60 getter, 60 getter,
61 setter, 61 setter,
62 v8::External::New(isolate, const_cast<WrapperTypeInfo*>(attribute.data)) , 62 v8::External::New(isolate, const_cast<WrapperTypeInfo*>(attribute.data)) ,
63 attribute.settings, 63 attribute.settings,
64 attribute.attribute); 64 attribute.attribute);
65 } 65 }
66 66
67 void installAccessorInternal(v8::Isolate* isolate, v8::Handle<v8::ObjectTemplate > prototype, v8::Handle<v8::Signature> signature, const V8DOMConfiguration::Acce ssorConfiguration& accessor, const DOMWrapperWorld& world) 67 v8::Local<v8::FunctionTemplate> functionOrTemplate(v8::Isolate* isolate, v8::Fun ctionCallback callback, const WrapperTypeInfo* wrapperTypeInfo, v8::Local<v8::Si gnature> signature, v8::Handle<v8::ObjectTemplate> prototypeTemplateForOverloadR esolution)
haraken 2015/02/28 15:14:00 What's the point of calling this method function"O
bashi 2015/03/02 03:00:08 It seems that |prototypeTemplateForOverloadResolut
Yuki 2015/03/03 07:11:47 It's a trick. We have two V8 APIs which take diff
68 {
69 v8::Local<v8::FunctionTemplate> functionTemplate;
70 if (callback) {
71 functionTemplate = v8::FunctionTemplate::New(isolate, callback, v8::Exte rnal::New(isolate, const_cast<WrapperTypeInfo*>(wrapperTypeInfo)), signature);
72 if (!functionTemplate.IsEmpty())
73 functionTemplate->RemovePrototype();
74 }
75 return functionTemplate;
76 }
77
78 v8::Local<v8::Function> functionOrTemplate(v8::Isolate* isolate, v8::FunctionCal lback callback, const WrapperTypeInfo*, v8::Local<v8::Signature>, v8::Handle<v8: :Object> prototypeForOverloadResolution)
haraken 2015/02/28 15:14:00 Ditto.
79 {
80 return callback ? v8::Function::New(isolate, callback) : v8::Local<v8::Funct ion>();
81 }
82
83 template<class ObjectOrTemplate>
84 void installAccessorInternal(v8::Isolate* isolate, v8::Handle<ObjectOrTemplate> prototypeOrTemplate, v8::Handle<v8::Signature> signature, const V8DOMConfigurati on::AccessorConfiguration& accessor, const DOMWrapperWorld& world)
68 { 85 {
69 if (accessor.exposeConfiguration == V8DOMConfiguration::OnlyExposedToPrivate Script 86 if (accessor.exposeConfiguration == V8DOMConfiguration::OnlyExposedToPrivate Script
70 && !world.isPrivateScriptIsolatedWorld()) 87 && !world.isPrivateScriptIsolatedWorld())
71 return; 88 return;
72 89
73 v8::FunctionCallback getterCallback = accessor.getter; 90 v8::FunctionCallback getterCallback = accessor.getter;
74 v8::FunctionCallback setterCallback = accessor.setter; 91 v8::FunctionCallback setterCallback = accessor.setter;
75 if (world.isMainWorld()) { 92 if (world.isMainWorld()) {
76 if (accessor.getterForMainWorld) 93 if (accessor.getterForMainWorld)
77 getterCallback = accessor.getterForMainWorld; 94 getterCallback = accessor.getterForMainWorld;
78 if (accessor.setterForMainWorld) 95 if (accessor.setterForMainWorld)
79 setterCallback = accessor.setterForMainWorld; 96 setterCallback = accessor.setterForMainWorld;
80 } 97 }
81 v8::Local<v8::FunctionTemplate> getter; 98 prototypeOrTemplate->SetAccessorProperty(
82 if (getterCallback) {
83 getter = v8::FunctionTemplate::New(isolate, getterCallback, v8::External ::New(isolate, const_cast<WrapperTypeInfo*>(accessor.data)), signature, 0);
84 getter->RemovePrototype();
85 }
86 v8::Local<v8::FunctionTemplate> setter;
87 if (setterCallback) {
88 setter = v8::FunctionTemplate::New(isolate, setterCallback, v8::External ::New(isolate, const_cast<WrapperTypeInfo*>(accessor.data)), signature, 1);
89 setter->RemovePrototype();
90 }
91 prototype->SetAccessorProperty(
92 v8AtomicString(isolate, accessor.name), 99 v8AtomicString(isolate, accessor.name),
93 getter, 100 functionOrTemplate(isolate, getterCallback, accessor.data, signature, pr ototypeOrTemplate),
94 setter, 101 functionOrTemplate(isolate, setterCallback, accessor.data, signature, pr ototypeOrTemplate),
95 accessor.attribute, 102 accessor.attribute,
96 accessor.settings); 103 accessor.settings);
97 } 104 }
98 105
99 void installConstantInternal(v8::Isolate* isolate, v8::Handle<v8::FunctionTempla te> functionDescriptor, v8::Handle<v8::ObjectTemplate> prototype, const V8DOMCon figuration::ConstantConfiguration& constant) 106 void installConstantInternal(v8::Isolate* isolate, v8::Handle<v8::FunctionTempla te> functionDescriptor, v8::Handle<v8::ObjectTemplate> prototypeTemplate, const V8DOMConfiguration::ConstantConfiguration& constant)
100 { 107 {
101 v8::Handle<v8::String> constantName = v8AtomicString(isolate, constant.name) ; 108 v8::Handle<v8::String> constantName = v8AtomicString(isolate, constant.name) ;
102 v8::PropertyAttribute attributes = 109 v8::PropertyAttribute attributes =
103 static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete); 110 static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete);
104 v8::Handle<v8::Primitive> value; 111 v8::Handle<v8::Primitive> value;
105 switch (constant.type) { 112 switch (constant.type) {
106 case V8DOMConfiguration::ConstantTypeShort: 113 case V8DOMConfiguration::ConstantTypeShort:
107 case V8DOMConfiguration::ConstantTypeLong: 114 case V8DOMConfiguration::ConstantTypeLong:
108 case V8DOMConfiguration::ConstantTypeUnsignedShort: 115 case V8DOMConfiguration::ConstantTypeUnsignedShort:
109 value = v8::Integer::New(isolate, constant.ivalue); 116 value = v8::Integer::New(isolate, constant.ivalue);
110 break; 117 break;
111 case V8DOMConfiguration::ConstantTypeUnsignedLong: 118 case V8DOMConfiguration::ConstantTypeUnsignedLong:
112 value = v8::Integer::NewFromUnsigned(isolate, constant.ivalue); 119 value = v8::Integer::NewFromUnsigned(isolate, constant.ivalue);
113 break; 120 break;
114 case V8DOMConfiguration::ConstantTypeFloat: 121 case V8DOMConfiguration::ConstantTypeFloat:
115 case V8DOMConfiguration::ConstantTypeDouble: 122 case V8DOMConfiguration::ConstantTypeDouble:
116 value = v8::Number::New(isolate, constant.dvalue); 123 value = v8::Number::New(isolate, constant.dvalue);
117 break; 124 break;
118 case V8DOMConfiguration::ConstantTypeString: 125 case V8DOMConfiguration::ConstantTypeString:
119 value = v8::String::NewFromUtf8(isolate, constant.svalue); 126 value = v8::String::NewFromUtf8(isolate, constant.svalue);
120 break; 127 break;
121 default: 128 default:
122 ASSERT_NOT_REACHED(); 129 ASSERT_NOT_REACHED();
123 } 130 }
124 functionDescriptor->Set(constantName, value, attributes); 131 functionDescriptor->Set(constantName, value, attributes);
125 prototype->Set(constantName, value, attributes); 132 prototypeTemplate->Set(constantName, value, attributes);
126 } 133 }
127 134
128 void doInstallMethodInternal(v8::Handle<v8::ObjectTemplate> target, v8::Handle<v 8::Name> name, v8::Handle<v8::FunctionTemplate> functionTemplate, v8::PropertyAt tribute attribute) 135 void doInstallMethodInternal(v8::Handle<v8::ObjectTemplate> target, v8::Handle<v 8::Name> name, v8::Handle<v8::FunctionTemplate> functionTemplate, v8::PropertyAt tribute attribute)
129 { 136 {
130 target->Set(name, functionTemplate, attribute); 137 target->Set(name, functionTemplate, attribute);
131 } 138 }
132 139
133 void doInstallMethodInternal(v8::Handle<v8::FunctionTemplate> target, v8::Handle <v8::Name> name, v8::Handle<v8::FunctionTemplate> functionTemplate, v8::Property Attribute attribute) 140 void doInstallMethodInternal(v8::Handle<v8::FunctionTemplate> target, v8::Handle <v8::Name> name, v8::Handle<v8::FunctionTemplate> functionTemplate, v8::Property Attribute attribute)
134 { 141 {
135 target->Set(name, functionTemplate, attribute); 142 target->Set(name, functionTemplate, attribute);
136 } 143 }
137 144
138 template<class ObjectOrTemplate, class Configuration> 145 template<class ObjectOrTemplate, class Configuration>
139 void installMethodInternal(v8::Isolate* isolate, v8::Handle<ObjectOrTemplate> ob jectOrTemplate, v8::Handle<v8::Signature> signature, v8::PropertyAttribute attri bute, const Configuration& callback, const DOMWrapperWorld& world) 146 void installMethodInternal(v8::Isolate* isolate, v8::Handle<ObjectOrTemplate> ob jectOrTemplate, v8::Handle<v8::Signature> signature, v8::PropertyAttribute attri bute, const Configuration& callback, const DOMWrapperWorld& world)
140 { 147 {
141 if (callback.exposeConfiguration == V8DOMConfiguration::OnlyExposedToPrivate Script 148 if (callback.exposeConfiguration == V8DOMConfiguration::OnlyExposedToPrivate Script
142 && !world.isPrivateScriptIsolatedWorld()) 149 && !world.isPrivateScriptIsolatedWorld())
143 return; 150 return;
144 151
145 v8::Local<v8::FunctionTemplate> functionTemplate = v8::FunctionTemplate::New (isolate, callback.callbackForWorld(world), v8Undefined(), signature, callback.l ength); 152 v8::Local<v8::FunctionTemplate> functionTemplate = v8::FunctionTemplate::New (isolate, callback.callbackForWorld(world), v8Undefined(), signature, callback.l ength);
146 functionTemplate->RemovePrototype(); 153 functionTemplate->RemovePrototype();
147 doInstallMethodInternal(objectOrTemplate, callback.methodName(isolate), func tionTemplate, attribute); 154 doInstallMethodInternal(objectOrTemplate, callback.methodName(isolate), func tionTemplate, attribute);
148 } 155 }
149 156
150 } // namespace 157 } // namespace
151 158
152 void V8DOMConfiguration::installAttributes(v8::Isolate* isolate, v8::Handle<v8:: ObjectTemplate> instanceTemplate, v8::Handle<v8::ObjectTemplate> prototype, cons t AttributeConfiguration* attributes, size_t attributeCount) 159 void V8DOMConfiguration::installAttributes(v8::Isolate* isolate, v8::Handle<v8:: ObjectTemplate> instanceTemplate, v8::Handle<v8::ObjectTemplate> prototypeTempla te, const AttributeConfiguration* attributes, size_t attributeCount)
153 { 160 {
154 const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate); 161 const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate);
155 for (size_t i = 0; i < attributeCount; ++i) 162 for (size_t i = 0; i < attributeCount; ++i)
156 installAttributeInternal(isolate, instanceTemplate, prototype, attribute s[i], world); 163 installAttributeInternal(isolate, instanceTemplate, prototypeTemplate, a ttributes[i], world);
157 } 164 }
158 165
159 void V8DOMConfiguration::installAttribute(v8::Isolate* isolate, v8::Handle<v8::O bjectTemplate> instanceTemplate, v8::Handle<v8::ObjectTemplate> prototype, const AttributeConfiguration& attribute) 166 void V8DOMConfiguration::installAttribute(v8::Isolate* isolate, v8::Handle<v8::O bjectTemplate> instanceTemplate, v8::Handle<v8::ObjectTemplate> prototypeTemplat e, const AttributeConfiguration& attribute)
160 { 167 {
161 const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate); 168 const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate);
162 installAttributeInternal(isolate, instanceTemplate, prototype, attribute, wo rld); 169 installAttributeInternal(isolate, instanceTemplate, prototypeTemplate, attri bute, world);
163 } 170 }
164 171
165 void V8DOMConfiguration::installAttribute(v8::Isolate* isolate, v8::Handle<v8::O bject> instanceTemplate, v8::Handle<v8::Object> prototype, const AttributeConfig uration& attribute) 172 void V8DOMConfiguration::installAttribute(v8::Isolate* isolate, v8::Handle<v8::O bject> instance, v8::Handle<v8::Object> prototype, const AttributeConfiguration& attribute)
166 { 173 {
167 const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate); 174 const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate);
168 installAttributeInternal(isolate, instanceTemplate, prototype, attribute, wo rld); 175 installAttributeInternal(isolate, instance, prototype, attribute, world);
169 } 176 }
170 177
171 void V8DOMConfiguration::installAccessors(v8::Isolate* isolate, v8::Handle<v8::O bjectTemplate> prototype, v8::Handle<v8::Signature> signature, const AccessorCon figuration* accessors, size_t accessorCount) 178 void V8DOMConfiguration::installAccessors(v8::Isolate* isolate, v8::Handle<v8::O bjectTemplate> prototypeTemplate, v8::Handle<v8::Signature> signature, const Acc essorConfiguration* accessors, size_t accessorCount)
172 { 179 {
173 const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate); 180 const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate);
174 for (size_t i = 0; i < accessorCount; ++i) 181 for (size_t i = 0; i < accessorCount; ++i)
175 installAccessorInternal(isolate, prototype, signature, accessors[i], wor ld); 182 installAccessorInternal(isolate, prototypeTemplate, signature, accessors [i], world);
176 } 183 }
177 184
178 void V8DOMConfiguration::installAccessor(v8::Isolate* isolate, v8::Handle<v8::Ob jectTemplate> prototype, v8::Handle<v8::Signature> signature, const AccessorConf iguration& accessor) 185 void V8DOMConfiguration::installAccessor(v8::Isolate* isolate, v8::Handle<v8::Ob jectTemplate> prototypeTemplate, v8::Handle<v8::Signature> signature, const Acce ssorConfiguration& accessor)
179 { 186 {
180 const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate); 187 const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate);
181 installAccessorInternal(isolate, prototype, signature, accessor, world); 188 installAccessorInternal(isolate, prototypeTemplate, signature, accessor, wor ld);
182 } 189 }
183 190
184 void V8DOMConfiguration::installConstants(v8::Isolate* isolate, v8::Handle<v8::F unctionTemplate> functionDescriptor, v8::Handle<v8::ObjectTemplate> prototype, c onst ConstantConfiguration* constants, size_t constantCount) 191 void V8DOMConfiguration::installAccessor(v8::Isolate* isolate, v8::Handle<v8::Ob ject> prototype, const AccessorConfiguration& accessor)
192 {
193 const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate);
194 installAccessorInternal(isolate, prototype, v8::Handle<v8::Signature>(), acc essor, world);
195 }
196
197 void V8DOMConfiguration::installConstants(v8::Isolate* isolate, v8::Handle<v8::F unctionTemplate> functionDescriptor, v8::Handle<v8::ObjectTemplate> prototypeTem plate, const ConstantConfiguration* constants, size_t constantCount)
185 { 198 {
186 for (size_t i = 0; i < constantCount; ++i) 199 for (size_t i = 0; i < constantCount; ++i)
187 installConstantInternal(isolate, functionDescriptor, prototype, constant s[i]); 200 installConstantInternal(isolate, functionDescriptor, prototypeTemplate, constants[i]);
188 } 201 }
189 202
190 void V8DOMConfiguration::installConstant(v8::Isolate* isolate, v8::Handle<v8::Fu nctionTemplate> functionDescriptor, v8::Handle<v8::ObjectTemplate> prototype, co nst ConstantConfiguration& constant) 203 void V8DOMConfiguration::installConstant(v8::Isolate* isolate, v8::Handle<v8::Fu nctionTemplate> functionDescriptor, v8::Handle<v8::ObjectTemplate> prototypeTemp late, const ConstantConfiguration& constant)
191 { 204 {
192 installConstantInternal(isolate, functionDescriptor, prototype, constant); 205 installConstantInternal(isolate, functionDescriptor, prototypeTemplate, cons tant);
193 } 206 }
194 207
195 void V8DOMConfiguration::installConstantWithGetter(v8::Isolate* isolate, v8::Han dle<v8::FunctionTemplate> functionDescriptor, v8::Handle<v8::ObjectTemplate> pro totype, const char* name, v8::AccessorGetterCallback getter) 208 void V8DOMConfiguration::installConstantWithGetter(v8::Isolate* isolate, v8::Han dle<v8::FunctionTemplate> functionDescriptor, v8::Handle<v8::ObjectTemplate> pro totypeTemplate, const char* name, v8::AccessorGetterCallback getter)
196 { 209 {
197 v8::Handle<v8::String> constantName = v8AtomicString(isolate, name); 210 v8::Handle<v8::String> constantName = v8AtomicString(isolate, name);
198 v8::PropertyAttribute attributes = 211 v8::PropertyAttribute attributes =
199 static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete); 212 static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete);
200 functionDescriptor->SetNativeDataProperty(constantName, getter, 0, v8::Handl e<v8::Value>(), attributes); 213 functionDescriptor->SetNativeDataProperty(constantName, getter, 0, v8::Handl e<v8::Value>(), attributes);
201 prototype->SetNativeDataProperty(constantName, getter, 0, v8::Handle<v8::Val ue>(), attributes); 214 prototypeTemplate->SetNativeDataProperty(constantName, getter, 0, v8::Handle <v8::Value>(), attributes);
202 } 215 }
203 216
204 void V8DOMConfiguration::installMethods(v8::Isolate* isolate, v8::Handle<v8::Obj ectTemplate> prototype, v8::Handle<v8::Signature> signature, v8::PropertyAttribu te attribute, const MethodConfiguration* callbacks, size_t callbackCount) 217 void V8DOMConfiguration::installMethods(v8::Isolate* isolate, v8::Handle<v8::Obj ectTemplate> prototypeTemplate, v8::Handle<v8::Signature> signature, v8::Propert yAttribute attribute, const MethodConfiguration* callbacks, size_t callbackCount )
205 { 218 {
206 const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate); 219 const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate);
207 for (size_t i = 0; i < callbackCount; ++i) 220 for (size_t i = 0; i < callbackCount; ++i)
208 installMethodInternal(isolate, prototype, signature, attribute, callback s[i], world); 221 installMethodInternal(isolate, prototypeTemplate, signature, attribute, callbacks[i], world);
209 } 222 }
210 223
211 void V8DOMConfiguration::installMethod(v8::Isolate* isolate, v8::Handle<v8::Func tionTemplate> functionDescriptor, v8::Handle<v8::Signature> signature, v8::Prope rtyAttribute attribute, const MethodConfiguration& callback) 224 void V8DOMConfiguration::installMethod(v8::Isolate* isolate, v8::Handle<v8::Func tionTemplate> functionDescriptor, v8::Handle<v8::Signature> signature, v8::Prope rtyAttribute attribute, const MethodConfiguration& callback)
212 { 225 {
213 const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate); 226 const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate);
214 installMethodInternal(isolate, functionDescriptor, signature, attribute, cal lback, world); 227 installMethodInternal(isolate, functionDescriptor, signature, attribute, cal lback, world);
215 } 228 }
216 229
217 void V8DOMConfiguration::installMethod(v8::Isolate* isolate, v8::Handle<v8::Obje ctTemplate> prototype, v8::Handle<v8::Signature> signature, v8::PropertyAttribut e attribute, const MethodConfiguration& callback) 230 void V8DOMConfiguration::installMethod(v8::Isolate* isolate, v8::Handle<v8::Obje ctTemplate> prototypeTemplate, v8::Handle<v8::Signature> signature, v8::Property Attribute attribute, const MethodConfiguration& callback)
218 { 231 {
219 const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate); 232 const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate);
220 installMethodInternal(isolate, prototype, signature, attribute, callback, wo rld); 233 installMethodInternal(isolate, prototypeTemplate, signature, attribute, call back, world);
221 } 234 }
222 235
223 void V8DOMConfiguration::installMethod(v8::Isolate* isolate, v8::Handle<v8::Obje ctTemplate> prototype, v8::Handle<v8::Signature> signature, v8::PropertyAttribut e attribute, const SymbolKeyedMethodConfiguration& callback) 236 void V8DOMConfiguration::installMethod(v8::Isolate* isolate, v8::Handle<v8::Obje ctTemplate> prototypeTemplate, v8::Handle<v8::Signature> signature, v8::Property Attribute attribute, const SymbolKeyedMethodConfiguration& callback)
224 { 237 {
225 const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate); 238 const DOMWrapperWorld& world = DOMWrapperWorld::current(isolate);
226 installMethodInternal(isolate, prototype, signature, attribute, callback, wo rld); 239 installMethodInternal(isolate, prototypeTemplate, signature, attribute, call back, world);
227 } 240 }
228 241
229 v8::Local<v8::Signature> V8DOMConfiguration::installDOMClassTemplate(v8::Isolate * isolate, v8::Local<v8::FunctionTemplate> functionDescriptor, const char* inter faceName, v8::Handle<v8::FunctionTemplate> parentClass, size_t fieldCount, 242 v8::Local<v8::Signature> V8DOMConfiguration::installDOMClassTemplate(v8::Isolate * isolate, v8::Local<v8::FunctionTemplate> functionDescriptor, const char* inter faceName, v8::Handle<v8::FunctionTemplate> parentClass, size_t fieldCount,
230 const AttributeConfiguration* attributes, size_t attributeCount, 243 const AttributeConfiguration* attributes, size_t attributeCount,
231 const AccessorConfiguration* accessors, size_t accessorCount, 244 const AccessorConfiguration* accessors, size_t accessorCount,
232 const MethodConfiguration* callbacks, size_t callbackCount) 245 const MethodConfiguration* callbacks, size_t callbackCount)
233 { 246 {
234 functionDescriptor->SetClassName(v8AtomicString(isolate, interfaceName)); 247 functionDescriptor->SetClassName(v8AtomicString(isolate, interfaceName));
235 v8::Local<v8::ObjectTemplate> instanceTemplate = functionDescriptor->Instanc eTemplate(); 248 v8::Local<v8::ObjectTemplate> instanceTemplate = functionDescriptor->Instanc eTemplate();
249 v8::Local<v8::ObjectTemplate> prototypeTemplate = functionDescriptor->Protot ypeTemplate();
236 instanceTemplate->SetInternalFieldCount(fieldCount); 250 instanceTemplate->SetInternalFieldCount(fieldCount);
237 if (!parentClass.IsEmpty()) { 251 if (!parentClass.IsEmpty()) {
238 functionDescriptor->Inherit(parentClass); 252 functionDescriptor->Inherit(parentClass);
239 // Marks the prototype object as one of native-backed objects. 253 // Marks the prototype object as one of native-backed objects.
240 // This is needed since bug 110436 asks WebKit to tell native-initiated prototypes from pure-JS ones. 254 // This is needed since bug 110436 asks WebKit to tell native-initiated prototypes from pure-JS ones.
241 // This doesn't mark kinds "root" classes like Node, where setting this changes prototype chain structure. 255 // This doesn't mark kinds "root" classes like Node, where setting this changes prototype chain structure.
242 v8::Local<v8::ObjectTemplate> prototype = functionDescriptor->PrototypeT emplate(); 256 prototypeTemplate->SetInternalFieldCount(v8PrototypeInternalFieldcount);
243 prototype->SetInternalFieldCount(v8PrototypeInternalFieldcount);
244 } 257 }
245 258
246 v8::Local<v8::Signature> defaultSignature = v8::Signature::New(isolate, func tionDescriptor); 259 v8::Local<v8::Signature> defaultSignature = v8::Signature::New(isolate, func tionDescriptor);
247 if (attributeCount) 260 if (attributeCount)
248 installAttributes(isolate, instanceTemplate, functionDescriptor->Prototy peTemplate(), attributes, attributeCount); 261 installAttributes(isolate, instanceTemplate, prototypeTemplate, attribut es, attributeCount);
249 if (accessorCount) 262 if (accessorCount)
250 installAccessors(isolate, functionDescriptor->PrototypeTemplate(), defau ltSignature, accessors, accessorCount); 263 installAccessors(isolate, prototypeTemplate, defaultSignature, accessors , accessorCount);
251 if (callbackCount) 264 if (callbackCount)
252 installMethods(isolate, functionDescriptor->PrototypeTemplate(), default Signature, static_cast<v8::PropertyAttribute>(v8::None), callbacks, callbackCoun t); 265 installMethods(isolate, prototypeTemplate, defaultSignature, static_cast <v8::PropertyAttribute>(v8::None), callbacks, callbackCount);
253 return defaultSignature; 266 return defaultSignature;
254 } 267 }
255 268
256 v8::Handle<v8::FunctionTemplate> V8DOMConfiguration::domClassTemplate(v8::Isolat e* isolate, WrapperTypeInfo* wrapperTypeInfo, void (*configureDOMClassTemplate)( v8::Local<v8::FunctionTemplate>, v8::Isolate*)) 269 v8::Handle<v8::FunctionTemplate> V8DOMConfiguration::domClassTemplate(v8::Isolat e* isolate, WrapperTypeInfo* wrapperTypeInfo, void (*configureDOMClassTemplate)( v8::Local<v8::FunctionTemplate>, v8::Isolate*))
257 { 270 {
258 V8PerIsolateData* data = V8PerIsolateData::from(isolate); 271 V8PerIsolateData* data = V8PerIsolateData::from(isolate);
259 v8::Local<v8::FunctionTemplate> result = data->existingDOMTemplate(wrapperTy peInfo); 272 v8::Local<v8::FunctionTemplate> result = data->existingDOMTemplate(wrapperTy peInfo);
260 if (!result.IsEmpty()) 273 if (!result.IsEmpty())
261 return result; 274 return result;
262 275
263 TRACE_EVENT_SCOPED_SAMPLING_STATE("blink", "BuildDOMTemplate"); 276 TRACE_EVENT_SCOPED_SAMPLING_STATE("blink", "BuildDOMTemplate");
264 result = v8::FunctionTemplate::New(isolate, V8ObjectConstructor::isValidCons tructorMode); 277 result = v8::FunctionTemplate::New(isolate, V8ObjectConstructor::isValidCons tructorMode);
265 configureDOMClassTemplate(result, isolate); 278 configureDOMClassTemplate(result, isolate);
266 data->setDOMTemplate(wrapperTypeInfo, result); 279 data->setDOMTemplate(wrapperTypeInfo, result);
267 return result; 280 return result;
268 } 281 }
269 282
270 } // namespace blink 283 } // namespace blink
OLDNEW
« no previous file with comments | « Source/bindings/core/v8/V8DOMConfiguration.h ('k') | Source/bindings/templates/interface.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698