| 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 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | 317 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
| 318 v8::Local<v8::Name> name = v8AtomicString(isolate, constant.name); | 318 v8::Local<v8::Name> name = v8AtomicString(isolate, constant.name); |
| 319 v8::PropertyAttribute attributes = | 319 v8::PropertyAttribute attributes = |
| 320 static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete); | 320 static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete); |
| 321 v8::Local<v8::Primitive> value = valueForConstant(isolate, constant); | 321 v8::Local<v8::Primitive> value = valueForConstant(isolate, constant); |
| 322 interface->DefineOwnProperty(context, name, value, attributes).ToChecked(); | 322 interface->DefineOwnProperty(context, name, value, attributes).ToChecked(); |
| 323 prototype->DefineOwnProperty(context, name, value, attributes).ToChecked(); | 323 prototype->DefineOwnProperty(context, name, value, attributes).ToChecked(); |
| 324 } | 324 } |
| 325 | 325 |
| 326 template <class Configuration> | 326 template <class Configuration> |
| 327 bool worldConfigurationApplies(const Configuration& config, |
| 328 const DOMWrapperWorld& world) { |
| 329 const auto currentWorldConfig = world.isMainWorld() |
| 330 ? V8DOMConfiguration::MainWorld |
| 331 : V8DOMConfiguration::NonMainWorlds; |
| 332 return config.worldConfiguration & currentWorldConfig; |
| 333 } |
| 334 |
| 335 template <> |
| 336 bool worldConfigurationApplies( |
| 337 const V8DOMConfiguration::SymbolKeyedMethodConfiguration&, |
| 338 const DOMWrapperWorld&) { |
| 339 return true; |
| 340 } |
| 341 |
| 342 template <class Configuration> |
| 327 void installMethodInternal(v8::Isolate* isolate, | 343 void installMethodInternal(v8::Isolate* isolate, |
| 328 v8::Local<v8::ObjectTemplate> instanceTemplate, | 344 v8::Local<v8::ObjectTemplate> instanceTemplate, |
| 329 v8::Local<v8::ObjectTemplate> prototypeTemplate, | 345 v8::Local<v8::ObjectTemplate> prototypeTemplate, |
| 330 v8::Local<v8::FunctionTemplate> interfaceTemplate, | 346 v8::Local<v8::FunctionTemplate> interfaceTemplate, |
| 331 v8::Local<v8::Signature> signature, | 347 v8::Local<v8::Signature> signature, |
| 332 const Configuration& method, | 348 const Configuration& method, |
| 333 const DOMWrapperWorld& world) { | 349 const DOMWrapperWorld& world) { |
| 350 if (!worldConfigurationApplies(method, world)) |
| 351 return; |
| 352 |
| 334 v8::Local<v8::Name> name = method.methodName(isolate); | 353 v8::Local<v8::Name> name = method.methodName(isolate); |
| 335 v8::FunctionCallback callback = method.callbackForWorld(world); | 354 v8::FunctionCallback callback = method.callback; |
| 336 // Promise-returning functions need to return a reject promise when | 355 // Promise-returning functions need to return a reject promise when |
| 337 // an exception occurs. This includes a case that the receiver object is not | 356 // an exception occurs. This includes a case that the receiver object is not |
| 338 // of the type. So, we disable the type check of the receiver object on V8 | 357 // of the type. So, we disable the type check of the receiver object on V8 |
| 339 // side so that V8 won't throw. Instead, we do the check on Blink side and | 358 // side so that V8 won't throw. Instead, we do the check on Blink side and |
| 340 // convert an exception to a reject promise. | 359 // convert an exception to a reject promise. |
| 341 if (method.holderCheckConfiguration == V8DOMConfiguration::DoNotCheckHolder) | 360 if (method.holderCheckConfiguration == V8DOMConfiguration::DoNotCheckHolder) |
| 342 signature = v8::Local<v8::Signature>(); | 361 signature = v8::Local<v8::Signature>(); |
| 343 | 362 |
| 344 DCHECK(method.propertyLocationConfiguration); | 363 DCHECK(method.propertyLocationConfiguration); |
| 345 if (method.propertyLocationConfiguration & | 364 if (method.propertyLocationConfiguration & |
| (...skipping 30 matching lines...) Expand all Loading... |
| 376 } | 395 } |
| 377 | 396 |
| 378 void installMethodInternal( | 397 void installMethodInternal( |
| 379 v8::Isolate* isolate, | 398 v8::Isolate* isolate, |
| 380 v8::Local<v8::Object> instance, | 399 v8::Local<v8::Object> instance, |
| 381 v8::Local<v8::Object> prototype, | 400 v8::Local<v8::Object> prototype, |
| 382 v8::Local<v8::Function> interface, | 401 v8::Local<v8::Function> interface, |
| 383 v8::Local<v8::Signature> signature, | 402 v8::Local<v8::Signature> signature, |
| 384 const V8DOMConfiguration::MethodConfiguration& method, | 403 const V8DOMConfiguration::MethodConfiguration& method, |
| 385 const DOMWrapperWorld& world) { | 404 const DOMWrapperWorld& world) { |
| 405 if (!worldConfigurationApplies(method, world)) |
| 406 return; |
| 407 |
| 386 v8::Local<v8::Name> name = method.methodName(isolate); | 408 v8::Local<v8::Name> name = method.methodName(isolate); |
| 387 v8::FunctionCallback callback = method.callbackForWorld(world); | 409 v8::FunctionCallback callback = method.callback; |
| 388 // Promise-returning functions need to return a reject promise when | 410 // Promise-returning functions need to return a reject promise when |
| 389 // an exception occurs. This includes a case that the receiver object is not | 411 // an exception occurs. This includes a case that the receiver object is not |
| 390 // of the type. So, we disable the type check of the receiver object on V8 | 412 // of the type. So, we disable the type check of the receiver object on V8 |
| 391 // side so that V8 won't throw. Instead, we do the check on Blink side and | 413 // side so that V8 won't throw. Instead, we do the check on Blink side and |
| 392 // convert an exception to a reject promise. | 414 // convert an exception to a reject promise. |
| 393 if (method.holderCheckConfiguration == V8DOMConfiguration::DoNotCheckHolder) | 415 if (method.holderCheckConfiguration == V8DOMConfiguration::DoNotCheckHolder) |
| 394 signature = v8::Local<v8::Signature>(); | 416 signature = v8::Local<v8::Signature>(); |
| 395 | 417 |
| 396 DCHECK(method.propertyLocationConfiguration); | 418 DCHECK(method.propertyLocationConfiguration); |
| 397 if (method.propertyLocationConfiguration & | 419 if (method.propertyLocationConfiguration & |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 670 void V8DOMConfiguration::setClassString( | 692 void V8DOMConfiguration::setClassString( |
| 671 v8::Isolate* isolate, | 693 v8::Isolate* isolate, |
| 672 v8::Local<v8::ObjectTemplate> objectTemplate, | 694 v8::Local<v8::ObjectTemplate> objectTemplate, |
| 673 const char* classString) { | 695 const char* classString) { |
| 674 objectTemplate->Set( | 696 objectTemplate->Set( |
| 675 v8::Symbol::GetToStringTag(isolate), v8AtomicString(isolate, classString), | 697 v8::Symbol::GetToStringTag(isolate), v8AtomicString(isolate, classString), |
| 676 static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); | 698 static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); |
| 677 } | 699 } |
| 678 | 700 |
| 679 } // namespace blink | 701 } // namespace blink |
| OLD | NEW |