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

Side by Side Diff: frog/value.dart

Issue 8577003: Convert most of the javascript isolate code into Dart, inject JS code only when (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: '' Created 9 years, 1 month 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
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 /** 5 /**
6 * Represents a meta-value for code generation. 6 * Represents a meta-value for code generation.
7 */ 7 */
8 class Value { 8 class Value {
9 /** The [Type] of the [Value]. */ 9 /** The [Type] of the [Value]. */
10 Type type; 10 Type type;
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 if (callMethod != null) { 236 if (callMethod != null) {
237 if (checked && !toType.isAssignable(type)) { 237 if (checked && !toType.isAssignable(type)) {
238 convertWarning(toType, node); 238 convertWarning(toType, node);
239 } 239 }
240 240
241 int arity = callMethod.parameters.length; 241 int arity = callMethod.parameters.length;
242 var myCall = type.getCallMethod(); 242 var myCall = type.getCallMethod();
243 if (myCall == null || myCall.parameters.length != arity) { 243 if (myCall == null || myCall.parameters.length != arity) {
244 final stub = world.functionType.getCallStub(new Arguments.bare(arity)); 244 final stub = world.functionType.getCallStub(new Arguments.bare(arity));
245 var val = new Value(toType, 'to\$${stub.name}($code)', node.span); 245 var val = new Value(toType, 'to\$${stub.name}($code)', node.span);
246 // TODO(sigmund): try to remove, see below
246 return _isDomCallback(toType) && !_isDomCallback(type) ? 247 return _isDomCallback(toType) && !_isDomCallback(type) ?
247 val._wrapDomCallback(toType, arity) : val; 248 val._wrapDomCallback(toType, arity) : val;
248 } else if (_isDomCallback(toType) && !_isDomCallback(type)) { 249 } else if (_isDomCallback(toType) && !_isDomCallback(type)) {
250 // TODO(sigmund): try to remove, see below
249 return _wrapDomCallback(toType, arity); 251 return _wrapDomCallback(toType, arity);
250 } 252 }
251 } 253 }
252 254
253 // If we're assigning from a var, pretend it's Object for the purpose of 255 // If we're assigning from a var, pretend it's Object for the purpose of
254 // runtime checks. 256 // runtime checks.
255 257
256 // TODO(jmesserly): I'm a little bothered by the fact that we can't call 258 // TODO(jmesserly): I'm a little bothered by the fact that we can't call
257 // isSubtypeOf directly. If we tracked null literals as the bottom type, 259 // isSubtypeOf directly. If we tracked null literals as the bottom type,
258 // and then only allowed Dynamic to be bottom for generic type args, I think 260 // and then only allowed Dynamic to be bottom for generic type args, I think
(...skipping 17 matching lines...) Expand all
276 } 278 }
277 279
278 // Generate a runtime checks if they're turned on, otherwise skip it. 280 // Generate a runtime checks if they're turned on, otherwise skip it.
279 if (options.enableTypeChecks) { 281 if (options.enableTypeChecks) {
280 return _typeAssert(context, toType, node); 282 return _typeAssert(context, toType, node);
281 } else { 283 } else {
282 return this; 284 return this;
283 } 285 }
284 } 286 }
285 287
288 /**
289 * Checks whether [toType] is a callback function, and it is defined in the
290 * dom library.
291 */
286 bool _isDomCallback(toType) { 292 bool _isDomCallback(toType) {
287 return (toType.definition is FunctionTypeDefinition 293 return (toType.definition is FunctionTypeDefinition
288 && toType.library == world.dom); 294 && toType.library == world.dom);
289 } 295 }
290 296
297 /**
298 * Wraps a callback attached to the dom (e.g. event listeners, setTimeout) so
299 * we can restore it's isolate context information. This is needed so that
300 * callbacks are executed withing the context of the isolate that created them
jimhug 2011/11/16 18:00:45 Nit: within
Siggi Cherem (dart-lang) 2011/11/17 16:50:11 Done.
301 * in the first place.
302 */
303 // TODO(sigmund): try to remove this specialized logic about isolates
304 // and the dom from the compiler, move into the actual dom library if
305 // possible.
Jennifer Messerly 2011/11/17 02:28:11 I still don't think this is special logic. :) All
Siggi Cherem (dart-lang) 2011/11/17 16:50:11 totally agree. Although I would be quite happy if
291 Value _wrapDomCallback(Type toType, int arity) { 306 Value _wrapDomCallback(Type toType, int arity) {
307 if (arity == 0) {
308 world.gen.corejs.useWrap0 = true;
Jennifer Messerly 2011/11/17 02:28:11 should this also set useIsolates to true? Or you c
Siggi Cherem (dart-lang) 2011/11/17 16:50:11 In this case no, we don't want to mark useIsolates
Jennifer Messerly 2011/11/17 19:18:03 My bad. I didn't read corejs.dart carefully enough
309 } else {
310 world.gen.corejs.useWrap1 = true;
311 }
292 return new Value(toType, '\$wrap_call\$$arity($code)', span); 312 return new Value(toType, '\$wrap_call\$$arity($code)', span);
293 } 313 }
294 314
295 /** 315 /**
296 * Generates a run time type assertion for the given value. This works like 316 * Generates a run time type assertion for the given value. This works like
297 * [instanceOf], but it allows null since Dart types are nullable. 317 * [instanceOf], but it allows null since Dart types are nullable.
298 * Also it will throw a TypeError if it gets the wrong type. 318 * Also it will throw a TypeError if it gets the wrong type.
299 */ 319 */
300 Value _typeAssert(MethodGenerator context, Type toType, Node node) { 320 Value _typeAssert(MethodGenerator context, Type toType, Node node) {
301 if (toType is ParameterType) { 321 if (toType is ParameterType) {
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 694
675 // Then look for members in my library. 695 // Then look for members in my library.
676 member = home.library.lookup(name, span); 696 member = home.library.lookup(name, span);
677 if (member != null) { 697 if (member != null) {
678 return member; 698 return member;
679 } 699 }
680 700
681 return null; 701 return null;
682 } 702 }
683 } 703 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698