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

Side by Side Diff: tool/input_sdk/private/ddc_runtime/operations.dart

Issue 2035583004: Fix a few cases were obj and name were used instead of $obj and $name. remove ProfileEntry class as… (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 4 years, 6 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
« no previous file with comments | « lib/runtime/dart_sdk.js ('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 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 /// This library defines runtime operations on objects used by the code 5 /// This library defines runtime operations on objects used by the code
6 /// generator. 6 /// generator.
7 part of dart._runtime; 7 part of dart._runtime;
8 8
9 _canonicalFieldName(obj, name, args, displayName) => JS('', '''(() => { 9 _canonicalFieldName(obj, name, args, displayName) => JS('', '''(() => {
10 $name = $canonicalMember($obj, $name); 10 $name = $canonicalMember($obj, $name);
11 if ($name) return $name; 11 if ($name) return $name;
12 // TODO(jmesserly): in the future we might have types that "overlay" Dart 12 // TODO(jmesserly): in the future we might have types that "overlay" Dart
13 // methods while also exposing the full native API, e.g. dart:html vs 13 // methods while also exposing the full native API, e.g. dart:html vs
14 // dart:dom. To support that we'd need to fall back to the normal name 14 // dart:dom. To support that we'd need to fall back to the normal name
15 // if an extension method wasn't found. 15 // if an extension method wasn't found.
16 $throwNoSuchMethodFunc($obj, $displayName, $args); 16 $throwNoSuchMethodFunc($obj, $displayName, $args);
17 })()'''); 17 })()''');
18 18
19 dload(obj, field) => JS('', '''(() => { 19 dload(obj, field) => JS('', '''(() => {
20 $field = $_canonicalFieldName($obj, $field, [], $field); 20 $field = $_canonicalFieldName($obj, $field, [], $field);
21 $_trackCall(obj, $field); 21 $_trackCall($obj, $field);
22 if ($hasMethod($obj, $field)) { 22 if ($hasMethod($obj, $field)) {
23 return $bind($obj, $field); 23 return $bind($obj, $field);
24 } 24 }
25 // TODO(vsm): Implement NSM robustly. An 'in' check breaks on certain 25 // TODO(vsm): Implement NSM robustly. An 'in' check breaks on certain
26 // types. hasOwnProperty doesn't chase the proto chain. 26 // types. hasOwnProperty doesn't chase the proto chain.
27 // Also, do we want an NSM on regular JS objects? 27 // Also, do we want an NSM on regular JS objects?
28 // See: https://github.com/dart-lang/dev_compiler/issues/169 28 // See: https://github.com/dart-lang/dev_compiler/issues/169
29 let result = $obj[$field]; 29 let result = $obj[$field];
30 return result; 30 return result;
31 })()'''); 31 })()''');
32 32
33 dput(obj, field, value) => JS('', '''(() => { 33 dput(obj, field, value) => JS('', '''(() => {
34 $field = $_canonicalFieldName($obj, $field, [$value], $field); 34 $field = $_canonicalFieldName($obj, $field, [$value], $field);
35 $_trackCall(obj, $field); 35 $_trackCall($obj, $field);
36 36
37 // TODO(vsm): Implement NSM and type checks. 37 // TODO(vsm): Implement NSM and type checks.
38 // See: https://github.com/dart-lang/dev_compiler/issues/170 38 // See: https://github.com/dart-lang/dev_compiler/issues/170
39 $obj[$field] = $value; 39 $obj[$field] = $value;
40 return $value; 40 return $value;
41 })()'''); 41 })()''');
42 42
43 /// Check that a function of a given type can be applied to 43 /// Check that a function of a given type can be applied to
44 /// actuals. 44 /// actuals.
45 _checkApply(type, actuals) => JS('', '''(() => { 45 _checkApply(type, actuals) => JS('', '''(() => {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 throwNoSuchMethod(obj, name, pArgs, nArgs, extras) => JS('', '''(() => { 84 throwNoSuchMethod(obj, name, pArgs, nArgs, extras) => JS('', '''(() => {
85 $throw_(new $NoSuchMethodError($obj, $_dartSymbol($name), $pArgs, $nArgs, $ext ras)); 85 $throw_(new $NoSuchMethodError($obj, $_dartSymbol($name), $pArgs, $nArgs, $ext ras));
86 })()'''); 86 })()''');
87 87
88 throwNoSuchMethodFunc(obj, name, pArgs, opt_func) => JS('', '''(() => { 88 throwNoSuchMethodFunc(obj, name, pArgs, opt_func) => JS('', '''(() => {
89 if ($obj === void 0) $obj = $opt_func; 89 if ($obj === void 0) $obj = $opt_func;
90 $throwNoSuchMethod($obj, $name, $pArgs); 90 $throwNoSuchMethod($obj, $name, $pArgs);
91 })()'''); 91 })()''');
92 92
93 _checkAndCall(f, ftype, obj, typeArgs, args, name) => JS('', '''(() => { 93 _checkAndCall(f, ftype, obj, typeArgs, args, name) => JS('', '''(() => {
94 $_trackCall(obj, name); 94 $_trackCall($obj, $name);
95 95
96 let originalFunction = $f; 96 let originalFunction = $f;
97 if (!($f instanceof Function)) { 97 if (!($f instanceof Function)) {
98 // We're not a function (and hence not a method either) 98 // We're not a function (and hence not a method either)
99 // Grab the `call` method if it's not a function. 99 // Grab the `call` method if it's not a function.
100 if ($f != null) { 100 if ($f != null) {
101 $ftype = $getMethodType($f, 'call'); 101 $ftype = $getMethodType($f, 'call');
102 $f = $f.call; 102 $f = $f.call;
103 } 103 }
104 if (!($f instanceof Function)) { 104 if (!($f instanceof Function)) {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 157
158 dcall(f, @rest args) => _checkAndCall( 158 dcall(f, @rest args) => _checkAndCall(
159 f, _getRuntimeType(f), JS('', 'void 0'), null, args, 'call'); 159 f, _getRuntimeType(f), JS('', 'void 0'), null, args, 'call');
160 160
161 161
162 dgcall(f, typeArgs, @rest args) => _checkAndCall( 162 dgcall(f, typeArgs, @rest args) => _checkAndCall(
163 f, _getRuntimeType(f), JS('', 'void 0'), typeArgs, args, 'call'); 163 f, _getRuntimeType(f), JS('', 'void 0'), typeArgs, args, 'call');
164 164
165 Map<String, int> _callMethodStats = new Map(); 165 Map<String, int> _callMethodStats = new Map();
166 166
167 class ProfileEntry { 167 List<List<Object>> getDynamicStats() {
168 final String key; 168 List<List<Object>> ret = [];
169 final num count;
170
171 ProfileEntry(this.key, this.count);
172 }
173
174 List<ProfileEntry> getDynamicStats() {
175 List<ProfileEntry> ret = new List();
176 169
177 var keys = _callMethodStats.keys.toList(); 170 var keys = _callMethodStats.keys.toList();
178 171
179 keys.sort((a, b) => _callMethodStats[b].compareTo(_callMethodStats[a])); 172 keys.sort((a, b) => _callMethodStats[b].compareTo(_callMethodStats[a]));
180 for (var key in keys) { 173 for (var key in keys) {
181 int count = _callMethodStats[key]; 174 int count = _callMethodStats[key];
182 ret.add(new ProfileEntry(key, count)); 175 ret.add([key, count]);
183 } 176 }
184 177
185 return ret; 178 return ret;
186 } 179 }
187 180
188 clearDynamicStats() { 181 clearDynamicStats() {
189 _callMethodStats.clear(); 182 _callMethodStats.clear();
190 } 183 }
191 184
192 _trackCall(obj, name) { 185 _trackCall(obj, name) {
193 if(JS('bool', '!window.trackDdcProfile')) return; 186 if (JS('bool', '!dart.global.trackDdcProfile')) return;
194
195 var actual = getReifiedType(obj); 187 var actual = getReifiedType(obj);
196 String stackStr = JS('String', "new Error().stack"); 188 String stackStr = JS('String', "new Error().stack");
197 var stack = stackStr.split('\n at '); 189 var stack = stackStr.split('\n at ');
198 var src = ''; 190 var src = '';
199 for (int i = 2; i < stack.length; ++i) { 191 for (int i = 2; i < stack.length; ++i) {
200 var frame = stack[i]; 192 var frame = stack[i];
201 if (!frame.contains('dev_compiler/lib/runtime/dart_sdk.js')) { 193 if (!frame.contains('dev_compiler/lib/runtime/dart_sdk.js')) {
202 src = frame; 194 src = frame;
203 break; 195 break;
204 } 196 }
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 constructor(dartIterator) { 646 constructor(dartIterator) {
655 this.dartIterator = dartIterator; 647 this.dartIterator = dartIterator;
656 } 648 }
657 next() { 649 next() {
658 let i = this.dartIterator; 650 let i = this.dartIterator;
659 let done = !i.moveNext(); 651 let done = !i.moveNext();
660 return { done: done, value: done ? void 0 : i.current }; 652 return { done: done, value: done ? void 0 : i.current };
661 } 653 }
662 } 654 }
663 '''); 655 ''');
OLDNEW
« no previous file with comments | « lib/runtime/dart_sdk.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698