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

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

Issue 11047021: New cross frame base types (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Regen dart:html Created 8 years, 2 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/html/scripts/systemhtml.py ('k') | lib/html/src/CrossFrameTypes.dart » ('j') | 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
11 from generator import * 11 from generator import *
12 12 from systemhtml import SecureOutputType
13 13
14 class DartiumBackend(object): 14 class DartiumBackend(object):
15 """Generates Dart implementation for one DOM IDL interface.""" 15 """Generates Dart implementation for one DOM IDL interface."""
16 16
17 def __init__(self, interface, cpp_library_emitter, options): 17 def __init__(self, interface, cpp_library_emitter, options):
18 self._interface = interface 18 self._interface = interface
19 self._cpp_library_emitter = cpp_library_emitter 19 self._cpp_library_emitter = cpp_library_emitter
20 self._database = options.database 20 self._database = options.database
21 self._template_loader = options.templates 21 self._template_loader = options.templates
22 self._type_registry = options.type_registry 22 self._type_registry = options.type_registry
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 if 'CheckSecurityForNode' in attribute.ext_attrs: 302 if 'CheckSecurityForNode' in attribute.ext_attrs:
303 # FIXME: exclude from interface as well. 303 # FIXME: exclude from interface as well.
304 return 304 return
305 305
306 self._AddGetter(attribute, html_name) 306 self._AddGetter(attribute, html_name)
307 if not read_only: 307 if not read_only:
308 self._AddSetter(attribute, html_name) 308 self._AddSetter(attribute, html_name)
309 309
310 def _AddGetter(self, attr, html_name): 310 def _AddGetter(self, attr, html_name):
311 type_info = self._TypeInfo(attr.type.id) 311 type_info = self._TypeInfo(attr.type.id)
312 dart_declaration = '%s get %s' % (self._DartType(attr.type.id), html_name) 312 dart_declaration = '%s get %s' % (SecureOutputType(self, attr.type.id), html _name)
313 is_custom = 'Custom' in attr.ext_attrs or 'CustomGetter' in attr.ext_attrs 313 is_custom = 'Custom' in attr.ext_attrs or 'CustomGetter' in attr.ext_attrs
314 cpp_callback_name = self._GenerateNativeBinding(attr.id, 1, 314 cpp_callback_name = self._GenerateNativeBinding(attr.id, 1,
315 dart_declaration, 'Getter', is_custom) 315 dart_declaration, 'Getter', is_custom)
316 if is_custom: 316 if is_custom:
317 return 317 return
318 318
319 if 'Reflect' in attr.ext_attrs: 319 if 'Reflect' in attr.ext_attrs:
320 webcore_function_name = self._TypeInfo(attr.type.id).webcore_getter_name() 320 webcore_function_name = self._TypeInfo(attr.type.id).webcore_getter_name()
321 if 'URL' in attr.ext_attrs: 321 if 'URL' in attr.ext_attrs:
322 if 'NonEmpty' in attr.ext_attrs: 322 if 'NonEmpty' in attr.ext_attrs:
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 # 393 #
394 # class YImpl extends ListBase<T> { copies of transitive XImpl methods; } 394 # class YImpl extends ListBase<T> { copies of transitive XImpl methods; }
395 # 395 #
396 dart_element_type = self._DartType(element_type) 396 dart_element_type = self._DartType(element_type)
397 if self._HasNativeIndexGetter(): 397 if self._HasNativeIndexGetter():
398 self._EmitNativeIndexGetter(dart_element_type) 398 self._EmitNativeIndexGetter(dart_element_type)
399 else: 399 else:
400 self._members_emitter.Emit( 400 self._members_emitter.Emit(
401 '\n' 401 '\n'
402 ' $TYPE operator[](int index) native "$(INTERFACE)_item_Callback";\n' , 402 ' $TYPE operator[](int index) native "$(INTERFACE)_item_Callback";\n' ,
403 TYPE=dart_element_type, INTERFACE=self._interface.id) 403 TYPE=SecureOutputType(self, element_type), INTERFACE=self._interface.i d)
404 404
405 if self._HasNativeIndexSetter(): 405 if self._HasNativeIndexSetter():
406 self._EmitNativeIndexSetter(dart_element_type) 406 self._EmitNativeIndexSetter(dart_element_type)
407 else: 407 else:
408 # The HTML library implementation of NodeList has a custom indexed setter 408 # The HTML library implementation of NodeList has a custom indexed setter
409 # implementation that uses the parent node the NodeList is associated 409 # implementation that uses the parent node the NodeList is associated
410 # with if one is available. 410 # with if one is available.
411 if self._interface.id != 'NodeList': 411 if self._interface.id != 'NodeList':
412 self._members_emitter.Emit( 412 self._members_emitter.Emit(
413 '\n' 413 '\n'
(...skipping 26 matching lines...) Expand all
440 self._EmitNativeIndexGetter(dart_element_type) 440 self._EmitNativeIndexGetter(dart_element_type)
441 if self._HasNativeIndexSetter(): 441 if self._HasNativeIndexSetter():
442 self._EmitNativeIndexSetter(dart_element_type) 442 self._EmitNativeIndexSetter(dart_element_type)
443 443
444 def _HasNativeIndexGetter(self): 444 def _HasNativeIndexGetter(self):
445 ext_attrs = self._interface.ext_attrs 445 ext_attrs = self._interface.ext_attrs
446 return ('CustomIndexedGetter' in ext_attrs or 446 return ('CustomIndexedGetter' in ext_attrs or
447 'NumericIndexedGetter' in ext_attrs) 447 'NumericIndexedGetter' in ext_attrs)
448 448
449 def _EmitNativeIndexGetter(self, element_type): 449 def _EmitNativeIndexGetter(self, element_type):
450 dart_declaration = '%s operator[](int index)' % element_type 450 dart_declaration = '%s operator[](int index)' % SecureOutputType(self, eleme nt_type)
451 self._GenerateNativeBinding('numericIndexGetter', 2, dart_declaration, 451 self._GenerateNativeBinding('numericIndexGetter', 2, dart_declaration,
452 'Callback', True) 452 'Callback', True)
453 453
454 def _HasNativeIndexSetter(self): 454 def _HasNativeIndexSetter(self):
455 return 'CustomIndexedSetter' in self._interface.ext_attrs 455 return 'CustomIndexedSetter' in self._interface.ext_attrs
456 456
457 def _EmitNativeIndexSetter(self, element_type): 457 def _EmitNativeIndexSetter(self, element_type):
458 dart_declaration = 'void operator[]=(int index, %s value)' % element_type 458 dart_declaration = 'void operator[]=(int index, %s value)' % element_type
459 self._GenerateNativeBinding('numericIndexSetter', 3, dart_declaration, 459 self._GenerateNativeBinding('numericIndexSetter', 3, dart_declaration,
460 'Callback', True) 460 'Callback', True)
461 461
462 def AddOperation(self, info, html_name): 462 def AddOperation(self, info, html_name):
463 """ 463 """
464 Arguments: 464 Arguments:
465 info: An OperationInfo object. 465 info: An OperationInfo object.
466 """ 466 """
467 467
468 operation = info.operations[0] 468 operation = info.operations[0]
469 469
470 if 'CheckSecurityForNode' in operation.ext_attrs: 470 if 'CheckSecurityForNode' in operation.ext_attrs:
471 # FIXME: exclude from interface as well. 471 # FIXME: exclude from interface as well.
472 return 472 return
473 473
474 is_custom = 'Custom' in operation.ext_attrs 474 is_custom = 'Custom' in operation.ext_attrs
475 has_optional_arguments = any(self._IsArgumentOptionalInWebCore(operation, ar gument) for argument in operation.arguments) 475 has_optional_arguments = any(self._IsArgumentOptionalInWebCore(operation, ar gument) for argument in operation.arguments)
476 needs_dispatcher = not is_custom and (len(info.operations) > 1 or has_option al_arguments) 476 needs_dispatcher = not is_custom and (len(info.operations) > 1 or has_option al_arguments)
477 477
478 dart_declaration = '%s%s %s(%s)' % ( 478 dart_declaration = '%s%s %s(%s)' % (
479 'static ' if info.IsStatic() else '', 479 'static ' if info.IsStatic() else '',
480 self._DartType(info.type_name), 480 SecureOutputType(self, info.type_name),
481 html_name, 481 html_name,
482 info.ParametersImplementationDeclaration( 482 info.ParametersImplementationDeclaration(
483 (lambda x: 'Dynamic') if needs_dispatcher else self._DartType)) 483 (lambda x: 'Dynamic') if needs_dispatcher else self._DartType))
484 484
485 if not needs_dispatcher: 485 if not needs_dispatcher:
486 # Bind directly to native implementation 486 # Bind directly to native implementation
487 argument_count = (0 if info.IsStatic() else 1) + len(info.param_infos) 487 argument_count = (0 if info.IsStatic() else 1) + len(info.param_infos)
488 cpp_callback_name = self._GenerateNativeBinding( 488 cpp_callback_name = self._GenerateNativeBinding(
489 info.name, argument_count, dart_declaration, 'Callback', is_custom) 489 info.name, argument_count, dart_declaration, 'Callback', is_custom)
490 if not is_custom: 490 if not is_custom:
(...skipping 24 matching lines...) Expand all
515 template = ' $CALL;\n' 515 template = ' $CALL;\n'
516 516
517 overload_name = '%s_%s' % (operation.id, version[0]) 517 overload_name = '%s_%s' % (operation.id, version[0])
518 version[0] += 1 518 version[0] += 1
519 argument_list = ', '.join(argument_names[:argument_count]) 519 argument_list = ', '.join(argument_names[:argument_count])
520 call = '_%s(%s)' % (overload_name, argument_list) 520 call = '_%s(%s)' % (overload_name, argument_list)
521 body.Emit(template, CHECKS=' && '.join(checks), CALL=call) 521 body.Emit(template, CHECKS=' && '.join(checks), CALL=call)
522 522
523 dart_declaration = '%s%s _%s(%s)' % ( 523 dart_declaration = '%s%s _%s(%s)' % (
524 'static ' if operation.is_static else '', 524 'static ' if operation.is_static else '',
525 self._DartType(operation.type.id), overload_name, argument_list) 525 SecureOutputType(self, operation.type.id), overload_name, argument_lis t)
526 cpp_callback_name = self._GenerateNativeBinding( 526 cpp_callback_name = self._GenerateNativeBinding(
527 overload_name, (0 if operation.is_static else 1) + argument_count, 527 overload_name, (0 if operation.is_static else 1) + argument_count,
528 dart_declaration, 'Callback', False) 528 dart_declaration, 'Callback', False)
529 self._GenerateOperationNativeCallback(operation, operation.arguments[:argu ment_count], cpp_callback_name) 529 self._GenerateOperationNativeCallback(operation, operation.arguments[:argu ment_count], cpp_callback_name)
530 530
531 def GenerateChecksAndCall(operation, argument_count): 531 def GenerateChecksAndCall(operation, argument_count):
532 checks = ['!?%s' % name for name in argument_names] 532 checks = ['!?%s' % name for name in argument_names]
533 for i in range(0, argument_count): 533 for i in range(0, argument_count):
534 argument = operation.arguments[i] 534 argument = operation.arguments[i]
535 argument_name = argument_names[i] 535 argument_name = argument_names[i]
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
886 def EmitResolver(self, template, output_dir): 886 def EmitResolver(self, template, output_dir):
887 file_path = os.path.join(output_dir, 'DartResolver.cpp') 887 file_path = os.path.join(output_dir, 'DartResolver.cpp')
888 includes_emitter, body_emitter = self._emitters.FileEmitter(file_path).Emit( template) 888 includes_emitter, body_emitter = self._emitters.FileEmitter(file_path).Emit( template)
889 for header_file in self._headers_list: 889 for header_file in self._headers_list:
890 path = os.path.relpath(header_file, output_dir) 890 path = os.path.relpath(header_file, output_dir)
891 includes_emitter.Emit('#include "$PATH"\n', PATH=path) 891 includes_emitter.Emit('#include "$PATH"\n', PATH=path)
892 body_emitter.Emit( 892 body_emitter.Emit(
893 ' if (Dart_NativeFunction func = $CLASS_NAME::resolver(name, argume ntCount))\n' 893 ' if (Dart_NativeFunction func = $CLASS_NAME::resolver(name, argume ntCount))\n'
894 ' return func;\n', 894 ' return func;\n',
895 CLASS_NAME=os.path.splitext(os.path.basename(path))[0]) 895 CLASS_NAME=os.path.splitext(os.path.basename(path))[0])
OLDNEW
« no previous file with comments | « lib/html/scripts/systemhtml.py ('k') | lib/html/src/CrossFrameTypes.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698