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

Side by Side Diff: lib/runtime/dart/_operations.js

Issue 1413683006: Move runtime js files down to lib/runtime/dart (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 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
« no previous file with comments | « lib/runtime/dart/_native_typed_data.js ('k') | lib/runtime/dart/_rtti.js » ('j') | 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 */ 7 */
8 dart_library.library('dart_runtime/_operations', null, /* Imports */[ 8 dart_library.library('dart/_operations', null, /* Imports */[
9 ], /* Lazy Imports */[ 9 ], /* Lazy Imports */[
10 'dart/async', 10 'dart/async',
11 'dart/collection', 11 'dart/collection',
12 'dart/core', 12 'dart/core',
13 'dart/_js_helper', 13 'dart/_js_helper',
14 'dart_runtime/_classes', 14 'dart/_classes',
15 'dart_runtime/_errors', 15 'dart/_errors',
16 'dart_runtime/_rtti', 16 'dart/_rtti',
17 'dart_runtime/_types' 17 'dart/_types'
18 ], function(exports, async, collection, core, _js_helper, classes, errors, rtti, 18 ], function(exports, async, collection, core, _js_helper, classes, errors, rtti,
19 types) { 19 types) {
20 'use strict'; 20 'use strict';
21 21
22 const getOwnNamesAndSymbols = dart_utils.getOwnNamesAndSymbols; 22 const getOwnNamesAndSymbols = dart_utils.getOwnNamesAndSymbols;
23 const throwError = dart_utils.throwError; 23 const throwError = dart_utils.throwError;
24 24
25 const getOwnPropertyNames = Object.getOwnPropertyNames; 25 const getOwnPropertyNames = Object.getOwnPropertyNames;
26 const hasOwnProperty = Object.prototype.hasOwnProperty; 26 const hasOwnProperty = Object.prototype.hasOwnProperty;
27 27
28 const slice = [].slice;
29
30 function _canonicalFieldName(obj, name, args, displayName) { 28 function _canonicalFieldName(obj, name, args, displayName) {
31 name = classes.canonicalMember(obj, name); 29 name = classes.canonicalMember(obj, name);
32 if (name) return name; 30 if (name) return name;
33 // TODO(jmesserly): in the future we might have types that "overlay" Dart 31 // TODO(jmesserly): in the future we might have types that "overlay" Dart
34 // methods while also exposing the full native API, e.g. dart:html vs 32 // methods while also exposing the full native API, e.g. dart:html vs
35 // dart:dom. To support that we'd need to fall back to the normal name 33 // dart:dom. To support that we'd need to fall back to the normal name
36 // if an extension method wasn't found. 34 // if an extension method wasn't found.
37 errors.throwNoSuchMethod(obj, displayName, args); 35 errors.throwNoSuchMethod(obj, displayName, args);
38 } 36 }
39 37
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 134
137 if (checkApply(ftype, args)) { 135 if (checkApply(ftype, args)) {
138 return f.apply(obj, args); 136 return f.apply(obj, args);
139 } 137 }
140 138
141 // TODO(leafp): throw a type error (rather than NSM) 139 // TODO(leafp): throw a type error (rather than NSM)
142 // if the arity matches but the types are wrong. 140 // if the arity matches but the types are wrong.
143 throwNoSuchMethod(obj, name, args, f); 141 throwNoSuchMethod(obj, name, args, f);
144 } 142 }
145 143
146 function dcall(f/*, ...args*/) { 144 function dcall(f, ...args) {
147 let args = slice.call(arguments, 1);
148 let ftype = rtti.read(f); 145 let ftype = rtti.read(f);
149 return checkAndCall(f, ftype, void 0, args, 'call'); 146 return checkAndCall(f, ftype, void 0, args, 'call');
150 } 147 }
151 exports.dcall = dcall; 148 exports.dcall = dcall;
152 149
153 /** Shared code for dsend, dindex, and dsetindex. */ 150 /** Shared code for dsend, dindex, and dsetindex. */
154 function callMethod(obj, name, args, displayName) { 151 function callMethod(obj, name, args, displayName) {
155 let symbol = _canonicalFieldName(obj, name, args, displayName); 152 let symbol = _canonicalFieldName(obj, name, args, displayName);
156 let f = obj != null ? obj[symbol] : null; 153 let f = obj != null ? obj[symbol] : null;
157 let ftype = classes.getMethodType(obj, name); 154 let ftype = classes.getMethodType(obj, name);
158 return checkAndCall(f, ftype, obj, args, displayName); 155 return checkAndCall(f, ftype, obj, args, displayName);
159 } 156 }
160 157
161 function dsend(obj, method/*, ...args*/) { 158 function dsend(obj, method, ...args) {
162 return callMethod(obj, method, slice.call(arguments, 2), method); 159 return callMethod(obj, method, args, method);
163 } 160 }
164 exports.dsend = dsend; 161 exports.dsend = dsend;
165 162
166 function dindex(obj, index) { 163 function dindex(obj, index) {
167 return callMethod(obj, 'get', [index], '[]'); 164 return callMethod(obj, 'get', [index], '[]');
168 } 165 }
169 exports.dindex = dindex; 166 exports.dindex = dindex;
170 167
171 function dsetindex(obj, index, value) { 168 function dsetindex(obj, index, value) {
172 callMethod(obj, 'set', [index, value], '[]='); 169 callMethod(obj, 'set', [index, value], '[]=');
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 return _js_helper.getTraceFromException(error); 325 return _js_helper.getTraceFromException(error);
329 } 326 }
330 exports.stackTrace = stackTrace; 327 exports.stackTrace = stackTrace;
331 328
332 /** 329 /**
333 * Implements a sequence of .? operations. 330 * Implements a sequence of .? operations.
334 * 331 *
335 * Will call each successive callback, unless one returns null, which stops 332 * Will call each successive callback, unless one returns null, which stops
336 * the sequence. 333 * the sequence.
337 */ 334 */
338 function nullSafe(obj /*, ...callbacks*/) { 335 function nullSafe(obj, ...callbacks) {
339 let callbacks = slice.call(arguments, 1);
340 if (obj == null) return obj; 336 if (obj == null) return obj;
341 for (const callback of callbacks) { 337 for (const callback of callbacks) {
342 obj = callback(obj); 338 obj = callback(obj);
343 if (obj == null) break; 339 if (obj == null) break;
344 } 340 }
345 return obj; 341 return obj;
346 } 342 }
347 exports.nullSafe = nullSafe; 343 exports.nullSafe = nullSafe;
348 344
349 let _value = Symbol('_value'); 345 let _value = Symbol('_value');
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 next() { 453 next() {
458 let i = this.dartIterator; 454 let i = this.dartIterator;
459 let done = !i.moveNext(); 455 let done = !i.moveNext();
460 return { done: done, value: done ? void 0 : i.current }; 456 return { done: done, value: done ? void 0 : i.current };
461 } 457 }
462 } 458 }
463 exports.JsIterator = JsIterator; 459 exports.JsIterator = JsIterator;
464 460
465 461
466 }); 462 });
OLDNEW
« no previous file with comments | « lib/runtime/dart/_native_typed_data.js ('k') | lib/runtime/dart/_rtti.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698