Skip to content

Commit

Permalink
fixes #193, factory constructors as static methods
Browse files Browse the repository at this point in the history
R=vsm@google.com

Review URL: https://codereview.chromium.org/1156993015
  • Loading branch information
John Messerly committed May 29, 2015
1 parent a73dec2 commit 81fc365
Show file tree
Hide file tree
Showing 17 changed files with 596 additions and 687 deletions.
3 changes: 2 additions & 1 deletion pkg/dev_compiler/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ packages
.pub/
node_modules

# Or our test output folder
# Or our test outputs
test/codegen/actual/
test/dart_codegen/actual/
test/generated_sdk/sdk_errors.txt

# Include when developing application packages.
pubspec.lock
2 changes: 1 addition & 1 deletion pkg/dev_compiler/lib/runtime/dart/_interceptors.js
Original file line number Diff line number Diff line change
Expand Up @@ -985,7 +985,7 @@ var _js_embedded_names = dart.import(_js_embedded_names);
function _symbolMapToStringMap(map) {
if (map == null)
return null;
let result = new (core.Map$(core.String, core.Object))();
let result = core.Map$(core.String, core.Object).new();
map.forEach(dart.fn((key, value) => {
result.set(_symbolToString(key), value);
}, core.Object, [core.Symbol, core.Object]));
Expand Down
38 changes: 19 additions & 19 deletions pkg/dev_compiler/lib/runtime/dart/_internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,18 +219,18 @@ var _js_primitives = dart.lazyImport(_js_primitives);
let growable = opts && 'growable' in opts ? opts.growable : true;
let result = null;
if (growable) {
result = new (core.List$(E))();
result = core.List$(E).new();
result[core.$length] = this[core.$length];
} else {
result = new (core.List$(E))(this[core.$length]);
result = core.List$(E).new(this[core.$length]);
}
for (let i = 0; dart.notNull(i) < dart.notNull(this[core.$length]); i = dart.notNull(i) + 1) {
result[core.$set](i, this[core.$elementAt](i));
}
return result;
}
[core.$toSet]() {
let result = new (core.Set$(E))();
let result = core.Set$(E).new();
for (let i = 0; dart.notNull(i) < dart.notNull(this[core.$length]); i = dart.notNull(i) + 1) {
result.add(this[core.$elementAt](i));
}
Expand Down Expand Up @@ -306,7 +306,7 @@ var _js_primitives = dart.lazyImport(_js_primitives);
[core.$elementAt](index) {
let realIndex = dart.notNull(this[_startIndex]) + dart.notNull(index);
if (dart.notNull(index) < 0 || dart.notNull(realIndex) >= dart.notNull(this[_endIndex])) {
throw new core.RangeError.index(index, this, "index");
throw core.RangeError.index(index, this, "index");
}
return this[_iterable][core.$elementAt](realIndex);
}
Expand Down Expand Up @@ -339,10 +339,10 @@ var _js_primitives = dart.lazyImport(_js_primitives);
if (dart.notNull(length) < 0)
length = 0;
let result = growable ? (() => {
let _ = new (core.List$(E))();
let _ = core.List$(E).new();
_[core.$length] = length;
return _;
})() : new (core.List$(E))(length);
})() : core.List$(E).new(length);
for (let i = 0; dart.notNull(i) < dart.notNull(length); i = dart.notNull(i) + 1) {
result[core.$set](i, this[_iterable][core.$elementAt](dart.notNull(start) + dart.notNull(i)));
if (dart.notNull(this[_iterable][core.$length]) < dart.notNull(end))
Expand Down Expand Up @@ -407,7 +407,7 @@ var _js_primitives = dart.lazyImport(_js_primitives);
let _f = dart.JsSymbol('_f');
let MappedIterable$ = dart.generic(function(S, T) {
class MappedIterable extends collection.IterableBase$(T) {
MappedIterable(iterable, func) {
static new(iterable, func) {
if (dart.is(iterable, EfficientLength)) {
return new (EfficientLengthMappedIterable$(S, T))(iterable, func);
}
Expand Down Expand Up @@ -443,7 +443,7 @@ var _js_primitives = dart.lazyImport(_js_primitives);
dart.defineNamedConstructor(MappedIterable, '_');
dart.setSignature(MappedIterable, {
constructors: () => ({
MappedIterable: [MappedIterable$(S, T), [core.Iterable, dart.functionType(T, [S])]],
new: [MappedIterable$(S, T), [core.Iterable, dart.functionType(T, [S])]],
_: [MappedIterable$(S, T), [core.Iterable$(S), dart.functionType(T, [S])]]
}),
methods: () => ({[core.$elementAt]: [T, [core.int]]})
Expand Down Expand Up @@ -627,7 +627,7 @@ var _js_primitives = dart.lazyImport(_js_primitives);
let _takeCount = dart.JsSymbol('_takeCount');
let TakeIterable$ = dart.generic(function(E) {
class TakeIterable extends collection.IterableBase$(E) {
TakeIterable(iterable, takeCount) {
static new(iterable, takeCount) {
if (!(typeof takeCount == 'number') || dart.notNull(takeCount) < 0) {
throw new core.ArgumentError(takeCount);
}
Expand All @@ -648,7 +648,7 @@ var _js_primitives = dart.lazyImport(_js_primitives);
dart.defineNamedConstructor(TakeIterable, '_');
dart.setSignature(TakeIterable, {
constructors: () => ({
TakeIterable: [TakeIterable$(E), [core.Iterable$(E), core.int]],
new: [TakeIterable$(E), [core.Iterable$(E), core.int]],
_: [TakeIterable$(E), [core.Iterable$(E), core.int]]
})
});
Expand Down Expand Up @@ -753,7 +753,7 @@ var _js_primitives = dart.lazyImport(_js_primitives);
let _skipCount = dart.JsSymbol('_skipCount');
let SkipIterable$ = dart.generic(function(E) {
class SkipIterable extends collection.IterableBase$(E) {
SkipIterable(iterable, count) {
static new(iterable, count) {
if (dart.is(iterable, EfficientLength)) {
return new (EfficientLengthSkipIterable$(E))(iterable, count);
}
Expand Down Expand Up @@ -782,7 +782,7 @@ var _js_primitives = dart.lazyImport(_js_primitives);
dart.defineNamedConstructor(SkipIterable, '_');
dart.setSignature(SkipIterable, {
constructors: () => ({
SkipIterable: [SkipIterable$(E), [core.Iterable$(E), core.int]],
new: [SkipIterable$(E), [core.Iterable$(E), core.int]],
_: [SkipIterable$(E), [core.Iterable$(E), core.int]]
}),
methods: () => ({[core.$skip]: [core.Iterable$(E), [core.int]]})
Expand Down Expand Up @@ -982,10 +982,10 @@ var _js_primitives = dart.lazyImport(_js_primitives);
}
[core.$toList](opts) {
let growable = opts && 'growable' in opts ? opts.growable : true;
return growable ? dart.setType([], core.List$(E)) : new (core.List$(E))(0);
return growable ? dart.setType([], core.List$(E)) : core.List$(E).new(0);
}
[core.$toSet]() {
return new (core.Set$(E))();
return core.Set$(E).new();
}
}
EmptyIterable[dart.implements] = () => [EfficientLength];
Expand Down Expand Up @@ -1205,7 +1205,7 @@ var _js_primitives = dart.lazyImport(_js_primitives);
return element;
elementIndex = dart.notNull(elementIndex) + 1;
}
throw new core.RangeError.index(index, iterable, "index", null, elementIndex);
throw core.RangeError.index(index, iterable, "index", null, elementIndex);
}
static join(iterable, separator) {
if (separator === void 0)
Expand Down Expand Up @@ -1241,7 +1241,7 @@ var _js_primitives = dart.lazyImport(_js_primitives);
}
static map(iterable, f) {
dart.as(f, dart.functionType(core.Object, [dart.bottom]));
return new MappedIterable(iterable, f);
return MappedIterable.new(iterable, f);
}
static mapList(list, f) {
dart.as(f, dart.functionType(core.Object, [dart.bottom]));
Expand Down Expand Up @@ -1276,7 +1276,7 @@ var _js_primitives = dart.lazyImport(_js_primitives);
}
static shuffleList(list, random) {
if (random == null)
random = new math.Random();
random = math.Random.new();
let length = list[core.$length];
while (dart.notNull(length) > 1) {
let pos = random.nextInt(length);
Expand Down Expand Up @@ -2272,10 +2272,10 @@ var _js_primitives = dart.lazyImport(_js_primitives);
let POWERS_OF_TEN = dart.const([1.0, 10.0, 100.0, 1000.0, 10000.0, 100000.0, 1000000.0, 10000000.0, 100000000.0, 1000000000.0, 10000000000.0, 100000000000.0, 1000000000000.0, 10000000000000.0, 100000000000000.0, 1000000000000000.0, 10000000000000000.0, 100000000000000000.0, 1000000000000000000.0, 10000000000000000000.0, 100000000000000000000.0, 1e+21, 1e+22]);
dart.defineLazyProperties(Symbol, {
get publicSymbolPattern() {
return new core.RegExp(`^(?:${Symbol.operatorRE}$|${Symbol.publicIdentifierRE}(?:=?$|[.](?!$)))+?$`);
return core.RegExp.new(`^(?:${Symbol.operatorRE}$|${Symbol.publicIdentifierRE}(?:=?$|[.](?!$)))+?$`);
},
get symbolPattern() {
return new core.RegExp(`^(?:${Symbol.operatorRE}$|${Symbol.identifierRE}(?:=?$|[.](?!$)))+?$`);
return core.RegExp.new(`^(?:${Symbol.operatorRE}$|${Symbol.identifierRE}(?:=?$|[.](?!$)))+?$`);
}
});
// Exports:
Expand Down
52 changes: 26 additions & 26 deletions pkg/dev_compiler/lib/runtime/dart/_isolate_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var async = dart.import(async);
class _Serializer extends core.Object {
_Serializer(opts) {
let serializeSendPorts = opts && 'serializeSendPorts' in opts ? opts.serializeSendPorts : true;
this.serializedObjectIds = new (core.Map$(core.Object, core.int)).identity();
this.serializedObjectIds = core.Map$(core.Object, core.int).identity();
this[_serializeSendPorts] = dart.as(serializeSendPorts, core.bool);
}
serialize(x) {
Expand Down Expand Up @@ -190,7 +190,7 @@ var async = dart.import(async);
class _Deserializer extends core.Object {
_Deserializer(opts) {
let adjustSendPorts = opts && 'adjustSendPorts' in opts ? opts.adjustSendPorts : true;
this.deserializedObjects = new core.List();
this.deserializedObjects = core.List.new();
this[_adjustSendPorts] = dart.as(adjustSendPorts, core.bool);
}
deserialize(x) {
Expand Down Expand Up @@ -290,13 +290,13 @@ var async = dart.import(async);
dart.assert(dart.equals(dart.dindex(x, 0), 'fixed'));
let result = dart.as(dart.dindex(x, 1), core.List);
this.deserializedObjects[core.$add](result);
return new _interceptors.JSArray.markFixed(this.deserializeArrayInPlace(dart.as(result, _interceptors.JSArray)));
return _interceptors.JSArray.markFixed(this.deserializeArrayInPlace(dart.as(result, _interceptors.JSArray)));
}
deserializeExtendable(x) {
dart.assert(dart.equals(dart.dindex(x, 0), 'extendable'));
let result = dart.as(dart.dindex(x, 1), core.List);
this.deserializedObjects[core.$add](result);
return new _interceptors.JSArray.markGrowable(this.deserializeArrayInPlace(dart.as(result, _interceptors.JSArray)));
return _interceptors.JSArray.markGrowable(this.deserializeArrayInPlace(dart.as(result, _interceptors.JSArray)));
}
deserializeMutable(x) {
dart.assert(dart.equals(dart.dindex(x, 0), 'mutable'));
Expand All @@ -308,7 +308,7 @@ var async = dart.import(async);
dart.assert(dart.equals(dart.dindex(x, 0), 'const'));
let result = dart.as(dart.dindex(x, 1), core.List);
this.deserializedObjects[core.$add](result);
return new _interceptors.JSArray.markFixed(this.deserializeArrayInPlace(dart.as(result, _interceptors.JSArray)));
return _interceptors.JSArray.markFixed(this.deserializeArrayInPlace(dart.as(result, _interceptors.JSArray)));
}
deserializeMap(x) {
dart.assert(dart.equals(dart.dindex(x, 0), 'map'));
Expand Down Expand Up @@ -484,8 +484,8 @@ var async = dart.import(async);
this.managers = null;
this[_nativeDetectEnvironment]();
this.topEventLoop = new _EventLoop();
this.isolates = new (core.Map$(core.int, _IsolateContext))();
this.managers = new (core.Map$(core.int, core.Object))();
this.isolates = core.Map$(core.int, _IsolateContext).new();
this.managers = core.Map$(core.int, core.Object).new();
if (this.isWorker) {
this.mainManager = new _MainManagerStub();
this[_nativeInitWorkerMessageHandler]();
Expand Down Expand Up @@ -547,15 +547,15 @@ var async = dart.import(async);
o.nextIsolateId = dart.notNull(x) + 1;
return x;
})();
this.ports = new (core.Map$(core.int, RawReceivePortImpl))();
this.weakPorts = new (core.Set$(core.int))();
this.ports = core.Map$(core.int, RawReceivePortImpl).new();
this.weakPorts = core.Set$(core.int).new();
this.isolateStatics = _foreign_helper.JS_CREATE_ISOLATE();
this.controlPort = new RawReceivePortImpl._controlPort();
this.pauseCapability = new isolate.Capability();
this.terminateCapability = new isolate.Capability();
this.pauseCapability = isolate.Capability.new();
this.terminateCapability = isolate.Capability.new();
this.delayedEvents = dart.setType([], core.List$(_IsolateEvent));
this.pauseTokens = new (core.Set$(isolate.Capability))();
this.errorPorts = new (core.Set$(isolate.SendPort))();
this.pauseTokens = core.Set$(isolate.Capability).new();
this.errorPorts = core.Set$(isolate.SendPort).new();
this.initialized = false;
this.isPaused = false;
this.doneHandlers = null;
Expand Down Expand Up @@ -618,7 +618,7 @@ var async = dart.import(async);
}
dart.assert(pingType == isolate.Isolate.BEFORE_NEXT_EVENT);
if (this[_scheduledControlEvents] == null) {
this[_scheduledControlEvents] = new collection.Queue();
this[_scheduledControlEvents] = collection.Queue.new();
}
dart.dsend(this[_scheduledControlEvents], 'addLast', respond);
}
Expand All @@ -635,7 +635,7 @@ var async = dart.import(async);
}
dart.assert(priority == isolate.Isolate.BEFORE_NEXT_EVENT);
if (this[_scheduledControlEvents] == null) {
this[_scheduledControlEvents] = new collection.Queue();
this[_scheduledControlEvents] = collection.Queue.new();
}
dart.dsend(this[_scheduledControlEvents], 'addLast', dart.bind(this, 'kill'));
}
Expand All @@ -659,7 +659,7 @@ var async = dart.import(async);
}
return;
}
let message = new core.List(2);
let message = core.List.new(2);
message[core.$set](0, dart.toString(error));
message[core.$set](1, stackTrace == null ? null : dart.toString(stackTrace));
for (let port of this.errorPorts)
Expand Down Expand Up @@ -754,7 +754,7 @@ var async = dart.import(async);
}
[_addRegistration](portId, port) {
if (this.ports.containsKey(portId)) {
throw new core.Exception("Registry: ports must be registered only once.");
throw core.Exception.new("Registry: ports must be registered only once.");
}
this.ports.set(portId, port);
}
Expand Down Expand Up @@ -826,7 +826,7 @@ var async = dart.import(async);
let _runHelper = Symbol('_runHelper');
class _EventLoop extends core.Object {
_EventLoop() {
this.events = new (collection.Queue$(_IsolateEvent))();
this.events = collection.Queue$(_IsolateEvent).new();
this[_activeJsAsyncCount] = 0;
}
enqueue(isolate, fn, msg) {
Expand All @@ -842,7 +842,7 @@ var async = dart.import(async);
}
checkOpenReceivePortsFromCommandLine() {
if (dart.notNull(exports._globalState.rootContext != null) && dart.notNull(exports._globalState.isolates.containsKey(exports._globalState.rootContext.id)) && dart.notNull(exports._globalState.fromCommandLine) && dart.notNull(exports._globalState.rootContext.ports.isEmpty)) {
throw new core.Exception("Program exited with open ReceivePorts.");
throw core.Exception.new("Program exited with open ReceivePorts.");
}
}
runIteration() {
Expand Down Expand Up @@ -1068,7 +1068,7 @@ var async = dart.import(async);
IsolateNatives._consoleLog(msg);
} catch (e) {
let trace = dart.stackTrace(e);
throw new core.Exception(trace);
throw core.Exception.new(trace);
}

}
Expand Down Expand Up @@ -1107,8 +1107,8 @@ var async = dart.import(async);
if (uri != null && dart.notNull(uri.endsWith(".dart"))) {
uri = dart.notNull(uri) + ".js";
}
let port = new isolate.ReceivePort();
let completer = new (async.Completer$(core.List))();
let port = isolate.ReceivePort.new();
let completer = async.Completer$(core.List).new();
port.first.then(dart.fn(msg => {
if (dart.equals(dart.dindex(msg, 0), _SPAWNED_SIGNAL)) {
completer.complete(msg);
Expand All @@ -1127,7 +1127,7 @@ var async = dart.import(async);
}
static _startWorker(functionName, uri, args, message, isSpawnUri, startPaused, replyPort, onError) {
if (args != null)
args = new (core.List$(core.String)).from(args);
args = core.List$(core.String).from(args);
if (exports._globalState.isWorker) {
exports._globalState.mainManager.postMessage(_serializeMessage(dart.map({command: 'spawn-worker', functionName: functionName, args: args, msg: message, uri: uri, isSpawnUri: isSpawnUri, startPaused: startPaused, replyPort: replyPort})));
} else {
Expand All @@ -1140,7 +1140,7 @@ var async = dart.import(async);
}
message = _clone(message);
if (args != null)
args = new (core.List$(core.String)).from(args);
args = core.List$(core.String).from(args);
exports._globalState.topEventLoop.enqueue(new _IsolateContext(), dart.fn(() => {
let func = IsolateNatives._getJSFunctionFromName(functionName);
IsolateNatives._startIsolate(dart.as(func, core.Function), args, message, isSpawnUri, startPaused, replyPort);
Expand Down Expand Up @@ -1252,7 +1252,7 @@ var async = dart.import(async);
}
[_checkReplyTo](replyTo) {
if (dart.notNull(replyTo != null) && !dart.is(replyTo, _NativeJsSendPort) && !dart.is(replyTo, _WorkerSendPort)) {
throw new core.Exception("SendPort.send: Illegal replyTo port type");
throw core.Exception.new("SendPort.send: Illegal replyTo port type");
}
}
}
Expand Down Expand Up @@ -1405,7 +1405,7 @@ var async = dart.import(async);
this[_rawPort] = rawPort;
this[_controller] = null;
super.Stream();
this[_controller] = new async.StreamController({onCancel: dart.bind(this, 'close'), sync: true});
this[_controller] = async.StreamController.new({onCancel: dart.bind(this, 'close'), sync: true});
this[_rawPort].handler = dart.bind(this[_controller], 'add');
}
listen(onData, opts) {
Expand Down
Loading

0 comments on commit 81fc365

Please sign in to comment.