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

Side by Side Diff: lib/dom/scripts/systemnative.py

Issue 10807007: Support proper emission of V8Scope handles. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 5 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 | « lib/dom/scripts/generator.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 2 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
3 # for details. All rights reserved. Use of this source code is governed by a 3 # for details. All rights reserved. Use of this source code is governed by a
4 # BSD-style license that can be found in the LICENSE file. 4 # BSD-style license that can be found in the LICENSE file.
5 5
6 """This module provides shared functionality for the systems to generate 6 """This module provides shared functionality for the systems to generate
7 native binding from the IDL database.""" 7 native binding from the IDL database."""
8 8
9 import emitter 9 import emitter
10 import os 10 import os
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 ' if (!RuntimeEnabledFeatures::$(FEATURE)Enabled()) {\n' 309 ' if (!RuntimeEnabledFeatures::$(FEATURE)Enabled()) {\n'
310 ' exception = Dart_NewString("Feature $FEATURE is not enabl ed");\n' 310 ' exception = Dart_NewString("Feature $FEATURE is not enabl ed");\n'
311 ' goto fail;\n' 311 ' goto fail;\n'
312 ' }', 312 ' }',
313 FEATURE=_ToWebKitName(ext_attrs['synthesizedV8EnabledAtRuntime'])) 313 FEATURE=_ToWebKitName(ext_attrs['synthesizedV8EnabledAtRuntime']))
314 314
315 self._GenerateNativeCallback(callback_name='constructorCallback', 315 self._GenerateNativeCallback(callback_name='constructorCallback',
316 parameter_definitions=parameter_definitions_emitter.Fragments(), 316 parameter_definitions=parameter_definitions_emitter.Fragments(),
317 needs_receiver=False, invocation=invocation, 317 needs_receiver=False, invocation=invocation,
318 raises_exceptions=raises_exceptions, 318 raises_exceptions=raises_exceptions,
319 runtime_check=runtime_check) 319 runtime_check=runtime_check,
320 requires_v8_scope=self._RequiresV8Scope(ext_attrs, constructor_info.idl_ args))
321
320 322
321 def _ImplClassName(self, interface_name): 323 def _ImplClassName(self, interface_name):
322 return '_%sImpl' % interface_name 324 return '_%sImpl' % interface_name
323 325
324 def _BaseClassName(self): 326 def _BaseClassName(self):
325 root_class = 'NativeFieldWrapperClass1' 327 root_class = 'NativeFieldWrapperClass1'
326 328
327 if not self._interface.parents: 329 if not self._interface.parents:
328 return root_class 330 return root_class
329 331
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 if call_with == 'ScriptExecutionContext': 447 if call_with == 'ScriptExecutionContext':
446 parameter_definitions_emitter.Emit( 448 parameter_definitions_emitter.Emit(
447 '\n' 449 '\n'
448 ' ScriptExecutionContext* context = DartUtilities::scriptExecut ionContext();\n' 450 ' ScriptExecutionContext* context = DartUtilities::scriptExecut ionContext();\n'
449 ' if (!context)\n' 451 ' if (!context)\n'
450 ' return;\n') 452 ' return;\n')
451 arguments.append('context') 453 arguments.append('context')
452 return False 454 return False
453 455
454 if call_with == 'ScriptArguments|CallStack': 456 if call_with == 'ScriptArguments|CallStack':
455 self._cpp_impl_includes.add('"DOMWindow.h"')
456 self._cpp_impl_includes.add('"ScriptArguments.h"') 457 self._cpp_impl_includes.add('"ScriptArguments.h"')
457 self._cpp_impl_includes.add('"ScriptCallStack.h"') 458 self._cpp_impl_includes.add('"ScriptCallStack.h"')
458 self._cpp_impl_includes.add('"V8Proxy.h"')
459 self._cpp_impl_includes.add('"v8.h"')
460 parameter_definitions_emitter.Emit( 459 parameter_definitions_emitter.Emit(
461 '\n' 460 '\n'
462 ' v8::HandleScope handleScope;\n'
463 ' v8::Context::Scope scope(V8Proxy::mainWorldContext(DartUtilit ies::domWindowForCurrentIsolate()->frame()));\n'
464 ' Dart_Handle customArgument = Dart_GetNativeArgument(args, $IN DEX);\n' 461 ' Dart_Handle customArgument = Dart_GetNativeArgument(args, $IN DEX);\n'
465 ' RefPtr<ScriptArguments> scriptArguments(DartUtilities::create ScriptArguments(customArgument, exception));\n' 462 ' RefPtr<ScriptArguments> scriptArguments(DartUtilities::create ScriptArguments(customArgument, exception));\n'
466 ' if (!scriptArguments)\n' 463 ' if (!scriptArguments)\n'
467 ' goto fail;\n' 464 ' goto fail;\n'
468 ' RefPtr<ScriptCallStack> scriptCallStack(DartUtilities::create ScriptCallStack());\n' 465 ' RefPtr<ScriptCallStack> scriptCallStack(DartUtilities::create ScriptCallStack());\n'
469 ' if (!scriptCallStack->size())\n' 466 ' if (!scriptCallStack->size())\n'
470 ' return;\n', 467 ' return;\n',
471 INDEX=len(node.arguments)) 468 INDEX=len(node.arguments))
472 arguments.extend(['scriptArguments', 'scriptCallStack']) 469 arguments.extend(['scriptArguments', 'scriptCallStack'])
473 return True 470 return True
(...skipping 13 matching lines...) Expand all
487 type_info = self._TypeInfo(attr.type.id) 484 type_info = self._TypeInfo(attr.type.id)
488 dart_declaration = '%s get %s()' % (self._DartType(attr.type.id), html_name) 485 dart_declaration = '%s get %s()' % (self._DartType(attr.type.id), html_name)
489 is_custom = 'Custom' in attr.ext_attrs or 'CustomGetter' in attr.ext_attrs 486 is_custom = 'Custom' in attr.ext_attrs or 'CustomGetter' in attr.ext_attrs
490 cpp_callback_name = self._GenerateNativeBinding(attr.id, 1, 487 cpp_callback_name = self._GenerateNativeBinding(attr.id, 1,
491 dart_declaration, 'Getter', is_custom) 488 dart_declaration, 'Getter', is_custom)
492 if is_custom: 489 if is_custom:
493 return 490 return
494 491
495 arguments = [] 492 arguments = []
496 parameter_definitions_emitter = emitter.Emitter() 493 parameter_definitions_emitter = emitter.Emitter()
497 raises_exceptions = self._GenerateCallWithHandling(attr, parameter_definitio ns_emitter, arguments) 494 raises_exceptions = self._GenerateCallWithHandling(
495 attr, parameter_definitions_emitter, arguments)
498 raises_exceptions = raises_exceptions or attr.get_raises 496 raises_exceptions = raises_exceptions or attr.get_raises
499 497
500 if 'Reflect' in attr.ext_attrs: 498 if 'Reflect' in attr.ext_attrs:
501 webcore_function_name = self._TypeInfo(attr.type.id).webcore_getter_name() 499 webcore_function_name = self._TypeInfo(attr.type.id).webcore_getter_name()
502 if 'URL' in attr.ext_attrs: 500 if 'URL' in attr.ext_attrs:
503 if 'NonEmpty' in attr.ext_attrs: 501 if 'NonEmpty' in attr.ext_attrs:
504 webcore_function_name = 'getNonEmptyURLAttribute' 502 webcore_function_name = 'getNonEmptyURLAttribute'
505 else: 503 else:
506 webcore_function_name = 'getURLAttribute' 504 webcore_function_name = 'getURLAttribute'
507 arguments.append(self._GenerateWebCoreReflectionAttributeName(attr)) 505 arguments.append(self._GenerateWebCoreReflectionAttributeName(attr))
508 else: 506 else:
509 if attr.id == 'operator': 507 if attr.id == 'operator':
510 webcore_function_name = '_operator' 508 webcore_function_name = '_operator'
511 elif attr.id == 'target' and attr.type.id == 'SVGAnimatedString': 509 elif attr.id == 'target' and attr.type.id == 'SVGAnimatedString':
512 webcore_function_name = 'svgTarget' 510 webcore_function_name = 'svgTarget'
513 else: 511 else:
514 webcore_function_name = _ToWebKitName(attr.id) 512 webcore_function_name = _ToWebKitName(attr.id)
515 if attr.type.id.startswith('SVGAnimated'): 513 if attr.type.id.startswith('SVGAnimated'):
516 webcore_function_name += 'Animated' 514 webcore_function_name += 'Animated'
517 515
518 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi on_name, attr) 516 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi on_name, attr)
519 invocation = self._GenerateWebCoreInvocation(function_expression, 517 invocation = self._GenerateWebCoreInvocation(function_expression,
520 arguments, attr.type.id, attr.ext_attrs, attr.get_raises) 518 arguments, attr.type.id, attr.ext_attrs, attr.get_raises)
521 self._GenerateNativeCallback(cpp_callback_name, parameter_definitions_emitte r.Fragments(), 519 self._GenerateNativeCallback(cpp_callback_name, parameter_definitions_emitte r.Fragments(),
522 True, invocation, raises_exceptions=raises_exceptions, runtime_check=Non e) 520 True, invocation, raises_exceptions=raises_exceptions,
521 runtime_check=None,
522 requires_v8_scope=self._RequiresV8Scope(attr.ext_attrs, []))
523 523
524 def _AddSetter(self, attr, html_name): 524 def _AddSetter(self, attr, html_name):
525 type_info = self._TypeInfo(attr.type.id) 525 type_info = self._TypeInfo(attr.type.id)
526 dart_declaration = 'void set %s(%s)' % (html_name, self._DartType(attr.type. id)) 526 dart_declaration = 'void set %s(%s)' % (html_name, self._DartType(attr.type. id))
527 is_custom = set(['Custom', 'CustomSetter', 'V8CustomSetter']) & set(attr.ext _attrs) 527 is_custom = set(['Custom', 'CustomSetter', 'V8CustomSetter']) & set(attr.ext _attrs)
528 cpp_callback_name = self._GenerateNativeBinding(attr.id, 2, 528 cpp_callback_name = self._GenerateNativeBinding(attr.id, 2,
529 dart_declaration, 'Setter', is_custom) 529 dart_declaration, 'Setter', is_custom)
530 if is_custom: 530 if is_custom:
531 return 531 return
532 532
(...skipping 15 matching lines...) Expand all
548 argument_expression = self._GenerateToNative( 548 argument_expression = self._GenerateToNative(
549 parameter_definitions_emitter, attr, 1, argument_name='value') 549 parameter_definitions_emitter, attr, 1, argument_name='value')
550 arguments.append(argument_expression) 550 arguments.append(argument_expression)
551 551
552 parameter_definitions = parameter_definitions_emitter.Fragments() 552 parameter_definitions = parameter_definitions_emitter.Fragments()
553 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi on_name, attr) 553 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi on_name, attr)
554 invocation = self._GenerateWebCoreInvocation(function_expression, 554 invocation = self._GenerateWebCoreInvocation(function_expression,
555 arguments, 'void', attr.ext_attrs, attr.set_raises) 555 arguments, 'void', attr.ext_attrs, attr.set_raises)
556 556
557 self._GenerateNativeCallback(cpp_callback_name, parameter_definitions_emitte r.Fragments(), 557 self._GenerateNativeCallback(cpp_callback_name, parameter_definitions_emitte r.Fragments(),
558 True, invocation, raises_exceptions=True, runtime_check=None) 558 True, invocation, raises_exceptions=True,
559 runtime_check=None,
560 requires_v8_scope=self._RequiresV8Scope(attr.ext_attrs, [attr]))
559 561
560 def AddIndexer(self, element_type): 562 def AddIndexer(self, element_type):
561 """Adds all the methods required to complete implementation of List.""" 563 """Adds all the methods required to complete implementation of List."""
562 # We would like to simply inherit the implementation of everything except 564 # We would like to simply inherit the implementation of everything except
563 # get length(), [], and maybe []=. It is possible to extend from a base 565 # get length(), [], and maybe []=. It is possible to extend from a base
564 # array implementation class only when there is no other implementation 566 # array implementation class only when there is no other implementation
565 # inheritance. There might be no implementation inheritance other than 567 # inheritance. There might be no implementation inheritance other than
566 # DOMBaseWrapper for many classes, but there might be some where the 568 # DOMBaseWrapper for many classes, but there might be some where the
567 # array-ness is introduced by a non-root interface: 569 # array-ness is introduced by a non-root interface:
568 # 570 #
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 if 'NeedsUserGestureCheck' in operation.ext_attrs: 786 if 'NeedsUserGestureCheck' in operation.ext_attrs:
785 cpp_arguments.append('DartUtilities::processingUserGesture') 787 cpp_arguments.append('DartUtilities::processingUserGesture')
786 788
787 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi on_name, operation) 789 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi on_name, operation)
788 invocation = self._GenerateWebCoreInvocation(function_expression, cpp_argume nts, 790 invocation = self._GenerateWebCoreInvocation(function_expression, cpp_argume nts,
789 operation.type.id, operation.ext_attrs, operation.raises) 791 operation.type.id, operation.ext_attrs, operation.raises)
790 self._GenerateNativeCallback(cpp_callback_name, 792 self._GenerateNativeCallback(cpp_callback_name,
791 parameter_definitions=parameter_definitions_emitter.Fragments(), 793 parameter_definitions=parameter_definitions_emitter.Fragments(),
792 needs_receiver=not operation.is_static, invocation=invocation, 794 needs_receiver=not operation.is_static, invocation=invocation,
793 raises_exceptions=raises_exceptions, 795 raises_exceptions=raises_exceptions,
794 runtime_check=None) 796 runtime_check=None,
797 requires_v8_scope=self._RequiresV8Scope(operation.ext_attrs, arguments))
795 798
796 def _GenerateNativeCallback(self, callback_name, parameter_definitions, 799 def _GenerateNativeCallback(self, callback_name, parameter_definitions,
797 needs_receiver, invocation, raises_exceptions, runtime_check): 800 needs_receiver, invocation, raises_exceptions, runtime_check,
801 requires_v8_scope):
798 802
799 head_emitter = emitter.Emitter() 803 head_emitter = emitter.Emitter()
800 804
805 if requires_v8_scope:
806 head_emitter.Emit(
807 ' V8Scope v8scope;\n\n')
808
801 if runtime_check: 809 if runtime_check:
802 head_emitter.Emit( 810 head_emitter.Emit(
803 '$RUNTIME_CHECK\n', 811 '$RUNTIME_CHECK\n',
804 RUNTIME_CHECK=runtime_check) 812 RUNTIME_CHECK=runtime_check)
805 813
806 if needs_receiver: 814 if needs_receiver:
807 head_emitter.Emit( 815 head_emitter.Emit(
808 ' $WEBCORE_CLASS_NAME* receiver = DartDOMWrapper::receiver< $WE BCORE_CLASS_NAME >(args);\n', 816 ' $WEBCORE_CLASS_NAME* receiver = DartDOMWrapper::receiver< $WE BCORE_CLASS_NAME >(args);\n',
809 WEBCORE_CLASS_NAME=self._interface_type_info.native_type()) 817 WEBCORE_CLASS_NAME=self._interface_type_info.native_type())
810 818
(...skipping 23 matching lines...) Expand all
834 self._cpp_definitions_emitter.Emit( 842 self._cpp_definitions_emitter.Emit(
835 '\n' 843 '\n'
836 'static void $CALLBACK_NAME(Dart_NativeArguments args)\n' 844 'static void $CALLBACK_NAME(Dart_NativeArguments args)\n'
837 '{\n' 845 '{\n'
838 ' DartApiScope dartApiScope;\n' 846 ' DartApiScope dartApiScope;\n'
839 '$BODY' 847 '$BODY'
840 '}\n', 848 '}\n',
841 CALLBACK_NAME=callback_name, 849 CALLBACK_NAME=callback_name,
842 BODY=body) 850 BODY=body)
843 851
844 def _GenerateToNative(self, emitter, idl_node, index, 852 def _GenerateToNative(self, emitter, idl_node, index, argument_name=None):
845 argument_name=None):
846 """idl_node is IDLArgument or IDLAttribute.""" 853 """idl_node is IDLArgument or IDLAttribute."""
847 type_info = self._TypeInfo(idl_node.type.id) 854 type_info = self._TypeInfo(idl_node.type.id)
848 self._cpp_impl_includes |= set(type_info.to_native_includes()) 855 self._cpp_impl_includes |= set(type_info.to_native_includes())
849 argument_name = argument_name or idl_node.id 856 argument_name = argument_name or idl_node.id
850 handle = 'Dart_GetNativeArgument(args, %i)' % index 857 handle = 'Dart_GetNativeArgument(args, %i)' % index
851 return type_info.emit_to_native(emitter, idl_node, argument_name, handle, se lf._interface.id) 858 argument_expression = type_info.emit_to_native(
859 emitter, idl_node, argument_name, handle, self._interface.id)
860 return argument_expression
861
862 def _RequiresV8Scope(self, ext_attrs, arguments):
863 if 'CallWith' in ext_attrs and ext_attrs['CallWith'] == 'ScriptArguments|Cal lStack':
864 return True
865 for argument in arguments:
866 if self._TypeInfo(argument.type.id).requires_v8_scope():
867 return True
868 return False
852 869
853 def _GenerateNativeBinding(self, idl_name, argument_count, dart_declaration, 870 def _GenerateNativeBinding(self, idl_name, argument_count, dart_declaration,
854 native_suffix, is_custom): 871 native_suffix, is_custom):
855 native_binding = '%s_%s_%s' % (self._interface.id, idl_name, native_suffix) 872 native_binding = '%s_%s_%s' % (self._interface.id, idl_name, native_suffix)
856 self._members_emitter.Emit( 873 self._members_emitter.Emit(
857 '\n' 874 '\n'
858 ' $DART_DECLARATION native "$NATIVE_BINDING";\n', 875 ' $DART_DECLARATION native "$NATIVE_BINDING";\n',
859 DART_DECLARATION=dart_declaration, NATIVE_BINDING=native_binding) 876 DART_DECLARATION=dart_declaration, NATIVE_BINDING=native_binding)
860 877
861 cpp_callback_name = '%s%s' % (idl_name, native_suffix) 878 cpp_callback_name = '%s%s' % (idl_name, native_suffix)
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
949 966
950 def _IsArgumentOptionalInWebCore(argument): 967 def _IsArgumentOptionalInWebCore(argument):
951 return IsOptional(argument) and not 'Callback' in argument.ext_attrs 968 return IsOptional(argument) and not 'Callback' in argument.ext_attrs
952 969
953 def _ToWebKitName(name): 970 def _ToWebKitName(name):
954 name = name[0].lower() + name[1:] 971 name = name[0].lower() + name[1:]
955 name = re.sub(r'^(hTML|uRL|jS|xML|xSLT)', lambda s: s.group(1).lower(), 972 name = re.sub(r'^(hTML|uRL|jS|xML|xSLT)', lambda s: s.group(1).lower(),
956 name) 973 name)
957 return re.sub(r'^(create|exclusive)', lambda s: 'is' + s.group(1).capitalize() , 974 return re.sub(r'^(create|exclusive)', lambda s: 'is' + s.group(1).capitalize() ,
958 name) 975 name)
OLDNEW
« no previous file with comments | « lib/dom/scripts/generator.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698