Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(920)

Side by Side Diff: Source/bindings/templates/interface.cpp

Issue 210663003: Use |isolate| local variable in bindings, clean up comments (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Update extension Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/bindings/templates/interface.h ('k') | Source/bindings/templates/interface_base.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 {% extends 'interface_base.cpp' %} 1 {% extends 'interface_base.cpp' %}
2 2
3 3
4 {##############################################################################} 4 {##############################################################################}
5 {% macro attribute_configuration(attribute) %} 5 {% macro attribute_configuration(attribute) %}
6 {% set getter_callback = 6 {% set getter_callback =
7 '%sV8Internal::%sAttributeGetterCallback' % 7 '%sV8Internal::%sAttributeGetterCallback' %
8 (cpp_class, attribute.name) 8 (cpp_class, attribute.name)
9 if not attribute.constructor_type else 9 if not attribute.constructor_type else
10 ('%sV8Internal::%sConstructorGetterCallback' % 10 ('%sV8Internal::%sConstructorGetterCallback' %
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 79
80 80
81 {##############################################################################} 81 {##############################################################################}
82 {% block replaceable_attribute_setter_and_callback %} 82 {% block replaceable_attribute_setter_and_callback %}
83 {% if has_replaceable_attributes or has_constructor_attributes %} 83 {% if has_replaceable_attributes or has_constructor_attributes %}
84 {# FIXME: rename to ForceSetAttributeOnThis, since also used for Constructors #} 84 {# FIXME: rename to ForceSetAttributeOnThis, since also used for Constructors #}
85 static void {{cpp_class}}ReplaceableAttributeSetter(v8::Local<v8::String> name, v8::Local<v8::Value> jsValue, const v8::PropertyCallbackInfo<void>& info) 85 static void {{cpp_class}}ReplaceableAttributeSetter(v8::Local<v8::String> name, v8::Local<v8::Value> jsValue, const v8::PropertyCallbackInfo<void>& info)
86 { 86 {
87 {% if is_check_security %} 87 {% if is_check_security %}
88 {{cpp_class}}* impl = {{v8_class}}::toNative(info.Holder()); 88 {{cpp_class}}* impl = {{v8_class}}::toNative(info.Holder());
89 v8::Isolate* isolate = info.GetIsolate();
89 v8::String::Utf8Value attributeName(name); 90 v8::String::Utf8Value attributeName(name);
90 ExceptionState exceptionState(ExceptionState::SetterContext, *attributeName, "{{interface_name}}", info.Holder(), info.GetIsolate()); 91 ExceptionState exceptionState(ExceptionState::SetterContext, *attributeName, "{{interface_name}}", info.Holder(), isolate);
91 if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), impl->fram e(), exceptionState)) { 92 if (!BindingSecurity::shouldAllowAccessToFrame(isolate, impl->frame(), excep tionState)) {
92 exceptionState.throwIfNeeded(); 93 exceptionState.throwIfNeeded();
93 return; 94 return;
94 } 95 }
95 {% endif %} 96 {% endif %}
96 info.This()->ForceSet(name, jsValue); 97 info.This()->ForceSet(name, jsValue);
97 } 98 }
98 99
99 {# FIXME: rename to ForceSetAttributeOnThisCallback, since also used for Constru ctors #} 100 {# FIXME: rename to ForceSetAttributeOnThisCallback, since also used for Constru ctors #}
100 static void {{cpp_class}}ReplaceableAttributeSetterCallback(v8::Local<v8::String > name, v8::Local<v8::Value> jsValue, const v8::PropertyCallbackInfo<void>& info ) 101 static void {{cpp_class}}ReplaceableAttributeSetterCallback(v8::Local<v8::String > name, v8::Local<v8::Value> jsValue, const v8::PropertyCallbackInfo<void>& info )
101 { 102 {
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 {% endblock %} 479 {% endblock %}
479 480
480 481
481 {##############################################################################} 482 {##############################################################################}
482 {% block named_property_enumerator %} 483 {% block named_property_enumerator %}
483 {% if named_property_getter and named_property_getter.is_enumerable and 484 {% if named_property_getter and named_property_getter.is_enumerable and
484 not named_property_getter.is_custom_property_enumerator %} 485 not named_property_getter.is_custom_property_enumerator %}
485 static void namedPropertyEnumerator(const v8::PropertyCallbackInfo<v8::Array>& i nfo) 486 static void namedPropertyEnumerator(const v8::PropertyCallbackInfo<v8::Array>& i nfo)
486 { 487 {
487 {{cpp_class}}* impl = {{v8_class}}::toNative(info.Holder()); 488 {{cpp_class}}* impl = {{v8_class}}::toNative(info.Holder());
489 v8::Isolate* isolate = info.GetIsolate();
488 Vector<String> names; 490 Vector<String> names;
489 ExceptionState exceptionState(ExceptionState::EnumerationContext, "{{interfa ce_name}}", info.Holder(), info.GetIsolate()); 491 ExceptionState exceptionState(ExceptionState::EnumerationContext, "{{interfa ce_name}}", info.Holder(), isolate);
490 impl->namedPropertyEnumerator(names, exceptionState); 492 impl->namedPropertyEnumerator(names, exceptionState);
491 if (exceptionState.throwIfNeeded()) 493 if (exceptionState.throwIfNeeded())
492 return; 494 return;
493 v8::Handle<v8::Array> v8names = v8::Array::New(info.GetIsolate(), names.size ()); 495 v8::Handle<v8::Array> v8names = v8::Array::New(isolate, names.size());
494 for (size_t i = 0; i < names.size(); ++i) 496 for (size_t i = 0; i < names.size(); ++i)
495 v8names->Set(v8::Integer::New(info.GetIsolate(), i), v8String(info.GetIs olate(), names[i])); 497 v8names->Set(v8::Integer::New(isolate, i), v8String(isolate, names[i]));
496 v8SetReturnValue(info, v8names); 498 v8SetReturnValue(info, v8names);
497 } 499 }
498 500
499 {% endif %} 501 {% endif %}
500 {% endblock %} 502 {% endblock %}
501 503
502 504
503 {##############################################################################} 505 {##############################################################################}
504 {% block named_property_enumerator_callback %} 506 {% block named_property_enumerator_callback %}
505 {% if named_property_getter and named_property_getter.is_enumerable %} 507 {% if named_property_getter and named_property_getter.is_enumerable %}
(...skipping 11 matching lines...) Expand all
517 519
518 {% endif %} 520 {% endif %}
519 {% endblock %} 521 {% endblock %}
520 522
521 523
522 {##############################################################################} 524 {##############################################################################}
523 {% block origin_safe_method_setter %} 525 {% block origin_safe_method_setter %}
524 {% if has_origin_safe_method_setter %} 526 {% if has_origin_safe_method_setter %}
525 static void {{cpp_class}}OriginSafeMethodSetter(v8::Local<v8::String> name, v8:: Local<v8::Value> jsValue, const v8::PropertyCallbackInfo<void>& info) 527 static void {{cpp_class}}OriginSafeMethodSetter(v8::Local<v8::String> name, v8:: Local<v8::Value> jsValue, const v8::PropertyCallbackInfo<void>& info)
526 { 528 {
527 {# FIXME: don't call GetIsolate 3 times #} 529 v8::Isolate* isolate = info.GetIsolate();
528 v8::Handle<v8::Object> holder = {{v8_class}}::findInstanceInPrototypeChain(i nfo.This(), info.GetIsolate()); 530 v8::Handle<v8::Object> holder = {{v8_class}}::findInstanceInPrototypeChain(i nfo.This(), isolate);
529 if (holder.IsEmpty()) 531 if (holder.IsEmpty())
530 return; 532 return;
531 {{cpp_class}}* impl = {{v8_class}}::toNative(holder); 533 {{cpp_class}}* impl = {{v8_class}}::toNative(holder);
532 v8::String::Utf8Value attributeName(name); 534 v8::String::Utf8Value attributeName(name);
533 ExceptionState exceptionState(ExceptionState::SetterContext, *attributeName, "{{interface_name}}", info.Holder(), info.GetIsolate()); 535 ExceptionState exceptionState(ExceptionState::SetterContext, *attributeName, "{{interface_name}}", info.Holder(), isolate);
534 if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), impl->fram e(), exceptionState)) { 536 if (!BindingSecurity::shouldAllowAccessToFrame(isolate, impl->frame(), excep tionState)) {
535 exceptionState.throwIfNeeded(); 537 exceptionState.throwIfNeeded();
536 return; 538 return;
537 } 539 }
538 540
539 V8HiddenValue::setHiddenValue(info.GetIsolate(), info.This(), name, jsValue) ; 541 V8HiddenValue::setHiddenValue(isolate, info.This(), name, jsValue);
540 } 542 }
541 543
542 static void {{cpp_class}}OriginSafeMethodSetterCallback(v8::Local<v8::String> na me, v8::Local<v8::Value> jsValue, const v8::PropertyCallbackInfo<void>& info) 544 static void {{cpp_class}}OriginSafeMethodSetterCallback(v8::Local<v8::String> na me, v8::Local<v8::Value> jsValue, const v8::PropertyCallbackInfo<void>& info)
543 { 545 {
544 TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMSetter"); 546 TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMSetter");
545 {{cpp_class}}V8Internal::{{cpp_class}}OriginSafeMethodSetter(name, jsValue, info); 547 {{cpp_class}}V8Internal::{{cpp_class}}OriginSafeMethodSetter(name, jsValue, info);
546 TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution"); 548 TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
547 } 549 }
548 550
549 {% endif %} 551 {% endif %}
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 611
610 {% endif %} 612 {% endif %}
611 {% endblock %} 613 {% endblock %}
612 614
613 615
614 {##############################################################################} 616 {##############################################################################}
615 {% block event_constructor %} 617 {% block event_constructor %}
616 {% if has_event_constructor %} 618 {% if has_event_constructor %}
617 static void constructor(const v8::FunctionCallbackInfo<v8::Value>& info) 619 static void constructor(const v8::FunctionCallbackInfo<v8::Value>& info)
618 { 620 {
619 ExceptionState exceptionState(ExceptionState::ConstructionContext, "{{interf ace_name}}", info.Holder(), info.GetIsolate()); 621 v8::Isolate* isolate = info.GetIsolate();
622 ExceptionState exceptionState(ExceptionState::ConstructionContext, "{{interf ace_name}}", info.Holder(), isolate);
620 if (info.Length() < 1) { 623 if (info.Length() < 1) {
621 exceptionState.throwTypeError("An event name must be provided."); 624 exceptionState.throwTypeError("An event name must be provided.");
622 exceptionState.throwIfNeeded(); 625 exceptionState.throwIfNeeded();
623 return; 626 return;
624 } 627 }
625 628
626 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, type, info[0]); 629 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, type, info[0]);
627 {% for attribute in any_type_attributes %} 630 {% for attribute in any_type_attributes %}
628 v8::Local<v8::Value> {{attribute.name}}; 631 v8::Local<v8::Value> {{attribute.name}};
629 {% endfor %} 632 {% endfor %}
630 {{cpp_class}}Init eventInit; 633 {{cpp_class}}Init eventInit;
631 if (info.Length() >= 2) { 634 if (info.Length() >= 2) {
632 V8TRYCATCH_VOID(Dictionary, options, Dictionary(info[1], info.GetIsolate ())); 635 V8TRYCATCH_VOID(Dictionary, options, Dictionary(info[1], isolate));
633 if (!initialize{{cpp_class}}(eventInit, options, exceptionState, info)) { 636 if (!initialize{{cpp_class}}(eventInit, options, exceptionState, info)) {
634 exceptionState.throwIfNeeded(); 637 exceptionState.throwIfNeeded();
635 return; 638 return;
636 } 639 }
637 {# Store attributes of type |any| on the wrapper to avoid leaking them 640 {# Store attributes of type |any| on the wrapper to avoid leaking them
638 between isolated worlds. #} 641 between isolated worlds. #}
639 {% for attribute in any_type_attributes %} 642 {% for attribute in any_type_attributes %}
640 options.get("{{attribute.name}}", {{attribute.name}}); 643 options.get("{{attribute.name}}", {{attribute.name}});
641 if (!{{attribute.name}}.IsEmpty()) 644 if (!{{attribute.name}}.IsEmpty())
642 V8HiddenValue::setHiddenValue(info.GetIsolate(), info.Holder(), v8At omicString(info.GetIsolate(), "{{attribute.name}}"), {{attribute.name}}); 645 V8HiddenValue::setHiddenValue(isolate, info.Holder(), v8AtomicString (isolate, "{{attribute.name}}"), {{attribute.name}});
643 {% endfor %} 646 {% endfor %}
644 } 647 }
645 {% if is_constructor_raises_exception %} 648 {% if is_constructor_raises_exception %}
646 RefPtr<{{cpp_class}}> event = {{cpp_class}}::create(type, eventInit, excepti onState); 649 RefPtr<{{cpp_class}}> event = {{cpp_class}}::create(type, eventInit, excepti onState);
647 if (exceptionState.throwIfNeeded()) 650 if (exceptionState.throwIfNeeded())
648 return; 651 return;
649 {% else %} 652 {% else %}
650 RefPtr<{{cpp_class}}> event = {{cpp_class}}::create(type, eventInit); 653 RefPtr<{{cpp_class}}> event = {{cpp_class}}::create(type, eventInit);
651 {% endif %} 654 {% endif %}
652 {% if any_type_attributes and not interface_name == 'ErrorEvent' %} 655 {% if any_type_attributes and not interface_name == 'ErrorEvent' %}
653 {# If we're in an isolated world, create a SerializedScriptValue and store 656 {# If we're in an isolated world, create a SerializedScriptValue and store
654 it in the event for later cloning if the property is accessed from 657 it in the event for later cloning if the property is accessed from
655 another world. The main world case is handled lazily (in custom code). 658 another world. The main world case is handled lazily (in custom code).
656 659
657 We do not clone Error objects (exceptions), for 2 reasons: 660 We do not clone Error objects (exceptions), for 2 reasons:
658 1) Errors carry a reference to the isolated world's global object, and 661 1) Errors carry a reference to the isolated world's global object, and
659 thus passing it around would cause leakage. 662 thus passing it around would cause leakage.
660 2) Errors cannot be cloned (or serialized): 663 2) Errors cannot be cloned (or serialized):
661 http://www.whatwg.org/specs/web-apps/current-work/multipage/common-dom-in terfaces.html#safe-passing-of-structured-data #} 664 http://www.whatwg.org/specs/web-apps/current-work/multipage/common-dom-in terfaces.html#safe-passing-of-structured-data #}
662 if (DOMWrapperWorld::current(info.GetIsolate())->isIsolatedWorld()) { 665 if (DOMWrapperWorld::current(isolate)->isIsolatedWorld()) {
663 {% for attribute in any_type_attributes %} 666 {% for attribute in any_type_attributes %}
664 if (!{{attribute.name}}.IsEmpty()) 667 if (!{{attribute.name}}.IsEmpty())
665 event->setSerialized{{attribute.name | blink_capitalize}}(Serialized ScriptValue::createAndSwallowExceptions({{attribute.name}}, info.GetIsolate())); 668 event->setSerialized{{attribute.name | blink_capitalize}}(Serialized ScriptValue::createAndSwallowExceptions({{attribute.name}}, isolate));
666 {% endfor %} 669 {% endfor %}
667 } 670 }
668 671
669 {% endif %} 672 {% endif %}
670 v8::Handle<v8::Object> wrapper = info.Holder(); 673 v8::Handle<v8::Object> wrapper = info.Holder();
671 V8DOMWrapper::associateObjectWithWrapper<{{v8_class}}>(event.release(), &{{v 8_class}}::wrapperTypeInfo, wrapper, info.GetIsolate(), {{wrapper_configuration} }); 674 V8DOMWrapper::associateObjectWithWrapper<{{v8_class}}>(event.release(), &{{v 8_class}}::wrapperTypeInfo, wrapper, isolate, {{wrapper_configuration}});
672 v8SetReturnValue(info, wrapper); 675 v8SetReturnValue(info, wrapper);
673 } 676 }
674 677
675 {% endif %} 678 {% endif %}
676 {% endblock %} 679 {% endblock %}
677 680
678 681
679 {##############################################################################} 682 {##############################################################################}
680 {% block visit_dom_wrapper %} 683 {% block visit_dom_wrapper %}
681 {% if reachable_node_function or set_wrapper_reference_to_list %} 684 {% if reachable_node_function or set_wrapper_reference_to_list %}
(...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after
1312 {% endfilter %} 1315 {% endfilter %}
1313 } 1316 }
1314 1317
1315 template<> 1318 template<>
1316 v8::Handle<v8::Value> toV8NoInline({{cpp_class}}* impl, v8::Handle<v8::Object> c reationContext, v8::Isolate* isolate) 1319 v8::Handle<v8::Value> toV8NoInline({{cpp_class}}* impl, v8::Handle<v8::Object> c reationContext, v8::Isolate* isolate)
1317 { 1320 {
1318 return toV8(impl, creationContext, isolate); 1321 return toV8(impl, creationContext, isolate);
1319 } 1322 }
1320 1323
1321 {% endblock %} 1324 {% endblock %}
OLDNEW
« no previous file with comments | « Source/bindings/templates/interface.h ('k') | Source/bindings/templates/interface_base.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698