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

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

Issue 10669031: Support V8EnabledAtRuntime in constructors. (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/databasebuilder.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 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 self._cpp_resolver_emitter.Emit( 248 self._cpp_resolver_emitter.Emit(
249 ' if (name == "$(INTERFACE_NAME)_constructor_Callback")\n' 249 ' if (name == "$(INTERFACE_NAME)_constructor_Callback")\n'
250 ' return Dart$(INTERFACE_NAME)Internal::constructorCallback;\n', 250 ' return Dart$(INTERFACE_NAME)Internal::constructorCallback;\n',
251 INTERFACE_NAME=self._interface.id) 251 INTERFACE_NAME=self._interface.id)
252 252
253 253
254 constructor_info = AnalyzeConstructor(self._interface) 254 constructor_info = AnalyzeConstructor(self._interface)
255 if constructor_info: 255 if constructor_info:
256 self._EmitFactoryProvider(self._interface.id, constructor_info) 256 self._EmitFactoryProvider(self._interface.id, constructor_info)
257 257
258 if 'CustomConstructor' in self._interface.ext_attrs: 258 ext_attrs = self._interface.ext_attrs
259
260 if 'CustomConstructor' in ext_attrs:
259 # We have a custom implementation for it. 261 # We have a custom implementation for it.
260 self._cpp_declarations_emitter.Emit( 262 self._cpp_declarations_emitter.Emit(
261 '\n' 263 '\n'
262 'void constructorCallback(Dart_NativeArguments);\n') 264 'void constructorCallback(Dart_NativeArguments);\n')
263 return 265 return
264 266
265 raises_dom_exceptions = 'ConstructorRaisesException' in self._interface.ext_ attrs 267 raises_dom_exceptions = 'ConstructorRaisesException' in ext_attrs
266 raises_exceptions = raises_dom_exceptions or len(constructor_info.idl_args) > 0 268 raises_exceptions = raises_dom_exceptions or len(constructor_info.idl_args) > 0
267 arguments = [] 269 arguments = []
268 parameter_definitions_emitter = emitter.Emitter() 270 parameter_definitions_emitter = emitter.Emitter()
269 create_function = 'create' 271 create_function = 'create'
270 if 'NamedConstructor' in self._interface.ext_attrs: 272 if 'NamedConstructor' in ext_attrs:
271 raises_exceptions = True 273 raises_exceptions = True
274 self._cpp_impl_includes.add('"DOMWindow.h"')
272 parameter_definitions_emitter.Emit( 275 parameter_definitions_emitter.Emit(
273 ' DOMWindow* domWindow = DartUtilities::domWindowForCurrentIs olate();\n' 276 ' DOMWindow* domWindow = DartUtilities::domWindowForCurrentIs olate();\n'
274 ' if (!domWindow) {\n' 277 ' if (!domWindow) {\n'
275 ' exception = Dart_NewString("Failed to fetch domWindow") ;\n' 278 ' exception = Dart_NewString("Failed to fetch domWindow") ;\n'
276 ' goto fail;\n' 279 ' goto fail;\n'
277 ' }\n' 280 ' }\n'
278 ' Document* document = domWindow->document();\n') 281 ' Document* document = domWindow->document();\n')
279 self._cpp_impl_includes.add('"DOMWindow.h"')
280 arguments.append('document') 282 arguments.append('document')
281 create_function = 'createForJSConstructor' 283 create_function = 'createForJSConstructor'
282 if 'CallWith' in self._interface.ext_attrs: 284 if 'CallWith' in ext_attrs:
283 call_with = self._interface.ext_attrs['CallWith'] 285 call_with = ext_attrs['CallWith']
284 if call_with == 'ScriptExecutionContext': 286 if call_with == 'ScriptExecutionContext':
285 raises_exceptions = True 287 raises_exceptions = True
286 parameter_definitions_emitter.Emit( 288 parameter_definitions_emitter.Emit(
287 ' ScriptExecutionContext* context = DartUtilities::scriptExec utionContext();\n' 289 ' ScriptExecutionContext* context = DartUtilities::scriptExec utionContext();\n'
288 ' if (!context) {\n' 290 ' if (!context) {\n'
289 ' exception = Dart_NewString("Failed to create an object" );\n' 291 ' exception = Dart_NewString("Failed to create an object" );\n'
290 ' goto fail;\n' 292 ' goto fail;\n'
291 ' }\n') 293 ' }\n')
292 arguments.append('context') 294 arguments.append('context')
293 else: 295 else:
294 raise Exception('Unsupported CallWith=%s attribute' % call_with) 296 raise Exception('Unsupported CallWith=%s attribute' % call_with)
295 297
296 # Process constructor arguments. 298 # Process constructor arguments.
297 for (i, argument) in enumerate(constructor_info.idl_args): 299 for (i, argument) in enumerate(constructor_info.idl_args):
298 argument_expression = self._GenerateToNative( 300 argument_expression = self._GenerateToNative(
299 parameter_definitions_emitter, argument, i) 301 parameter_definitions_emitter, argument, i)
300 arguments.append(argument_expression) 302 arguments.append(argument_expression)
301 303
302 function_expression = '%s::%s' % (self._interface_type_info.native_type(), c reate_function) 304 function_expression = '%s::%s' % (self._interface_type_info.native_type(), c reate_function)
303 invocation = self._GenerateWebCoreInvocation(function_expression, arguments, 305 invocation = self._GenerateWebCoreInvocation(function_expression, arguments,
304 self._interface.id, self._interface.ext_attrs, raises_dom_exceptions) 306 self._interface.id, ext_attrs, raises_dom_exceptions)
305 307
306 runtime_check = None 308 runtime_check = None
307 database = self._system._database 309 database = self._system._database
308 if 'synthesizedV8EnabledPerContext' in self._interface.ext_attrs: 310 assert (not (
311 'synthesizedV8EnabledPerContext' in ext_attrs and
312 'synthesizedV8EnabledAtRuntime' in ext_attrs))
313 if 'synthesizedV8EnabledPerContext' in ext_attrs:
309 raises_exceptions = True 314 raises_exceptions = True
310 self._cpp_impl_includes.add('"ContextFeatures.h"') 315 self._cpp_impl_includes.add('"ContextFeatures.h"')
311 runtime_check = emitter.Format( 316 runtime_check = emitter.Format(
312 ' if (!ContextFeatures::$(FEATURE)Enabled(DartUtilities::domWin dowForCurrentIsolate()->document())) {\n' 317 ' if (!ContextFeatures::$(FEATURE)Enabled(DartUtilities::domWin dowForCurrentIsolate()->document())) {\n'
313 ' exception = Dart_NewString("Feature $FEATURE is not enabl ed");\n' 318 ' exception = Dart_NewString("Feature $FEATURE is not enabl ed");\n'
314 ' goto fail;\n' 319 ' goto fail;\n'
315 ' }', 320 ' }',
316 FEATURE=self._interface.ext_attrs['synthesizedV8EnabledPerContext']) 321 FEATURE=ext_attrs['synthesizedV8EnabledPerContext'])
322
323 if 'synthesizedV8EnabledAtRuntime' in ext_attrs:
324 raises_exceptions = True
325 self._cpp_impl_includes.add('"RuntimeEnabledFeatures.h"')
326 runtime_check = emitter.Format(
327 ' if (!RuntimeEnabledFeatures::$(FEATURE)Enabled()) {\n'
328 ' exception = Dart_NewString("Feature $FEATURE is not enabl ed");\n'
329 ' goto fail;\n'
330 ' }',
331 FEATURE=_ToWebKitName(ext_attrs['synthesizedV8EnabledAtRuntime']))
317 332
318 self._GenerateNativeCallback(callback_name='constructorCallback', 333 self._GenerateNativeCallback(callback_name='constructorCallback',
319 parameter_definitions=parameter_definitions_emitter.Fragments(), 334 parameter_definitions=parameter_definitions_emitter.Fragments(),
320 needs_receiver=False, invocation=invocation, 335 needs_receiver=False, invocation=invocation,
321 raises_exceptions=raises_exceptions, 336 raises_exceptions=raises_exceptions,
322 runtime_check=runtime_check) 337 runtime_check=runtime_check)
323 338
324 def _EmitHtmlElementFactoryConstructors(self, infos, html_interface_name): 339 def _EmitHtmlElementFactoryConstructors(self, infos, html_interface_name):
325 EmitHtmlElementFactoryConstructors( 340 EmitHtmlElementFactoryConstructors(
326 self._system._EmitterForFactoryProviderBody( 341 self._system._EmitterForFactoryProviderBody(
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 webcore_function_name = 'getNonEmptyURLAttribute' 619 webcore_function_name = 'getNonEmptyURLAttribute'
605 else: 620 else:
606 webcore_function_name = 'getURLAttribute' 621 webcore_function_name = 'getURLAttribute'
607 arguments.append(self._GenerateWebCoreReflectionAttributeName(attr)) 622 arguments.append(self._GenerateWebCoreReflectionAttributeName(attr))
608 else: 623 else:
609 if attr.id == 'operator': 624 if attr.id == 'operator':
610 webcore_function_name = '_operator' 625 webcore_function_name = '_operator'
611 elif attr.id == 'target' and attr.type.id == 'SVGAnimatedString': 626 elif attr.id == 'target' and attr.type.id == 'SVGAnimatedString':
612 webcore_function_name = 'svgTarget' 627 webcore_function_name = 'svgTarget'
613 else: 628 else:
614 webcore_function_name = re.sub(r'^(HTML|URL|JS|XML|XSLT|\w)', 629 webcore_function_name = _ToWebKitName(attr.id)
615 lambda s: s.group(1).lower(),
616 attr.id)
617 webcore_function_name = re.sub(r'^(create|exclusive)',
618 lambda s: 'is' + s.group(1).capitalize(),
619 webcore_function_name)
620 if attr.type.id.startswith('SVGAnimated'): 630 if attr.type.id.startswith('SVGAnimated'):
621 webcore_function_name += 'Animated' 631 webcore_function_name += 'Animated'
622 632
623 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi on_name, attr) 633 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi on_name, attr)
624 invocation = self._GenerateWebCoreInvocation(function_expression, 634 invocation = self._GenerateWebCoreInvocation(function_expression,
625 arguments, attr.type.id, attr.ext_attrs, attr.get_raises) 635 arguments, attr.type.id, attr.ext_attrs, attr.get_raises)
626 self._GenerateNativeCallback(cpp_callback_name, parameter_definitions_emitte r.Fragments(), 636 self._GenerateNativeCallback(cpp_callback_name, parameter_definitions_emitte r.Fragments(),
627 True, invocation, raises_exceptions=raises_exceptions) 637 True, invocation, raises_exceptions=raises_exceptions)
628 638
629 def _AddSetter(self, attr, html_name): 639 def _AddSetter(self, attr, html_name):
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after
1072 continue 1082 continue
1073 parent_interface = database.GetInterface(parent.type.id) 1083 parent_interface = database.GetInterface(parent.type.id)
1074 if callback(parent_interface): 1084 if callback(parent_interface):
1075 return parent_interface 1085 return parent_interface
1076 parent_interface = _FindParent(parent_interface, database, callback) 1086 parent_interface = _FindParent(parent_interface, database, callback)
1077 if parent_interface: 1087 if parent_interface:
1078 return parent_interface 1088 return parent_interface
1079 1089
1080 def _IsArgumentOptionalInWebCore(argument): 1090 def _IsArgumentOptionalInWebCore(argument):
1081 return IsOptional(argument) and not 'Callback' in argument.ext_attrs 1091 return IsOptional(argument) and not 'Callback' in argument.ext_attrs
1092
1093 def _ToWebKitName(name):
1094 name = name[0].lower() + name[1:]
1095 name = re.sub(r'^(hTML|uRL|jS|xML|xSLT)', lambda s: s.group(1).lower(),
1096 name)
1097 return re.sub(r'^(create|exclusive)', lambda s: 'is' + s.group(1).capitalize() ,
1098 name)
OLDNEW
« no previous file with comments | « lib/dom/scripts/databasebuilder.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698