Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 WrapperType Info* type) | |
| 202 { | |
| 203 V8PerContextData* perContextData = V8PerContextData::from(isolate->GetCurren tContext()); | |
| 204 v8::Local<v8::Function> interface = perContextData->constructorForType(type) ; | |
|
Yuki
2016/06/16 08:01:08
I'd prefer that the caller passes |interface| to i
iclelland
2016/06/16 22:55:37
Done. I've made the interface consistent, and redu
| |
| 205 v8::Local<v8::Name> name = v8AtomicString(isolate, constant.name); | |
| 206 v8::Local<v8::Primitive> value = valueForConstant(isolate, constant); | |
| 207 v8CallOrCrash(interface->DefineOwnProperty(isolate->GetCurrentContext(), nam e, value)); | |
|
Yuki
2016/06/16 08:01:08
You need to specify the fourth argument |attribute
iclelland
2016/06/16 22:55:37
Done.
| |
| 208 v8CallOrCrash(prototype->DefineOwnProperty(isolate->GetCurrentContext(), nam e, value)); | |
| 209 } | |
| 210 | |
| 195 template<class Configuration> | 211 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) | 212 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 { | 213 { |
| 198 if (method.exposeConfiguration == V8DOMConfiguration::OnlyExposedToPrivateSc ript | 214 if (method.exposeConfiguration == V8DOMConfiguration::OnlyExposedToPrivateSc ript |
| 199 && !world.isPrivateScriptIsolatedWorld()) | 215 && !world.isPrivateScriptIsolatedWorld()) |
| 200 return; | 216 return; |
| 201 | 217 |
| 202 v8::Local<v8::Name> name = method.methodName(isolate); | 218 v8::Local<v8::Name> name = method.methodName(isolate); |
| 203 v8::FunctionCallback callback = method.callbackForWorld(world); | 219 v8::FunctionCallback callback = method.callbackForWorld(world); |
| 204 | 220 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 291 { | 307 { |
| 292 for (size_t i = 0; i < constantCount; ++i) | 308 for (size_t i = 0; i < constantCount; ++i) |
| 293 installConstantInternal(isolate, interfaceTemplate, prototypeTemplate, c onstants[i]); | 309 installConstantInternal(isolate, interfaceTemplate, prototypeTemplate, c onstants[i]); |
| 294 } | 310 } |
| 295 | 311 |
| 296 void V8DOMConfiguration::installConstant(v8::Isolate* isolate, v8::Local<v8::Fun ctionTemplate> interfaceTemplate, v8::Local<v8::ObjectTemplate> prototypeTemplat e, const ConstantConfiguration& constant) | 312 void V8DOMConfiguration::installConstant(v8::Isolate* isolate, v8::Local<v8::Fun ctionTemplate> interfaceTemplate, v8::Local<v8::ObjectTemplate> prototypeTemplat e, const ConstantConfiguration& constant) |
| 297 { | 313 { |
| 298 installConstantInternal(isolate, interfaceTemplate, prototypeTemplate, const ant); | 314 installConstantInternal(isolate, interfaceTemplate, prototypeTemplate, const ant); |
| 299 } | 315 } |
| 300 | 316 |
| 317 void V8DOMConfiguration::installConstant(v8::Isolate* isolate, v8::Local<v8::Obj ect> prototype, const ConstantConfiguration& constant, const WrapperTypeInfo* ty pe) | |
| 318 { | |
| 319 installConstantInternal(isolate, prototype, constant, type); | |
| 320 } | |
| 321 | |
| 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) | 322 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 { | 323 { |
| 303 v8::Local<v8::String> constantName = v8AtomicString(isolate, name); | 324 v8::Local<v8::String> constantName = v8AtomicString(isolate, name); |
| 304 v8::PropertyAttribute attributes = | 325 v8::PropertyAttribute attributes = |
| 305 static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete); | 326 static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete); |
| 306 interfaceTemplate->SetNativeDataProperty(constantName, getter, 0, v8::Local< v8::Value>(), attributes); | 327 interfaceTemplate->SetNativeDataProperty(constantName, getter, 0, v8::Local< v8::Value>(), attributes); |
| 307 prototypeTemplate->SetNativeDataProperty(constantName, getter, 0, v8::Local< v8::Value>(), attributes); | 328 prototypeTemplate->SetNativeDataProperty(constantName, getter, 0, v8::Local< v8::Value>(), attributes); |
| 308 } | 329 } |
| 309 | 330 |
| 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) | 331 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 Loading... | |
| 363 data->setInterfaceTemplate(world, wrapperTypeInfo, result); | 384 data->setInterfaceTemplate(world, wrapperTypeInfo, result); |
| 364 return result; | 385 return result; |
| 365 } | 386 } |
| 366 | 387 |
| 367 void V8DOMConfiguration::setClassString(v8::Isolate* isolate, v8::Local<v8::Obje ctTemplate> objectTemplate, const char* classString) | 388 void V8DOMConfiguration::setClassString(v8::Isolate* isolate, v8::Local<v8::Obje ctTemplate> objectTemplate, const char* classString) |
| 368 { | 389 { |
| 369 objectTemplate->Set(v8::Symbol::GetToStringTag(isolate), v8AtomicString(isol ate, classString), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnu m)); | 390 objectTemplate->Set(v8::Symbol::GetToStringTag(isolate), v8AtomicString(isol ate, classString), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnu m)); |
| 370 } | 391 } |
| 371 | 392 |
| 372 } // namespace blink | 393 } // namespace blink |
| OLD | NEW |