| 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::Function> inter
face, v8::Local<v8::Object> prototype, const V8DOMConfiguration::ConstantConfigu
ration& constant) |
| 202 { |
| 203 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
| 204 v8::Local<v8::Name> name = v8AtomicString(isolate, constant.name); |
| 205 v8::PropertyAttribute attributes = |
| 206 static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete); |
| 207 v8::Local<v8::Primitive> value = valueForConstant(isolate, constant); |
| 208 v8CallOrCrash(interface->DefineOwnProperty(context, name, value, attributes)
); |
| 209 v8CallOrCrash(prototype->DefineOwnProperty(context, name, value, attributes)
); |
| 210 } |
| 211 |
| 195 template<class Configuration> | 212 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) | 213 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 { | 214 { |
| 198 if (method.exposeConfiguration == V8DOMConfiguration::OnlyExposedToPrivateSc
ript | 215 if (method.exposeConfiguration == V8DOMConfiguration::OnlyExposedToPrivateSc
ript |
| 199 && !world.isPrivateScriptIsolatedWorld()) | 216 && !world.isPrivateScriptIsolatedWorld()) |
| 200 return; | 217 return; |
| 201 | 218 |
| 202 v8::Local<v8::Name> name = method.methodName(isolate); | 219 v8::Local<v8::Name> name = method.methodName(isolate); |
| 203 v8::FunctionCallback callback = method.callbackForWorld(world); | 220 v8::FunctionCallback callback = method.callbackForWorld(world); |
| 204 | 221 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 { | 308 { |
| 292 for (size_t i = 0; i < constantCount; ++i) | 309 for (size_t i = 0; i < constantCount; ++i) |
| 293 installConstantInternal(isolate, interfaceTemplate, prototypeTemplate, c
onstants[i]); | 310 installConstantInternal(isolate, interfaceTemplate, prototypeTemplate, c
onstants[i]); |
| 294 } | 311 } |
| 295 | 312 |
| 296 void V8DOMConfiguration::installConstant(v8::Isolate* isolate, v8::Local<v8::Fun
ctionTemplate> interfaceTemplate, v8::Local<v8::ObjectTemplate> prototypeTemplat
e, const ConstantConfiguration& constant) | 313 void V8DOMConfiguration::installConstant(v8::Isolate* isolate, v8::Local<v8::Fun
ctionTemplate> interfaceTemplate, v8::Local<v8::ObjectTemplate> prototypeTemplat
e, const ConstantConfiguration& constant) |
| 297 { | 314 { |
| 298 installConstantInternal(isolate, interfaceTemplate, prototypeTemplate, const
ant); | 315 installConstantInternal(isolate, interfaceTemplate, prototypeTemplate, const
ant); |
| 299 } | 316 } |
| 300 | 317 |
| 318 void V8DOMConfiguration::installConstant(v8::Isolate* isolate, v8::Local<v8::Fun
ction> interface, v8::Local<v8::Object> prototype, const ConstantConfiguration&
constant) |
| 319 { |
| 320 installConstantInternal(isolate, interface, prototype, constant); |
| 321 } |
| 322 |
| 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) | 323 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 { | 324 { |
| 303 v8::Local<v8::String> constantName = v8AtomicString(isolate, name); | 325 v8::Local<v8::String> constantName = v8AtomicString(isolate, name); |
| 304 v8::PropertyAttribute attributes = | 326 v8::PropertyAttribute attributes = |
| 305 static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete); | 327 static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete); |
| 306 interfaceTemplate->SetNativeDataProperty(constantName, getter, 0, v8::Local<
v8::Value>(), attributes); | 328 interfaceTemplate->SetNativeDataProperty(constantName, getter, 0, v8::Local<
v8::Value>(), attributes); |
| 307 prototypeTemplate->SetNativeDataProperty(constantName, getter, 0, v8::Local<
v8::Value>(), attributes); | 329 prototypeTemplate->SetNativeDataProperty(constantName, getter, 0, v8::Local<
v8::Value>(), attributes); |
| 308 } | 330 } |
| 309 | 331 |
| 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) | 332 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); | 385 data->setInterfaceTemplate(world, wrapperTypeInfo, result); |
| 364 return result; | 386 return result; |
| 365 } | 387 } |
| 366 | 388 |
| 367 void V8DOMConfiguration::setClassString(v8::Isolate* isolate, v8::Local<v8::Obje
ctTemplate> objectTemplate, const char* classString) | 389 void V8DOMConfiguration::setClassString(v8::Isolate* isolate, v8::Local<v8::Obje
ctTemplate> objectTemplate, const char* classString) |
| 368 { | 390 { |
| 369 objectTemplate->Set(v8::Symbol::GetToStringTag(isolate), v8AtomicString(isol
ate, classString), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnu
m)); | 391 objectTemplate->Set(v8::Symbol::GetToStringTag(isolate), v8AtomicString(isol
ate, classString), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnu
m)); |
| 370 } | 392 } |
| 371 | 393 |
| 372 } // namespace blink | 394 } // namespace blink |
| OLD | NEW |