| 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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 static_cast<v8::PropertyAttribute>(attribute.attribute)); | 153 static_cast<v8::PropertyAttribute>(attribute.attribute)); |
| 154 } | 154 } |
| 155 if (attribute.propertyLocationConfiguration & V8DOMConfiguration::OnInterface) | 155 if (attribute.propertyLocationConfiguration & V8DOMConfiguration::OnInterface) |
| 156 NOTREACHED(); | 156 NOTREACHED(); |
| 157 } | 157 } |
| 158 | 158 |
| 159 template <class FunctionOrTemplate> | 159 template <class FunctionOrTemplate> |
| 160 v8::Local<FunctionOrTemplate> createAccessorFunctionOrTemplate( | 160 v8::Local<FunctionOrTemplate> createAccessorFunctionOrTemplate( |
| 161 v8::Isolate*, | 161 v8::Isolate*, |
| 162 v8::FunctionCallback, | 162 v8::FunctionCallback, |
| 163 V8DOMConfiguration::CachedAccessorCallback, |
| 163 v8::Local<v8::Value> data, | 164 v8::Local<v8::Value> data, |
| 164 v8::Local<v8::Signature>, | 165 v8::Local<v8::Signature>, |
| 165 int length); | 166 int length); |
| 166 | 167 |
| 167 template <> | 168 template <> |
| 168 v8::Local<v8::FunctionTemplate> | 169 v8::Local<v8::FunctionTemplate> |
| 169 createAccessorFunctionOrTemplate<v8::FunctionTemplate>( | 170 createAccessorFunctionOrTemplate<v8::FunctionTemplate>( |
| 170 v8::Isolate* isolate, | 171 v8::Isolate* isolate, |
| 171 v8::FunctionCallback callback, | 172 v8::FunctionCallback callback, |
| 173 V8DOMConfiguration::CachedAccessorCallback cachedAccessorCallback, |
| 172 v8::Local<v8::Value> data, | 174 v8::Local<v8::Value> data, |
| 173 v8::Local<v8::Signature> signature, | 175 v8::Local<v8::Signature> signature, |
| 174 int length) { | 176 int length) { |
| 175 v8::Local<v8::FunctionTemplate> functionTemplate; | 177 v8::Local<v8::FunctionTemplate> functionTemplate; |
| 176 if (callback) { | 178 if (callback) { |
| 177 functionTemplate = | 179 if (cachedAccessorCallback) { |
| 178 v8::FunctionTemplate::New(isolate, callback, data, signature, length); | 180 functionTemplate = v8::FunctionTemplate::NewWithCache( |
| 181 isolate, callback, cachedAccessorCallback(isolate), data, signature, |
| 182 length); |
| 183 } else { |
| 184 functionTemplate = |
| 185 v8::FunctionTemplate::New(isolate, callback, data, signature, length); |
| 186 } |
| 187 |
| 179 if (!functionTemplate.IsEmpty()) { | 188 if (!functionTemplate.IsEmpty()) { |
| 180 functionTemplate->RemovePrototype(); | 189 functionTemplate->RemovePrototype(); |
| 181 functionTemplate->SetAcceptAnyReceiver(false); | 190 functionTemplate->SetAcceptAnyReceiver(false); |
| 182 } | 191 } |
| 183 } | 192 } |
| 184 return functionTemplate; | 193 return functionTemplate; |
| 185 } | 194 } |
| 186 | 195 |
| 187 template <> | 196 template <> |
| 188 v8::Local<v8::Function> createAccessorFunctionOrTemplate<v8::Function>( | 197 v8::Local<v8::Function> createAccessorFunctionOrTemplate<v8::Function>( |
| 189 v8::Isolate* isolate, | 198 v8::Isolate* isolate, |
| 190 v8::FunctionCallback callback, | 199 v8::FunctionCallback callback, |
| 200 V8DOMConfiguration::CachedAccessorCallback, |
| 191 v8::Local<v8::Value> data, | 201 v8::Local<v8::Value> data, |
| 192 v8::Local<v8::Signature> signature, | 202 v8::Local<v8::Signature> signature, |
| 193 int length) { | 203 int length) { |
| 194 if (!callback) | 204 if (!callback) |
| 195 return v8::Local<v8::Function>(); | 205 return v8::Local<v8::Function>(); |
| 196 | 206 |
| 197 v8::Local<v8::FunctionTemplate> functionTemplate = | 207 v8::Local<v8::FunctionTemplate> functionTemplate = |
| 198 createAccessorFunctionOrTemplate<v8::FunctionTemplate>( | 208 createAccessorFunctionOrTemplate<v8::FunctionTemplate>( |
| 199 isolate, callback, data, signature, length); | 209 isolate, callback, nullptr, data, signature, length); |
| 200 if (functionTemplate.IsEmpty()) | 210 if (functionTemplate.IsEmpty()) |
| 201 return v8::Local<v8::Function>(); | 211 return v8::Local<v8::Function>(); |
| 202 | 212 |
| 203 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | 213 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
| 204 v8::Local<v8::Function> function; | 214 v8::Local<v8::Function> function; |
| 205 if (!functionTemplate->GetFunction(context).ToLocal(&function)) | 215 if (!functionTemplate->GetFunction(context).ToLocal(&function)) |
| 206 return v8::Local<v8::Function>(); | 216 return v8::Local<v8::Function>(); |
| 207 return function; | 217 return function; |
| 208 } | 218 } |
| 209 | 219 |
| 210 template <class ObjectOrTemplate, class FunctionOrTemplate> | 220 template <class ObjectOrTemplate, class FunctionOrTemplate> |
| 211 void installAccessorInternal( | 221 void installAccessorInternal( |
| 212 v8::Isolate* isolate, | 222 v8::Isolate* isolate, |
| 213 v8::Local<ObjectOrTemplate> instanceOrTemplate, | 223 v8::Local<ObjectOrTemplate> instanceOrTemplate, |
| 214 v8::Local<ObjectOrTemplate> prototypeOrTemplate, | 224 v8::Local<ObjectOrTemplate> prototypeOrTemplate, |
| 215 v8::Local<FunctionOrTemplate> interfaceOrTemplate, | 225 v8::Local<FunctionOrTemplate> interfaceOrTemplate, |
| 216 v8::Local<v8::Signature> signature, | 226 v8::Local<v8::Signature> signature, |
| 217 const V8DOMConfiguration::AccessorConfiguration& accessor, | 227 const V8DOMConfiguration::AccessorConfiguration& accessor, |
| 218 const DOMWrapperWorld& world) { | 228 const DOMWrapperWorld& world) { |
| 219 if (accessor.exposeConfiguration == | 229 if (accessor.exposeConfiguration == |
| 220 V8DOMConfiguration::OnlyExposedToPrivateScript && | 230 V8DOMConfiguration::OnlyExposedToPrivateScript && |
| 221 !world.isPrivateScriptIsolatedWorld()) | 231 !world.isPrivateScriptIsolatedWorld()) |
| 222 return; | 232 return; |
| 223 | 233 |
| 224 v8::Local<v8::Name> name = v8AtomicString(isolate, accessor.name); | 234 v8::Local<v8::Name> name = v8AtomicString(isolate, accessor.name); |
| 225 v8::FunctionCallback getterCallback = accessor.getter; | 235 v8::FunctionCallback getterCallback = accessor.getter; |
| 226 v8::FunctionCallback setterCallback = accessor.setter; | 236 v8::FunctionCallback setterCallback = accessor.setter; |
| 237 V8DOMConfiguration::CachedAccessorCallback cachedAccessorCallback = nullptr; |
| 227 if (world.isMainWorld()) { | 238 if (world.isMainWorld()) { |
| 228 if (accessor.getterForMainWorld) | 239 if (accessor.getterForMainWorld) |
| 229 getterCallback = accessor.getterForMainWorld; | 240 getterCallback = accessor.getterForMainWorld; |
| 230 if (accessor.setterForMainWorld) | 241 if (accessor.setterForMainWorld) |
| 231 setterCallback = accessor.setterForMainWorld; | 242 setterCallback = accessor.setterForMainWorld; |
| 243 cachedAccessorCallback = accessor.cachedAccessorCallback; |
| 232 } | 244 } |
| 245 |
| 233 // Support [LenientThis] by not specifying the signature. V8 does not do | 246 // Support [LenientThis] by not specifying the signature. V8 does not do |
| 234 // the type checking against holder if no signature is specified. Note that | 247 // the type checking against holder if no signature is specified. Note that |
| 235 // info.Holder() passed to callbacks will be *unsafe*. | 248 // info.Holder() passed to callbacks will be *unsafe*. |
| 236 if (accessor.holderCheckConfiguration == V8DOMConfiguration::DoNotCheckHolder) | 249 if (accessor.holderCheckConfiguration == V8DOMConfiguration::DoNotCheckHolder) |
| 237 signature = v8::Local<v8::Signature>(); | 250 signature = v8::Local<v8::Signature>(); |
| 238 v8::Local<v8::Value> data = | 251 v8::Local<v8::Value> data = |
| 239 v8::External::New(isolate, const_cast<WrapperTypeInfo*>(accessor.data)); | 252 v8::External::New(isolate, const_cast<WrapperTypeInfo*>(accessor.data)); |
| 240 | 253 |
| 241 DCHECK(accessor.propertyLocationConfiguration); | 254 DCHECK(accessor.propertyLocationConfiguration); |
| 242 if (accessor.propertyLocationConfiguration & | 255 if (accessor.propertyLocationConfiguration & |
| 243 (V8DOMConfiguration::OnInstance | V8DOMConfiguration::OnPrototype)) { | 256 (V8DOMConfiguration::OnInstance | V8DOMConfiguration::OnPrototype)) { |
| 244 v8::Local<FunctionOrTemplate> getter = | 257 v8::Local<FunctionOrTemplate> getter = |
| 245 createAccessorFunctionOrTemplate<FunctionOrTemplate>( | 258 createAccessorFunctionOrTemplate<FunctionOrTemplate>( |
| 246 isolate, getterCallback, data, signature, 0); | 259 isolate, getterCallback, cachedAccessorCallback, data, signature, |
| 260 0); |
| 247 v8::Local<FunctionOrTemplate> setter = | 261 v8::Local<FunctionOrTemplate> setter = |
| 248 createAccessorFunctionOrTemplate<FunctionOrTemplate>( | 262 createAccessorFunctionOrTemplate<FunctionOrTemplate>( |
| 249 isolate, setterCallback, data, signature, 1); | 263 isolate, setterCallback, nullptr, data, signature, 1); |
| 250 if (accessor.propertyLocationConfiguration & V8DOMConfiguration::OnInstance) | 264 if (accessor.propertyLocationConfiguration & V8DOMConfiguration::OnInstance) |
| 251 instanceOrTemplate->SetAccessorProperty( | 265 instanceOrTemplate->SetAccessorProperty( |
| 252 name, getter, setter, | 266 name, getter, setter, |
| 253 static_cast<v8::PropertyAttribute>(accessor.attribute), | 267 static_cast<v8::PropertyAttribute>(accessor.attribute), |
| 254 static_cast<v8::AccessControl>(accessor.settings)); | 268 static_cast<v8::AccessControl>(accessor.settings)); |
| 255 if (accessor.propertyLocationConfiguration & | 269 if (accessor.propertyLocationConfiguration & |
| 256 V8DOMConfiguration::OnPrototype) | 270 V8DOMConfiguration::OnPrototype) |
| 257 prototypeOrTemplate->SetAccessorProperty( | 271 prototypeOrTemplate->SetAccessorProperty( |
| 258 name, getter, setter, | 272 name, getter, setter, |
| 259 static_cast<v8::PropertyAttribute>(accessor.attribute), | 273 static_cast<v8::PropertyAttribute>(accessor.attribute), |
| 260 static_cast<v8::AccessControl>(accessor.settings)); | 274 static_cast<v8::AccessControl>(accessor.settings)); |
| 261 } | 275 } |
| 262 if (accessor.propertyLocationConfiguration & | 276 if (accessor.propertyLocationConfiguration & |
| 263 V8DOMConfiguration::OnInterface) { | 277 V8DOMConfiguration::OnInterface) { |
| 264 // Attributes installed on the interface object must be static | 278 // Attributes installed on the interface object must be static |
| 265 // attributes, so no need to specify a signature, i.e. no need to do | 279 // attributes, so no need to specify a signature, i.e. no need to do |
| 266 // type check against a holder. | 280 // type check against a holder. |
| 267 v8::Local<FunctionOrTemplate> getter = | 281 v8::Local<FunctionOrTemplate> getter = |
| 268 createAccessorFunctionOrTemplate<FunctionOrTemplate>( | 282 createAccessorFunctionOrTemplate<FunctionOrTemplate>( |
| 269 isolate, getterCallback, data, v8::Local<v8::Signature>(), 0); | 283 isolate, getterCallback, nullptr, data, v8::Local<v8::Signature>(), |
| 284 0); |
| 270 v8::Local<FunctionOrTemplate> setter = | 285 v8::Local<FunctionOrTemplate> setter = |
| 271 createAccessorFunctionOrTemplate<FunctionOrTemplate>( | 286 createAccessorFunctionOrTemplate<FunctionOrTemplate>( |
| 272 isolate, setterCallback, data, v8::Local<v8::Signature>(), 1); | 287 isolate, setterCallback, nullptr, data, v8::Local<v8::Signature>(), |
| 288 1); |
| 273 interfaceOrTemplate->SetAccessorProperty( | 289 interfaceOrTemplate->SetAccessorProperty( |
| 274 name, getter, setter, | 290 name, getter, setter, |
| 275 static_cast<v8::PropertyAttribute>(accessor.attribute), | 291 static_cast<v8::PropertyAttribute>(accessor.attribute), |
| 276 static_cast<v8::AccessControl>(accessor.settings)); | 292 static_cast<v8::AccessControl>(accessor.settings)); |
| 277 } | 293 } |
| 278 } | 294 } |
| 279 | 295 |
| 280 v8::Local<v8::Primitive> valueForConstant( | 296 v8::Local<v8::Primitive> valueForConstant( |
| 281 v8::Isolate* isolate, | 297 v8::Isolate* isolate, |
| 282 const V8DOMConfiguration::ConstantConfiguration& constant) { | 298 const V8DOMConfiguration::ConstantConfiguration& constant) { |
| (...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 652 void V8DOMConfiguration::setClassString( | 668 void V8DOMConfiguration::setClassString( |
| 653 v8::Isolate* isolate, | 669 v8::Isolate* isolate, |
| 654 v8::Local<v8::ObjectTemplate> objectTemplate, | 670 v8::Local<v8::ObjectTemplate> objectTemplate, |
| 655 const char* classString) { | 671 const char* classString) { |
| 656 objectTemplate->Set( | 672 objectTemplate->Set( |
| 657 v8::Symbol::GetToStringTag(isolate), v8AtomicString(isolate, classString), | 673 v8::Symbol::GetToStringTag(isolate), v8AtomicString(isolate, classString), |
| 658 static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); | 674 static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); |
| 659 } | 675 } |
| 660 | 676 |
| 661 } // namespace blink | 677 } // namespace blink |
| OLD | NEW |