| 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 // an attribute configuration for a constructor. | 75 // an attribute configuration for a constructor. |
| 76 // TODO(iclelland): Relax this constraint and allow arbitrary data-type | 76 // TODO(iclelland): Relax this constraint and allow arbitrary data-type |
| 77 // properties to be added here. | 77 // properties to be added here. |
| 78 DCHECK_EQ(&v8ConstructorAttributeGetter, attribute.getter); | 78 DCHECK_EQ(&v8ConstructorAttributeGetter, attribute.getter); |
| 79 | 79 |
| 80 V8PerContextData* perContextData = V8PerContextData::from(isolate->GetCurren
tContext()); | 80 V8PerContextData* perContextData = V8PerContextData::from(isolate->GetCurren
tContext()); |
| 81 v8::Local<v8::Function> data = perContextData->constructorForType(attribute.
data); | 81 v8::Local<v8::Function> data = perContextData->constructorForType(attribute.
data); |
| 82 | 82 |
| 83 DCHECK(attribute.propertyLocationConfiguration); | 83 DCHECK(attribute.propertyLocationConfiguration); |
| 84 if (attribute.propertyLocationConfiguration & V8DOMConfiguration::OnInstance
) | 84 if (attribute.propertyLocationConfiguration & V8DOMConfiguration::OnInstance
) |
| 85 v8CallOrCrash(instance->DefineOwnProperty(isolate->GetCurrentContext(),
name, data, static_cast<v8::PropertyAttribute>(attribute.attribute))); | 85 instance->DefineOwnProperty(isolate->GetCurrentContext(), name, data, st
atic_cast<v8::PropertyAttribute>(attribute.attribute)).ToChecked(); |
| 86 if (attribute.propertyLocationConfiguration & V8DOMConfiguration::OnPrototyp
e) | 86 if (attribute.propertyLocationConfiguration & V8DOMConfiguration::OnPrototyp
e) |
| 87 v8CallOrCrash(prototype->DefineOwnProperty(isolate->GetCurrentContext(),
name, data, static_cast<v8::PropertyAttribute>(attribute.attribute))); | 87 prototype->DefineOwnProperty(isolate->GetCurrentContext(), name, data, s
tatic_cast<v8::PropertyAttribute>(attribute.attribute)).ToChecked(); |
| 88 if (attribute.propertyLocationConfiguration & V8DOMConfiguration::OnInterfac
e) | 88 if (attribute.propertyLocationConfiguration & V8DOMConfiguration::OnInterfac
e) |
| 89 NOTREACHED(); | 89 NOTREACHED(); |
| 90 } | 90 } |
| 91 | 91 |
| 92 template<class FunctionOrTemplate> | 92 template<class FunctionOrTemplate> |
| 93 v8::Local<FunctionOrTemplate> createAccessorFunctionOrTemplate(v8::Isolate*, v8:
:FunctionCallback, v8::Local<v8::Value> data, v8::Local<v8::Signature>, int leng
th); | 93 v8::Local<FunctionOrTemplate> createAccessorFunctionOrTemplate(v8::Isolate*, v8:
:FunctionCallback, v8::Local<v8::Value> data, v8::Local<v8::Signature>, int leng
th); |
| 94 | 94 |
| 95 template<> | 95 template<> |
| 96 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) | 96 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) |
| 97 { | 97 { |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 prototypeTemplate->Set(constantName, value, attributes); | 198 prototypeTemplate->Set(constantName, value, attributes); |
| 199 } | 199 } |
| 200 | 200 |
| 201 void installConstantInternal(v8::Isolate* isolate, v8::Local<v8::Function> inter
face, v8::Local<v8::Object> prototype, const V8DOMConfiguration::ConstantConfigu
ration& constant) | 201 void installConstantInternal(v8::Isolate* isolate, v8::Local<v8::Function> inter
face, v8::Local<v8::Object> prototype, const V8DOMConfiguration::ConstantConfigu
ration& constant) |
| 202 { | 202 { |
| 203 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | 203 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
| 204 v8::Local<v8::Name> name = v8AtomicString(isolate, constant.name); | 204 v8::Local<v8::Name> name = v8AtomicString(isolate, constant.name); |
| 205 v8::PropertyAttribute attributes = | 205 v8::PropertyAttribute attributes = |
| 206 static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete); | 206 static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete); |
| 207 v8::Local<v8::Primitive> value = valueForConstant(isolate, constant); | 207 v8::Local<v8::Primitive> value = valueForConstant(isolate, constant); |
| 208 v8CallOrCrash(interface->DefineOwnProperty(context, name, value, attributes)
); | 208 interface->DefineOwnProperty(context, name, value, attributes).ToChecked(); |
| 209 v8CallOrCrash(prototype->DefineOwnProperty(context, name, value, attributes)
); | 209 prototype->DefineOwnProperty(context, name, value, attributes).ToChecked(); |
| 210 } | 210 } |
| 211 | 211 |
| 212 template<class Configuration> | 212 template<class Configuration> |
| 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) | 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) |
| 214 { | 214 { |
| 215 if (method.exposeConfiguration == V8DOMConfiguration::OnlyExposedToPrivateSc
ript | 215 if (method.exposeConfiguration == V8DOMConfiguration::OnlyExposedToPrivateSc
ript |
| 216 && !world.isPrivateScriptIsolatedWorld()) | 216 && !world.isPrivateScriptIsolatedWorld()) |
| 217 return; | 217 return; |
| 218 | 218 |
| 219 v8::Local<v8::Name> name = method.methodName(isolate); | 219 v8::Local<v8::Name> name = method.methodName(isolate); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 246 return; | 246 return; |
| 247 | 247 |
| 248 v8::Local<v8::Name> name = method.methodName(isolate); | 248 v8::Local<v8::Name> name = method.methodName(isolate); |
| 249 v8::FunctionCallback callback = method.callbackForWorld(world); | 249 v8::FunctionCallback callback = method.callbackForWorld(world); |
| 250 | 250 |
| 251 DCHECK(method.propertyLocationConfiguration); | 251 DCHECK(method.propertyLocationConfiguration); |
| 252 if (method.propertyLocationConfiguration & | 252 if (method.propertyLocationConfiguration & |
| 253 (V8DOMConfiguration::OnInstance | V8DOMConfiguration::OnPrototype)) { | 253 (V8DOMConfiguration::OnInstance | V8DOMConfiguration::OnPrototype)) { |
| 254 v8::Local<v8::FunctionTemplate> functionTemplate = v8::FunctionTemplate:
:New(isolate, callback, v8::Local<v8::Value>(), signature, method.length); | 254 v8::Local<v8::FunctionTemplate> functionTemplate = v8::FunctionTemplate:
:New(isolate, callback, v8::Local<v8::Value>(), signature, method.length); |
| 255 functionTemplate->RemovePrototype(); | 255 functionTemplate->RemovePrototype(); |
| 256 v8::Local<v8::Function> function = v8CallOrCrash(functionTemplate->GetFu
nction(isolate->GetCurrentContext())); | 256 v8::Local<v8::Function> function = functionTemplate->GetFunction(isolate
->GetCurrentContext()).ToLocalChecked(); |
| 257 if (method.propertyLocationConfiguration & V8DOMConfiguration::OnInstanc
e) | 257 if (method.propertyLocationConfiguration & V8DOMConfiguration::OnInstanc
e) |
| 258 v8CallOrCrash(instance->DefineOwnProperty(isolate->GetCurrentContext
(), name, function, static_cast<v8::PropertyAttribute>(method.attribute))); | 258 instance->DefineOwnProperty(isolate->GetCurrentContext(), name, func
tion, static_cast<v8::PropertyAttribute>(method.attribute)).ToChecked(); |
| 259 if (method.propertyLocationConfiguration & V8DOMConfiguration::OnPrototy
pe) | 259 if (method.propertyLocationConfiguration & V8DOMConfiguration::OnPrototy
pe) |
| 260 v8CallOrCrash(prototype->DefineOwnProperty(isolate->GetCurrentContex
t(), name, function, static_cast<v8::PropertyAttribute>(method.attribute))); | 260 prototype->DefineOwnProperty(isolate->GetCurrentContext(), name, fun
ction, static_cast<v8::PropertyAttribute>(method.attribute)).ToChecked(); |
| 261 } | 261 } |
| 262 if (method.propertyLocationConfiguration & V8DOMConfiguration::OnInterface)
{ | 262 if (method.propertyLocationConfiguration & V8DOMConfiguration::OnInterface)
{ |
| 263 // Operations installed on the interface object must be static | 263 // Operations installed on the interface object must be static |
| 264 // operations, so no need to specify a signature, i.e. no need to do | 264 // operations, so no need to specify a signature, i.e. no need to do |
| 265 // type check against a holder. | 265 // type check against a holder. |
| 266 v8::Local<v8::FunctionTemplate> functionTemplate = v8::FunctionTemplate:
:New(isolate, callback, v8::Local<v8::Value>(), v8::Local<v8::Signature>(), meth
od.length); | 266 v8::Local<v8::FunctionTemplate> functionTemplate = v8::FunctionTemplate:
:New(isolate, callback, v8::Local<v8::Value>(), v8::Local<v8::Signature>(), meth
od.length); |
| 267 functionTemplate->RemovePrototype(); | 267 functionTemplate->RemovePrototype(); |
| 268 v8::Local<v8::Function> function = v8CallOrCrash(functionTemplate->GetFu
nction(isolate->GetCurrentContext())); | 268 v8::Local<v8::Function> function = functionTemplate->GetFunction(isolate
->GetCurrentContext()).ToLocalChecked(); |
| 269 v8CallOrCrash(interface->DefineOwnProperty(isolate->GetCurrentContext(),
name, function, static_cast<v8::PropertyAttribute>(method.attribute))); | 269 interface->DefineOwnProperty(isolate->GetCurrentContext(), name, functio
n, static_cast<v8::PropertyAttribute>(method.attribute)).ToChecked(); |
| 270 } | 270 } |
| 271 } | 271 } |
| 272 | 272 |
| 273 } // namespace | 273 } // namespace |
| 274 | 274 |
| 275 void V8DOMConfiguration::installAttributes(v8::Isolate* isolate, const DOMWrappe
rWorld& world, v8::Local<v8::ObjectTemplate> instanceTemplate, v8::Local<v8::Obj
ectTemplate> prototypeTemplate, const AttributeConfiguration* attributes, size_t
attributeCount) | 275 void V8DOMConfiguration::installAttributes(v8::Isolate* isolate, const DOMWrappe
rWorld& world, v8::Local<v8::ObjectTemplate> instanceTemplate, v8::Local<v8::Obj
ectTemplate> prototypeTemplate, const AttributeConfiguration* attributes, size_t
attributeCount) |
| 276 { | 276 { |
| 277 for (size_t i = 0; i < attributeCount; ++i) | 277 for (size_t i = 0; i < attributeCount; ++i) |
| 278 installAttributeInternal(isolate, instanceTemplate, prototypeTemplate, a
ttributes[i], world); | 278 installAttributeInternal(isolate, instanceTemplate, prototypeTemplate, a
ttributes[i], world); |
| 279 } | 279 } |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 data->setInterfaceTemplate(world, wrapperTypeInfo, result); | 385 data->setInterfaceTemplate(world, wrapperTypeInfo, result); |
| 386 return result; | 386 return result; |
| 387 } | 387 } |
| 388 | 388 |
| 389 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) |
| 390 { | 390 { |
| 391 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)); |
| 392 } | 392 } |
| 393 | 393 |
| 394 } // namespace blink | 394 } // namespace blink |
| OLD | NEW |