From 3f8541719958a4bff5e89f4d52bdb1fa60d8cd1e Mon Sep 17 00:00:00 2001 From: Vijay Menon Date: Thu, 11 Feb 2016 14:36:27 -0800 Subject: [PATCH] Support for dart:typed_data Fixes #441 Fixes #444 R=jmesserly@google.com Review URL: https://codereview.chromium.org/1680263002 . --- .../lib/runtime/dart/_internal.js | 65 +- .../lib/runtime/dart/_native_typed_data.js | 772 +++++++++++------- pkg/dev_compiler/lib/runtime/dart/_runtime.js | 32 +- .../lib/runtime/dart/collection.js | 469 +++++------ pkg/dev_compiler/lib/runtime/dart/convert.js | 14 +- pkg/dev_compiler/lib/runtime/dart/html.js | 2 +- .../lib/runtime/dart/typed_data.js | 32 +- .../lib/src/codegen/js_codegen.dart | 117 ++- .../lib/src/codegen/js_interop.dart | 23 +- .../lib/src/codegen/module_builder.dart | 3 +- .../test/browser/language_tests.js | 57 +- .../collection/src/unmodifiable_wrappers.txt | 4 +- .../expect/collection/src/wrappers.txt | 4 +- .../test/codegen/expect/dom/dom.js | 6 +- .../test/codegen/expect/language-all.js | 15 +- .../test/codegen/expect/lib-typed_data-all.js | 244 +++--- .../test/codegen/expect/sunflower/dom.js | 6 +- .../tool/input_sdk/private/classes.dart | 23 +- .../input_sdk/private/native_typed_data.dart | 1 - .../tool/input_sdk/private/operations.dart | 3 +- .../tool/input_sdk/private/rtti.dart | 23 +- 21 files changed, 1118 insertions(+), 797 deletions(-) diff --git a/pkg/dev_compiler/lib/runtime/dart/_internal.js b/pkg/dev_compiler/lib/runtime/dart/_internal.js index 4d761a9939a1..f773eb973799 100644 --- a/pkg/dev_compiler/lib/runtime/dart/_internal.js +++ b/pkg/dev_compiler/lib/runtime/dart/_internal.js @@ -1525,68 +1525,83 @@ dart_library.library('dart/_internal', null, /* Imports */[ }); let __CastType2 = __CastType2$(); const FixedLengthListMixin$ = dart.generic(function(E) { + dart.defineExtensionNames([ + 'length', + 'add', + 'insert', + 'insertAll', + 'addAll', + 'remove', + 'removeWhere', + 'retainWhere', + 'clear', + 'removeAt', + 'removeLast', + 'removeRange', + 'replaceRange' + ]); class FixedLengthListMixin extends core.Object { - set length(newLength) { + set [dartx.length](newLength) { dart.throw(new core.UnsupportedError("Cannot change the length of a fixed-length list")); } - add(value) { + [dartx.add](value) { dart.as(value, E); dart.throw(new core.UnsupportedError("Cannot add to a fixed-length list")); } - insert(index, value) { + [dartx.insert](index, value) { dart.as(value, E); dart.throw(new core.UnsupportedError("Cannot add to a fixed-length list")); } - insertAll(at, iterable) { + [dartx.insertAll](at, iterable) { dart.as(iterable, core.Iterable$(E)); dart.throw(new core.UnsupportedError("Cannot add to a fixed-length list")); } - addAll(iterable) { + [dartx.addAll](iterable) { dart.as(iterable, core.Iterable$(E)); dart.throw(new core.UnsupportedError("Cannot add to a fixed-length list")); } - remove(element) { + [dartx.remove](element) { dart.throw(new core.UnsupportedError("Cannot remove from a fixed-length list")); } - removeWhere(test) { + [dartx.removeWhere](test) { dart.as(test, dart.functionType(core.bool, [E])); dart.throw(new core.UnsupportedError("Cannot remove from a fixed-length list")); } - retainWhere(test) { + [dartx.retainWhere](test) { dart.as(test, dart.functionType(core.bool, [E])); dart.throw(new core.UnsupportedError("Cannot remove from a fixed-length list")); } - clear() { + [dartx.clear]() { dart.throw(new core.UnsupportedError("Cannot clear a fixed-length list")); } - removeAt(index) { + [dartx.removeAt](index) { dart.throw(new core.UnsupportedError("Cannot remove from a fixed-length list")); } - removeLast() { + [dartx.removeLast]() { dart.throw(new core.UnsupportedError("Cannot remove from a fixed-length list")); } - removeRange(start, end) { + [dartx.removeRange](start, end) { dart.throw(new core.UnsupportedError("Cannot remove from a fixed-length list")); } - replaceRange(start, end, iterable) { + [dartx.replaceRange](start, end, iterable) { dart.as(iterable, core.Iterable$(E)); dart.throw(new core.UnsupportedError("Cannot remove from a fixed-length list")); } } dart.setSignature(FixedLengthListMixin, { methods: () => ({ - add: [dart.void, [E]], - insert: [dart.void, [core.int, E]], - insertAll: [dart.void, [core.int, core.Iterable$(E)]], - addAll: [dart.void, [core.Iterable$(E)]], - remove: [core.bool, [core.Object]], - removeWhere: [dart.void, [dart.functionType(core.bool, [E])]], - retainWhere: [dart.void, [dart.functionType(core.bool, [E])]], - clear: [dart.void, []], - removeAt: [E, [core.int]], - removeLast: [E, []], - removeRange: [dart.void, [core.int, core.int]], - replaceRange: [dart.void, [core.int, core.int, core.Iterable$(E)]] + [dartx.add]: [dart.void, [E]], + [dartx.insert]: [dart.void, [core.int, E]], + [dartx.insertAll]: [dart.void, [core.int, core.Iterable$(E)]], + [dartx.addAll]: [dart.void, [core.Iterable$(E)]], + [dartx.remove]: [core.bool, [core.Object]], + [dartx.removeWhere]: [dart.void, [dart.functionType(core.bool, [E])]], + [dartx.retainWhere]: [dart.void, [dart.functionType(core.bool, [E])]], + [dartx.clear]: [dart.void, []], + [dartx.removeAt]: [E, [core.int]], + [dartx.removeLast]: [E, []], + [dartx.removeRange]: [dart.void, [core.int, core.int]], + [dartx.replaceRange]: [dart.void, [core.int, core.int, core.Iterable$(E)]] }) }); return FixedLengthListMixin; diff --git a/pkg/dev_compiler/lib/runtime/dart/_native_typed_data.js b/pkg/dev_compiler/lib/runtime/dart/_native_typed_data.js index 418c77b97130..0b54d702742b 100644 --- a/pkg/dev_compiler/lib/runtime/dart/_native_typed_data.js +++ b/pkg/dev_compiler/lib/runtime/dart/_native_typed_data.js @@ -11,84 +11,106 @@ dart_library.library('dart/_native_typed_data', null, /* Imports */[ ], function(exports, dart, core, typed_data, _js_helper, collection, _internal, _interceptors, math) { 'use strict'; let dartx = dart.dartx; + dart.defineExtensionNames([ + 'lengthInBytes', + 'runtimeType', + 'asUint8List', + 'asInt8List', + 'asUint8ClampedList', + 'asUint16List', + 'asInt16List', + 'asUint32List', + 'asInt32List', + 'asUint64List', + 'asInt64List', + 'asInt32x4List', + 'asFloat32List', + 'asFloat64List', + 'asFloat32x4List', + 'asFloat64x2List', + 'asByteData' + ]); class NativeByteBuffer extends core.Object { + get [dartx.lengthInBytes]() { + return this.byteLength; + } get runtimeType() { return typed_data.ByteBuffer; } - asUint8List(offsetInBytes, length) { + [dartx.asUint8List](offsetInBytes, length) { if (offsetInBytes === void 0) offsetInBytes = 0; if (length === void 0) length = null; return NativeUint8List.view(this, offsetInBytes, length); } - asInt8List(offsetInBytes, length) { + [dartx.asInt8List](offsetInBytes, length) { if (offsetInBytes === void 0) offsetInBytes = 0; if (length === void 0) length = null; return NativeInt8List.view(this, offsetInBytes, length); } - asUint8ClampedList(offsetInBytes, length) { + [dartx.asUint8ClampedList](offsetInBytes, length) { if (offsetInBytes === void 0) offsetInBytes = 0; if (length === void 0) length = null; return NativeUint8ClampedList.view(this, offsetInBytes, length); } - asUint16List(offsetInBytes, length) { + [dartx.asUint16List](offsetInBytes, length) { if (offsetInBytes === void 0) offsetInBytes = 0; if (length === void 0) length = null; return NativeUint16List.view(this, offsetInBytes, length); } - asInt16List(offsetInBytes, length) { + [dartx.asInt16List](offsetInBytes, length) { if (offsetInBytes === void 0) offsetInBytes = 0; if (length === void 0) length = null; return NativeInt16List.view(this, offsetInBytes, length); } - asUint32List(offsetInBytes, length) { + [dartx.asUint32List](offsetInBytes, length) { if (offsetInBytes === void 0) offsetInBytes = 0; if (length === void 0) length = null; return NativeUint32List.view(this, offsetInBytes, length); } - asInt32List(offsetInBytes, length) { + [dartx.asInt32List](offsetInBytes, length) { if (offsetInBytes === void 0) offsetInBytes = 0; if (length === void 0) length = null; return NativeInt32List.view(this, offsetInBytes, length); } - asUint64List(offsetInBytes, length) { + [dartx.asUint64List](offsetInBytes, length) { if (offsetInBytes === void 0) offsetInBytes = 0; if (length === void 0) length = null; dart.throw(new core.UnsupportedError("Uint64List not supported by dart2js.")); } - asInt64List(offsetInBytes, length) { + [dartx.asInt64List](offsetInBytes, length) { if (offsetInBytes === void 0) offsetInBytes = 0; if (length === void 0) length = null; dart.throw(new core.UnsupportedError("Int64List not supported by dart2js.")); } - asInt32x4List(offsetInBytes, length) { + [dartx.asInt32x4List](offsetInBytes, length) { if (offsetInBytes === void 0) offsetInBytes = 0; if (length === void 0) length = null; - let storage = dart.as(this.asInt32List(offsetInBytes, length != null ? dart.notNull(length) * 4 : null), NativeInt32List); + let storage = dart.as(this[dartx.asInt32List](offsetInBytes, length != null ? dart.notNull(length) * 4 : null), NativeInt32List); return new NativeInt32x4List._externalStorage(storage); } - asFloat32List(offsetInBytes, length) { + [dartx.asFloat32List](offsetInBytes, length) { if (offsetInBytes === void 0) offsetInBytes = 0; if (length === void 0) length = null; return NativeFloat32List.view(this, offsetInBytes, length); } - asFloat64List(offsetInBytes, length) { + [dartx.asFloat64List](offsetInBytes, length) { if (offsetInBytes === void 0) offsetInBytes = 0; if (length === void 0) length = null; return NativeFloat64List.view(this, offsetInBytes, length); } - asFloat32x4List(offsetInBytes, length) { + [dartx.asFloat32x4List](offsetInBytes, length) { if (offsetInBytes === void 0) offsetInBytes = 0; if (length === void 0) length = null; - let storage = dart.as(this.asFloat32List(offsetInBytes, length != null ? dart.notNull(length) * 4 : null), NativeFloat32List); + let storage = dart.as(this[dartx.asFloat32List](offsetInBytes, length != null ? dart.notNull(length) * 4 : null), NativeFloat32List); return new NativeFloat32x4List._externalStorage(storage); } - asFloat64x2List(offsetInBytes, length) { + [dartx.asFloat64x2List](offsetInBytes, length) { if (offsetInBytes === void 0) offsetInBytes = 0; if (length === void 0) length = null; - let storage = dart.as(this.asFloat64List(offsetInBytes, length != null ? dart.notNull(length) * 2 : null), NativeFloat64List); + let storage = dart.as(this[dartx.asFloat64List](offsetInBytes, length != null ? dart.notNull(length) * 2 : null), NativeFloat64List); return new NativeFloat64x2List._externalStorage(storage); } - asByteData(offsetInBytes, length) { + [dartx.asByteData](offsetInBytes, length) { if (offsetInBytes === void 0) offsetInBytes = 0; if (length === void 0) length = null; return NativeByteData.view(this, offsetInBytes, length); @@ -97,24 +119,25 @@ dart_library.library('dart/_native_typed_data', null, /* Imports */[ NativeByteBuffer[dart.implements] = () => [typed_data.ByteBuffer]; dart.setSignature(NativeByteBuffer, { methods: () => ({ - asUint8List: [typed_data.Uint8List, [], [core.int, core.int]], - asInt8List: [typed_data.Int8List, [], [core.int, core.int]], - asUint8ClampedList: [typed_data.Uint8ClampedList, [], [core.int, core.int]], - asUint16List: [typed_data.Uint16List, [], [core.int, core.int]], - asInt16List: [typed_data.Int16List, [], [core.int, core.int]], - asUint32List: [typed_data.Uint32List, [], [core.int, core.int]], - asInt32List: [typed_data.Int32List, [], [core.int, core.int]], - asUint64List: [typed_data.Uint64List, [], [core.int, core.int]], - asInt64List: [typed_data.Int64List, [], [core.int, core.int]], - asInt32x4List: [typed_data.Int32x4List, [], [core.int, core.int]], - asFloat32List: [typed_data.Float32List, [], [core.int, core.int]], - asFloat64List: [typed_data.Float64List, [], [core.int, core.int]], - asFloat32x4List: [typed_data.Float32x4List, [], [core.int, core.int]], - asFloat64x2List: [typed_data.Float64x2List, [], [core.int, core.int]], - asByteData: [typed_data.ByteData, [], [core.int, core.int]] + [dartx.asUint8List]: [typed_data.Uint8List, [], [core.int, core.int]], + [dartx.asInt8List]: [typed_data.Int8List, [], [core.int, core.int]], + [dartx.asUint8ClampedList]: [typed_data.Uint8ClampedList, [], [core.int, core.int]], + [dartx.asUint16List]: [typed_data.Uint16List, [], [core.int, core.int]], + [dartx.asInt16List]: [typed_data.Int16List, [], [core.int, core.int]], + [dartx.asUint32List]: [typed_data.Uint32List, [], [core.int, core.int]], + [dartx.asInt32List]: [typed_data.Int32List, [], [core.int, core.int]], + [dartx.asUint64List]: [typed_data.Uint64List, [], [core.int, core.int]], + [dartx.asInt64List]: [typed_data.Int64List, [], [core.int, core.int]], + [dartx.asInt32x4List]: [typed_data.Int32x4List, [], [core.int, core.int]], + [dartx.asFloat32List]: [typed_data.Float32List, [], [core.int, core.int]], + [dartx.asFloat64List]: [typed_data.Float64List, [], [core.int, core.int]], + [dartx.asFloat32x4List]: [typed_data.Float32x4List, [], [core.int, core.int]], + [dartx.asFloat64x2List]: [typed_data.Float64x2List, [], [core.int, core.int]], + [dartx.asByteData]: [typed_data.ByteData, [], [core.int, core.int]] }) }); NativeByteBuffer[dart.metadata] = () => [dart.const(new _js_helper.Native("ArrayBuffer"))]; + dart.registerExtension(dart.global.ArrayBuffer, NativeByteBuffer); const _storage = Symbol('_storage'); const _invalidIndex = Symbol('_invalidIndex'); const _checkIndex = Symbol('_checkIndex'); @@ -130,10 +153,10 @@ dart_library.library('dart/_native_typed_data', null, /* Imports */[ this[_storage] = NativeFloat32List.new(dart.notNull(list[dartx.length]) * 4); for (let i = 0; i < dart.notNull(list[dartx.length]); i++) { let e = list[dartx.get](i); - this[_storage].set(i * 4 + 0, e.x); - this[_storage].set(i * 4 + 1, e.y); - this[_storage].set(i * 4 + 2, e.z); - this[_storage].set(i * 4 + 3, e.w); + this[_storage][dartx.set](i * 4 + 0, e.x); + this[_storage][dartx.set](i * 4 + 1, e.y); + this[_storage][dartx.set](i * 4 + 2, e.z); + this[_storage][dartx.set](i * 4 + 3, e.w); } } get runtimeType() { @@ -147,13 +170,13 @@ dart_library.library('dart/_native_typed_data', null, /* Imports */[ } } get buffer() { - return this[_storage].buffer; + return this[_storage][dartx.buffer]; } get lengthInBytes() { - return this[_storage].lengthInBytes; + return this[_storage][dartx.lengthInBytes]; } get offsetInBytes() { - return this[_storage].offsetInBytes; + return this[_storage][dartx.offsetInBytes]; } get elementSizeInBytes() { return typed_data.Float32x4List.BYTES_PER_ELEMENT; @@ -181,28 +204,28 @@ dart_library.library('dart/_native_typed_data', null, /* Imports */[ return end; } get length() { - return (dart.notNull(this[_storage].length) / 4)[dartx.truncate](); + return (dart.notNull(this[_storage][dartx.length]) / 4)[dartx.truncate](); } get(index) { this[_checkIndex](index, this.length); - let _x = this[_storage].get(dart.notNull(index) * 4 + 0); - let _y = this[_storage].get(dart.notNull(index) * 4 + 1); - let _z = this[_storage].get(dart.notNull(index) * 4 + 2); - let _w = this[_storage].get(dart.notNull(index) * 4 + 3); + let _x = this[_storage][dartx.get](dart.notNull(index) * 4 + 0); + let _y = this[_storage][dartx.get](dart.notNull(index) * 4 + 1); + let _z = this[_storage][dartx.get](dart.notNull(index) * 4 + 2); + let _w = this[_storage][dartx.get](dart.notNull(index) * 4 + 3); return new NativeFloat32x4._truncated(_x, _y, _z, _w); } set(index, value) { this[_checkIndex](index, this.length); - this[_storage].set(dart.notNull(index) * 4 + 0, value.x); - this[_storage].set(dart.notNull(index) * 4 + 1, value.y); - this[_storage].set(dart.notNull(index) * 4 + 2, value.z); - this[_storage].set(dart.notNull(index) * 4 + 3, value.w); + this[_storage][dartx.set](dart.notNull(index) * 4 + 0, value.x); + this[_storage][dartx.set](dart.notNull(index) * 4 + 1, value.y); + this[_storage][dartx.set](dart.notNull(index) * 4 + 2, value.z); + this[_storage][dartx.set](dart.notNull(index) * 4 + 3, value.w); return value; } sublist(start, end) { if (end === void 0) end = null; end = this[_checkSublistArguments](start, end, this.length); - return new NativeFloat32x4List._externalStorage(dart.as(this[_storage].sublist(dart.notNull(start) * 4, dart.notNull(end) * 4), NativeFloat32List)); + return new NativeFloat32x4List._externalStorage(dart.as(this[_storage][dartx.sublist](dart.notNull(start) * 4, dart.notNull(end) * 4), NativeFloat32List)); } } NativeFloat32x4List[dart.implements] = () => [typed_data.Float32x4List]; @@ -224,7 +247,16 @@ dart_library.library('dart/_native_typed_data', null, /* Imports */[ sublist: [core.List$(typed_data.Float32x4), [core.int], [core.int]] }) }); - dart.defineExtensionMembers(NativeFloat32x4List, ['get', 'set', 'sublist', 'length']); + dart.defineExtensionMembers(NativeFloat32x4List, [ + 'get', + 'set', + 'sublist', + 'buffer', + 'lengthInBytes', + 'offsetInBytes', + 'elementSizeInBytes', + 'length' + ]); class NativeInt32x4List extends dart.mixin(core.Object, collection.ListMixin$(typed_data.Int32x4), _internal.FixedLengthListMixin$(typed_data.Int32x4)) { NativeInt32x4List(length) { this[_storage] = NativeInt32List.new(dart.notNull(length) * 4); @@ -236,10 +268,10 @@ dart_library.library('dart/_native_typed_data', null, /* Imports */[ this[_storage] = NativeInt32List.new(dart.notNull(list[dartx.length]) * 4); for (let i = 0; i < dart.notNull(list[dartx.length]); i++) { let e = list[dartx.get](i); - this[_storage].set(i * 4 + 0, e.x); - this[_storage].set(i * 4 + 1, e.y); - this[_storage].set(i * 4 + 2, e.z); - this[_storage].set(i * 4 + 3, e.w); + this[_storage][dartx.set](i * 4 + 0, e.x); + this[_storage][dartx.set](i * 4 + 1, e.y); + this[_storage][dartx.set](i * 4 + 2, e.z); + this[_storage][dartx.set](i * 4 + 3, e.w); } } get runtimeType() { @@ -253,13 +285,13 @@ dart_library.library('dart/_native_typed_data', null, /* Imports */[ } } get buffer() { - return this[_storage].buffer; + return this[_storage][dartx.buffer]; } get lengthInBytes() { - return this[_storage].lengthInBytes; + return this[_storage][dartx.lengthInBytes]; } get offsetInBytes() { - return this[_storage].offsetInBytes; + return this[_storage][dartx.offsetInBytes]; } get elementSizeInBytes() { return typed_data.Int32x4List.BYTES_PER_ELEMENT; @@ -287,28 +319,28 @@ dart_library.library('dart/_native_typed_data', null, /* Imports */[ return end; } get length() { - return (dart.notNull(this[_storage].length) / 4)[dartx.truncate](); + return (dart.notNull(this[_storage][dartx.length]) / 4)[dartx.truncate](); } get(index) { this[_checkIndex](index, this.length); - let _x = this[_storage].get(dart.notNull(index) * 4 + 0); - let _y = this[_storage].get(dart.notNull(index) * 4 + 1); - let _z = this[_storage].get(dart.notNull(index) * 4 + 2); - let _w = this[_storage].get(dart.notNull(index) * 4 + 3); + let _x = this[_storage][dartx.get](dart.notNull(index) * 4 + 0); + let _y = this[_storage][dartx.get](dart.notNull(index) * 4 + 1); + let _z = this[_storage][dartx.get](dart.notNull(index) * 4 + 2); + let _w = this[_storage][dartx.get](dart.notNull(index) * 4 + 3); return new NativeInt32x4._truncated(_x, _y, _z, _w); } set(index, value) { this[_checkIndex](index, this.length); - this[_storage].set(dart.notNull(index) * 4 + 0, value.x); - this[_storage].set(dart.notNull(index) * 4 + 1, value.y); - this[_storage].set(dart.notNull(index) * 4 + 2, value.z); - this[_storage].set(dart.notNull(index) * 4 + 3, value.w); + this[_storage][dartx.set](dart.notNull(index) * 4 + 0, value.x); + this[_storage][dartx.set](dart.notNull(index) * 4 + 1, value.y); + this[_storage][dartx.set](dart.notNull(index) * 4 + 2, value.z); + this[_storage][dartx.set](dart.notNull(index) * 4 + 3, value.w); return value; } sublist(start, end) { if (end === void 0) end = null; end = this[_checkSublistArguments](start, end, this.length); - return new NativeInt32x4List._externalStorage(dart.as(this[_storage].sublist(dart.notNull(start) * 4, dart.notNull(end) * 4), typed_data.Int32List)); + return new NativeInt32x4List._externalStorage(dart.as(this[_storage][dartx.sublist](dart.notNull(start) * 4, dart.notNull(end) * 4), typed_data.Int32List)); } } NativeInt32x4List[dart.implements] = () => [typed_data.Int32x4List]; @@ -330,7 +362,16 @@ dart_library.library('dart/_native_typed_data', null, /* Imports */[ sublist: [core.List$(typed_data.Int32x4), [core.int], [core.int]] }) }); - dart.defineExtensionMembers(NativeInt32x4List, ['get', 'set', 'sublist', 'length']); + dart.defineExtensionMembers(NativeInt32x4List, [ + 'get', + 'set', + 'sublist', + 'buffer', + 'lengthInBytes', + 'offsetInBytes', + 'elementSizeInBytes', + 'length' + ]); class NativeFloat64x2List extends dart.mixin(core.Object, collection.ListMixin$(typed_data.Float64x2), _internal.FixedLengthListMixin$(typed_data.Float64x2)) { NativeFloat64x2List(length) { this[_storage] = NativeFloat64List.new(dart.notNull(length) * 2); @@ -342,8 +383,8 @@ dart_library.library('dart/_native_typed_data', null, /* Imports */[ this[_storage] = NativeFloat64List.new(dart.notNull(list[dartx.length]) * 2); for (let i = 0; i < dart.notNull(list[dartx.length]); i++) { let e = list[dartx.get](i); - this[_storage].set(i * 2 + 0, e.x); - this[_storage].set(i * 2 + 1, e.y); + this[_storage][dartx.set](i * 2 + 0, e.x); + this[_storage][dartx.set](i * 2 + 1, e.y); } } static fromList(list) { @@ -357,13 +398,13 @@ dart_library.library('dart/_native_typed_data', null, /* Imports */[ return typed_data.Float64x2List; } get buffer() { - return this[_storage].buffer; + return this[_storage][dartx.buffer]; } get lengthInBytes() { - return this[_storage].lengthInBytes; + return this[_storage][dartx.lengthInBytes]; } get offsetInBytes() { - return this[_storage].offsetInBytes; + return this[_storage][dartx.offsetInBytes]; } get elementSizeInBytes() { return typed_data.Float64x2List.BYTES_PER_ELEMENT; @@ -391,24 +432,24 @@ dart_library.library('dart/_native_typed_data', null, /* Imports */[ return end; } get length() { - return (dart.notNull(this[_storage].length) / 2)[dartx.truncate](); + return (dart.notNull(this[_storage][dartx.length]) / 2)[dartx.truncate](); } get(index) { this[_checkIndex](index, this.length); - let _x = this[_storage].get(dart.notNull(index) * 2 + 0); - let _y = this[_storage].get(dart.notNull(index) * 2 + 1); + let _x = this[_storage][dartx.get](dart.notNull(index) * 2 + 0); + let _y = this[_storage][dartx.get](dart.notNull(index) * 2 + 1); return typed_data.Float64x2.new(_x, _y); } set(index, value) { this[_checkIndex](index, this.length); - this[_storage].set(dart.notNull(index) * 2 + 0, value.x); - this[_storage].set(dart.notNull(index) * 2 + 1, value.y); + this[_storage][dartx.set](dart.notNull(index) * 2 + 0, value.x); + this[_storage][dartx.set](dart.notNull(index) * 2 + 1, value.y); return value; } sublist(start, end) { if (end === void 0) end = null; end = this[_checkSublistArguments](start, end, this.length); - return new NativeFloat64x2List._externalStorage(dart.as(this[_storage].sublist(dart.notNull(start) * 2, dart.notNull(end) * 2), NativeFloat64List)); + return new NativeFloat64x2List._externalStorage(dart.as(this[_storage][dartx.sublist](dart.notNull(start) * 2, dart.notNull(end) * 2), NativeFloat64List)); } } NativeFloat64x2List[dart.implements] = () => [typed_data.Float64x2List]; @@ -430,8 +471,35 @@ dart_library.library('dart/_native_typed_data', null, /* Imports */[ sublist: [core.List$(typed_data.Float64x2), [core.int], [core.int]] }) }); - dart.defineExtensionMembers(NativeFloat64x2List, ['get', 'set', 'sublist', 'length']); + dart.defineExtensionMembers(NativeFloat64x2List, [ + 'get', + 'set', + 'sublist', + 'buffer', + 'lengthInBytes', + 'offsetInBytes', + 'elementSizeInBytes', + 'length' + ]); + dart.defineExtensionNames([ + 'buffer', + 'lengthInBytes', + 'offsetInBytes', + 'elementSizeInBytes' + ]); class NativeTypedData extends core.Object { + get [dartx.buffer]() { + return this.buffer; + } + get [dartx.lengthInBytes]() { + return this.byteLength; + } + get [dartx.offsetInBytes]() { + return this.byteOffset; + } + get [dartx.elementSizeInBytes]() { + return this.BYTES_PER_ELEMENT; + } [_invalidIndex](index, length) { if (dart.notNull(index) < 0 || dart.notNull(index) >= dart.notNull(length)) { if (dart.is(this, core.List)) { @@ -465,7 +533,6 @@ dart_library.library('dart/_native_typed_data', null, /* Imports */[ [_checkSublistArguments]: [core.int, [core.int, core.int, core.int]] }) }); - NativeTypedData[dart.metadata] = () => [dart.const(new _js_helper.Native("ArrayBufferView"))]; function _checkLength(length) { if (!(typeof length == 'number')) dart.throw(new core.ArgumentError(`Invalid length ${length}`)); return dart.as(length, core.int); @@ -504,6 +571,30 @@ dart_library.library('dart/_native_typed_data', null, /* Imports */[ const _setInt32 = Symbol('_setInt32'); const _setUint16 = Symbol('_setUint16'); const _setUint32 = Symbol('_setUint32'); + dart.defineExtensionNames([ + 'runtimeType', + 'elementSizeInBytes', + 'getFloat32', + 'getFloat64', + 'getInt16', + 'getInt32', + 'getInt64', + 'getInt8', + 'getUint16', + 'getUint32', + 'getUint64', + 'getUint8', + 'setFloat32', + 'setFloat64', + 'setInt16', + 'setInt32', + 'setInt64', + 'setInt8', + 'setUint16', + 'setUint32', + 'setUint64', + 'setUint8' + ]); class NativeByteData extends NativeTypedData { static new(length) { return NativeByteData._create1(_checkLength(length)); @@ -515,73 +606,121 @@ dart_library.library('dart/_native_typed_data', null, /* Imports */[ get runtimeType() { return typed_data.ByteData; } - get elementSizeInBytes() { + get [dartx.elementSizeInBytes]() { return 1; } - getFloat32(byteOffset, endian) { + [dartx.getFloat32](byteOffset, endian) { if (endian === void 0) endian = typed_data.Endianness.BIG_ENDIAN; return this[_getFloat32](byteOffset, dart.equals(typed_data.Endianness.LITTLE_ENDIAN, endian)); } - getFloat64(byteOffset, endian) { + [_getFloat32](byteOffset, littleEndian) { + return this.getFloat32(byteOffset, littleEndian); + } + [dartx.getFloat64](byteOffset, endian) { if (endian === void 0) endian = typed_data.Endianness.BIG_ENDIAN; return this[_getFloat64](byteOffset, dart.equals(typed_data.Endianness.LITTLE_ENDIAN, endian)); } - getInt16(byteOffset, endian) { + [_getFloat64](byteOffset, littleEndian) { + return this.getFloat64(byteOffset, littleEndian); + } + [dartx.getInt16](byteOffset, endian) { if (endian === void 0) endian = typed_data.Endianness.BIG_ENDIAN; return this[_getInt16](byteOffset, dart.equals(typed_data.Endianness.LITTLE_ENDIAN, endian)); } - getInt32(byteOffset, endian) { + [_getInt16](byteOffset, littleEndian) { + return this.getInt16(byteOffset, littleEndian); + } + [dartx.getInt32](byteOffset, endian) { if (endian === void 0) endian = typed_data.Endianness.BIG_ENDIAN; return this[_getInt32](byteOffset, dart.equals(typed_data.Endianness.LITTLE_ENDIAN, endian)); } - getInt64(byteOffset, endian) { + [_getInt32](byteOffset, littleEndian) { + return this.getInt32(byteOffset, littleEndian); + } + [dartx.getInt64](byteOffset, endian) { if (endian === void 0) endian = typed_data.Endianness.BIG_ENDIAN; dart.throw(new core.UnsupportedError('Int64 accessor not supported by dart2js.')); } - getUint16(byteOffset, endian) { + [dartx.getInt8](byteOffset) { + return this.getInt8(byteOffset); + } + [dartx.getUint16](byteOffset, endian) { if (endian === void 0) endian = typed_data.Endianness.BIG_ENDIAN; return this[_getUint16](byteOffset, dart.equals(typed_data.Endianness.LITTLE_ENDIAN, endian)); } - getUint32(byteOffset, endian) { + [_getUint16](byteOffset, littleEndian) { + return this.getUint16(byteOffset, littleEndian); + } + [dartx.getUint32](byteOffset, endian) { if (endian === void 0) endian = typed_data.Endianness.BIG_ENDIAN; return this[_getUint32](byteOffset, dart.equals(typed_data.Endianness.LITTLE_ENDIAN, endian)); } - getUint64(byteOffset, endian) { + [_getUint32](byteOffset, littleEndian) { + return this.getUint32(byteOffset, littleEndian); + } + [dartx.getUint64](byteOffset, endian) { if (endian === void 0) endian = typed_data.Endianness.BIG_ENDIAN; dart.throw(new core.UnsupportedError('Uint64 accessor not supported by dart2js.')); } - setFloat32(byteOffset, value, endian) { + [dartx.getUint8](byteOffset) { + return this.getUint8(byteOffset); + } + [dartx.setFloat32](byteOffset, value, endian) { if (endian === void 0) endian = typed_data.Endianness.BIG_ENDIAN; return this[_setFloat32](byteOffset, value, dart.equals(typed_data.Endianness.LITTLE_ENDIAN, endian)); } - setFloat64(byteOffset, value, endian) { + [_setFloat32](byteOffset, value, littleEndian) { + return this.setFloat32(byteOffset, value, littleEndian); + } + [dartx.setFloat64](byteOffset, value, endian) { if (endian === void 0) endian = typed_data.Endianness.BIG_ENDIAN; return this[_setFloat64](byteOffset, value, dart.equals(typed_data.Endianness.LITTLE_ENDIAN, endian)); } - setInt16(byteOffset, value, endian) { + [_setFloat64](byteOffset, value, littleEndian) { + return this.setFloat64(byteOffset, value, littleEndian); + } + [dartx.setInt16](byteOffset, value, endian) { if (endian === void 0) endian = typed_data.Endianness.BIG_ENDIAN; return this[_setInt16](byteOffset, value, dart.equals(typed_data.Endianness.LITTLE_ENDIAN, endian)); } - setInt32(byteOffset, value, endian) { + [_setInt16](byteOffset, value, littleEndian) { + return this.setInt16(byteOffset, value, littleEndian); + } + [dartx.setInt32](byteOffset, value, endian) { if (endian === void 0) endian = typed_data.Endianness.BIG_ENDIAN; return this[_setInt32](byteOffset, value, dart.equals(typed_data.Endianness.LITTLE_ENDIAN, endian)); } - setInt64(byteOffset, value, endian) { + [_setInt32](byteOffset, value, littleEndian) { + return this.setInt32(byteOffset, value, littleEndian); + } + [dartx.setInt64](byteOffset, value, endian) { if (endian === void 0) endian = typed_data.Endianness.BIG_ENDIAN; dart.throw(new core.UnsupportedError('Int64 accessor not supported by dart2js.')); } - setUint16(byteOffset, value, endian) { + [dartx.setInt8](byteOffset, value) { + return this.setInt8(byteOffset, value); + } + [dartx.setUint16](byteOffset, value, endian) { if (endian === void 0) endian = typed_data.Endianness.BIG_ENDIAN; return this[_setUint16](byteOffset, value, dart.equals(typed_data.Endianness.LITTLE_ENDIAN, endian)); } - setUint32(byteOffset, value, endian) { + [_setUint16](byteOffset, value, littleEndian) { + return this.setUint16(byteOffset, value, littleEndian); + } + [dartx.setUint32](byteOffset, value, endian) { if (endian === void 0) endian = typed_data.Endianness.BIG_ENDIAN; return this[_setUint32](byteOffset, value, dart.equals(typed_data.Endianness.LITTLE_ENDIAN, endian)); } - setUint64(byteOffset, value, endian) { + [_setUint32](byteOffset, value, littleEndian) { + return this.setUint32(byteOffset, value, littleEndian); + } + [dartx.setUint64](byteOffset, value, endian) { if (endian === void 0) endian = typed_data.Endianness.BIG_ENDIAN; dart.throw(new core.UnsupportedError('Uint64 accessor not supported by dart2js.')); } + [dartx.setUint8](byteOffset, value) { + return this.setUint8(byteOffset, value); + } static _create1(arg) { return dart.as(new DataView(new ArrayBuffer(arg)), NativeByteData); } @@ -599,38 +738,38 @@ dart_library.library('dart/_native_typed_data', null, /* Imports */[ view: [NativeByteData, [typed_data.ByteBuffer, core.int, core.int]] }), methods: () => ({ - getFloat32: [core.double, [core.int], [typed_data.Endianness]], + [dartx.getFloat32]: [core.double, [core.int], [typed_data.Endianness]], [_getFloat32]: [core.double, [core.int], [core.bool]], - getFloat64: [core.double, [core.int], [typed_data.Endianness]], + [dartx.getFloat64]: [core.double, [core.int], [typed_data.Endianness]], [_getFloat64]: [core.double, [core.int], [core.bool]], - getInt16: [core.int, [core.int], [typed_data.Endianness]], + [dartx.getInt16]: [core.int, [core.int], [typed_data.Endianness]], [_getInt16]: [core.int, [core.int], [core.bool]], - getInt32: [core.int, [core.int], [typed_data.Endianness]], + [dartx.getInt32]: [core.int, [core.int], [typed_data.Endianness]], [_getInt32]: [core.int, [core.int], [core.bool]], - getInt64: [core.int, [core.int], [typed_data.Endianness]], - getInt8: [core.int, [core.int]], - getUint16: [core.int, [core.int], [typed_data.Endianness]], + [dartx.getInt64]: [core.int, [core.int], [typed_data.Endianness]], + [dartx.getInt8]: [core.int, [core.int]], + [dartx.getUint16]: [core.int, [core.int], [typed_data.Endianness]], [_getUint16]: [core.int, [core.int], [core.bool]], - getUint32: [core.int, [core.int], [typed_data.Endianness]], + [dartx.getUint32]: [core.int, [core.int], [typed_data.Endianness]], [_getUint32]: [core.int, [core.int], [core.bool]], - getUint64: [core.int, [core.int], [typed_data.Endianness]], - getUint8: [core.int, [core.int]], - setFloat32: [dart.void, [core.int, core.num], [typed_data.Endianness]], + [dartx.getUint64]: [core.int, [core.int], [typed_data.Endianness]], + [dartx.getUint8]: [core.int, [core.int]], + [dartx.setFloat32]: [dart.void, [core.int, core.num], [typed_data.Endianness]], [_setFloat32]: [dart.void, [core.int, core.num], [core.bool]], - setFloat64: [dart.void, [core.int, core.num], [typed_data.Endianness]], + [dartx.setFloat64]: [dart.void, [core.int, core.num], [typed_data.Endianness]], [_setFloat64]: [dart.void, [core.int, core.num], [core.bool]], - setInt16: [dart.void, [core.int, core.int], [typed_data.Endianness]], + [dartx.setInt16]: [dart.void, [core.int, core.int], [typed_data.Endianness]], [_setInt16]: [dart.void, [core.int, core.int], [core.bool]], - setInt32: [dart.void, [core.int, core.int], [typed_data.Endianness]], + [dartx.setInt32]: [dart.void, [core.int, core.int], [typed_data.Endianness]], [_setInt32]: [dart.void, [core.int, core.int], [core.bool]], - setInt64: [dart.void, [core.int, core.int], [typed_data.Endianness]], - setInt8: [dart.void, [core.int, core.int]], - setUint16: [dart.void, [core.int, core.int], [typed_data.Endianness]], + [dartx.setInt64]: [dart.void, [core.int, core.int], [typed_data.Endianness]], + [dartx.setInt8]: [dart.void, [core.int, core.int]], + [dartx.setUint16]: [dart.void, [core.int, core.int], [typed_data.Endianness]], [_setUint16]: [dart.void, [core.int, core.int], [core.bool]], - setUint32: [dart.void, [core.int, core.int], [typed_data.Endianness]], + [dartx.setUint32]: [dart.void, [core.int, core.int], [typed_data.Endianness]], [_setUint32]: [dart.void, [core.int, core.int], [core.bool]], - setUint64: [dart.void, [core.int, core.int], [typed_data.Endianness]], - setUint8: [dart.void, [core.int, core.int]] + [dartx.setUint64]: [dart.void, [core.int, core.int], [typed_data.Endianness]], + [dartx.setUint8]: [dart.void, [core.int, core.int]] }), statics: () => ({ _create1: [NativeByteData, [dart.dynamic]], @@ -640,16 +779,17 @@ dart_library.library('dart/_native_typed_data', null, /* Imports */[ names: ['_create1', '_create2', '_create3'] }); NativeByteData[dart.metadata] = () => [dart.const(new _js_helper.Native("DataView"))]; + dart.registerExtension(dart.global.DataView, NativeByteData); const _setRangeFast = Symbol('_setRangeFast'); class NativeTypedArray extends NativeTypedData { [_setRangeFast](start, end, source, skipCount) { - let targetLength = this.length; + let targetLength = this[dartx.length]; this[_checkIndex](start, dart.notNull(targetLength) + 1); this[_checkIndex](end, dart.notNull(targetLength) + 1); if (dart.notNull(start) > dart.notNull(end)) dart.throw(new core.RangeError.range(start, 0, end)); let count = dart.notNull(end) - dart.notNull(start); if (dart.notNull(skipCount) < 0) dart.throw(new core.ArgumentError(skipCount)); - let sourceLength = source.length; + let sourceLength = source[dartx.length]; if (dart.notNull(sourceLength) - dart.notNull(skipCount) < count) { dart.throw(new core.StateError('Not enough elements')); } @@ -663,62 +803,75 @@ dart_library.library('dart/_native_typed_data', null, /* Imports */[ dart.setSignature(NativeTypedArray, { methods: () => ({[_setRangeFast]: [dart.void, [core.int, core.int, NativeTypedArray, core.int]]}) }); + dart.defineExtensionNames([ + 'length', + 'get', + 'set', + 'setRange' + ]); class NativeTypedArrayOfDouble extends dart.mixin(NativeTypedArray, collection.ListMixin$(core.double), _internal.FixedLengthListMixin$(core.double)) { - get length() { + get [dartx.length]() { return this.length; } - get(index) { - this[_checkIndex](index, this.length); + [dartx.get](index) { + this[_checkIndex](index, this[dartx.length]); return this[index]; } - set(index, value) { - this[_checkIndex](index, this.length); + [dartx.set](index, value) { + this[_checkIndex](index, this[dartx.length]); this[index] = value; return value; } - setRange(start, end, iterable, skipCount) { + [dartx.setRange](start, end, iterable, skipCount) { if (skipCount === void 0) skipCount = 0; if (dart.is(iterable, NativeTypedArrayOfDouble)) { this[_setRangeFast](start, end, iterable, skipCount); return; } - super.setRange(start, end, iterable, skipCount); + super[dartx.setRange](start, end, iterable, skipCount); } } dart.setSignature(NativeTypedArrayOfDouble, { methods: () => ({ - get: [core.double, [core.int]], - set: [dart.void, [core.int, core.num]], - setRange: [dart.void, [core.int, core.int, core.Iterable$(core.double)], [core.int]] + [dartx.get]: [core.double, [core.int]], + [dartx.set]: [dart.void, [core.int, core.num]], + [dartx.setRange]: [dart.void, [core.int, core.int, core.Iterable$(core.double)], [core.int]] }) }); - dart.defineExtensionMembers(NativeTypedArrayOfDouble, ['get', 'set', 'setRange', 'length']); + dart.defineExtensionNames([ + 'length', + 'set', + 'setRange' + ]); class NativeTypedArrayOfInt extends dart.mixin(NativeTypedArray, collection.ListMixin$(core.int), _internal.FixedLengthListMixin$(core.int)) { - get length() { + get [dartx.length]() { return this.length; } - set(index, value) { - this[_checkIndex](index, this.length); + [dartx.set](index, value) { + this[_checkIndex](index, this[dartx.length]); this[index] = value; return value; } - setRange(start, end, iterable, skipCount) { + [dartx.setRange](start, end, iterable, skipCount) { if (skipCount === void 0) skipCount = 0; if (dart.is(iterable, NativeTypedArrayOfInt)) { this[_setRangeFast](start, end, iterable, skipCount); return; } - super.setRange(start, end, iterable, skipCount); + super[dartx.setRange](start, end, iterable, skipCount); } } NativeTypedArrayOfInt[dart.implements] = () => [core.List$(core.int)]; dart.setSignature(NativeTypedArrayOfInt, { methods: () => ({ - set: [dart.void, [core.int, core.int]], - setRange: [dart.void, [core.int, core.int, core.Iterable$(core.int)], [core.int]] + [dartx.set]: [dart.void, [core.int, core.int]], + [dartx.setRange]: [dart.void, [core.int, core.int, core.Iterable$(core.int)], [core.int]] }) }); - dart.defineExtensionMembers(NativeTypedArrayOfInt, ['set', 'setRange', 'length']); + dart.defineExtensionNames([ + 'runtimeType', + 'sublist' + ]); class NativeFloat32List extends NativeTypedArrayOfDouble { static new(length) { return NativeFloat32List._create1(_checkLength(length)); @@ -733,9 +886,9 @@ dart_library.library('dart/_native_typed_data', null, /* Imports */[ get runtimeType() { return typed_data.Float32List; } - sublist(start, end) { + [dartx.sublist](start, end) { if (end === void 0) end = null; - end = this[_checkSublistArguments](start, end, this.length); + end = this[_checkSublistArguments](start, end, this[dartx.length]); let source = this.subarray(start, end); return NativeFloat32List._create1(source); } @@ -756,7 +909,7 @@ dart_library.library('dart/_native_typed_data', null, /* Imports */[ fromList: [NativeFloat32List, [core.List$(core.double)]], view: [NativeFloat32List, [typed_data.ByteBuffer, core.int, core.int]] }), - methods: () => ({sublist: [core.List$(core.double), [core.int], [core.int]]}), + methods: () => ({[dartx.sublist]: [core.List$(core.double), [core.int], [core.int]]}), statics: () => ({ _create1: [NativeFloat32List, [dart.dynamic]], _create2: [NativeFloat32List, [dart.dynamic, dart.dynamic]], @@ -764,8 +917,12 @@ dart_library.library('dart/_native_typed_data', null, /* Imports */[ }), names: ['_create1', '_create2', '_create3'] }); - dart.defineExtensionMembers(NativeFloat32List, ['sublist']); NativeFloat32List[dart.metadata] = () => [dart.const(new _js_helper.Native("Float32Array"))]; + dart.registerExtension(dart.global.Float32Array, NativeFloat32List); + dart.defineExtensionNames([ + 'runtimeType', + 'sublist' + ]); class NativeFloat64List extends NativeTypedArrayOfDouble { static new(length) { return NativeFloat64List._create1(_checkLength(length)); @@ -780,9 +937,9 @@ dart_library.library('dart/_native_typed_data', null, /* Imports */[ get runtimeType() { return typed_data.Float64List; } - sublist(start, end) { + [dartx.sublist](start, end) { if (end === void 0) end = null; - end = this[_checkSublistArguments](start, end, this.length); + end = this[_checkSublistArguments](start, end, this[dartx.length]); let source = this.subarray(start, end); return NativeFloat64List._create1(source); } @@ -803,7 +960,7 @@ dart_library.library('dart/_native_typed_data', null, /* Imports */[ fromList: [NativeFloat64List, [core.List$(core.double)]], view: [NativeFloat64List, [typed_data.ByteBuffer, core.int, core.int]] }), - methods: () => ({sublist: [core.List$(core.double), [core.int], [core.int]]}), + methods: () => ({[dartx.sublist]: [core.List$(core.double), [core.int], [core.int]]}), statics: () => ({ _create1: [NativeFloat64List, [dart.dynamic]], _create2: [NativeFloat64List, [dart.dynamic, dart.dynamic]], @@ -811,8 +968,13 @@ dart_library.library('dart/_native_typed_data', null, /* Imports */[ }), names: ['_create1', '_create2', '_create3'] }); - dart.defineExtensionMembers(NativeFloat64List, ['sublist']); NativeFloat64List[dart.metadata] = () => [dart.const(new _js_helper.Native("Float64Array"))]; + dart.registerExtension(dart.global.Float64Array, NativeFloat64List); + dart.defineExtensionNames([ + 'runtimeType', + 'get', + 'sublist' + ]); class NativeInt16List extends NativeTypedArrayOfInt { static new(length) { return NativeInt16List._create1(_checkLength(length)); @@ -827,13 +989,13 @@ dart_library.library('dart/_native_typed_data', null, /* Imports */[ get runtimeType() { return typed_data.Int16List; } - get(index) { - this[_checkIndex](index, this.length); + [dartx.get](index) { + this[_checkIndex](index, this[dartx.length]); return this[index]; } - sublist(start, end) { + [dartx.sublist](start, end) { if (end === void 0) end = null; - end = this[_checkSublistArguments](start, end, this.length); + end = this[_checkSublistArguments](start, end, this[dartx.length]); let source = this.subarray(start, end); return NativeInt16List._create1(source); } @@ -855,8 +1017,8 @@ dart_library.library('dart/_native_typed_data', null, /* Imports */[ view: [NativeInt16List, [NativeByteBuffer, core.int, core.int]] }), methods: () => ({ - get: [core.int, [core.int]], - sublist: [core.List$(core.int), [core.int], [core.int]] + [dartx.get]: [core.int, [core.int]], + [dartx.sublist]: [core.List$(core.int), [core.int], [core.int]] }), statics: () => ({ _create1: [NativeInt16List, [dart.dynamic]], @@ -865,8 +1027,13 @@ dart_library.library('dart/_native_typed_data', null, /* Imports */[ }), names: ['_create1', '_create2', '_create3'] }); - dart.defineExtensionMembers(NativeInt16List, ['get', 'sublist']); NativeInt16List[dart.metadata] = () => [dart.const(new _js_helper.Native("Int16Array"))]; + dart.registerExtension(dart.global.Int16Array, NativeInt16List); + dart.defineExtensionNames([ + 'runtimeType', + 'get', + 'sublist' + ]); class NativeInt32List extends NativeTypedArrayOfInt { static new(length) { return NativeInt32List._create1(_checkLength(length)); @@ -881,13 +1048,13 @@ dart_library.library('dart/_native_typed_data', null, /* Imports */[ get runtimeType() { return typed_data.Int32List; } - get(index) { - this[_checkIndex](index, this.length); + [dartx.get](index) { + this[_checkIndex](index, this[dartx.length]); return this[index]; } - sublist(start, end) { + [dartx.sublist](start, end) { if (end === void 0) end = null; - end = this[_checkSublistArguments](start, end, this.length); + end = this[_checkSublistArguments](start, end, this[dartx.length]); let source = this.subarray(start, end); return NativeInt32List._create1(source); } @@ -909,8 +1076,8 @@ dart_library.library('dart/_native_typed_data', null, /* Imports */[ view: [NativeInt32List, [typed_data.ByteBuffer, core.int, core.int]] }), methods: () => ({ - get: [core.int, [core.int]], - sublist: [core.List$(core.int), [core.int], [core.int]] + [dartx.get]: [core.int, [core.int]], + [dartx.sublist]: [core.List$(core.int), [core.int], [core.int]] }), statics: () => ({ _create1: [NativeInt32List, [dart.dynamic]], @@ -919,8 +1086,13 @@ dart_library.library('dart/_native_typed_data', null, /* Imports */[ }), names: ['_create1', '_create2', '_create3'] }); - dart.defineExtensionMembers(NativeInt32List, ['get', 'sublist']); NativeInt32List[dart.metadata] = () => [dart.const(new _js_helper.Native("Int32Array"))]; + dart.registerExtension(dart.global.Int32Array, NativeInt32List); + dart.defineExtensionNames([ + 'runtimeType', + 'get', + 'sublist' + ]); class NativeInt8List extends NativeTypedArrayOfInt { static new(length) { return NativeInt8List._create1(_checkLength(length)); @@ -935,13 +1107,13 @@ dart_library.library('dart/_native_typed_data', null, /* Imports */[ get runtimeType() { return typed_data.Int8List; } - get(index) { - this[_checkIndex](index, this.length); + [dartx.get](index) { + this[_checkIndex](index, this[dartx.length]); return this[index]; } - sublist(start, end) { + [dartx.sublist](start, end) { if (end === void 0) end = null; - end = this[_checkSublistArguments](start, end, this.length); + end = this[_checkSublistArguments](start, end, this[dartx.length]); let source = this.subarray(start, end); return NativeInt8List._create1(source); } @@ -963,8 +1135,8 @@ dart_library.library('dart/_native_typed_data', null, /* Imports */[ view: [NativeInt8List, [typed_data.ByteBuffer, core.int, core.int]] }), methods: () => ({ - get: [core.int, [core.int]], - sublist: [core.List$(core.int), [core.int], [core.int]] + [dartx.get]: [core.int, [core.int]], + [dartx.sublist]: [core.List$(core.int), [core.int], [core.int]] }), statics: () => ({ _create1: [NativeInt8List, [dart.dynamic]], @@ -973,8 +1145,13 @@ dart_library.library('dart/_native_typed_data', null, /* Imports */[ }), names: ['_create1', '_create2', '_create3'] }); - dart.defineExtensionMembers(NativeInt8List, ['get', 'sublist']); NativeInt8List[dart.metadata] = () => [dart.const(new _js_helper.Native("Int8Array"))]; + dart.registerExtension(dart.global.Int8Array, NativeInt8List); + dart.defineExtensionNames([ + 'runtimeType', + 'get', + 'sublist' + ]); class NativeUint16List extends NativeTypedArrayOfInt { static new(length) { return NativeUint16List._create1(_checkLength(length)); @@ -989,13 +1166,13 @@ dart_library.library('dart/_native_typed_data', null, /* Imports */[ get runtimeType() { return typed_data.Uint16List; } - get(index) { - this[_checkIndex](index, this.length); + [dartx.get](index) { + this[_checkIndex](index, this[dartx.length]); return this[index]; } - sublist(start, end) { + [dartx.sublist](start, end) { if (end === void 0) end = null; - end = this[_checkSublistArguments](start, end, this.length); + end = this[_checkSublistArguments](start, end, this[dartx.length]); let source = this.subarray(start, end); return NativeUint16List._create1(source); } @@ -1017,8 +1194,8 @@ dart_library.library('dart/_native_typed_data', null, /* Imports */[ view: [NativeUint16List, [typed_data.ByteBuffer, core.int, core.int]] }), methods: () => ({ - get: [core.int, [core.int]], - sublist: [core.List$(core.int), [core.int], [core.int]] + [dartx.get]: [core.int, [core.int]], + [dartx.sublist]: [core.List$(core.int), [core.int], [core.int]] }), statics: () => ({ _create1: [NativeUint16List, [dart.dynamic]], @@ -1027,8 +1204,13 @@ dart_library.library('dart/_native_typed_data', null, /* Imports */[ }), names: ['_create1', '_create2', '_create3'] }); - dart.defineExtensionMembers(NativeUint16List, ['get', 'sublist']); NativeUint16List[dart.metadata] = () => [dart.const(new _js_helper.Native("Uint16Array"))]; + dart.registerExtension(dart.global.Uint16Array, NativeUint16List); + dart.defineExtensionNames([ + 'runtimeType', + 'get', + 'sublist' + ]); class NativeUint32List extends NativeTypedArrayOfInt { static new(length) { return NativeUint32List._create1(_checkLength(length)); @@ -1043,13 +1225,13 @@ dart_library.library('dart/_native_typed_data', null, /* Imports */[ get runtimeType() { return typed_data.Uint32List; } - get(index) { - this[_checkIndex](index, this.length); + [dartx.get](index) { + this[_checkIndex](index, this[dartx.length]); return this[index]; } - sublist(start, end) { + [dartx.sublist](start, end) { if (end === void 0) end = null; - end = this[_checkSublistArguments](start, end, this.length); + end = this[_checkSublistArguments](start, end, this[dartx.length]); let source = this.subarray(start, end); return NativeUint32List._create1(source); } @@ -1071,8 +1253,8 @@ dart_library.library('dart/_native_typed_data', null, /* Imports */[ view: [NativeUint32List, [typed_data.ByteBuffer, core.int, core.int]] }), methods: () => ({ - get: [core.int, [core.int]], - sublist: [core.List$(core.int), [core.int], [core.int]] + [dartx.get]: [core.int, [core.int]], + [dartx.sublist]: [core.List$(core.int), [core.int], [core.int]] }), statics: () => ({ _create1: [NativeUint32List, [dart.dynamic]], @@ -1081,8 +1263,14 @@ dart_library.library('dart/_native_typed_data', null, /* Imports */[ }), names: ['_create1', '_create2', '_create3'] }); - dart.defineExtensionMembers(NativeUint32List, ['get', 'sublist']); NativeUint32List[dart.metadata] = () => [dart.const(new _js_helper.Native("Uint32Array"))]; + dart.registerExtension(dart.global.Uint32Array, NativeUint32List); + dart.defineExtensionNames([ + 'runtimeType', + 'length', + 'get', + 'sublist' + ]); class NativeUint8ClampedList extends NativeTypedArrayOfInt { static new(length) { return NativeUint8ClampedList._create1(_checkLength(length)); @@ -1097,16 +1285,16 @@ dart_library.library('dart/_native_typed_data', null, /* Imports */[ get runtimeType() { return typed_data.Uint8ClampedList; } - get length() { + get [dartx.length]() { return this.length; } - get(index) { - this[_checkIndex](index, this.length); + [dartx.get](index) { + this[_checkIndex](index, this[dartx.length]); return this[index]; } - sublist(start, end) { + [dartx.sublist](start, end) { if (end === void 0) end = null; - end = this[_checkSublistArguments](start, end, this.length); + end = this[_checkSublistArguments](start, end, this[dartx.length]); let source = this.subarray(start, end); return NativeUint8ClampedList._create1(source); } @@ -1128,8 +1316,8 @@ dart_library.library('dart/_native_typed_data', null, /* Imports */[ view: [NativeUint8ClampedList, [typed_data.ByteBuffer, core.int, core.int]] }), methods: () => ({ - get: [core.int, [core.int]], - sublist: [core.List$(core.int), [core.int], [core.int]] + [dartx.get]: [core.int, [core.int]], + [dartx.sublist]: [core.List$(core.int), [core.int], [core.int]] }), statics: () => ({ _create1: [NativeUint8ClampedList, [dart.dynamic]], @@ -1138,8 +1326,14 @@ dart_library.library('dart/_native_typed_data', null, /* Imports */[ }), names: ['_create1', '_create2', '_create3'] }); - dart.defineExtensionMembers(NativeUint8ClampedList, ['get', 'sublist', 'length']); NativeUint8ClampedList[dart.metadata] = () => [dart.const(new _js_helper.Native("Uint8ClampedArray,CanvasPixelArray"))]; + dart.registerExtension(dart.global.Uint8ClampedArray, NativeUint8ClampedList); + dart.defineExtensionNames([ + 'runtimeType', + 'length', + 'get', + 'sublist' + ]); class NativeUint8List extends NativeTypedArrayOfInt { static new(length) { return NativeUint8List._create1(_checkLength(length)); @@ -1154,16 +1348,16 @@ dart_library.library('dart/_native_typed_data', null, /* Imports */[ get runtimeType() { return typed_data.Uint8List; } - get length() { + get [dartx.length]() { return this.length; } - get(index) { - this[_checkIndex](index, this.length); + [dartx.get](index) { + this[_checkIndex](index, this[dartx.length]); return this[index]; } - sublist(start, end) { + [dartx.sublist](start, end) { if (end === void 0) end = null; - end = this[_checkSublistArguments](start, end, this.length); + end = this[_checkSublistArguments](start, end, this[dartx.length]); let source = this.subarray(start, end); return NativeUint8List._create1(source); } @@ -1185,8 +1379,8 @@ dart_library.library('dart/_native_typed_data', null, /* Imports */[ view: [NativeUint8List, [typed_data.ByteBuffer, core.int, core.int]] }), methods: () => ({ - get: [core.int, [core.int]], - sublist: [core.List$(core.int), [core.int], [core.int]] + [dartx.get]: [core.int, [core.int]], + [dartx.sublist]: [core.List$(core.int), [core.int], [core.int]] }), statics: () => ({ _create1: [NativeUint8List, [dart.dynamic]], @@ -1195,12 +1389,12 @@ dart_library.library('dart/_native_typed_data', null, /* Imports */[ }), names: ['_create1', '_create2', '_create3'] }); - dart.defineExtensionMembers(NativeUint8List, ['get', 'sublist', 'length']); NativeUint8List[dart.metadata] = () => [dart.const(new _js_helper.Native("Uint8Array,!nonleaf"))]; + dart.registerExtension(dart.global.Uint8Array, NativeUint8List); class NativeFloat32x4 extends core.Object { static _truncate(x) { - NativeFloat32x4._list.set(0, dart.as(x, core.num)); - return NativeFloat32x4._list.get(0); + NativeFloat32x4._list[dartx.set](0, dart.as(x, core.num)); + return NativeFloat32x4._list[dartx.get](0); } NativeFloat32x4(x, y, z, w) { this.x = dart.as(NativeFloat32x4._truncate(x), core.double); @@ -1219,11 +1413,11 @@ dart_library.library('dart/_native_typed_data', null, /* Imports */[ this._truncated(0.0, 0.0, 0.0, 0.0); } static fromInt32x4Bits(i) { - NativeFloat32x4._uint32view.set(0, i.x); - NativeFloat32x4._uint32view.set(1, i.y); - NativeFloat32x4._uint32view.set(2, i.z); - NativeFloat32x4._uint32view.set(3, i.w); - return new NativeFloat32x4._truncated(NativeFloat32x4._list.get(0), NativeFloat32x4._list.get(1), NativeFloat32x4._list.get(2), NativeFloat32x4._list.get(3)); + NativeFloat32x4._uint32view[dartx.set](0, i.x); + NativeFloat32x4._uint32view[dartx.set](1, i.y); + NativeFloat32x4._uint32view[dartx.set](2, i.z); + NativeFloat32x4._uint32view[dartx.set](3, i.w); + return new NativeFloat32x4._truncated(NativeFloat32x4._list[dartx.get](0), NativeFloat32x4._list[dartx.get](1), NativeFloat32x4._list[dartx.get](2), NativeFloat32x4._list[dartx.get](3)); } fromFloat64x2(v) { this._truncated(dart.as(NativeFloat32x4._truncate(v.x), core.double), dart.as(NativeFloat32x4._truncate(v.y), core.double), 0.0, 0.0); @@ -1356,46 +1550,46 @@ dart_library.library('dart/_native_typed_data', null, /* Imports */[ get signMask() { let view = NativeFloat32x4._uint32view; let mx = null, my = null, mz = null, mw = null; - NativeFloat32x4._list.set(0, this.x); - NativeFloat32x4._list.set(1, this.y); - NativeFloat32x4._list.set(2, this.z); - NativeFloat32x4._list.set(3, this.w); - mx = (dart.notNull(view.get(0)) & 2147483648) >> 31; - my = (dart.notNull(view.get(1)) & 2147483648) >> 30; - mz = (dart.notNull(view.get(2)) & 2147483648) >> 29; - mw = (dart.notNull(view.get(3)) & 2147483648) >> 28; + NativeFloat32x4._list[dartx.set](0, this.x); + NativeFloat32x4._list[dartx.set](1, this.y); + NativeFloat32x4._list[dartx.set](2, this.z); + NativeFloat32x4._list[dartx.set](3, this.w); + mx = (dart.notNull(view[dartx.get](0)) & 2147483648) >> 31; + my = (dart.notNull(view[dartx.get](1)) & 2147483648) >> 30; + mz = (dart.notNull(view[dartx.get](2)) & 2147483648) >> 29; + mw = (dart.notNull(view[dartx.get](3)) & 2147483648) >> 28; return dart.as(dart.dsend(dart.dsend(dart.dsend(mx, '|', my), '|', mz), '|', mw), core.int); } shuffle(m) { if (dart.notNull(m) < 0 || dart.notNull(m) > 255) { dart.throw(new core.RangeError(`mask ${m} must be in the range [0..256)`)); } - NativeFloat32x4._list.set(0, this.x); - NativeFloat32x4._list.set(1, this.y); - NativeFloat32x4._list.set(2, this.z); - NativeFloat32x4._list.set(3, this.w); - let _x = NativeFloat32x4._list.get(dart.notNull(m) & 3); - let _y = NativeFloat32x4._list.get(dart.notNull(m) >> 2 & 3); - let _z = NativeFloat32x4._list.get(dart.notNull(m) >> 4 & 3); - let _w = NativeFloat32x4._list.get(dart.notNull(m) >> 6 & 3); + NativeFloat32x4._list[dartx.set](0, this.x); + NativeFloat32x4._list[dartx.set](1, this.y); + NativeFloat32x4._list[dartx.set](2, this.z); + NativeFloat32x4._list[dartx.set](3, this.w); + let _x = NativeFloat32x4._list[dartx.get](dart.notNull(m) & 3); + let _y = NativeFloat32x4._list[dartx.get](dart.notNull(m) >> 2 & 3); + let _z = NativeFloat32x4._list[dartx.get](dart.notNull(m) >> 4 & 3); + let _w = NativeFloat32x4._list[dartx.get](dart.notNull(m) >> 6 & 3); return new NativeFloat32x4._truncated(_x, _y, _z, _w); } shuffleMix(other, m) { if (dart.notNull(m) < 0 || dart.notNull(m) > 255) { dart.throw(new core.RangeError(`mask ${m} must be in the range [0..256)`)); } - NativeFloat32x4._list.set(0, this.x); - NativeFloat32x4._list.set(1, this.y); - NativeFloat32x4._list.set(2, this.z); - NativeFloat32x4._list.set(3, this.w); - let _x = NativeFloat32x4._list.get(dart.notNull(m) & 3); - let _y = NativeFloat32x4._list.get(dart.notNull(m) >> 2 & 3); - NativeFloat32x4._list.set(0, other.x); - NativeFloat32x4._list.set(1, other.y); - NativeFloat32x4._list.set(2, other.z); - NativeFloat32x4._list.set(3, other.w); - let _z = NativeFloat32x4._list.get(dart.notNull(m) >> 4 & 3); - let _w = NativeFloat32x4._list.get(dart.notNull(m) >> 6 & 3); + NativeFloat32x4._list[dartx.set](0, this.x); + NativeFloat32x4._list[dartx.set](1, this.y); + NativeFloat32x4._list[dartx.set](2, this.z); + NativeFloat32x4._list[dartx.set](3, this.w); + let _x = NativeFloat32x4._list[dartx.get](dart.notNull(m) & 3); + let _y = NativeFloat32x4._list[dartx.get](dart.notNull(m) >> 2 & 3); + NativeFloat32x4._list[dartx.set](0, other.x); + NativeFloat32x4._list[dartx.set](1, other.y); + NativeFloat32x4._list[dartx.set](2, other.z); + NativeFloat32x4._list[dartx.set](3, other.w); + let _z = NativeFloat32x4._list[dartx.get](dart.notNull(m) >> 4 & 3); + let _w = NativeFloat32x4._list[dartx.get](dart.notNull(m) >> 6 & 3); return new NativeFloat32x4._truncated(_x, _y, _z, _w); } withX(newX) { @@ -1497,13 +1691,13 @@ dart_library.library('dart/_native_typed_data', null, /* Imports */[ return NativeFloat32List.new(4); }, get _uint32view() { - return NativeFloat32x4._list.buffer.asUint32List(); + return NativeFloat32x4._list[dartx.buffer][dartx.asUint32List](); } }); class NativeInt32x4 extends core.Object { static _truncate(x) { - NativeInt32x4._list.set(0, dart.as(x, core.int)); - return NativeInt32x4._list.get(0); + NativeInt32x4._list[dartx.set](0, dart.as(x, core.int)); + return NativeInt32x4._list[dartx.get](0); } NativeInt32x4(x, y, z, w) { this.x = dart.as(NativeInt32x4._truncate(x), core.int); @@ -1523,12 +1717,12 @@ dart_library.library('dart/_native_typed_data', null, /* Imports */[ } static fromFloat32x4Bits(f) { let floatList = NativeFloat32x4._list; - floatList.set(0, f.x); - floatList.set(1, f.y); - floatList.set(2, f.z); - floatList.set(3, f.w); - let view = dart.as(floatList.buffer.asInt32List(), NativeInt32List); - return new NativeInt32x4._truncated(view.get(0), view.get(1), view.get(2), view.get(3)); + floatList[dartx.set](0, f.x); + floatList[dartx.set](1, f.y); + floatList[dartx.set](2, f.z); + floatList[dartx.set](3, f.w); + let view = dart.as(floatList[dartx.buffer][dartx.asInt32List](), NativeInt32List); + return new NativeInt32x4._truncated(view[dartx.get](0), view[dartx.get](1), view[dartx.get](2), view[dartx.get](3)); } _truncated(x, y, z, w) { this.x = x; @@ -1568,32 +1762,32 @@ dart_library.library('dart/_native_typed_data', null, /* Imports */[ if (dart.notNull(mask) < 0 || dart.notNull(mask) > 255) { dart.throw(new core.RangeError(`mask ${mask} must be in the range [0..256)`)); } - NativeInt32x4._list.set(0, this.x); - NativeInt32x4._list.set(1, this.y); - NativeInt32x4._list.set(2, this.z); - NativeInt32x4._list.set(3, this.w); - let _x = NativeInt32x4._list.get(dart.notNull(mask) & 3); - let _y = NativeInt32x4._list.get(dart.notNull(mask) >> 2 & 3); - let _z = NativeInt32x4._list.get(dart.notNull(mask) >> 4 & 3); - let _w = NativeInt32x4._list.get(dart.notNull(mask) >> 6 & 3); + NativeInt32x4._list[dartx.set](0, this.x); + NativeInt32x4._list[dartx.set](1, this.y); + NativeInt32x4._list[dartx.set](2, this.z); + NativeInt32x4._list[dartx.set](3, this.w); + let _x = NativeInt32x4._list[dartx.get](dart.notNull(mask) & 3); + let _y = NativeInt32x4._list[dartx.get](dart.notNull(mask) >> 2 & 3); + let _z = NativeInt32x4._list[dartx.get](dart.notNull(mask) >> 4 & 3); + let _w = NativeInt32x4._list[dartx.get](dart.notNull(mask) >> 6 & 3); return new NativeInt32x4._truncated(_x, _y, _z, _w); } shuffleMix(other, mask) { if (dart.notNull(mask) < 0 || dart.notNull(mask) > 255) { dart.throw(new core.RangeError(`mask ${mask} must be in the range [0..256)`)); } - NativeInt32x4._list.set(0, this.x); - NativeInt32x4._list.set(1, this.y); - NativeInt32x4._list.set(2, this.z); - NativeInt32x4._list.set(3, this.w); - let _x = NativeInt32x4._list.get(dart.notNull(mask) & 3); - let _y = NativeInt32x4._list.get(dart.notNull(mask) >> 2 & 3); - NativeInt32x4._list.set(0, other.x); - NativeInt32x4._list.set(1, other.y); - NativeInt32x4._list.set(2, other.z); - NativeInt32x4._list.set(3, other.w); - let _z = NativeInt32x4._list.get(dart.notNull(mask) >> 4 & 3); - let _w = NativeInt32x4._list.get(dart.notNull(mask) >> 6 & 3); + NativeInt32x4._list[dartx.set](0, this.x); + NativeInt32x4._list[dartx.set](1, this.y); + NativeInt32x4._list[dartx.set](2, this.z); + NativeInt32x4._list[dartx.set](3, this.w); + let _x = NativeInt32x4._list[dartx.get](dart.notNull(mask) & 3); + let _y = NativeInt32x4._list[dartx.get](dart.notNull(mask) >> 2 & 3); + NativeInt32x4._list[dartx.set](0, other.x); + NativeInt32x4._list[dartx.set](1, other.y); + NativeInt32x4._list[dartx.set](2, other.z); + NativeInt32x4._list[dartx.set](3, other.w); + let _z = NativeInt32x4._list[dartx.get](dart.notNull(mask) >> 4 & 3); + let _w = NativeInt32x4._list[dartx.get](dart.notNull(mask) >> 6 & 3); return new NativeInt32x4._truncated(_x, _y, _z, _w); } withX(x) { @@ -1643,31 +1837,31 @@ dart_library.library('dart/_native_typed_data', null, /* Imports */[ select(trueValue, falseValue) { let floatList = NativeFloat32x4._list; let intView = NativeFloat32x4._uint32view; - floatList.set(0, trueValue.x); - floatList.set(1, trueValue.y); - floatList.set(2, trueValue.z); - floatList.set(3, trueValue.w); - let stx = intView.get(0); - let sty = intView.get(1); - let stz = intView.get(2); - let stw = intView.get(3); - floatList.set(0, falseValue.x); - floatList.set(1, falseValue.y); - floatList.set(2, falseValue.z); - floatList.set(3, falseValue.w); - let sfx = intView.get(0); - let sfy = intView.get(1); - let sfz = intView.get(2); - let sfw = intView.get(3); + floatList[dartx.set](0, trueValue.x); + floatList[dartx.set](1, trueValue.y); + floatList[dartx.set](2, trueValue.z); + floatList[dartx.set](3, trueValue.w); + let stx = intView[dartx.get](0); + let sty = intView[dartx.get](1); + let stz = intView[dartx.get](2); + let stw = intView[dartx.get](3); + floatList[dartx.set](0, falseValue.x); + floatList[dartx.set](1, falseValue.y); + floatList[dartx.set](2, falseValue.z); + floatList[dartx.set](3, falseValue.w); + let sfx = intView[dartx.get](0); + let sfy = intView[dartx.get](1); + let sfz = intView[dartx.get](2); + let sfw = intView[dartx.get](3); let _x = dart.notNull(this.x) & dart.notNull(stx) | ~dart.notNull(this.x) & dart.notNull(sfx); let _y = dart.notNull(this.y) & dart.notNull(sty) | ~dart.notNull(this.y) & dart.notNull(sfy); let _z = dart.notNull(this.z) & dart.notNull(stz) | ~dart.notNull(this.z) & dart.notNull(sfz); let _w = dart.notNull(this.w) & dart.notNull(stw) | ~dart.notNull(this.w) & dart.notNull(sfw); - intView.set(0, _x); - intView.set(1, _y); - intView.set(2, _z); - intView.set(3, _w); - return new NativeFloat32x4._truncated(floatList.get(0), floatList.get(1), floatList.get(2), floatList.get(3)); + intView[dartx.set](0, _x); + intView[dartx.set](1, _y); + intView[dartx.set](2, _z); + intView[dartx.set](3, _w); + return new NativeFloat32x4._truncated(floatList[dartx.get](0), floatList[dartx.get](1), floatList[dartx.get](2), floatList[dartx.get](3)); } } NativeInt32x4[dart.implements] = () => [typed_data.Int32x4]; @@ -1766,10 +1960,10 @@ dart_library.library('dart/_native_typed_data', null, /* Imports */[ } get signMask() { let view = NativeFloat64x2._uint32View; - NativeFloat64x2._list.set(0, this.x); - NativeFloat64x2._list.set(1, this.y); - let mx = (dart.notNull(view.get(1)) & 2147483648) >> 31; - let my = (dart.notNull(view.get(3)) & 2147483648) >> 31; + NativeFloat64x2._list[dartx.set](0, this.x); + NativeFloat64x2._list[dartx.set](1, this.y); + let mx = (dart.notNull(view[dartx.get](1)) & 2147483648) >> 31; + let my = (dart.notNull(view[dartx.get](3)) & 2147483648) >> 31; return mx | my << 1; } withX(x) { @@ -1825,7 +2019,7 @@ dart_library.library('dart/_native_typed_data', null, /* Imports */[ }, set _list(_) {}, get _uint32View() { - return dart.as(NativeFloat64x2._list.buffer.asUint32List(), NativeUint32List); + return dart.as(NativeFloat64x2._list[dartx.buffer][dartx.asUint32List](), NativeUint32List); }, set _uint32View(_) {} }); diff --git a/pkg/dev_compiler/lib/runtime/dart/_runtime.js b/pkg/dev_compiler/lib/runtime/dart/_runtime.js index 9906e2d1ea9c..80227d1379f0 100644 --- a/pkg/dev_compiler/lib/runtime/dart/_runtime.js +++ b/pkg/dev_compiler/lib/runtime/dart/_runtime.js @@ -173,6 +173,9 @@ dart_library.library('dart/_runtime', null, /* Imports */[ defineProperty(clazz, name, {value: ctor, configurable: true}); } const _extensionType = Symbol("extensionType"); + function getExtensionType(obj) { + return obj[_extensionType]; + } const dartx = {}; function getExtensionSymbol(name) { let sym = dartx[name]; @@ -182,16 +185,18 @@ dart_library.library('dart/_runtime', null, /* Imports */[ function defineExtensionNames(names) { return names.forEach(getExtensionSymbol); } + function _installProperties(jsProto, extProto) { + if (extProto !== core.Object.prototype && extProto !== jsProto) { + _installProperties(jsProto, extProto.__proto__); + } + copyTheseProperties(jsProto, extProto, getOwnPropertySymbols(extProto)); + } function registerExtension(jsType, dartExtType) { let extProto = dartExtType.prototype; let jsProto = jsType.prototype; assert_(jsProto[_extensionType] === void 0); - jsProto[_extensionType] = extProto; - let dartObjProto = core.Object.prototype; - while (extProto !== dartObjProto && extProto !== jsProto) { - copyTheseProperties(jsProto, extProto, getOwnPropertySymbols(extProto)); - extProto = extProto.__proto__; - } + jsProto[_extensionType] = dartExtType; + _installProperties(jsProto, extProto); let originalSigFn = getOwnPropertyDescriptor(dartExtType, _methodSig).get; assert_(originalSigFn); defineMemoizedGetter(jsType, _methodSig, originalSigFn); @@ -220,6 +225,7 @@ dart_library.library('dart/_runtime', null, /* Imports */[ } function setType(obj, type) { obj.__proto__ = type.prototype; + obj.__proto__[_extensionType] = type; return obj; } function list(obj, elementType) { @@ -476,7 +482,7 @@ dart_library.library('dart/_runtime', null, /* Imports */[ } function strongInstanceOf(obj, type, ignoreFromWhiteList) { let actual = realRuntimeType(obj); - if (isSubtype(actual, type) || actual == jsobject) return true; + if (isSubtype(actual, type) || actual == jsobject || actual == core.int && type == core.double) return true; if (ignoreFromWhiteList == void 0) return false; if (isGroundType(type)) return false; if (_ignoreTypeFailure(actual, type)) return true; @@ -685,7 +691,9 @@ dart_library.library('dart/_runtime', null, /* Imports */[ function runtimeType(obj) { let result = checkPrimitiveType(obj); if (result !== null) return result; - return obj.runtimeType; + result = obj.runtimeType; + if (result) return result; + return _nonPrimitiveRuntimeType(obj); } function getFunctionType(obj) { let args = Array(obj.length).fill(dynamicR); @@ -694,7 +702,12 @@ dart_library.library('dart/_runtime', null, /* Imports */[ function realRuntimeType(obj) { let result = checkPrimitiveType(obj); if (result !== null) return result; - result = obj[_runtimeType]; + return _nonPrimitiveRuntimeType(obj); + } + function _nonPrimitiveRuntimeType(obj) { + let result = obj[_runtimeType]; + if (result) return result; + result = obj[_extensionType]; if (result) return result; result = obj.constructor; if (result == Function) { @@ -1199,6 +1212,7 @@ dart_library.library('dart/_runtime', null, /* Imports */[ exports.hasMethod = hasMethod; exports.virtualField = virtualField; exports.defineNamedConstructor = defineNamedConstructor; + exports.getExtensionType = getExtensionType; exports.dartx = dartx; exports.getExtensionSymbol = getExtensionSymbol; exports.defineExtensionNames = defineExtensionNames; diff --git a/pkg/dev_compiler/lib/runtime/dart/collection.js b/pkg/dev_compiler/lib/runtime/dart/collection.js index cf1b9cb23c6d..ad9a60590b64 100644 --- a/pkg/dev_compiler/lib/runtime/dart/collection.js +++ b/pkg/dev_compiler/lib/runtime/dart/collection.js @@ -1556,114 +1556,166 @@ dart_library.library('dart/collection', null, /* Imports */[ }); let LinkedListEntry = LinkedListEntry$(); const ListMixin$ = dart.generic(function(E) { + dart.defineExtensionNames([ + 'iterator', + 'elementAt', + 'forEach', + 'isEmpty', + 'isNotEmpty', + 'first', + 'last', + 'single', + 'contains', + 'every', + 'any', + 'firstWhere', + 'lastWhere', + 'singleWhere', + 'join', + 'where', + 'map', + 'expand', + 'reduce', + 'fold', + 'skip', + 'skipWhile', + 'take', + 'takeWhile', + 'toList', + 'toSet', + 'add', + 'addAll', + 'remove', + 'removeWhere', + 'retainWhere', + 'clear', + 'removeLast', + 'sort', + 'shuffle', + 'asMap', + 'sublist', + 'getRange', + 'removeRange', + 'fillRange', + 'setRange', + 'replaceRange', + 'indexOf', + 'lastIndexOf', + 'insert', + 'removeAt', + 'insertAll', + 'setAll', + 'reversed', + 'toString' + ]); class ListMixin extends core.Object { - get iterator() { + get [dartx.iterator]() { return new (_internal.ListIterator$(E))(this); } [Symbol.iterator]() { - return new dart.JsIterator(this.iterator); + return new dart.JsIterator(this[dartx.iterator]); } - elementAt(index) { - return this.get(index); + [dartx.elementAt](index) { + return this[dartx.get](index); } - forEach(action) { + [dartx.forEach](action) { dart.as(action, dart.functionType(dart.void, [E])); - let length = this.length; + let length = this[dartx.length]; for (let i = 0; i < dart.notNull(length); i++) { - action(this.get(i)); - if (length != this.length) { + action(this[dartx.get](i)); + if (length != this[dartx.length]) { dart.throw(new core.ConcurrentModificationError(this)); } } } - get isEmpty() { + get [dartx.isEmpty]() { return this[dartx.length] == 0; } - get isNotEmpty() { - return !dart.notNull(this.isEmpty); + get [dartx.isNotEmpty]() { + return !dart.notNull(this[dartx.isEmpty]); } - get first() { + get [dartx.first]() { if (this[dartx.length] == 0) dart.throw(_internal.IterableElementError.noElement()); - return this.get(0); + return this[dartx.get](0); } - get last() { + get [dartx.last]() { if (this[dartx.length] == 0) dart.throw(_internal.IterableElementError.noElement()); - return this.get(dart.notNull(this[dartx.length]) - 1); + return this[dartx.get](dart.notNull(this[dartx.length]) - 1); } - get single() { + get [dartx.single]() { if (this[dartx.length] == 0) dart.throw(_internal.IterableElementError.noElement()); if (dart.notNull(this[dartx.length]) > 1) dart.throw(_internal.IterableElementError.tooMany()); - return this.get(0); + return this[dartx.get](0); } - contains(element) { - let length = this.length; - for (let i = 0; i < dart.notNull(this.length); i++) { - if (dart.equals(this.get(i), element)) return true; - if (length != this.length) { + [dartx.contains](element) { + let length = this[dartx.length]; + for (let i = 0; i < dart.notNull(this[dartx.length]); i++) { + if (dart.equals(this[dartx.get](i), element)) return true; + if (length != this[dartx.length]) { dart.throw(new core.ConcurrentModificationError(this)); } } return false; } - every(test) { + [dartx.every](test) { dart.as(test, dart.functionType(core.bool, [E])); - let length = this.length; + let length = this[dartx.length]; for (let i = 0; i < dart.notNull(length); i++) { - if (!dart.notNull(test(this.get(i)))) return false; - if (length != this.length) { + if (!dart.notNull(test(this[dartx.get](i)))) return false; + if (length != this[dartx.length]) { dart.throw(new core.ConcurrentModificationError(this)); } } return true; } - any(test) { + [dartx.any](test) { dart.as(test, dart.functionType(core.bool, [E])); - let length = this.length; + let length = this[dartx.length]; for (let i = 0; i < dart.notNull(length); i++) { - if (dart.notNull(test(this.get(i)))) return true; - if (length != this.length) { + if (dart.notNull(test(this[dartx.get](i)))) return true; + if (length != this[dartx.length]) { dart.throw(new core.ConcurrentModificationError(this)); } } return false; } - firstWhere(test, opts) { + [dartx.firstWhere](test, opts) { dart.as(test, dart.functionType(core.bool, [E])); let orElse = opts && 'orElse' in opts ? opts.orElse : null; dart.as(orElse, dart.functionType(E, [])); - let length = this.length; + let length = this[dartx.length]; for (let i = 0; i < dart.notNull(length); i++) { - let element = this.get(i); + let element = this[dartx.get](i); if (dart.notNull(test(element))) return element; - if (length != this.length) { + if (length != this[dartx.length]) { dart.throw(new core.ConcurrentModificationError(this)); } } if (orElse != null) return orElse(); dart.throw(_internal.IterableElementError.noElement()); } - lastWhere(test, opts) { + [dartx.lastWhere](test, opts) { dart.as(test, dart.functionType(core.bool, [E])); let orElse = opts && 'orElse' in opts ? opts.orElse : null; dart.as(orElse, dart.functionType(E, [])); - let length = this.length; + let length = this[dartx.length]; for (let i = dart.notNull(length) - 1; i >= 0; i--) { - let element = this.get(i); + let element = this[dartx.get](i); if (dart.notNull(test(element))) return element; - if (length != this.length) { + if (length != this[dartx.length]) { dart.throw(new core.ConcurrentModificationError(this)); } } if (orElse != null) return orElse(); dart.throw(_internal.IterableElementError.noElement()); } - singleWhere(test) { + [dartx.singleWhere](test) { dart.as(test, dart.functionType(core.bool, [E])); - let length = this.length; + let length = this[dartx.length]; let match = null; let matchFound = false; for (let i = 0; i < dart.notNull(length); i++) { - let element = this.get(i); + let element = this[dartx.get](i); if (dart.notNull(test(element))) { if (matchFound) { dart.throw(_internal.IterableElementError.tooMany()); @@ -1671,72 +1723,72 @@ dart_library.library('dart/collection', null, /* Imports */[ matchFound = true; match = element; } - if (length != this.length) { + if (length != this[dartx.length]) { dart.throw(new core.ConcurrentModificationError(this)); } } if (matchFound) return match; dart.throw(_internal.IterableElementError.noElement()); } - join(separator) { + [dartx.join](separator) { if (separator === void 0) separator = ""; if (this[dartx.length] == 0) return ""; let buffer = new core.StringBuffer(); buffer.writeAll(this, separator); return dart.toString(buffer); } - where(test) { + [dartx.where](test) { dart.as(test, dart.functionType(core.bool, [E])); return new (_internal.WhereIterable$(E))(this, test); } - map(f) { + [dartx.map](f) { dart.as(f, dart.functionType(dart.dynamic, [E])); return new (_internal.MappedListIterable$(E, dart.dynamic))(this, f); } - expand(f) { + [dartx.expand](f) { dart.as(f, dart.functionType(core.Iterable, [E])); return new (_internal.ExpandIterable$(E, dart.dynamic))(this, f); } - reduce(combine) { + [dartx.reduce](combine) { dart.as(combine, dart.functionType(E, [E, E])); - let length = this.length; + let length = this[dartx.length]; if (length == 0) dart.throw(_internal.IterableElementError.noElement()); - let value = this.get(0); + let value = this[dartx.get](0); for (let i = 1; i < dart.notNull(length); i++) { - value = combine(value, this.get(i)); - if (length != this.length) { + value = combine(value, this[dartx.get](i)); + if (length != this[dartx.length]) { dart.throw(new core.ConcurrentModificationError(this)); } } return value; } - fold(initialValue, combine) { + [dartx.fold](initialValue, combine) { dart.as(combine, dart.functionType(dart.dynamic, [dart.dynamic, E])); let value = initialValue; - let length = this.length; + let length = this[dartx.length]; for (let i = 0; i < dart.notNull(length); i++) { - value = combine(value, this.get(i)); - if (length != this.length) { + value = combine(value, this[dartx.get](i)); + if (length != this[dartx.length]) { dart.throw(new core.ConcurrentModificationError(this)); } } return value; } - skip(count) { + [dartx.skip](count) { return new (_internal.SubListIterable$(E))(this, count, null); } - skipWhile(test) { + [dartx.skipWhile](test) { dart.as(test, dart.functionType(core.bool, [E])); return new (_internal.SkipWhileIterable$(E))(this, test); } - take(count) { + [dartx.take](count) { return new (_internal.SubListIterable$(E))(this, 0, count); } - takeWhile(test) { + [dartx.takeWhile](test) { dart.as(test, dart.functionType(core.bool, [E])); return new (_internal.TakeWhileIterable$(E))(this, test); } - toList(opts) { + [dartx.toList](opts) { let growable = opts && 'growable' in opts ? opts.growable : true; let result = null; if (dart.notNull(growable)) { @@ -1746,50 +1798,50 @@ dart_library.library('dart/collection', null, /* Imports */[ result = core.List$(E).new(this[dartx.length]); } for (let i = 0; i < dart.notNull(this[dartx.length]); i++) { - result[dartx.set](i, this.get(i)); + result[dartx.set](i, this[dartx.get](i)); } return result; } - toSet() { + [dartx.toSet]() { let result = core.Set$(E).new(); for (let i = 0; i < dart.notNull(this[dartx.length]); i++) { - result.add(this.get(i)); + result.add(this[dartx.get](i)); } return result; } - add(element) { + [dartx.add](element) { dart.as(element, E); - this.set((() => { - let x = this.length; - this.length = dart.notNull(x) + 1; + this[dartx.set]((() => { + let x = this[dartx.length]; + this[dartx.length] = dart.notNull(x) + 1; return x; })(), element); } - addAll(iterable) { + [dartx.addAll](iterable) { dart.as(iterable, core.Iterable$(E)); for (let element of iterable) { - this.set((() => { - let x = this.length; - this.length = dart.notNull(x) + 1; + this[dartx.set]((() => { + let x = this[dartx.length]; + this[dartx.length] = dart.notNull(x) + 1; return x; })(), element); } } - remove(element) { - for (let i = 0; i < dart.notNull(this.length); i++) { - if (dart.equals(this.get(i), element)) { - this.setRange(i, dart.notNull(this.length) - 1, this, i + 1); - this.length = dart.notNull(this.length) - 1; + [dartx.remove](element) { + for (let i = 0; i < dart.notNull(this[dartx.length]); i++) { + if (dart.equals(this[dartx.get](i), element)) { + this[dartx.setRange](i, dart.notNull(this[dartx.length]) - 1, this, i + 1); + this[dartx.length] = dart.notNull(this[dartx.length]) - 1; return true; } } return false; } - removeWhere(test) { + [dartx.removeWhere](test) { dart.as(test, dart.functionType(core.bool, [E])); ListMixin$()._filter(this, test, false); } - retainWhere(test) { + [dartx.retainWhere](test) { dart.as(test, dart.functionType(core.bool, [E])); ListMixin$()._filter(this, test, true); } @@ -1811,72 +1863,72 @@ dart_library.library('dart/collection', null, /* Imports */[ source[dartx.length] = retained[dartx.length]; } } - clear() { - this.length = 0; + [dartx.clear]() { + this[dartx.length] = 0; } - removeLast() { + [dartx.removeLast]() { if (this[dartx.length] == 0) { dart.throw(_internal.IterableElementError.noElement()); } - let result = this.get(dart.notNull(this[dartx.length]) - 1); + let result = this[dartx.get](dart.notNull(this[dartx.length]) - 1); this[dartx.length] = dart.notNull(this[dartx.length]) - 1; return result; } - sort(compare) { + [dartx.sort](compare) { if (compare === void 0) compare = null; dart.as(compare, dart.functionType(core.int, [E, E])); _internal.Sort.sort(this, dart.as(compare == null ? core.Comparable.compare : compare, __CastType0)); } - shuffle(random) { + [dartx.shuffle](random) { if (random === void 0) random = null; if (random == null) random = math.Random.new(); - let length = this.length; + let length = this[dartx.length]; while (dart.notNull(length) > 1) { let pos = random.nextInt(length); length = dart.notNull(length) - 1; - let tmp = this.get(length); - this.set(length, this.get(pos)); - this.set(pos, tmp); + let tmp = this[dartx.get](length); + this[dartx.set](length, this[dartx.get](pos)); + this[dartx.set](pos, tmp); } } - asMap() { + [dartx.asMap]() { return new (_internal.ListMapView$(E))(this); } - sublist(start, end) { + [dartx.sublist](start, end) { if (end === void 0) end = null; - let listLength = this.length; + let listLength = this[dartx.length]; if (end == null) end = listLength; core.RangeError.checkValidRange(start, end, listLength); let length = dart.notNull(end) - dart.notNull(start); let result = core.List$(E).new(); result[dartx.length] = length; for (let i = 0; i < length; i++) { - result[dartx.set](i, this.get(dart.notNull(start) + i)); + result[dartx.set](i, this[dartx.get](dart.notNull(start) + i)); } return result; } - getRange(start, end) { - core.RangeError.checkValidRange(start, end, this.length); + [dartx.getRange](start, end) { + core.RangeError.checkValidRange(start, end, this[dartx.length]); return new (_internal.SubListIterable$(E))(this, start, end); } - removeRange(start, end) { - core.RangeError.checkValidRange(start, end, this.length); + [dartx.removeRange](start, end) { + core.RangeError.checkValidRange(start, end, this[dartx.length]); let length = dart.notNull(end) - dart.notNull(start); - this.setRange(start, dart.notNull(this.length) - length, this, end); - this.length = dart.notNull(this.length) - length; + this[dartx.setRange](start, dart.notNull(this[dartx.length]) - length, this, end); + this[dartx.length] = dart.notNull(this[dartx.length]) - length; } - fillRange(start, end, fill) { + [dartx.fillRange](start, end, fill) { if (fill === void 0) fill = null; dart.as(fill, E); - core.RangeError.checkValidRange(start, end, this.length); + core.RangeError.checkValidRange(start, end, this[dartx.length]); for (let i = start; dart.notNull(i) < dart.notNull(end); i = dart.notNull(i) + 1) { - this.set(i, fill); + this[dartx.set](i, fill); } } - setRange(start, end, iterable, skipCount) { + [dartx.setRange](start, end, iterable, skipCount) { dart.as(iterable, core.Iterable$(E)); if (skipCount === void 0) skipCount = 0; - core.RangeError.checkValidRange(start, end, this.length); + core.RangeError.checkValidRange(start, end, this[dartx.length]); let length = dart.notNull(end) - dart.notNull(start); if (length == 0) return; core.RangeError.checkNotNegative(skipCount, "skipCount"); @@ -1894,17 +1946,17 @@ dart_library.library('dart/collection', null, /* Imports */[ } if (dart.notNull(otherStart) < dart.notNull(start)) { for (let i = length - 1; i >= 0; i--) { - this.set(dart.notNull(start) + i, dart.as(otherList[dartx.get](dart.notNull(otherStart) + i), E)); + this[dartx.set](dart.notNull(start) + i, dart.as(otherList[dartx.get](dart.notNull(otherStart) + i), E)); } } else { for (let i = 0; i < length; i++) { - this.set(dart.notNull(start) + i, dart.as(otherList[dartx.get](dart.notNull(otherStart) + i), E)); + this[dartx.set](dart.notNull(start) + i, dart.as(otherList[dartx.get](dart.notNull(otherStart) + i), E)); } } } - replaceRange(start, end, newContents) { + [dartx.replaceRange](start, end, newContents) { dart.as(newContents, core.Iterable$(E)); - core.RangeError.checkValidRange(start, end, this.length); + core.RangeError.checkValidRange(start, end, this[dartx.length]); if (!dart.is(newContents, _internal.EfficientLength)) { newContents = newContents[dartx.toList](); } @@ -1913,91 +1965,91 @@ dart_library.library('dart/collection', null, /* Imports */[ if (removeLength >= dart.notNull(insertLength)) { let delta = removeLength - dart.notNull(insertLength); let insertEnd = dart.notNull(start) + dart.notNull(insertLength); - let newLength = dart.notNull(this.length) - delta; - this.setRange(start, insertEnd, newContents); + let newLength = dart.notNull(this[dartx.length]) - delta; + this[dartx.setRange](start, insertEnd, newContents); if (delta != 0) { - this.setRange(insertEnd, newLength, this, end); - this.length = newLength; + this[dartx.setRange](insertEnd, newLength, this, end); + this[dartx.length] = newLength; } } else { let delta = dart.notNull(insertLength) - removeLength; - let newLength = dart.notNull(this.length) + delta; + let newLength = dart.notNull(this[dartx.length]) + delta; let insertEnd = dart.notNull(start) + dart.notNull(insertLength); - this.length = newLength; - this.setRange(insertEnd, newLength, this, end); - this.setRange(start, insertEnd, newContents); + this[dartx.length] = newLength; + this[dartx.setRange](insertEnd, newLength, this, end); + this[dartx.setRange](start, insertEnd, newContents); } } - indexOf(element, startIndex) { + [dartx.indexOf](element, startIndex) { if (startIndex === void 0) startIndex = 0; - if (dart.notNull(startIndex) >= dart.notNull(this.length)) { + if (dart.notNull(startIndex) >= dart.notNull(this[dartx.length])) { return -1; } if (dart.notNull(startIndex) < 0) { startIndex = 0; } - for (let i = startIndex; dart.notNull(i) < dart.notNull(this.length); i = dart.notNull(i) + 1) { - if (dart.equals(this.get(i), element)) { + for (let i = startIndex; dart.notNull(i) < dart.notNull(this[dartx.length]); i = dart.notNull(i) + 1) { + if (dart.equals(this[dartx.get](i), element)) { return i; } } return -1; } - lastIndexOf(element, startIndex) { + [dartx.lastIndexOf](element, startIndex) { if (startIndex === void 0) startIndex = null; if (startIndex == null) { - startIndex = dart.notNull(this.length) - 1; + startIndex = dart.notNull(this[dartx.length]) - 1; } else { if (dart.notNull(startIndex) < 0) { return -1; } - if (dart.notNull(startIndex) >= dart.notNull(this.length)) { - startIndex = dart.notNull(this.length) - 1; + if (dart.notNull(startIndex) >= dart.notNull(this[dartx.length])) { + startIndex = dart.notNull(this[dartx.length]) - 1; } } for (let i = startIndex; dart.notNull(i) >= 0; i = dart.notNull(i) - 1) { - if (dart.equals(this.get(i), element)) { + if (dart.equals(this[dartx.get](i), element)) { return i; } } return -1; } - insert(index, element) { + [dartx.insert](index, element) { dart.as(element, E); core.RangeError.checkValueInInterval(index, 0, this[dartx.length], "index"); - if (index == this.length) { - this.add(element); + if (index == this[dartx.length]) { + this[dartx.add](element); return; } if (!(typeof index == 'number')) dart.throw(new core.ArgumentError(index)); - this.length = dart.notNull(this.length) + 1; - this.setRange(dart.notNull(index) + 1, this.length, this, index); - this.set(index, element); + this[dartx.length] = dart.notNull(this[dartx.length]) + 1; + this[dartx.setRange](dart.notNull(index) + 1, this[dartx.length], this, index); + this[dartx.set](index, element); } - removeAt(index) { - let result = this.get(index); - this.setRange(index, dart.notNull(this.length) - 1, this, dart.notNull(index) + 1); + [dartx.removeAt](index) { + let result = this[dartx.get](index); + this[dartx.setRange](index, dart.notNull(this[dartx.length]) - 1, this, dart.notNull(index) + 1); this[dartx.length] = dart.notNull(this[dartx.length]) - 1; return result; } - insertAll(index, iterable) { + [dartx.insertAll](index, iterable) { dart.as(iterable, core.Iterable$(E)); core.RangeError.checkValueInInterval(index, 0, this[dartx.length], "index"); if (dart.is(iterable, _internal.EfficientLength)) { iterable = iterable[dartx.toList](); } let insertionLength = iterable[dartx.length]; - this.length = dart.notNull(this.length) + dart.notNull(insertionLength); - this.setRange(dart.notNull(index) + dart.notNull(insertionLength), this.length, this, index); - this.setAll(index, iterable); + this[dartx.length] = dart.notNull(this[dartx.length]) + dart.notNull(insertionLength); + this[dartx.setRange](dart.notNull(index) + dart.notNull(insertionLength), this[dartx.length], this, index); + this[dartx.setAll](index, iterable); } - setAll(index, iterable) { + [dartx.setAll](index, iterable) { dart.as(iterable, core.Iterable$(E)); if (dart.is(iterable, core.List)) { - this.setRange(index, dart.notNull(index) + dart.notNull(iterable[dartx.length]), iterable); + this[dartx.setRange](index, dart.notNull(index) + dart.notNull(iterable[dartx.length]), iterable); } else { for (let element of iterable) { - this.set((() => { + this[dartx.set]((() => { let x = index; index = dart.notNull(x) + 1; return x; @@ -2005,7 +2057,7 @@ dart_library.library('dart/collection', null, /* Imports */[ } } } - get reversed() { + get [dartx.reversed]() { return new (_internal.ReversedListIterable$(E))(this); } toString() { @@ -2015,103 +2067,52 @@ dart_library.library('dart/collection', null, /* Imports */[ ListMixin[dart.implements] = () => [core.List$(E)]; dart.setSignature(ListMixin, { methods: () => ({ - elementAt: [E, [core.int]], - forEach: [dart.void, [dart.functionType(dart.void, [E])]], - contains: [core.bool, [core.Object]], - every: [core.bool, [dart.functionType(core.bool, [E])]], - any: [core.bool, [dart.functionType(core.bool, [E])]], - firstWhere: [E, [dart.functionType(core.bool, [E])], {orElse: dart.functionType(E, [])}], - lastWhere: [E, [dart.functionType(core.bool, [E])], {orElse: dart.functionType(E, [])}], - singleWhere: [E, [dart.functionType(core.bool, [E])]], - join: [core.String, [], [core.String]], - where: [core.Iterable$(E), [dart.functionType(core.bool, [E])]], - map: [core.Iterable, [dart.functionType(dart.dynamic, [E])]], - expand: [core.Iterable, [dart.functionType(core.Iterable, [E])]], - reduce: [E, [dart.functionType(E, [E, E])]], - fold: [dart.dynamic, [dart.dynamic, dart.functionType(dart.dynamic, [dart.dynamic, E])]], - skip: [core.Iterable$(E), [core.int]], - skipWhile: [core.Iterable$(E), [dart.functionType(core.bool, [E])]], - take: [core.Iterable$(E), [core.int]], - takeWhile: [core.Iterable$(E), [dart.functionType(core.bool, [E])]], - toList: [core.List$(E), [], {growable: core.bool}], - toSet: [core.Set$(E), []], - add: [dart.void, [E]], - addAll: [dart.void, [core.Iterable$(E)]], - remove: [core.bool, [core.Object]], - removeWhere: [dart.void, [dart.functionType(core.bool, [E])]], - retainWhere: [dart.void, [dart.functionType(core.bool, [E])]], - clear: [dart.void, []], - removeLast: [E, []], - sort: [dart.void, [], [dart.functionType(core.int, [E, E])]], - shuffle: [dart.void, [], [math.Random]], - asMap: [core.Map$(core.int, E), []], - sublist: [core.List$(E), [core.int], [core.int]], - getRange: [core.Iterable$(E), [core.int, core.int]], - removeRange: [dart.void, [core.int, core.int]], - fillRange: [dart.void, [core.int, core.int], [E]], - setRange: [dart.void, [core.int, core.int, core.Iterable$(E)], [core.int]], - replaceRange: [dart.void, [core.int, core.int, core.Iterable$(E)]], - indexOf: [core.int, [core.Object], [core.int]], - lastIndexOf: [core.int, [core.Object], [core.int]], - insert: [dart.void, [core.int, E]], - removeAt: [E, [core.int]], - insertAll: [dart.void, [core.int, core.Iterable$(E)]], - setAll: [dart.void, [core.int, core.Iterable$(E)]] + [dartx.elementAt]: [E, [core.int]], + [dartx.forEach]: [dart.void, [dart.functionType(dart.void, [E])]], + [dartx.contains]: [core.bool, [core.Object]], + [dartx.every]: [core.bool, [dart.functionType(core.bool, [E])]], + [dartx.any]: [core.bool, [dart.functionType(core.bool, [E])]], + [dartx.firstWhere]: [E, [dart.functionType(core.bool, [E])], {orElse: dart.functionType(E, [])}], + [dartx.lastWhere]: [E, [dart.functionType(core.bool, [E])], {orElse: dart.functionType(E, [])}], + [dartx.singleWhere]: [E, [dart.functionType(core.bool, [E])]], + [dartx.join]: [core.String, [], [core.String]], + [dartx.where]: [core.Iterable$(E), [dart.functionType(core.bool, [E])]], + [dartx.map]: [core.Iterable, [dart.functionType(dart.dynamic, [E])]], + [dartx.expand]: [core.Iterable, [dart.functionType(core.Iterable, [E])]], + [dartx.reduce]: [E, [dart.functionType(E, [E, E])]], + [dartx.fold]: [dart.dynamic, [dart.dynamic, dart.functionType(dart.dynamic, [dart.dynamic, E])]], + [dartx.skip]: [core.Iterable$(E), [core.int]], + [dartx.skipWhile]: [core.Iterable$(E), [dart.functionType(core.bool, [E])]], + [dartx.take]: [core.Iterable$(E), [core.int]], + [dartx.takeWhile]: [core.Iterable$(E), [dart.functionType(core.bool, [E])]], + [dartx.toList]: [core.List$(E), [], {growable: core.bool}], + [dartx.toSet]: [core.Set$(E), []], + [dartx.add]: [dart.void, [E]], + [dartx.addAll]: [dart.void, [core.Iterable$(E)]], + [dartx.remove]: [core.bool, [core.Object]], + [dartx.removeWhere]: [dart.void, [dart.functionType(core.bool, [E])]], + [dartx.retainWhere]: [dart.void, [dart.functionType(core.bool, [E])]], + [dartx.clear]: [dart.void, []], + [dartx.removeLast]: [E, []], + [dartx.sort]: [dart.void, [], [dart.functionType(core.int, [E, E])]], + [dartx.shuffle]: [dart.void, [], [math.Random]], + [dartx.asMap]: [core.Map$(core.int, E), []], + [dartx.sublist]: [core.List$(E), [core.int], [core.int]], + [dartx.getRange]: [core.Iterable$(E), [core.int, core.int]], + [dartx.removeRange]: [dart.void, [core.int, core.int]], + [dartx.fillRange]: [dart.void, [core.int, core.int], [E]], + [dartx.setRange]: [dart.void, [core.int, core.int, core.Iterable$(E)], [core.int]], + [dartx.replaceRange]: [dart.void, [core.int, core.int, core.Iterable$(E)]], + [dartx.indexOf]: [core.int, [core.Object], [core.int]], + [dartx.lastIndexOf]: [core.int, [core.Object], [core.int]], + [dartx.insert]: [dart.void, [core.int, E]], + [dartx.removeAt]: [E, [core.int]], + [dartx.insertAll]: [dart.void, [core.int, core.Iterable$(E)]], + [dartx.setAll]: [dart.void, [core.int, core.Iterable$(E)]] }), statics: () => ({_filter: [dart.void, [core.List, dart.functionType(core.bool, [dart.dynamic]), core.bool]]}), names: ['_filter'] }); - dart.defineExtensionMembers(ListMixin, [ - 'elementAt', - 'forEach', - 'contains', - 'every', - 'any', - 'firstWhere', - 'lastWhere', - 'singleWhere', - 'join', - 'where', - 'map', - 'expand', - 'reduce', - 'fold', - 'skip', - 'skipWhile', - 'take', - 'takeWhile', - 'toList', - 'toSet', - 'add', - 'addAll', - 'remove', - 'removeWhere', - 'retainWhere', - 'clear', - 'removeLast', - 'sort', - 'shuffle', - 'asMap', - 'sublist', - 'getRange', - 'removeRange', - 'fillRange', - 'setRange', - 'replaceRange', - 'indexOf', - 'lastIndexOf', - 'insert', - 'removeAt', - 'insertAll', - 'setAll', - 'iterator', - 'isEmpty', - 'isNotEmpty', - 'first', - 'last', - 'single', - 'reversed' - ]); return ListMixin; }); let ListMixin = ListMixin$(); diff --git a/pkg/dev_compiler/lib/runtime/dart/convert.js b/pkg/dev_compiler/lib/runtime/dart/convert.js index 149bcbc14965..f968486b286e 100644 --- a/pkg/dev_compiler/lib/runtime/dart/convert.js +++ b/pkg/dev_compiler/lib/runtime/dart/convert.js @@ -917,9 +917,9 @@ dart_library.library('dart/convert', null, /* Imports */[ convert(object) { let bytes = dart.list([], core.List$(core.int)); function addChunk(chunk, start, end) { - if (dart.notNull(start) > 0 || dart.notNull(end) < dart.notNull(chunk.length)) { + if (dart.notNull(start) > 0 || dart.notNull(end) < dart.notNull(chunk[dartx.length])) { let length = dart.notNull(end) - dart.notNull(start); - chunk = typed_data.Uint8List.view(chunk.buffer, dart.notNull(chunk.offsetInBytes) + dart.notNull(start), length); + chunk = typed_data.Uint8List.view(chunk[dartx.buffer], dart.notNull(chunk[dartx.offsetInBytes]) + dart.notNull(start), length); } bytes[dartx.add](chunk); } @@ -934,7 +934,7 @@ dart_library.library('dart/convert', null, /* Imports */[ for (let i = 0, offset = 0; i < dart.notNull(bytes[dartx.length]); i++) { let byteList = bytes[dartx.get](i); let end = offset + dart.notNull(byteList[dartx.length]); - result.setRange(offset, end, byteList); + result[dartx.setRange](offset, end, byteList); offset = end; } return result; @@ -1459,12 +1459,12 @@ dart_library.library('dart/convert', null, /* Imports */[ } writeByte(byte) { dart.assert(dart.notNull(byte) <= 255); - if (this.index == this.buffer.length) { + if (this.index == this.buffer[dartx.length]) { dart.dcall(this.addChunk, this.buffer, 0, this.index); this.buffer = typed_data.Uint8List.new(this.bufferSize); this.index = 0; } - this.buffer.set((() => { + this.buffer[dartx.set]((() => { let x = this.index; this.index = dart.notNull(x) + 1; return x; @@ -1506,8 +1506,8 @@ dart_library.library('dart/convert', null, /* Imports */[ while (dart.notNull(count) > 0) { count = dart.notNull(count) - 1; let end = dart.notNull(this.index) + dart.notNull(indentLength); - if (end <= dart.notNull(this.buffer.length)) { - this.buffer.setRange(this.index, end, indent); + if (end <= dart.notNull(this.buffer[dartx.length])) { + this.buffer[dartx.setRange](this.index, end, indent); this.index = end; } else { for (let i = 0; i < dart.notNull(indentLength); i++) { diff --git a/pkg/dev_compiler/lib/runtime/dart/html.js b/pkg/dev_compiler/lib/runtime/dart/html.js index 28397f300458..33ddd5c5cd15 100644 --- a/pkg/dev_compiler/lib/runtime/dart/html.js +++ b/pkg/dev_compiler/lib/runtime/dart/html.js @@ -5273,7 +5273,7 @@ dart_library.library('dart/html', null, /* Imports */[ return value; } get iterator() { - return this.toList()[dartx.iterator]; + return this[dartx.toList]()[dartx.iterator]; } addAll(iterable) { if (dart.is(iterable, _ChildNodeListLazy)) { diff --git a/pkg/dev_compiler/lib/runtime/dart/typed_data.js b/pkg/dev_compiler/lib/runtime/dart/typed_data.js index 2b13d81d183b..edeb05c52147 100644 --- a/pkg/dev_compiler/lib/runtime/dart/typed_data.js +++ b/pkg/dev_compiler/lib/runtime/dart/typed_data.js @@ -26,7 +26,7 @@ dart_library.library('dart/typed_data', null, /* Imports */[ return dart.const(new Endianness._(true)); }, get HOST_ENDIAN() { - return ByteData.view(Uint16List.fromList(dart.list([1], core.int)).buffer).getInt8(0) == 1 ? Endianness.LITTLE_ENDIAN : Endianness.BIG_ENDIAN; + return ByteData.view(Uint16List.fromList(dart.list([1], core.int))[dartx.buffer])[dartx.getInt8](0) == 1 ? Endianness.LITTLE_ENDIAN : Endianness.BIG_ENDIAN; } }); class ByteData extends core.Object { @@ -36,7 +36,7 @@ dart_library.library('dart/typed_data', null, /* Imports */[ static view(buffer, offsetInBytes, length) { if (offsetInBytes === void 0) offsetInBytes = 0; if (length === void 0) length = null; - return buffer.asByteData(offsetInBytes, length); + return buffer[dartx.asByteData](offsetInBytes, length); } } ByteData[dart.implements] = () => [TypedData]; @@ -56,7 +56,7 @@ dart_library.library('dart/typed_data', null, /* Imports */[ static view(buffer, offsetInBytes, length) { if (offsetInBytes === void 0) offsetInBytes = 0; if (length === void 0) length = null; - return buffer.asInt8List(offsetInBytes, length); + return buffer[dartx.asInt8List](offsetInBytes, length); } } Int8List[dart.implements] = () => [core.List$(core.int), TypedData]; @@ -78,7 +78,7 @@ dart_library.library('dart/typed_data', null, /* Imports */[ static view(buffer, offsetInBytes, length) { if (offsetInBytes === void 0) offsetInBytes = 0; if (length === void 0) length = null; - return buffer.asUint8List(offsetInBytes, length); + return buffer[dartx.asUint8List](offsetInBytes, length); } } Uint8List[dart.implements] = () => [core.List$(core.int), TypedData]; @@ -100,7 +100,7 @@ dart_library.library('dart/typed_data', null, /* Imports */[ static view(buffer, offsetInBytes, length) { if (offsetInBytes === void 0) offsetInBytes = 0; if (length === void 0) length = null; - return buffer.asUint8ClampedList(offsetInBytes, length); + return buffer[dartx.asUint8ClampedList](offsetInBytes, length); } } Uint8ClampedList[dart.implements] = () => [core.List$(core.int), TypedData]; @@ -122,7 +122,7 @@ dart_library.library('dart/typed_data', null, /* Imports */[ static view(buffer, offsetInBytes, length) { if (offsetInBytes === void 0) offsetInBytes = 0; if (length === void 0) length = null; - return buffer.asInt16List(offsetInBytes, length); + return buffer[dartx.asInt16List](offsetInBytes, length); } } Int16List[dart.implements] = () => [core.List$(core.int), TypedData]; @@ -144,7 +144,7 @@ dart_library.library('dart/typed_data', null, /* Imports */[ static view(buffer, offsetInBytes, length) { if (offsetInBytes === void 0) offsetInBytes = 0; if (length === void 0) length = null; - return buffer.asUint16List(offsetInBytes, length); + return buffer[dartx.asUint16List](offsetInBytes, length); } } Uint16List[dart.implements] = () => [core.List$(core.int), TypedData]; @@ -166,7 +166,7 @@ dart_library.library('dart/typed_data', null, /* Imports */[ static view(buffer, offsetInBytes, length) { if (offsetInBytes === void 0) offsetInBytes = 0; if (length === void 0) length = null; - return buffer.asInt32List(offsetInBytes, length); + return buffer[dartx.asInt32List](offsetInBytes, length); } } Int32List[dart.implements] = () => [core.List$(core.int), TypedData]; @@ -188,7 +188,7 @@ dart_library.library('dart/typed_data', null, /* Imports */[ static view(buffer, offsetInBytes, length) { if (offsetInBytes === void 0) offsetInBytes = 0; if (length === void 0) length = null; - return buffer.asUint32List(offsetInBytes, length); + return buffer[dartx.asUint32List](offsetInBytes, length); } } Uint32List[dart.implements] = () => [core.List$(core.int), TypedData]; @@ -210,7 +210,7 @@ dart_library.library('dart/typed_data', null, /* Imports */[ static view(buffer, offsetInBytes, length) { if (offsetInBytes === void 0) offsetInBytes = 0; if (length === void 0) length = null; - return buffer.asInt64List(offsetInBytes, length); + return buffer[dartx.asInt64List](offsetInBytes, length); } } Int64List[dart.implements] = () => [core.List$(core.int), TypedData]; @@ -232,7 +232,7 @@ dart_library.library('dart/typed_data', null, /* Imports */[ static view(buffer, offsetInBytes, length) { if (offsetInBytes === void 0) offsetInBytes = 0; if (length === void 0) length = null; - return buffer.asUint64List(offsetInBytes, length); + return buffer[dartx.asUint64List](offsetInBytes, length); } } Uint64List[dart.implements] = () => [core.List$(core.int), TypedData]; @@ -254,7 +254,7 @@ dart_library.library('dart/typed_data', null, /* Imports */[ static view(buffer, offsetInBytes, length) { if (offsetInBytes === void 0) offsetInBytes = 0; if (length === void 0) length = null; - return buffer.asFloat32List(offsetInBytes, length); + return buffer[dartx.asFloat32List](offsetInBytes, length); } } Float32List[dart.implements] = () => [core.List$(core.double), TypedData]; @@ -276,7 +276,7 @@ dart_library.library('dart/typed_data', null, /* Imports */[ static view(buffer, offsetInBytes, length) { if (offsetInBytes === void 0) offsetInBytes = 0; if (length === void 0) length = null; - return buffer.asFloat64List(offsetInBytes, length); + return buffer[dartx.asFloat64List](offsetInBytes, length); } } Float64List[dart.implements] = () => [core.List$(core.double), TypedData]; @@ -298,7 +298,7 @@ dart_library.library('dart/typed_data', null, /* Imports */[ static view(buffer, offsetInBytes, length) { if (offsetInBytes === void 0) offsetInBytes = 0; if (length === void 0) length = null; - return buffer.asFloat32x4List(offsetInBytes, length); + return buffer[dartx.asFloat32x4List](offsetInBytes, length); } } Float32x4List[dart.implements] = () => [core.List$(Float32x4), TypedData]; @@ -320,7 +320,7 @@ dart_library.library('dart/typed_data', null, /* Imports */[ static view(buffer, offsetInBytes, length) { if (offsetInBytes === void 0) offsetInBytes = 0; if (length === void 0) length = null; - return buffer.asInt32x4List(offsetInBytes, length); + return buffer[dartx.asInt32x4List](offsetInBytes, length); } } Int32x4List[dart.implements] = () => [core.List$(Int32x4), TypedData]; @@ -342,7 +342,7 @@ dart_library.library('dart/typed_data', null, /* Imports */[ static view(buffer, offsetInBytes, length) { if (offsetInBytes === void 0) offsetInBytes = 0; if (length === void 0) length = null; - return buffer.asFloat64x2List(offsetInBytes, length); + return buffer[dartx.asFloat64x2List](offsetInBytes, length); } } Float64x2List[dart.implements] = () => [core.List$(Float64x2), TypedData]; diff --git a/pkg/dev_compiler/lib/src/codegen/js_codegen.dart b/pkg/dev_compiler/lib/src/codegen/js_codegen.dart index 64ab40352f67..b41607f168ac 100644 --- a/pkg/dev_compiler/lib/src/codegen/js_codegen.dart +++ b/pkg/dev_compiler/lib/src/codegen/js_codegen.dart @@ -10,6 +10,7 @@ import 'package:analyzer/analyzer.dart' hide ConstantEvaluator; import 'package:analyzer/src/generated/ast.dart' hide ConstantEvaluator; import 'package:analyzer/src/generated/constant.dart'; import 'package:analyzer/src/generated/element.dart'; +import 'package:analyzer/src/generated/engine.dart' show AnalysisContext; import 'package:analyzer/src/generated/resolver.dart' show TypeProvider; import 'package:analyzer/src/generated/scanner.dart' show StringToken, Token, TokenType; @@ -218,10 +219,7 @@ class JSCodegenVisitor extends GeneralizingAstVisitor // String scriptTag = null; // if (library.library.scriptTag != null) scriptTag = '/usr/bin/env $jsBin'; return moduleBuilder.build( - currentModuleName, - _jsModuleValue, - _exportsVar, - items); + currentModuleName, _jsModuleValue, _exportsVar, items); } void _emitModuleItem(AstNode node) { @@ -439,9 +437,17 @@ class JSCodegenVisitor extends GeneralizingAstVisitor String jsPeerName; var jsPeer = findAnnotation(classElem, isJsPeerInterface); + // Only look at "Native" annotations on registered extension types. + // E.g., we're current ignoring the ones in dart:html. + if (jsPeer == null && _extensionTypes.contains(classElem)) { + jsPeer = findAnnotation(classElem, isNativeAnnotation); + } if (jsPeer != null) { jsPeerName = getConstantField(jsPeer, 'name', types.stringType)?.toStringValue(); + if (jsPeerName.contains(',')) { + jsPeerName = jsPeerName.split(',')[0]; + } } var body = _finishClassMembers(classElem, classExpr, ctors, fields, @@ -1322,17 +1328,49 @@ class JSCodegenVisitor extends GeneralizingAstVisitor } } + JS.Fun _emitNativeFunctionBody( + List params, MethodDeclaration node) { + if (node.isStatic) { + // TODO(vsm): Do we need to handle this case? + return null; + } + + String name = node.name.name; + var annotation = findAnnotation(node.element, isJsName); + if (annotation != null) { + name = getConstantField(annotation, 'name', types.stringType) + ?.toStringValue(); + } + if (node.isGetter) { + return new JS.Fun(params, js.statement('{ return this.#; }', [name])); + } else if (node.isSetter) { + return new JS.Fun( + params, js.statement('{ this.# = #; }', [name, params.last])); + } else { + return new JS.Fun( + params, js.statement('{ return this.#(#); }', [name, params])); + } + } + JS.Method _emitMethodDeclaration(DartType type, MethodDeclaration node) { - if (node.isAbstract || _externalOrNative(node)) { + if (node.isAbstract) { return null; } var params = _visit(node.parameters) as List; if (params == null) params = []; - var typeParams = _emitTypeParams(node.element).toList(); - var returnType = emitTypeRef(node.element.returnType); - JS.Fun fn = _emitFunctionBody(params, node.body, typeParams, returnType); + JS.Fun fn; + if (_externalOrNative(node)) { + fn = _emitNativeFunctionBody(params, node); + // TODO(vsm): Remove if / when we handle the static case above. + if (fn == null) return null; + } else { + var typeParams = _emitTypeParams(node.element).toList(); + var returnType = emitTypeRef(node.element.returnType); + fn = _emitFunctionBody(params, node.body, typeParams, returnType); + } + if (node.operatorKeyword != null && node.name.name == '[]=' && params.isNotEmpty) { @@ -2931,7 +2969,10 @@ class JSCodegenVisitor extends GeneralizingAstVisitor if (!_isObjectProperty(memberName)) { return false; } - if (!type.isObject && !_isJSBuiltinType(type) && !_isNullable(target)) { + if (!type.isObject && + !_isJSBuiltinType(type) && + !_extensionTypes.contains(type.element) && + !_isNullable(target)) { return false; } return true; @@ -3625,27 +3666,18 @@ class JSCodegenVisitor extends GeneralizingAstVisitor } } -class JSGenerator extends CodeGenerator { - final _extensionTypes = new HashSet(); +class _ExtensionFinder extends GeneralizingElementVisitor { + final AnalysisContext _context; + final HashSet _extensionTypes; final TypeProvider _types; - JSGenerator(AbstractCompiler compiler) - : _types = compiler.context.typeProvider, - super(compiler) { - // TODO(jacobr): determine the the set of types with extension methods from - // the annotations rather than hard coding the list once the analyzer - // supports summaries. - var context = compiler.context; - var src = context.sourceFactory.forUri('dart:_interceptors'); - var interceptors = context.computeLibraryElement(src); - for (var t in ['JSArray', 'JSString', 'JSNumber', 'JSBool']) { - _addExtensionType(interceptors.getType(t).type); + + _ExtensionFinder(this._context, this._extensionTypes, this._types); + + visitClassElement(ClassElement element) { + if (findAnnotation(element, isJsPeerInterface) != null || + findAnnotation(element, isNativeAnnotation) != null) { + _addExtensionType(element.type); } - // TODO(jmesserly): manually add `int` and `double` - // Unfortunately our current analyzer rejects "implements int". - // Fix was landed, so we can remove this hack once we're updated: - // https://github.com/dart-lang/sdk/commit/d7cd11f86a02f55269fc8d9843e7758ebeeb81c8 - _addExtensionType(_types.intType); - _addExtensionType(_types.doubleType); } void _addExtensionType(InterfaceType t) { @@ -3656,6 +3688,35 @@ class JSGenerator extends CodeGenerator { _addExtensionType(t.superclass); } + void _addExtensionTypes(String libraryUri) { + var sourceFactory = _context.sourceFactory.forUri(libraryUri); + var library = _context.computeLibraryElement(sourceFactory); + visitLibraryElement(library); + } +} + +class JSGenerator extends CodeGenerator { + final _extensionTypes = new HashSet(); + final TypeProvider _types; + + JSGenerator(AbstractCompiler compiler) + : _types = compiler.context.typeProvider, + super(compiler) { + // TODO(vsm): Eventually, we want to make this extensible - i.e., find + // annotations in user code as well. It would need to be summarized in + // the element model - not searched this way on every compile. + var finder = new _ExtensionFinder(context, _extensionTypes, _types); + finder._addExtensionTypes('dart:_interceptors'); + finder._addExtensionTypes('dart:_native_typed_data'); + + // TODO(vsm): If we're analyzing against the main SDK, those + // types are not explicitly annotated. + finder._addExtensionType(_types.intType); + finder._addExtensionType(_types.doubleType); + finder._addExtensionType(_types.boolType); + finder._addExtensionType(_types.stringType); + } + String generateLibrary(LibraryUnit unit) { // Clone the AST first, so we can mutate it. unit = unit.clone(); diff --git a/pkg/dev_compiler/lib/src/codegen/js_interop.dart b/pkg/dev_compiler/lib/src/codegen/js_interop.dart index 73a03deb1bfa..54fc8fccb35a 100644 --- a/pkg/dev_compiler/lib/src/codegen/js_interop.dart +++ b/pkg/dev_compiler/lib/src/codegen/js_interop.dart @@ -35,14 +35,25 @@ bool isJsSpreadInvocation(MethodInvocation i) => bool isJSAnnotation(DartObjectImpl value) => _isJsLibType('JS', value.type.element); -/// Whether [value] is a `@JSExportName` (internal annotation used in SDK -/// instead of `@JS` from `package:js`). -bool isJSExportNameAnnotation(DartObjectImpl value) { +bool _isBuiltinAnnotation( + DartObjectImpl value, String libraryName, String annotationName) { var e = value?.type?.element; - if (e?.name != 'JSExportName') return false; + if (e?.name != annotationName) return false; var uri = e.source.uri; - return uri.scheme == 'dart' && uri.path == '_foreign_helper'; + var path = uri.pathSegments[0]; + return uri.scheme == 'dart' && path == libraryName; } +/// Whether [value] is a `@JSExportName` (internal annotation used in SDK +/// instead of `@JS` from `package:js`). +bool isJSExportNameAnnotation(DartObjectImpl value) => + _isBuiltinAnnotation(value, '_foreign_helper', 'JSExportName'); + +bool isJsName(DartObjectImpl value) => + _isBuiltinAnnotation(value, '_js_helper', 'JSName'); + bool isJsPeerInterface(DartObjectImpl value) => - value.type.name == 'JsPeerInterface'; + _isBuiltinAnnotation(value, '_js_helper', 'JsPeerInterface'); + +bool isNativeAnnotation(DartObjectImpl value) => + _isBuiltinAnnotation(value, '_js_helper', 'Native'); diff --git a/pkg/dev_compiler/lib/src/codegen/module_builder.dart b/pkg/dev_compiler/lib/src/codegen/module_builder.dart index e34efc87b445..6e20cd314727 100644 --- a/pkg/dev_compiler/lib/src/codegen/module_builder.dart +++ b/pkg/dev_compiler/lib/src/codegen/module_builder.dart @@ -155,8 +155,7 @@ class ES6ModuleBuilder extends ModuleBuilder { .add(js.statement('#.# = #;', [exportsVar, exportName, name])); }); } - moduleStatements - .add(new JS.ExportDeclaration(exportsVar, isDefault: true)); + moduleStatements.add(new JS.ExportDeclaration(exportsVar, isDefault: true)); // TODO(ochafik): What to do with jsModuleValue? return new JS.Program(moduleStatements); } diff --git a/pkg/dev_compiler/test/browser/language_tests.js b/pkg/dev_compiler/test/browser/language_tests.js index 794138398d26..0dc3631b7e93 100644 --- a/pkg/dev_compiler/test/browser/language_tests.js +++ b/pkg/dev_compiler/test/browser/language_tests.js @@ -14,7 +14,7 @@ 'language': { expectedFailures: new Set([ 'arithmetic2_test', - 'assert_with_type_test_or_cast_test', + 'assert_with_type_test_or_cast_test', 'assertion_test', 'async_star_await_pauses_test', 'async_star_cancel_while_paused_test', @@ -326,40 +326,27 @@ }, 'lib/typed_data': { expectedFailures: new Set([ - 'byte_data_test', - 'constructor_checks_test', - 'endianness_test', - 'float32x4_clamp_test', - 'float32x4_cross_test', - 'float32x4_list_test', - 'float32x4_shuffle_test', - 'float32x4_sign_mask_test', - 'float32x4_transpose_test', - 'float32x4_two_arg_shuffle_test', - 'float32x4_unbox_phi_test', - 'float32x4_unbox_regress_test', - 'float64x2_typed_list_test', - 'int32x4_arithmetic_test', - 'int32x4_bigint_test', - 'int32x4_list_test', - 'int32x4_shuffle_test', - 'int32x4_sign_mask_test', - 'int64_list_load_store_test', - 'native_interceptor_no_own_method_to_intercept_test', - 'setRange_1_test', - 'setRange_2_test', - 'setRange_3_test', - 'setRange_4_test', - 'setRange_5_test', - 'simd_store_to_load_forward_test', - 'typed_data_from_list_test', - 'typed_data_hierarchy_int64_test', - 'typed_data_hierarchy_test', - 'typed_data_list_test', - 'typed_data_load2_test', - 'typed_data_load_test', - 'typed_data_sublist_type_test', - 'typed_list_iterable_test', + // TODO(vsm): Right shift should not propagate sign + // https://github.com/dart-lang/dev_compiler/issues/446 + 'float32x4_sign_mask_test', + 'int32x4_sign_mask_test', + + // No bigint or int64 support + 'int32x4_bigint_test', + 'int64_list_load_store_test', + 'typed_data_hierarchy_int64_test', + + // TODO(vsm): List.toString is different in DDC + // https://github.com/dart-lang/dev_compiler/issues/445 + 'setRange_1_test', + 'setRange_2_test', + 'setRange_3_test', + 'setRange_4_test', + 'setRange_5_test', + + // TODO(vsm): Triage further + // exports._GeneratorIterable$ is not a function + 'typed_data_list_test', ]), helpers: new Set([ ]) diff --git a/pkg/dev_compiler/test/codegen/expect/collection/src/unmodifiable_wrappers.txt b/pkg/dev_compiler/test/codegen/expect/collection/src/unmodifiable_wrappers.txt index f1348aceb8bc..01c0f87082db 100644 --- a/pkg/dev_compiler/test/codegen/expect/collection/src/unmodifiable_wrappers.txt +++ b/pkg/dev_compiler/test/codegen/expect/collection/src/unmodifiable_wrappers.txt @@ -1,6 +1,6 @@ // Messages from compiling unmodifiable_wrappers.dart -severe: [AnalyzerMessage] Missing concrete implementation of 'Iterable.map' and 'Iterable.expand' (package:collection/src/unmodifiable_wrappers.dart, line 20, col 7) -severe: [AnalyzerMessage] Missing concrete implementation of 'Iterable.expand' and 'Iterable.map' (package:collection/src/unmodifiable_wrappers.dart, line 93, col 7) +severe: [AnalyzerMessage] Missing concrete implementation of 'Iterable.expand' and 'Iterable.map' (package:collection/src/unmodifiable_wrappers.dart, line 20, col 7) +severe: [AnalyzerMessage] Missing concrete implementation of 'Iterable.map' and 'Iterable.expand' (package:collection/src/unmodifiable_wrappers.dart, line 93, col 7) warning: [DOWN_CAST_COMPOSITE] Unsound implicit cast from dynamic to E (package:collection/src/unmodifiable_wrappers.dart, line 59, col 28) warning: [DOWN_CAST_COMPOSITE] Unsound implicit cast from dynamic to E (package:collection/src/unmodifiable_wrappers.dart, line 63, col 21) warning: [DOWN_CAST_COMPOSITE] Unsound implicit cast from dynamic to V (package:collection/src/unmodifiable_wrappers.dart, line 151, col 41) diff --git a/pkg/dev_compiler/test/codegen/expect/collection/src/wrappers.txt b/pkg/dev_compiler/test/codegen/expect/collection/src/wrappers.txt index 3be4c77ea948..37601fcff937 100644 --- a/pkg/dev_compiler/test/codegen/expect/collection/src/wrappers.txt +++ b/pkg/dev_compiler/test/codegen/expect/collection/src/wrappers.txt @@ -4,10 +4,10 @@ severe: [INVALID_METHOD_OVERRIDE] Invalid override. The type of _DelegatingItera severe: [AnalyzerMessage] Missing concrete implementation of 'Iterable.map' and 'Iterable.expand' (package:collection/src/wrappers.dart, line 97, col 7) severe: [INVALID_METHOD_OVERRIDE] Base class introduces an invalid override. The type of _DelegatingIterableBase.expand (((E) → Iterable) → Iterable) is not a subtype of Iterable.expand (((E) → Iterable) → Iterable). (package:collection/src/wrappers.dart, line 97, col 25) severe: [INVALID_METHOD_OVERRIDE] Base class introduces an invalid override. The type of _DelegatingIterableBase.map (((E) → dynamic) → Iterable) is not a subtype of Iterable.map (((E) → T) → Iterable). (package:collection/src/wrappers.dart, line 97, col 25) -severe: [AnalyzerMessage] Missing concrete implementation of 'Iterable.expand' and 'Iterable.map' (package:collection/src/wrappers.dart, line 194, col 7) +severe: [AnalyzerMessage] Missing concrete implementation of 'Iterable.map' and 'Iterable.expand' (package:collection/src/wrappers.dart, line 194, col 7) severe: [INVALID_METHOD_OVERRIDE] Base class introduces an invalid override. The type of _DelegatingIterableBase.expand (((E) → Iterable) → Iterable) is not a subtype of Iterable.expand (((E) → Iterable) → Iterable). (package:collection/src/wrappers.dart, line 194, col 24) severe: [INVALID_METHOD_OVERRIDE] Base class introduces an invalid override. The type of _DelegatingIterableBase.map (((E) → dynamic) → Iterable) is not a subtype of Iterable.map (((E) → T) → Iterable). (package:collection/src/wrappers.dart, line 194, col 24) -severe: [AnalyzerMessage] Missing concrete implementation of 'Iterable.expand' and 'Iterable.map' (package:collection/src/wrappers.dart, line 245, col 7) +severe: [AnalyzerMessage] Missing concrete implementation of 'Iterable.map' and 'Iterable.expand' (package:collection/src/wrappers.dart, line 245, col 7) severe: [INVALID_METHOD_OVERRIDE] Base class introduces an invalid override. The type of _DelegatingIterableBase.expand (((E) → Iterable) → Iterable) is not a subtype of Iterable.expand (((E) → Iterable) → Iterable). (package:collection/src/wrappers.dart, line 245, col 26) severe: [INVALID_METHOD_OVERRIDE] Base class introduces an invalid override. The type of _DelegatingIterableBase.map (((E) → dynamic) → Iterable) is not a subtype of Iterable.map (((E) → T) → Iterable). (package:collection/src/wrappers.dart, line 245, col 26) severe: [AnalyzerMessage] Missing concrete implementation of 'Iterable.map' and 'Iterable.expand' (package:collection/src/wrappers.dart, line 339, col 7) diff --git a/pkg/dev_compiler/test/codegen/expect/dom/dom.js b/pkg/dev_compiler/test/codegen/expect/dom/dom.js index c577cada7d04..9640c32a5fa5 100644 --- a/pkg/dev_compiler/test/codegen/expect/dom/dom.js +++ b/pkg/dev_compiler/test/codegen/expect/dom/dom.js @@ -17,7 +17,11 @@ dart_library.library('dom/dom', window, /* Imports */[ dart.setSignature(CustomEvent, { constructors: () => ({CustomEvent: [CustomEvent, [core.String], {detail: dart.dynamic, bubbles: dart.dynamic, cancelable: dart.dynamic}]}) }); - class HTMLCollection extends core.Object {} + class HTMLCollection extends core.Object { + get(index) { + return this["[]"](index); + } + } dart.setSignature(HTMLCollection, { methods: () => ({get: [Element, [core.num]]}) }); diff --git a/pkg/dev_compiler/test/codegen/expect/language-all.js b/pkg/dev_compiler/test/codegen/expect/language-all.js index 527cfb202876..78f6248c62d9 100644 --- a/pkg/dev_compiler/test/codegen/expect/language-all.js +++ b/pkg/dev_compiler/test/codegen/expect/language-all.js @@ -55079,6 +55079,9 @@ dart_library.library('language/external_test_10_multi', null, /* Imports */[ Foo() { this.x = 0; } + f10() { + return this.f10(); + } } dart.setSignature(Foo, { constructors: () => ({Foo: [Foo, []]}), @@ -119493,10 +119496,10 @@ dart_library.library('language/nan_identical_test', null, /* Imports */[ 'use strict'; let dartx = dart.dartx; function uint64toDouble(i) { - let buffer = typed_data.Uint8List.new(8).buffer; + let buffer = typed_data.Uint8List.new(8)[dartx.buffer]; let bdata = typed_data.ByteData.view(buffer); - bdata.setUint64(0, i); - return bdata.getFloat64(0); + bdata[dartx.setUint64](0, i); + return bdata[dartx.getFloat64](0); } dart.fn(uint64toDouble, core.double, [core.int]); function createOtherNAN() { @@ -120602,10 +120605,10 @@ dart_library.library('language/number_identity2_test', null, /* Imports */[ 'use strict'; let dartx = dart.dartx; function uint64toDouble(i) { - let buffer = typed_data.Uint8List.new(8).buffer; + let buffer = typed_data.Uint8List.new(8)[dartx.buffer]; let bdata = typed_data.ByteData.view(buffer); - bdata.setUint64(0, i); - return bdata.getFloat64(0); + bdata[dartx.setUint64](0, i); + return bdata[dartx.getFloat64](0); } dart.fn(uint64toDouble, core.double, [core.int]); function testNumberIdentity() { diff --git a/pkg/dev_compiler/test/codegen/expect/lib-typed_data-all.js b/pkg/dev_compiler/test/codegen/expect/lib-typed_data-all.js index 3a92d4018bb0..1691ef7778fd 100644 --- a/pkg/dev_compiler/test/codegen/expect/lib-typed_data-all.js +++ b/pkg/dev_compiler/test/codegen/expect/lib-typed_data-all.js @@ -12,28 +12,28 @@ dart_library.library('lib/typed_data/byte_data_test', null, /* Imports */[ dart.fn(main); function testRegress10898() { let data = typed_data.ByteData.new(16); - expect.Expect.equals(16, data.lengthInBytes); - for (let i = 0; i < dart.notNull(data.lengthInBytes); i++) { - expect.Expect.equals(0, data.getInt8(i)); - data.setInt8(i, 42 + i); - expect.Expect.equals(42 + i, data.getInt8(i)); + expect.Expect.equals(16, data[dartx.lengthInBytes]); + for (let i = 0; i < dart.notNull(data[dartx.lengthInBytes]); i++) { + expect.Expect.equals(0, data[dartx.getInt8](i)); + data[dartx.setInt8](i, 42 + i); + expect.Expect.equals(42 + i, data[dartx.getInt8](i)); } let backing = typed_data.ByteData.new(16); - let view = typed_data.ByteData.view(backing.buffer); - for (let i = 0; i < dart.notNull(view.lengthInBytes); i++) { - expect.Expect.equals(0, view.getInt8(i)); - view.setInt8(i, 87 + i); - expect.Expect.equals(87 + i, view.getInt8(i)); + let view = typed_data.ByteData.view(backing[dartx.buffer]); + for (let i = 0; i < dart.notNull(view[dartx.lengthInBytes]); i++) { + expect.Expect.equals(0, view[dartx.getInt8](i)); + view[dartx.setInt8](i, 87 + i); + expect.Expect.equals(87 + i, view[dartx.getInt8](i)); } - view = typed_data.ByteData.view(backing.buffer, 4); - expect.Expect.equals(12, view.lengthInBytes); - for (let i = 0; i < dart.notNull(view.lengthInBytes); i++) { - expect.Expect.equals(87 + i + 4, view.getInt8(i)); + view = typed_data.ByteData.view(backing[dartx.buffer], 4); + expect.Expect.equals(12, view[dartx.lengthInBytes]); + for (let i = 0; i < dart.notNull(view[dartx.lengthInBytes]); i++) { + expect.Expect.equals(87 + i + 4, view[dartx.getInt8](i)); } - view = typed_data.ByteData.view(backing.buffer, 8, 4); - expect.Expect.equals(4, view.lengthInBytes); - for (let i = 0; i < dart.notNull(view.lengthInBytes); i++) { - expect.Expect.equals(87 + i + 8, view.getInt8(i)); + view = typed_data.ByteData.view(backing[dartx.buffer], 8, 4); + expect.Expect.equals(4, view[dartx.lengthInBytes]); + for (let i = 0; i < dart.notNull(view[dartx.lengthInBytes]); i++) { + expect.Expect.equals(87 + i + 8, view[dartx.getInt8](i)); } } dart.fn(testRegress10898); @@ -71,7 +71,7 @@ dart_library.library('lib/typed_data/constructor_checks_test', null, /* Imports } dart.fn(checkLengthConstructors); function checkViewConstructors() { - let buffer = typed_data.Int8List.new(256).buffer; + let buffer = typed_data.Int8List.new(256)[dartx.buffer]; function check1(creator) { expect.Expect.throws(dart.fn(() => dart.dcall(creator, 10), dart.void, [])); expect.Expect.throws(dart.fn(() => dart.dcall(creator, null), dart.void, [])); @@ -134,58 +134,58 @@ dart_library.library('lib/typed_data/endianness_test', null, /* Imports */[ dart.fn(main); function swapTest() { let data = typed_data.ByteData.new(16); - expect.Expect.equals(16, data.lengthInBytes); + expect.Expect.equals(16, data[dartx.lengthInBytes]); for (let i = 0; i < 4; i++) { - data.setInt32(i * 4, i); + data[dartx.setInt32](i * 4, i); } - for (let i = 0; i < dart.notNull(data.lengthInBytes); i = i + 4) { - let e = data.getInt32(i, typed_data.Endianness.BIG_ENDIAN); - data.setInt32(i, e, typed_data.Endianness.LITTLE_ENDIAN); + for (let i = 0; i < dart.notNull(data[dartx.lengthInBytes]); i = i + 4) { + let e = data[dartx.getInt32](i, typed_data.Endianness.BIG_ENDIAN); + data[dartx.setInt32](i, e, typed_data.Endianness.LITTLE_ENDIAN); } - expect.Expect.equals(33554432, data.getInt32(8)); - for (let i = 0; i < dart.notNull(data.lengthInBytes); i = i + 2) { - let e = data.getInt16(i, typed_data.Endianness.BIG_ENDIAN); - data.setInt16(i, e, typed_data.Endianness.LITTLE_ENDIAN); + expect.Expect.equals(33554432, data[dartx.getInt32](8)); + for (let i = 0; i < dart.notNull(data[dartx.lengthInBytes]); i = i + 2) { + let e = data[dartx.getInt16](i, typed_data.Endianness.BIG_ENDIAN); + data[dartx.setInt16](i, e, typed_data.Endianness.LITTLE_ENDIAN); } - expect.Expect.equals(131072, data.getInt32(8)); - for (let i = 0; i < dart.notNull(data.lengthInBytes); i = i + 4) { - let e = data.getUint32(i, typed_data.Endianness.LITTLE_ENDIAN); - data.setUint32(i, e, typed_data.Endianness.BIG_ENDIAN); + expect.Expect.equals(131072, data[dartx.getInt32](8)); + for (let i = 0; i < dart.notNull(data[dartx.lengthInBytes]); i = i + 4) { + let e = data[dartx.getUint32](i, typed_data.Endianness.LITTLE_ENDIAN); + data[dartx.setUint32](i, e, typed_data.Endianness.BIG_ENDIAN); } - expect.Expect.equals(512, data.getInt32(8)); - for (let i = 0; i < dart.notNull(data.lengthInBytes); i = i + 2) { - let e = data.getUint16(i, typed_data.Endianness.LITTLE_ENDIAN); - data.setUint16(i, e, typed_data.Endianness.BIG_ENDIAN); + expect.Expect.equals(512, data[dartx.getInt32](8)); + for (let i = 0; i < dart.notNull(data[dartx.lengthInBytes]); i = i + 2) { + let e = data[dartx.getUint16](i, typed_data.Endianness.LITTLE_ENDIAN); + data[dartx.setUint16](i, e, typed_data.Endianness.BIG_ENDIAN); } - expect.Expect.equals(2, data.getInt32(8)); + expect.Expect.equals(2, data[dartx.getInt32](8)); } dart.fn(swapTest); function swapTestVar(read, write) { let data = typed_data.ByteData.new(16); - expect.Expect.equals(16, data.lengthInBytes); + expect.Expect.equals(16, data[dartx.lengthInBytes]); for (let i = 0; i < 4; i++) { - data.setInt32(i * 4, i); + data[dartx.setInt32](i * 4, i); } - for (let i = 0; i < dart.notNull(data.lengthInBytes); i = i + 4) { - let e = data.getInt32(i, dart.as(read, typed_data.Endianness)); - data.setInt32(i, e, dart.as(write, typed_data.Endianness)); + for (let i = 0; i < dart.notNull(data[dartx.lengthInBytes]); i = i + 4) { + let e = data[dartx.getInt32](i, dart.as(read, typed_data.Endianness)); + data[dartx.setInt32](i, e, dart.as(write, typed_data.Endianness)); } - expect.Expect.equals(33554432, data.getInt32(8)); - for (let i = 0; i < dart.notNull(data.lengthInBytes); i = i + 2) { - let e = data.getInt16(i, dart.as(read, typed_data.Endianness)); - data.setInt16(i, e, dart.as(write, typed_data.Endianness)); + expect.Expect.equals(33554432, data[dartx.getInt32](8)); + for (let i = 0; i < dart.notNull(data[dartx.lengthInBytes]); i = i + 2) { + let e = data[dartx.getInt16](i, dart.as(read, typed_data.Endianness)); + data[dartx.setInt16](i, e, dart.as(write, typed_data.Endianness)); } - expect.Expect.equals(131072, data.getInt32(8)); - for (let i = 0; i < dart.notNull(data.lengthInBytes); i = i + 4) { - let e = data.getUint32(i, dart.as(read, typed_data.Endianness)); - data.setUint32(i, e, dart.as(write, typed_data.Endianness)); + expect.Expect.equals(131072, data[dartx.getInt32](8)); + for (let i = 0; i < dart.notNull(data[dartx.lengthInBytes]); i = i + 4) { + let e = data[dartx.getUint32](i, dart.as(read, typed_data.Endianness)); + data[dartx.setUint32](i, e, dart.as(write, typed_data.Endianness)); } - expect.Expect.equals(512, data.getInt32(8)); - for (let i = 0; i < dart.notNull(data.lengthInBytes); i = i + 2) { - let e = data.getUint16(i, dart.as(read, typed_data.Endianness)); - data.setUint16(i, e, dart.as(write, typed_data.Endianness)); + expect.Expect.equals(512, data[dartx.getInt32](8)); + for (let i = 0; i < dart.notNull(data[dartx.lengthInBytes]); i = i + 2) { + let e = data[dartx.getUint16](i, dart.as(read, typed_data.Endianness)); + data[dartx.setUint16](i, e, dart.as(write, typed_data.Endianness)); } - expect.Expect.equals(2, data.getInt32(8)); + expect.Expect.equals(2, data[dartx.getInt32](8)); } dart.fn(swapTestVar); // Exports: @@ -484,10 +484,10 @@ dart_library.library('lib/typed_data/float32x4_list_test', null, /* Imports */[ testLoadStore(list); } let floatList = typed_data.Float32List.new(32); - for (let i = 0; i < dart.notNull(floatList.length); i++) { - floatList.set(i, i[dartx.toDouble]()); + for (let i = 0; i < dart.notNull(floatList[dartx.length]); i++) { + floatList[dartx.set](i, i[dartx.toDouble]()); } - list = typed_data.Float32x4List.view(floatList.buffer); + list = typed_data.Float32x4List.view(floatList[dartx.buffer]); for (let i = 0; i < 20; i++) { testView(list); } @@ -2199,8 +2199,8 @@ dart_library.library('lib/typed_data/float32x4_unbox_phi_test', null, /* Imports function main() { let list = typed_data.Float32x4List.new(10); let floatList = typed_data.Float32List.view(list.buffer); - for (let i = 0; i < dart.notNull(floatList.length); i++) { - floatList.set(i, i[dartx.toDouble]()); + for (let i = 0; i < dart.notNull(floatList[dartx.length]); i++) { + floatList[dartx.set](i, i[dartx.toDouble]()); } for (let i = 0; i < 20; i++) { let r = testUnboxPhi(list); @@ -2667,10 +2667,10 @@ dart_library.library('lib/typed_data/int32x4_list_test', null, /* Imports */[ testSpecialValues(list); } let uint32List = typed_data.Uint32List.new(32); - for (let i = 0; i < dart.notNull(uint32List.length); i++) { - uint32List.set(i, i); + for (let i = 0; i < dart.notNull(uint32List[dartx.length]); i++) { + uint32List[dartx.set](i, i); } - list = typed_data.Int32x4List.view(uint32List.buffer); + list = typed_data.Int32x4List.view(uint32List[dartx.buffer]); for (let i = 0; i < 20; i++) { testView(list); } @@ -2940,15 +2940,15 @@ dart_library.library('lib/typed_data/setRange_3_test', null, /* Imports */[ let dartx = dart.dartx; function expandContractTest() { let a1 = typed_data.Int32List.new(8); - let buffer = a1.buffer; + let buffer = a1[dartx.buffer]; let a2 = typed_data.Int8List.view(buffer, 12, 8); setRange_lib.initialize(a2); expect.Expect.equals('[1, 2, 3, 4, 5, 6, 7, 8]', `${a2}`); - a1.setRange(0, 8, a2); + a1[dartx.setRange](0, 8, a2); expect.Expect.equals('[1, 2, 3, 4, 5, 6, 7, 8]', `${a1}`); setRange_lib.initialize(a1); expect.Expect.equals('[1, 2, 3, 4, 5, 6, 7, 8]', `${a1}`); - a2.setRange(0, 8, a1); + a2[dartx.setRange](0, 8, a1); expect.Expect.equals('[1, 2, 3, 4, 5, 6, 7, 8]', `${a2}`); } dart.fn(expandContractTest); @@ -2971,12 +2971,12 @@ dart_library.library('lib/typed_data/setRange_4_test', null, /* Imports */[ let dartx = dart.dartx; function clampingTest() { let a1 = typed_data.Int8List.new(8); - let a2 = typed_data.Uint8ClampedList.view(a1.buffer); + let a2 = typed_data.Uint8ClampedList.view(a1[dartx.buffer]); setRange_lib.initialize(a1); expect.Expect.equals('[1, 2, 3, 4, 5, 6, 7, 8]', `${a1}`); expect.Expect.equals('[1, 2, 3, 4, 5, 6, 7, 8]', `${a2}`); - a1.set(0, -1); - a2.setRange(0, 2, a1); + a1[dartx.set](0, -1); + a2[dartx.setRange](0, 2, a1); expect.Expect.equals('[0, 2, 3, 4, 5, 6, 7, 8]', `${a2}`); } dart.fn(clampingTest); @@ -2998,7 +2998,7 @@ dart_library.library('lib/typed_data/setRange_5_test', null, /* Imports */[ 'use strict'; let dartx = dart.dartx; function overlapTest() { - let buffer = typed_data.Float32List.new(3).buffer; + let buffer = typed_data.Float32List.new(3)[dartx.buffer]; let a0 = typed_data.Int8List.view(buffer); let a1 = typed_data.Int8List.view(buffer, 1, 5); let a2 = typed_data.Int8List.view(buffer, 2, 5); @@ -3006,13 +3006,13 @@ dart_library.library('lib/typed_data/setRange_5_test', null, /* Imports */[ expect.Expect.equals('[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]', `${a0}`); expect.Expect.equals('[2, 3, 4, 5, 6]', `${a1}`); expect.Expect.equals('[3, 4, 5, 6, 7]', `${a2}`); - a1.setRange(0, 5, a2); + a1[dartx.setRange](0, 5, a2); expect.Expect.equals('[1, 3, 4, 5, 6, 7, 7, 8, 9, 10, 11, 12]', `${a0}`); setRange_lib.initialize(a0); expect.Expect.equals('[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]', `${a0}`); expect.Expect.equals('[2, 3, 4, 5, 6]', `${a1}`); expect.Expect.equals('[3, 4, 5, 6, 7]', `${a2}`); - a2.setRange(0, 5, a1); + a2[dartx.setRange](0, 5, a1); expect.Expect.equals('[1, 2, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12]', `${a0}`); } dart.fn(overlapTest); @@ -3135,7 +3135,7 @@ dart_library.library('lib/typed_data/typed_data_from_list_test', null, /* Import function main() { let list = new collection.UnmodifiableListView([1, 2]); let typed = typed_data.Uint8List.fromList(dart.as(list, core.List$(core.int))); - if (typed.get(0) != 1 || typed.get(1) != 2 || typed.length != 2) { + if (typed[dartx.get](0) != 1 || typed[dartx.get](1) != 2 || typed[dartx.length] != 2) { dart.throw('Test failed'); } } @@ -3403,77 +3403,77 @@ dart_library.library('lib/typed_data/typed_data_load2_test', null, /* Imports */ let dartx = dart.dartx; function aliasWithByteData1() { let aa = typed_data.Int8List.new(10); - let b = typed_data.ByteData.view(aa.buffer); - for (let i = 0; i < dart.notNull(aa.length); i++) - aa.set(i, 9); - let x1 = aa.get(3); - b.setInt8(3, 1); - let x2 = aa.get(3); + let b = typed_data.ByteData.view(aa[dartx.buffer]); + for (let i = 0; i < dart.notNull(aa[dartx.length]); i++) + aa[dartx.set](i, 9); + let x1 = aa[dartx.get](3); + b[dartx.setInt8](3, 1); + let x2 = aa[dartx.get](3); expect.Expect.equals(9, x1); expect.Expect.equals(1, x2); } dart.fn(aliasWithByteData1); function aliasWithByteData2() { let b = typed_data.ByteData.new(10); - let aa = typed_data.Int8List.view(b.buffer); - for (let i = 0; i < dart.notNull(aa.length); i++) - aa.set(i, 9); - let x1 = aa.get(3); - b.setInt8(3, 1); - let x2 = aa.get(3); + let aa = typed_data.Int8List.view(b[dartx.buffer]); + for (let i = 0; i < dart.notNull(aa[dartx.length]); i++) + aa[dartx.set](i, 9); + let x1 = aa[dartx.get](3); + b[dartx.setInt8](3, 1); + let x2 = aa[dartx.get](3); expect.Expect.equals(9, x1); expect.Expect.equals(1, x2); } dart.fn(aliasWithByteData2); function alias8x8() { - let buffer = typed_data.Int8List.new(10).buffer; + let buffer = typed_data.Int8List.new(10)[dartx.buffer]; let a1 = typed_data.Int8List.view(buffer); let a2 = typed_data.Int8List.view(buffer, 1); - for (let i = 0; i < dart.notNull(a1.length); i++) - a1.set(i, 9); - let x1 = a1.get(1); - a2.set(0, 0); - let x2 = a1.get(1); + for (let i = 0; i < dart.notNull(a1[dartx.length]); i++) + a1[dartx.set](i, 9); + let x1 = a1[dartx.get](1); + a2[dartx.set](0, 0); + let x2 = a1[dartx.get](1); expect.Expect.equals(9, x1); expect.Expect.equals(0, x2); - for (let i = 0; i < dart.notNull(a1.length); i++) - a1.set(i, 9); - x1 = a1.get(1); - a2.set(1, 5); - x2 = a1.get(1); + for (let i = 0; i < dart.notNull(a1[dartx.length]); i++) + a1[dartx.set](i, 9); + x1 = a1[dartx.get](1); + a2[dartx.set](1, 5); + x2 = a1[dartx.get](1); expect.Expect.equals(9, x1); expect.Expect.equals(9, x2); } dart.fn(alias8x8); function alias8x16() { let a1 = typed_data.Int8List.new(10); - let a2 = typed_data.Int16List.view(a1.buffer); - for (let i = 0; i < dart.notNull(a1.length); i++) - a1.set(i, 9); - let x1 = a1.get(0); - a2.set(0, 257); - let x2 = a1.get(0); + let a2 = typed_data.Int16List.view(a1[dartx.buffer]); + for (let i = 0; i < dart.notNull(a1[dartx.length]); i++) + a1[dartx.set](i, 9); + let x1 = a1[dartx.get](0); + a2[dartx.set](0, 257); + let x2 = a1[dartx.get](0); expect.Expect.equals(9, x1); expect.Expect.equals(1, x2); - for (let i = 0; i < dart.notNull(a1.length); i++) - a1.set(i, 9); - x1 = a1.get(4); - a2.set(2, 1285); - x2 = a1.get(4); + for (let i = 0; i < dart.notNull(a1[dartx.length]); i++) + a1[dartx.set](i, 9); + x1 = a1[dartx.get](4); + a2[dartx.set](2, 1285); + x2 = a1[dartx.get](4); expect.Expect.equals(9, x1); expect.Expect.equals(5, x2); - for (let i = 0; i < dart.notNull(a1.length); i++) - a1.set(i, 9); - x1 = a1.get(3); - a2.set(3, 1285); - x2 = a1.get(3); + for (let i = 0; i < dart.notNull(a1[dartx.length]); i++) + a1[dartx.set](i, 9); + x1 = a1[dartx.get](3); + a2[dartx.set](3, 1285); + x2 = a1[dartx.get](3); expect.Expect.equals(9, x1); expect.Expect.equals(9, x2); - for (let i = 0; i < dart.notNull(a1.length); i++) - a1.set(i, 9); - x1 = a1.get(2); - a2.set(0, 1285); - x2 = a1.get(2); + for (let i = 0; i < dart.notNull(a1[dartx.length]); i++) + a1[dartx.set](i, 9); + x1 = a1[dartx.get](2); + a2[dartx.set](0, 1285); + x2 = a1[dartx.get](2); expect.Expect.equals(9, x1); expect.Expect.equals(9, x2); } @@ -3501,13 +3501,13 @@ dart_library.library('lib/typed_data/typed_data_load_test', null, /* Imports */[ let dartx = dart.dartx; function main() { let list = typed_data.Int8List.new(1); - list.set(0, 300); - if (list.get(0) != 44) { + list[dartx.set](0, 300); + if (list[dartx.get](0) != 44) { dart.throw('Test failed'); } - let a = list.get(0); - list.set(0, 0); - if (list.get(0) != 0) { + let a = list[dartx.get](0); + list[dartx.set](0, 0); + if (list[dartx.get](0) != 0) { dart.throw('Test failed'); } } diff --git a/pkg/dev_compiler/test/codegen/expect/sunflower/dom.js b/pkg/dev_compiler/test/codegen/expect/sunflower/dom.js index c324f7956167..d9299c2427eb 100644 --- a/pkg/dev_compiler/test/codegen/expect/sunflower/dom.js +++ b/pkg/dev_compiler/test/codegen/expect/sunflower/dom.js @@ -17,7 +17,11 @@ dart_library.library('sunflower/dom', window, /* Imports */[ dart.setSignature(CustomEvent, { constructors: () => ({CustomEvent: [CustomEvent, [core.String], {detail: dart.dynamic, bubbles: dart.dynamic, cancelable: dart.dynamic}]}) }); - class HTMLCollection extends core.Object {} + class HTMLCollection extends core.Object { + get(index) { + return this["[]"](index); + } + } dart.setSignature(HTMLCollection, { methods: () => ({get: [Element, [core.num]]}) }); diff --git a/pkg/dev_compiler/tool/input_sdk/private/classes.dart b/pkg/dev_compiler/tool/input_sdk/private/classes.dart index 7a784a4257c3..d10c6d727e23 100644 --- a/pkg/dev_compiler/tool/input_sdk/private/classes.dart +++ b/pkg/dev_compiler/tool/input_sdk/private/classes.dart @@ -259,6 +259,8 @@ defineNamedConstructor(clazz, name) => JS('', '''(() => { final _extensionType = JS('', 'Symbol("extensionType")'); +getExtensionType(obj) => JS('', '$obj[$_extensionType]'); + final dartx = JS('', '{}'); getExtensionSymbol(name) => JS('', '''(() => { @@ -269,6 +271,15 @@ getExtensionSymbol(name) => JS('', '''(() => { defineExtensionNames(names) => JS('', '$names.forEach($getExtensionSymbol)'); +// Install properties in prototype order. Properties / descriptors from +// more specific types should overwrite ones from less specific types. +_installProperties(jsProto, extProto) => JS('', '''(() => { + if (extProto !== $Object.prototype && extProto !== jsProto) { + $_installProperties(jsProto, extProto.__proto__); + } + $copyTheseProperties(jsProto, extProto, $getOwnPropertySymbols(extProto)); +})()'''); + /// /// Copy symbols from the prototype of the source to destination. /// These are the only properties safe to copy onto an existing public @@ -280,13 +291,8 @@ registerExtension(jsType, dartExtType) => JS('', '''(() => { // Mark the JS type's instances so we can easily check for extensions. $assert_(jsProto[$_extensionType] === void 0); - jsProto[$_extensionType] = extProto; - - let dartObjProto = $Object.prototype; - while (extProto !== dartObjProto && extProto !== jsProto) { - $copyTheseProperties(jsProto, extProto, $getOwnPropertySymbols(extProto)); - extProto = extProto.__proto__; - } + jsProto[$_extensionType] = $dartExtType; + $_installProperties(jsProto, extProto); let originalSigFn = $getOwnPropertyDescriptor($dartExtType, $_methodSig).get; $assert_(originalSigFn); $defineMemoizedGetter($jsType, $_methodSig, originalSigFn); @@ -345,6 +351,9 @@ canonicalMember(obj, name) => JS('', '''(() => { /// Sets the type of `obj` to be `type` setType(obj, type) => JS('', '''(() => { $obj.__proto__ = $type.prototype; + // TODO(vsm): This should be set in registerExtension, but that is only + // invoked on the generic type (e.g., JSArray, not JSArray). + $obj.__proto__[$_extensionType] = $type; return $obj; })()'''); diff --git a/pkg/dev_compiler/tool/input_sdk/private/native_typed_data.dart b/pkg/dev_compiler/tool/input_sdk/private/native_typed_data.dart index d77cfdfe0a4d..b9b4343ecd0a 100644 --- a/pkg/dev_compiler/tool/input_sdk/private/native_typed_data.dart +++ b/pkg/dev_compiler/tool/input_sdk/private/native_typed_data.dart @@ -416,7 +416,6 @@ class NativeFloat64x2List } } -@Native("ArrayBufferView") class NativeTypedData implements TypedData { /** * Returns the byte buffer associated with this object. diff --git a/pkg/dev_compiler/tool/input_sdk/private/operations.dart b/pkg/dev_compiler/tool/input_sdk/private/operations.dart index a79fc5bea998..dcac6ff47eb4 100644 --- a/pkg/dev_compiler/tool/input_sdk/private/operations.dart +++ b/pkg/dev_compiler/tool/input_sdk/private/operations.dart @@ -165,7 +165,8 @@ _ignoreTypeFailure(actual, type) => JS('', '''(() => { strongInstanceOf(obj, type, ignoreFromWhiteList) => JS('', '''(() => { let actual = $realRuntimeType($obj); - if ($isSubtype(actual, $type) || actual == $jsobject) return true; + if ($isSubtype(actual, $type) || actual == $jsobject || + actual == $int && type == $double) return true; if ($ignoreFromWhiteList == void 0) return false; if ($isGroundType($type)) return false; if ($_ignoreTypeFailure(actual, $type)) return true; diff --git a/pkg/dev_compiler/tool/input_sdk/private/rtti.dart b/pkg/dev_compiler/tool/input_sdk/private/rtti.dart index 8694daa6e380..b0b65876a254 100644 --- a/pkg/dev_compiler/tool/input_sdk/private/rtti.dart +++ b/pkg/dev_compiler/tool/input_sdk/private/rtti.dart @@ -93,9 +93,15 @@ checkPrimitiveType(obj) => JS('', '''(() => { })()'''); runtimeType(obj) => JS('', '''(() => { + // Lookup primitive (int/double/string) let result = $checkPrimitiveType($obj); if (result !== null) return result; - return $obj.runtimeType; + + // Lookup recorded type + result = $obj.runtimeType; + if (result) return result; + + return $_nonPrimitiveRuntimeType(obj); })()'''); getFunctionType(obj) => JS('', '''(() => { @@ -111,12 +117,25 @@ getFunctionType(obj) => JS('', '''(() => { /// Currently this will return null for non-Dart objects. /// realRuntimeType(obj) => JS('', '''(() => { + // Lookup primitive type let result = $checkPrimitiveType($obj); if (result !== null) return result; + + return $_nonPrimitiveRuntimeType(obj); +})()'''); + +_nonPrimitiveRuntimeType(obj) => JS('', '''(() => { + // Lookup recorded *real* type (not user definable runtimeType) // TODO(vsm): Should we treat Dart and JS objects differently here? // E.g., we can check if obj instanceof core.Object to differentiate. - result = $obj[$_runtimeType]; + let result = $obj[$_runtimeType]; + if (result) return result; + + // Lookup extension type + result = $obj[$_extensionType]; if (result) return result; + + // Fallback on constructor for class types result = $obj.constructor; if (result == Function) { // An undecorated Function should have come from