| 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 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | 326 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
| 327 v8::Local<v8::Name> name = V8AtomicString(isolate, constant.name); | 327 v8::Local<v8::Name> name = V8AtomicString(isolate, constant.name); |
| 328 v8::PropertyAttribute attributes = | 328 v8::PropertyAttribute attributes = |
| 329 static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete); | 329 static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete); |
| 330 v8::Local<v8::Primitive> value = ValueForConstant(isolate, constant); | 330 v8::Local<v8::Primitive> value = ValueForConstant(isolate, constant); |
| 331 interface->DefineOwnProperty(context, name, value, attributes).ToChecked(); | 331 interface->DefineOwnProperty(context, name, value, attributes).ToChecked(); |
| 332 prototype->DefineOwnProperty(context, name, value, attributes).ToChecked(); | 332 prototype->DefineOwnProperty(context, name, value, attributes).ToChecked(); |
| 333 } | 333 } |
| 334 | 334 |
| 335 template <class Configuration> | 335 template <class Configuration> |
| 336 void AddMethodToTemplate(v8::Isolate* isolate, |
| 337 v8::Local<v8::Template> v8_template, |
| 338 v8::Local<v8::FunctionTemplate> function_template, |
| 339 const Configuration& method) { |
| 340 v8_template->Set(method.MethodName(isolate), function_template, |
| 341 static_cast<v8::PropertyAttribute>(method.attribute)); |
| 342 } |
| 343 |
| 344 template <> |
| 345 void AddMethodToTemplate( |
| 346 v8::Isolate* isolate, |
| 347 v8::Local<v8::Template> v8_template, |
| 348 v8::Local<v8::FunctionTemplate> function_template, |
| 349 const V8DOMConfiguration::SymbolKeyedMethodConfiguration& method) { |
| 350 // The order matters here: if the Symbol is added first, the Function object |
| 351 // will have no associated name. For example, WebIDL states, among other |
| 352 // things, that a pair iterator's @@iterator Function object's name must be |
| 353 // set to "entries". |
| 354 if (method.symbol_alias) { |
| 355 v8_template->Set(V8AtomicString(isolate, method.symbol_alias), |
| 356 function_template); |
| 357 } |
| 358 v8_template->Set(method.MethodName(isolate), function_template, |
| 359 static_cast<v8::PropertyAttribute>(method.attribute)); |
| 360 } |
| 361 |
| 362 template <class Configuration> |
| 336 void InstallMethodInternal(v8::Isolate* isolate, | 363 void InstallMethodInternal(v8::Isolate* isolate, |
| 337 v8::Local<v8::ObjectTemplate> instance_template, | 364 v8::Local<v8::ObjectTemplate> instance_template, |
| 338 v8::Local<v8::ObjectTemplate> prototype_template, | 365 v8::Local<v8::ObjectTemplate> prototype_template, |
| 339 v8::Local<v8::FunctionTemplate> interface_template, | 366 v8::Local<v8::FunctionTemplate> interface_template, |
| 340 v8::Local<v8::Signature> signature, | 367 v8::Local<v8::Signature> signature, |
| 341 const Configuration& method, | 368 const Configuration& method, |
| 342 const DOMWrapperWorld& world) { | 369 const DOMWrapperWorld& world) { |
| 343 if (!WorldConfigurationApplies(method, world)) | 370 if (!WorldConfigurationApplies(method, world)) |
| 344 return; | 371 return; |
| 345 | 372 |
| 346 v8::Local<v8::Name> name = method.MethodName(isolate); | |
| 347 v8::FunctionCallback callback = method.callback; | 373 v8::FunctionCallback callback = method.callback; |
| 348 // Promise-returning functions need to return a reject promise when | 374 // Promise-returning functions need to return a reject promise when |
| 349 // an exception occurs. This includes a case that the receiver object is not | 375 // an exception occurs. This includes a case that the receiver object is not |
| 350 // of the type. So, we disable the type check of the receiver object on V8 | 376 // of the type. So, we disable the type check of the receiver object on V8 |
| 351 // side so that V8 won't throw. Instead, we do the check on Blink side and | 377 // side so that V8 won't throw. Instead, we do the check on Blink side and |
| 352 // convert an exception to a reject promise. | 378 // convert an exception to a reject promise. |
| 353 if (method.holder_check_configuration == | 379 if (method.holder_check_configuration == |
| 354 V8DOMConfiguration::kDoNotCheckHolder) | 380 V8DOMConfiguration::kDoNotCheckHolder) |
| 355 signature = v8::Local<v8::Signature>(); | 381 signature = v8::Local<v8::Signature>(); |
| 356 | 382 |
| 357 DCHECK(method.property_location_configuration); | 383 DCHECK(method.property_location_configuration); |
| 358 if (method.property_location_configuration & | 384 if (method.property_location_configuration & |
| 359 (V8DOMConfiguration::kOnInstance | V8DOMConfiguration::kOnPrototype)) { | 385 (V8DOMConfiguration::kOnInstance | V8DOMConfiguration::kOnPrototype)) { |
| 360 v8::Local<v8::FunctionTemplate> function_template = | 386 v8::Local<v8::FunctionTemplate> function_template = |
| 361 v8::FunctionTemplate::New(isolate, callback, v8::Local<v8::Value>(), | 387 v8::FunctionTemplate::New(isolate, callback, v8::Local<v8::Value>(), |
| 362 signature, method.length); | 388 signature, method.length); |
| 363 function_template->RemovePrototype(); | 389 function_template->RemovePrototype(); |
| 364 if (method.access_check_configuration == V8DOMConfiguration::kCheckAccess) | 390 if (method.access_check_configuration == V8DOMConfiguration::kCheckAccess) |
| 365 function_template->SetAcceptAnyReceiver(false); | 391 function_template->SetAcceptAnyReceiver(false); |
| 366 if (method.property_location_configuration & | 392 if (method.property_location_configuration & |
| 367 V8DOMConfiguration::kOnInstance) | 393 V8DOMConfiguration::kOnInstance) { |
| 368 instance_template->Set( | 394 AddMethodToTemplate(isolate, instance_template, function_template, |
| 369 name, function_template, | 395 method); |
| 370 static_cast<v8::PropertyAttribute>(method.attribute)); | 396 } |
| 371 if (method.property_location_configuration & | 397 if (method.property_location_configuration & |
| 372 V8DOMConfiguration::kOnPrototype) | 398 V8DOMConfiguration::kOnPrototype) { |
| 373 prototype_template->Set( | 399 AddMethodToTemplate(isolate, prototype_template, function_template, |
| 374 name, function_template, | 400 method); |
| 375 static_cast<v8::PropertyAttribute>(method.attribute)); | 401 } |
| 376 } | 402 } |
| 377 if (method.property_location_configuration & | 403 if (method.property_location_configuration & |
| 378 V8DOMConfiguration::kOnInterface) { | 404 V8DOMConfiguration::kOnInterface) { |
| 379 // Operations installed on the interface object must be static methods, so | 405 // Operations installed on the interface object must be static methods, so |
| 380 // no need to specify a signature, i.e. no need to do type check against a | 406 // no need to specify a signature, i.e. no need to do type check against a |
| 381 // holder. | 407 // holder. |
| 382 v8::Local<v8::FunctionTemplate> function_template = | 408 v8::Local<v8::FunctionTemplate> function_template = |
| 383 v8::FunctionTemplate::New(isolate, callback, v8::Local<v8::Value>(), | 409 v8::FunctionTemplate::New(isolate, callback, v8::Local<v8::Value>(), |
| 384 v8::Local<v8::Signature>(), method.length); | 410 v8::Local<v8::Signature>(), method.length); |
| 385 function_template->RemovePrototype(); | 411 function_template->RemovePrototype(); |
| 386 // Similarly, there is no need to do an access check for static methods, as | 412 // Similarly, there is no need to do an access check for static methods, as |
| 387 // there is no holder to check against. | 413 // there is no holder to check against. |
| 388 interface_template->Set( | 414 AddMethodToTemplate(isolate, interface_template, function_template, method); |
| 389 name, function_template, | |
| 390 static_cast<v8::PropertyAttribute>(method.attribute)); | |
| 391 } | 415 } |
| 392 } | 416 } |
| 393 | 417 |
| 394 void InstallMethodInternal( | 418 void InstallMethodInternal( |
| 395 v8::Isolate* isolate, | 419 v8::Isolate* isolate, |
| 396 v8::Local<v8::Object> instance, | 420 v8::Local<v8::Object> instance, |
| 397 v8::Local<v8::Object> prototype, | 421 v8::Local<v8::Object> prototype, |
| 398 v8::Local<v8::Function> interface, | 422 v8::Local<v8::Function> interface, |
| 399 v8::Local<v8::Signature> signature, | 423 v8::Local<v8::Signature> signature, |
| 400 const V8DOMConfiguration::MethodConfiguration& method, | 424 const V8DOMConfiguration::MethodConfiguration& method, |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 694 v8::Isolate* isolate, | 718 v8::Isolate* isolate, |
| 695 v8::Local<v8::ObjectTemplate> object_template, | 719 v8::Local<v8::ObjectTemplate> object_template, |
| 696 const char* class_string) { | 720 const char* class_string) { |
| 697 object_template->Set( | 721 object_template->Set( |
| 698 v8::Symbol::GetToStringTag(isolate), | 722 v8::Symbol::GetToStringTag(isolate), |
| 699 V8AtomicString(isolate, class_string), | 723 V8AtomicString(isolate, class_string), |
| 700 static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); | 724 static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); |
| 701 } | 725 } |
| 702 | 726 |
| 703 } // namespace blink | 727 } // namespace blink |
| OLD | NEW |