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

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

Issue 2057273002: [OriginTrials] Support OriginTrialEnabled IDL attribute on constants (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing comments from PS#1 Created 4 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
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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 if (accessor.propertyLocationConfiguration & V8DOMConfiguration::OnInterface ) { 159 if (accessor.propertyLocationConfiguration & V8DOMConfiguration::OnInterface ) {
160 // Attributes installed on the interface object must be static 160 // Attributes installed on the interface object must be static
161 // attributes, so no need to specify a signature, i.e. no need to do 161 // attributes, so no need to specify a signature, i.e. no need to do
162 // type check against a holder. 162 // type check against a holder.
163 v8::Local<FunctionOrTemplate> getter = createAccessorFunctionOrTemplate< FunctionOrTemplate>(isolate, getterCallback, data, v8::Local<v8::Signature>(), 0 ); 163 v8::Local<FunctionOrTemplate> getter = createAccessorFunctionOrTemplate< FunctionOrTemplate>(isolate, getterCallback, data, v8::Local<v8::Signature>(), 0 );
164 v8::Local<FunctionOrTemplate> setter = createAccessorFunctionOrTemplate< FunctionOrTemplate>(isolate, setterCallback, data, v8::Local<v8::Signature>(), 1 ); 164 v8::Local<FunctionOrTemplate> setter = createAccessorFunctionOrTemplate< FunctionOrTemplate>(isolate, setterCallback, data, v8::Local<v8::Signature>(), 1 );
165 interfaceOrTemplate->SetAccessorProperty(name, getter, setter, static_ca st<v8::PropertyAttribute>(accessor.attribute), static_cast<v8::AccessControl>(ac cessor.settings)); 165 interfaceOrTemplate->SetAccessorProperty(name, getter, setter, static_ca st<v8::PropertyAttribute>(accessor.attribute), static_cast<v8::AccessControl>(ac cessor.settings));
166 } 166 }
167 } 167 }
168 168
169 void installConstantInternal(v8::Isolate* isolate, v8::Local<v8::FunctionTemplat e> interfaceTemplate, v8::Local<v8::ObjectTemplate> prototypeTemplate, const V8D OMConfiguration::ConstantConfiguration& constant) 169 v8::Local<v8::Primitive> valueForConstant(v8::Isolate* isolate, const V8DOMConfi guration::ConstantConfiguration& constant)
170 { 170 {
171 v8::Local<v8::String> constantName = v8AtomicString(isolate, constant.name);
172 v8::PropertyAttribute attributes =
173 static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete);
174 v8::Local<v8::Primitive> value; 171 v8::Local<v8::Primitive> value;
175 switch (constant.type) { 172 switch (constant.type) {
176 case V8DOMConfiguration::ConstantTypeShort: 173 case V8DOMConfiguration::ConstantTypeShort:
177 case V8DOMConfiguration::ConstantTypeLong: 174 case V8DOMConfiguration::ConstantTypeLong:
178 case V8DOMConfiguration::ConstantTypeUnsignedShort: 175 case V8DOMConfiguration::ConstantTypeUnsignedShort:
179 value = v8::Integer::New(isolate, constant.ivalue); 176 value = v8::Integer::New(isolate, constant.ivalue);
180 break; 177 break;
181 case V8DOMConfiguration::ConstantTypeUnsignedLong: 178 case V8DOMConfiguration::ConstantTypeUnsignedLong:
182 value = v8::Integer::NewFromUnsigned(isolate, constant.ivalue); 179 value = v8::Integer::NewFromUnsigned(isolate, constant.ivalue);
183 break; 180 break;
184 case V8DOMConfiguration::ConstantTypeFloat: 181 case V8DOMConfiguration::ConstantTypeFloat:
185 case V8DOMConfiguration::ConstantTypeDouble: 182 case V8DOMConfiguration::ConstantTypeDouble:
186 value = v8::Number::New(isolate, constant.dvalue); 183 value = v8::Number::New(isolate, constant.dvalue);
187 break; 184 break;
188 default: 185 default:
189 NOTREACHED(); 186 NOTREACHED();
190 } 187 }
188 return value;
189 }
190
191 void installConstantInternal(v8::Isolate* isolate, v8::Local<v8::FunctionTemplat e> interfaceTemplate, v8::Local<v8::ObjectTemplate> prototypeTemplate, const V8D OMConfiguration::ConstantConfiguration& constant)
192 {
193 v8::Local<v8::String> constantName = v8AtomicString(isolate, constant.name);
194 v8::PropertyAttribute attributes =
195 static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete);
196 v8::Local<v8::Primitive> value = valueForConstant(isolate, constant);
191 interfaceTemplate->Set(constantName, value, attributes); 197 interfaceTemplate->Set(constantName, value, attributes);
192 prototypeTemplate->Set(constantName, value, attributes); 198 prototypeTemplate->Set(constantName, value, attributes);
193 } 199 }
194 200
201 void installConstantInternal(v8::Isolate* isolate, v8::Local<v8::Object> prototy pe, const V8DOMConfiguration::ConstantConfiguration& constant, const DOMWrapperW orld& world)
haraken 2016/06/13 01:12:59 Why do you need to pass DOMWrapperWorld? It's unus
iclelland 2016/06/15 14:08:40 Not needed. removed. (Replaced with WrapperTypeInf
202 {
203 v8::Local<v8::Name> name = v8AtomicString(isolate, constant.name);
204 v8::Local<v8::Primitive> value = valueForConstant(isolate, constant);
205 v8CallOrCrash(prototype->DefineOwnProperty(isolate->GetCurrentContext(), nam e, value));
haraken 2016/06/13 01:12:59 Per the spec, constant must be defined on both pro
iclelland 2016/06/15 12:12:04 I'm adding them now on the object returned from co
Yuki 2016/06/15 12:32:11 Yes, the function object returned by constructorFo
iclelland 2016/06/15 14:08:41 I see, thanks. I'm not sure how to write a proper
206 }
207
195 template<class Configuration> 208 template<class Configuration>
196 void installMethodInternal(v8::Isolate* isolate, v8::Local<v8::ObjectTemplate> i nstanceTemplate, v8::Local<v8::ObjectTemplate> prototypeTemplate, v8::Local<v8:: FunctionTemplate> interfaceTemplate, v8::Local<v8::Signature> signature, const C onfiguration& method, const DOMWrapperWorld& world) 209 void installMethodInternal(v8::Isolate* isolate, v8::Local<v8::ObjectTemplate> i nstanceTemplate, v8::Local<v8::ObjectTemplate> prototypeTemplate, v8::Local<v8:: FunctionTemplate> interfaceTemplate, v8::Local<v8::Signature> signature, const C onfiguration& method, const DOMWrapperWorld& world)
197 { 210 {
198 if (method.exposeConfiguration == V8DOMConfiguration::OnlyExposedToPrivateSc ript 211 if (method.exposeConfiguration == V8DOMConfiguration::OnlyExposedToPrivateSc ript
199 && !world.isPrivateScriptIsolatedWorld()) 212 && !world.isPrivateScriptIsolatedWorld())
200 return; 213 return;
201 214
202 v8::Local<v8::Name> name = method.methodName(isolate); 215 v8::Local<v8::Name> name = method.methodName(isolate);
203 v8::FunctionCallback callback = method.callbackForWorld(world); 216 v8::FunctionCallback callback = method.callbackForWorld(world);
204 217
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 { 304 {
292 for (size_t i = 0; i < constantCount; ++i) 305 for (size_t i = 0; i < constantCount; ++i)
293 installConstantInternal(isolate, interfaceTemplate, prototypeTemplate, c onstants[i]); 306 installConstantInternal(isolate, interfaceTemplate, prototypeTemplate, c onstants[i]);
294 } 307 }
295 308
296 void V8DOMConfiguration::installConstant(v8::Isolate* isolate, v8::Local<v8::Fun ctionTemplate> interfaceTemplate, v8::Local<v8::ObjectTemplate> prototypeTemplat e, const ConstantConfiguration& constant) 309 void V8DOMConfiguration::installConstant(v8::Isolate* isolate, v8::Local<v8::Fun ctionTemplate> interfaceTemplate, v8::Local<v8::ObjectTemplate> prototypeTemplat e, const ConstantConfiguration& constant)
297 { 310 {
298 installConstantInternal(isolate, interfaceTemplate, prototypeTemplate, const ant); 311 installConstantInternal(isolate, interfaceTemplate, prototypeTemplate, const ant);
299 } 312 }
300 313
314 void V8DOMConfiguration::installConstant(v8::Isolate* isolate, const DOMWrapperW orld& world, v8::Local<v8::Object> prototype, const ConstantConfiguration& const ant)
315 {
316 installConstantInternal(isolate, prototype, constant, world);
317 }
318
301 void V8DOMConfiguration::installConstantWithGetter(v8::Isolate* isolate, v8::Loc al<v8::FunctionTemplate> interfaceTemplate, v8::Local<v8::ObjectTemplate> protot ypeTemplate, const char* name, v8::AccessorNameGetterCallback getter) 319 void V8DOMConfiguration::installConstantWithGetter(v8::Isolate* isolate, v8::Loc al<v8::FunctionTemplate> interfaceTemplate, v8::Local<v8::ObjectTemplate> protot ypeTemplate, const char* name, v8::AccessorNameGetterCallback getter)
302 { 320 {
303 v8::Local<v8::String> constantName = v8AtomicString(isolate, name); 321 v8::Local<v8::String> constantName = v8AtomicString(isolate, name);
304 v8::PropertyAttribute attributes = 322 v8::PropertyAttribute attributes =
305 static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete); 323 static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete);
306 interfaceTemplate->SetNativeDataProperty(constantName, getter, 0, v8::Local< v8::Value>(), attributes); 324 interfaceTemplate->SetNativeDataProperty(constantName, getter, 0, v8::Local< v8::Value>(), attributes);
307 prototypeTemplate->SetNativeDataProperty(constantName, getter, 0, v8::Local< v8::Value>(), attributes); 325 prototypeTemplate->SetNativeDataProperty(constantName, getter, 0, v8::Local< v8::Value>(), attributes);
308 } 326 }
309 327
310 void V8DOMConfiguration::installMethods(v8::Isolate* isolate, const DOMWrapperWo rld& world, v8::Local<v8::ObjectTemplate> instanceTemplate, v8::Local<v8::Object Template> prototypeTemplate, v8::Local<v8::FunctionTemplate> interfaceTemplate, v8::Local<v8::Signature> signature, const MethodConfiguration* methods, size_t m ethodCount) 328 void V8DOMConfiguration::installMethods(v8::Isolate* isolate, const DOMWrapperWo rld& world, v8::Local<v8::ObjectTemplate> instanceTemplate, v8::Local<v8::Object Template> prototypeTemplate, v8::Local<v8::FunctionTemplate> interfaceTemplate, v8::Local<v8::Signature> signature, const MethodConfiguration* methods, size_t m ethodCount)
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 data->setInterfaceTemplate(world, wrapperTypeInfo, result); 381 data->setInterfaceTemplate(world, wrapperTypeInfo, result);
364 return result; 382 return result;
365 } 383 }
366 384
367 void V8DOMConfiguration::setClassString(v8::Isolate* isolate, v8::Local<v8::Obje ctTemplate> objectTemplate, const char* classString) 385 void V8DOMConfiguration::setClassString(v8::Isolate* isolate, v8::Local<v8::Obje ctTemplate> objectTemplate, const char* classString)
368 { 386 {
369 objectTemplate->Set(v8::Symbol::GetToStringTag(isolate), v8AtomicString(isol ate, classString), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnu m)); 387 objectTemplate->Set(v8::Symbol::GetToStringTag(isolate), v8AtomicString(isol ate, classString), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnu m));
370 } 388 }
371 389
372 } // namespace blink 390 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698