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

Side by Side Diff: dart/sdk/lib/_internal/lib/js_mirrors.dart

Issue 19575004: Implement accessing lazily initialized static fields. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 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
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 library dart._js_mirrors; 5 library dart._js_mirrors;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:mirrors'; 8 import 'dart:mirrors';
9 9
10 import 'dart:_foreign_helper' show JS, JS_CURRENT_ISOLATE; 10 import 'dart:_foreign_helper' show JS, JS_CURRENT_ISOLATE;
(...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 throw new NoSuchMethodError(this, '${n(fieldName)}=', [arg], null); 626 throw new NoSuchMethodError(this, '${n(fieldName)}=', [arg], null);
627 } 627 }
628 628
629 InstanceMirror getField(Symbol fieldName) { 629 InstanceMirror getField(Symbol fieldName) {
630 JsVariableMirror mirror = variables[fieldName]; 630 JsVariableMirror mirror = variables[fieldName];
631 if (mirror != null && mirror.isStatic) { 631 if (mirror != null && mirror.isStatic) {
632 String jsName = mirror._jsName; 632 String jsName = mirror._jsName;
633 if (!JS('bool', '# in #', jsName, JS_CURRENT_ISOLATE())) { 633 if (!JS('bool', '# in #', jsName, JS_CURRENT_ISOLATE())) {
634 throw new RuntimeError('Cannot find "$jsName" in current isolate.'); 634 throw new RuntimeError('Cannot find "$jsName" in current isolate.');
635 } 635 }
636 return reflect(JS('', '#[#]', JS_CURRENT_ISOLATE(), jsName)); 636 if (JS('bool', '# in init.lazies', jsName)) {
637 String getterName = JS('String', 'init.lazies[#]', jsName);
638 return reflect(JS('', '#[#]()', JS_CURRENT_ISOLATE(), getterName));
639 } else {
640 return reflect(JS('', '#[#]', JS_CURRENT_ISOLATE(), jsName));
641 }
637 } 642 }
638 // TODO(ahe): What receiver to use? 643 // TODO(ahe): What receiver to use?
639 throw new NoSuchMethodError(this, n(fieldName), null, null); 644 throw new NoSuchMethodError(this, n(fieldName), null, null);
640 } 645 }
641 646
642 InstanceMirror newInstance(Symbol constructorName, 647 InstanceMirror newInstance(Symbol constructorName,
643 List positionalArguments, 648 List positionalArguments,
644 [Map<Symbol, dynamic> namedArguments]) { 649 [Map<Symbol, dynamic> namedArguments]) {
645 if (namedArguments != null && !namedArguments.isEmpty) { 650 if (namedArguments != null && !namedArguments.isEmpty) {
646 throw new UnsupportedError('Named arguments are not implemented.'); 651 throw new UnsupportedError('Named arguments are not implemented.');
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after
1041 var metadataFunction = JS('', '#["@"]', victim); 1046 var metadataFunction = JS('', '#["@"]', victim);
1042 if (metadataFunction != null) return JS('', '#()', metadataFunction); 1047 if (metadataFunction != null) return JS('', '#()', metadataFunction);
1043 String source = JS('String', 'Function.prototype.toString.call(#)', victim); 1048 String source = JS('String', 'Function.prototype.toString.call(#)', victim);
1044 int index = source.lastIndexOf(new RegExp('"[0-9,]*";?[ \n\r]*}')); 1049 int index = source.lastIndexOf(new RegExp('"[0-9,]*";?[ \n\r]*}'));
1045 if (index == -1) return const []; 1050 if (index == -1) return const [];
1046 index++; 1051 index++;
1047 int endQuote = source.indexOf('"', index); 1052 int endQuote = source.indexOf('"', index);
1048 return source.substring(index, endQuote).split(',').map(int.parse).map( 1053 return source.substring(index, endQuote).split(',').map(int.parse).map(
1049 (int i) => JS('', 'init.metadata[#]', i)).toList(); 1054 (int i) => JS('', 'init.metadata[#]', i)).toList();
1050 } 1055 }
OLDNEW
« no previous file with comments | « dart/sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart ('k') | dart/tests/lib/mirrors/lazy_static_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698