Skip to content

Commit

Permalink
fixes #158, precendence of call and access in new
Browse files Browse the repository at this point in the history
  • Loading branch information
John Messerly committed May 5, 2015
1 parent 071e6d0 commit a281dba
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 39 deletions.
8 changes: 4 additions & 4 deletions pkg/dev_compiler/lib/runtime/dart/_internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ var _internal;
if (dart.is(iterable, EfficientLength)) {
return new (EfficientLengthMappedIterable$(S, T))(iterable, func);
}
return new MappedIterable$(S, T)._(dart.as(iterable, core.Iterable$(S)), func);
return new (MappedIterable$(S, T))._(dart.as(iterable, core.Iterable$(S)), func);
}
_(iterable, f) {
this[_iterable] = iterable;
Expand Down Expand Up @@ -560,7 +560,7 @@ var _internal;
if (dart.is(iterable, EfficientLength)) {
return new (EfficientLengthTakeIterable$(E))(iterable, takeCount);
}
return new TakeIterable$(E)._(iterable, takeCount);
return new (TakeIterable$(E))._(iterable, takeCount);
}
_(iterable, takeCount) {
this[_iterable] = iterable;
Expand Down Expand Up @@ -663,7 +663,7 @@ var _internal;
if (dart.is(iterable, EfficientLength)) {
return new (EfficientLengthSkipIterable$(E))(iterable, count);
}
return new SkipIterable$(E)._(iterable, count);
return new (SkipIterable$(E))._(iterable, count);
}
_(iterable, skipCount) {
this[_iterable] = iterable;
Expand All @@ -679,7 +679,7 @@ var _internal;
throw new core.ArgumentError.value(this[_skipCount], "count is not an integer");
}
core.RangeError.checkNotNegative(this[_skipCount], "count");
return new SkipIterable$(E)._(this[_iterable], dart.notNull(this[_skipCount]) + dart.notNull(count));
return new (SkipIterable$(E))._(this[_iterable], dart.notNull(this[_skipCount]) + dart.notNull(count));
}
get [core.$iterator]() {
return new (SkipIterator$(E))(this[_iterable][core.$iterator], this[_skipCount]);
Expand Down
6 changes: 3 additions & 3 deletions pkg/dev_compiler/lib/runtime/dart/_isolate_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var _isolate_helper;
class _Serializer extends core.Object {
_Serializer(opts) {
let serializeSendPorts = opts && 'serializeSendPorts' in opts ? opts.serializeSendPorts : true;
this.serializedObjectIds = new core.Map$(dart.dynamic, core.int).identity();
this.serializedObjectIds = new (core.Map$(dart.dynamic, core.int)).identity();
this[_serializeSendPorts] = dart.as(serializeSendPorts, core.bool);
}
serialize(x) {
Expand Down Expand Up @@ -1022,7 +1022,7 @@ var _isolate_helper;
}
static _startWorker(functionName, uri, args, message, isSpawnUri, startPaused, replyPort, onError) {
if (args != null)
args = new core.List$(core.String).from(args);
args = new (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 @@ -1035,7 +1035,7 @@ var _isolate_helper;
}
message = _clone(message);
if (args != null)
args = new core.List$(core.String).from(args);
args = new (core.List$(core.String)).from(args);
exports._globalState.topEventLoop.enqueue(new _IsolateContext(), () => {
let func = IsolateNatives._getJSFunctionFromName(functionName);
IsolateNatives._startIsolate(dart.as(func, core.Function), args, message, isSpawnUri, startPaused, replyPort);
Expand Down
4 changes: 2 additions & 2 deletions pkg/dev_compiler/lib/runtime/dart/_js_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -3736,8 +3736,8 @@ var _js_helper;
let hashesMap = _foreign_helper.JS_EMBEDDED_GLOBAL('', _js_embedded_names.DEFERRED_LIBRARY_HASHES);
let hashes = dart.as(hashesMap[loadId], core.List$(core.String));
if (uris == null)
return new async.Future$(core.Null).value(null);
let indices = new core.List$(core.int).generate(uris[core.$length], i => dart.as(i, core.int));
return new (async.Future$(core.Null)).value(null);
let indices = new (core.List$(core.int)).generate(uris[core.$length], i => dart.as(i, core.int));
let isHunkLoaded = _foreign_helper.JS_EMBEDDED_GLOBAL('', _js_embedded_names.IS_HUNK_LOADED);
let isHunkInitialized = _foreign_helper.JS_EMBEDDED_GLOBAL('', _js_embedded_names.IS_HUNK_INITIALIZED);
let indicesToLoad = indices[core.$where](i => !isHunkLoaded(hashes[core.$get](i)))[core.$toList]();
Expand Down
20 changes: 10 additions & 10 deletions pkg/dev_compiler/lib/runtime/dart/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -1774,17 +1774,17 @@ var async;
sync(computation) {
try {
let result = computation();
return new Future$(T).value(result);
return new (Future$(T)).value(result);
} catch (error) {
let stackTrace = dart.stackTrace(error);
return new Future$(T).error(error, stackTrace);
return new (Future$(T)).error(error, stackTrace);
}

}
value(value) {
if (value === void 0)
value = null;
return new _Future$(T).immediate(value);
return new (_Future$(T)).immediate(value);
}
error(error, stackTrace) {
if (stackTrace === void 0)
Expand All @@ -1797,7 +1797,7 @@ var async;
stackTrace = replacement.stackTrace;
}
}
return new _Future$(T).immediateError(error, stackTrace);
return new (_Future$(T)).immediateError(error, stackTrace);
}
delayed(duration, computation) {
if (computation === void 0)
Expand Down Expand Up @@ -1870,7 +1870,7 @@ var async;
}, {onError: handleError});
}
if (remaining == 0) {
return new Future$(core.List).value(dart.const([]));
return new (Future$(core.List)).value(dart.const([]));
}
values = new core.List(remaining);
return result;
Expand Down Expand Up @@ -2198,7 +2198,7 @@ var async;
return dart.as(result, Future$(T));
}
asStream() {
return new Stream$(T).fromFuture(this);
return new (Stream$(T)).fromFuture(this);
}
[_markPendingCompletion]() {
if (!dart.notNull(this[_mayComplete]))
Expand Down Expand Up @@ -3695,7 +3695,7 @@ var async;
}
moveNext() {
if (this[_state] == _StreamIteratorImpl._STATE_DONE) {
return new _Future$(core.bool).immediate(false);
return new (_Future$(core.bool)).immediate(false);
}
if (this[_state] == _StreamIteratorImpl._STATE_MOVING) {
throw new core.StateError("Already waiting for next.");
Expand All @@ -3714,18 +3714,18 @@ var async;
this[_current] = dart.as(this[_futureOrPrefetch], T);
this[_futureOrPrefetch] = null;
this[_subscription].resume();
return new _Future$(core.bool).immediate(true);
return new (_Future$(core.bool)).immediate(true);
}
case _StreamIteratorImpl._STATE_EXTRA_ERROR:
{
let prefetch = dart.as(this[_futureOrPrefetch], AsyncError);
this[_clear]();
return new _Future$(core.bool).immediateError(prefetch.error, prefetch.stackTrace);
return new (_Future$(core.bool)).immediateError(prefetch.error, prefetch.stackTrace);
}
case _StreamIteratorImpl._STATE_EXTRA_DONE:
{
this[_clear]();
return new _Future$(core.bool).immediate(false);
return new (_Future$(core.bool)).immediate(false);
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/dev_compiler/lib/runtime/dart/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -560,10 +560,10 @@ var collection;
}
[core.$toList](opts) {
let growable = opts && 'growable' in opts ? opts.growable : true;
return new core.List$(E).from(this, {growable: growable});
return new (core.List$(E)).from(this, {growable: growable});
}
[core.$toSet]() {
return new core.Set$(E).from(this);
return new (core.Set$(E)).from(this);
}
get [core.$length]() {
dart.assert(!dart.is(this, _internal.EfficientLength));
Expand Down Expand Up @@ -776,10 +776,10 @@ var collection;
}
[core.$toList](opts) {
let growable = opts && 'growable' in opts ? opts.growable : true;
return new core.List$(E).from(this, {growable: growable});
return new (core.List$(E)).from(this, {growable: growable});
}
[core.$toSet]() {
return new core.Set$(E).from(this);
return new (core.Set$(E)).from(this);
}
get [core.$length]() {
dart.assert(!dart.is(this, _internal.EfficientLength));
Expand Down Expand Up @@ -2219,7 +2219,7 @@ var collection;
return new (ListQueue$(E))();
}
from(elements) {
return new ListQueue$(E).from(elements);
return new (ListQueue$(E)).from(elements);
}
[Symbol.iterator]() {
return new dart.JsIterator(this[core.$iterator]);
Expand Down
24 changes: 12 additions & 12 deletions pkg/dev_compiler/lib/runtime/dart/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -1150,7 +1150,7 @@ var core;
let newStart = dart.notNull(this[_start]) + dart.notNull(count);
if (dart.notNull(newStart) >= dart.notNull(this[_end]))
return new (_internal.EmptyIterable$(E))();
return new exports._GeneratorIterable$(E).slice(newStart, this[_end], this[_generator]);
return new (exports._GeneratorIterable$(E)).slice(newStart, this[_end], this[_generator]);
}
[$take](count) {
RangeError.checkNotNegative(count, "count");
Expand All @@ -1159,7 +1159,7 @@ var core;
let newEnd = dart.notNull(this[_start]) + dart.notNull(count);
if (dart.notNull(newEnd) >= dart.notNull(this[_end]))
return this;
return new exports._GeneratorIterable$(E).slice(this[_start], newEnd, this[_generator]);
return new (exports._GeneratorIterable$(E)).slice(this[_start], newEnd, this[_generator]);
}
static _id(n) {
return n;
Expand Down Expand Up @@ -1428,13 +1428,13 @@ var core;
[$toList](opts) {
let growable = opts && 'growable' in opts ? opts.growable : true;
if (growable) {
return new _interceptors.JSArray$(E).markGrowable(this.slice());
return new (_interceptors.JSArray$(E)).markGrowable(this.slice());
} else {
return new _interceptors.JSArray$(E).markFixed(this.slice());
return new (_interceptors.JSArray$(E)).markFixed(this.slice());
}
}
[$toSet]() {
return new exports.Set$(E).from(this);
return new (exports.Set$(E)).from(this);
}
get [$iterator]() {
return new (_internal.ListIterator$(E))(this);
Expand Down Expand Up @@ -1583,7 +1583,7 @@ var core;
}
if (start == end)
return dart.setType([], List$(E));
return new _interceptors.JSArray$(E).markGrowable(this.slice(start, end));
return new (_interceptors.JSArray$(E)).markGrowable(this.slice(start, end));
}
[$getRange](start, end) {
return new (_internal.IterableMixinWorkaround$(E))().getRangeList(this, start, end);
Expand Down Expand Up @@ -1638,16 +1638,16 @@ var core;
return new (collection.LinkedHashMap$(K, V))();
}
from(other) {
return new collection.LinkedHashMap$(K, V).from(other);
return new (collection.LinkedHashMap$(K, V)).from(other);
}
identity() {
return new collection.LinkedHashMap$(K, V).identity();
return new (collection.LinkedHashMap$(K, V)).identity();
}
fromIterable(iterable, opts) {
return new collection.LinkedHashMap$(K, V).fromIterable(iterable, opts);
return new (collection.LinkedHashMap$(K, V)).fromIterable(iterable, opts);
}
fromIterables(keys, values) {
return new collection.LinkedHashMap$(K, V).fromIterables(keys, values);
return new (collection.LinkedHashMap$(K, V)).fromIterables(keys, values);
}
}
dart.defineNamedConstructor(Map, 'from');
Expand Down Expand Up @@ -1691,10 +1691,10 @@ var core;
return new (collection.LinkedHashSet$(E))();
}
identity() {
return new collection.LinkedHashSet$(E).identity();
return new (collection.LinkedHashSet$(E)).identity();
}
from(elements) {
return new collection.LinkedHashSet$(E).from(elements);
return new (collection.LinkedHashSet$(E)).from(elements);
}
}
Set[dart.implements] = () => [_internal.EfficientLength];
Expand Down
4 changes: 2 additions & 2 deletions pkg/dev_compiler/lib/runtime/dart/isolate.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var isolate;
return dart.as(_isolate_helper.IsolateNatives.spawnFunction(entryPoint, message, paused).then(msg => new Isolate(dart.as(dart.dindex(msg, 1), SendPort), {pauseCapability: dart.as(dart.dindex(msg, 2), Capability), terminateCapability: dart.as(dart.dindex(msg, 3), Capability)})), async.Future$(Isolate));
} catch (e) {
let st = dart.stackTrace(e);
return new async.Future$(Isolate).error(e, st);
return new (async.Future$(Isolate)).error(e, st);
}

}
Expand All @@ -55,7 +55,7 @@ var isolate;
return dart.as(_isolate_helper.IsolateNatives.spawnUri(uri, args, message, paused).then(msg => new Isolate(dart.as(dart.dindex(msg, 1), SendPort), {pauseCapability: dart.as(dart.dindex(msg, 2), Capability), terminateCapability: dart.as(dart.dindex(msg, 3), Capability)})), async.Future$(Isolate));
} catch (e) {
let st = dart.stackTrace(e);
return new async.Future$(Isolate).error(e, st);
return new (async.Future$(Isolate)).error(e, st);
}

}
Expand Down
22 changes: 21 additions & 1 deletion pkg/dev_compiler/lib/src/js/printer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class Printer implements NodeVisitor {

bool inForInit = false;
bool atStatementBegin = false;
bool inNewTarget = false;
bool pendingSemicolon = false;
bool pendingSpace = false;

Expand Down Expand Up @@ -560,6 +561,7 @@ class Printer implements NodeVisitor {
if (needsParentheses) {
inForInit = false;
atStatementBegin = false;
inNewTarget = false;
out("(");
visit(node);
out(")");
Expand Down Expand Up @@ -616,8 +618,10 @@ class Printer implements NodeVisitor {

visitNew(New node) {
out("new ");
inNewTarget = true;
visitNestedExpression(node.target, ACCESS,
newInForInit: inForInit, newAtStatementBegin: false);
inNewTarget = false;
out("(");
visitCommaSeparated(node.arguments, ASSIGNMENT,
newInForInit: false, newAtStatementBegin: false);
Expand Down Expand Up @@ -809,7 +813,23 @@ class Printer implements NodeVisitor {
}

visitAccess(PropertyAccess access) {
visitNestedExpression(access.receiver, CALL,
// Normally we can omit parens on the receiver if it is a Call, even though
// Call expressions have lower precedence. However this optimization doesn't
// work inside New expressions:
//
// new obj.foo().bar()
//
// This will be parsed as:
//
// (new obj.foo()).bar()
//
// Which is incorrect. So we must have parenthesis in this case:
//
// new (obj.foo()).bar()
//
int precedence = inNewTarget ? ACCESS : CALL;

visitNestedExpression(access.receiver, precedence,
newInForInit: inForInit,
newAtStatementBegin: atStatementBegin);
propertyNameOut(access.selector, inAccess: true);
Expand Down

0 comments on commit a281dba

Please sign in to comment.