From da91435c66173cc5a6944fa75a68187a1d1f72d7 Mon Sep 17 00:00:00 2001 From: John Messerly Date: Tue, 14 Apr 2015 18:04:14 -0700 Subject: [PATCH] fixes for angular hello: String + and disable broken arg parsing R=jacobr@google.com Review URL: https://codereview.chromium.org/1085723002 --- .../lib/runtime/dart/_interceptors.js | 10 +- .../lib/runtime/dart/_internal.js | 2 +- .../lib/runtime/dart/_isolate_helper.js | 6 +- .../lib/runtime/dart/_js_helper.js | 94 +++++++++---------- pkg/dev_compiler/lib/runtime/dart/async.js | 2 +- .../lib/runtime/dart/collection.js | 8 +- pkg/dev_compiler/lib/runtime/dart/convert.js | 2 +- pkg/dev_compiler/lib/runtime/dart/core.js | 60 ++++++------ pkg/dev_compiler/lib/runtime/dart_runtime.js | 3 + .../lib/src/codegen/js_codegen.dart | 21 +++-- .../test/codegen/expect/fieldtest.js | 2 +- 11 files changed, 109 insertions(+), 101 deletions(-) diff --git a/pkg/dev_compiler/lib/runtime/dart/_interceptors.js b/pkg/dev_compiler/lib/runtime/dart/_interceptors.js index 3884e240785c..413850622076 100644 --- a/pkg/dev_compiler/lib/runtime/dart/_interceptors.js +++ b/pkg/dev_compiler/lib/runtime/dart/_interceptors.js @@ -78,7 +78,7 @@ var _interceptors; } } get isNegative() { - return dart.equals(this, 0) ? 1['/'](this) < 0 : this['<'](0); + return dart.equals(this, 0) ? core.int['/'](1, this) < 0 : this['<'](0); } get isNaN() { return isNaN(this); @@ -214,7 +214,7 @@ var _interceptors; result = result + dart.dindex(match, 2); exponent = dart.notNull(exponent) - dart.dindex(match, 2).length; } - return core.String['+'](result, core.String['*']("0", exponent)); + return dart.notNull(result) + core.String['*']("0", exponent); } toString() { if (dart.notNull(dart.equals(this, 0)) && 1 / this < 0) { @@ -387,8 +387,8 @@ var _interceptors; } static [_bitCount](i) { i = dart.as(dart.dsend(JSInt[_shru](i, 0), '-', dart.dsend(JSInt[_shru](i, 1), '&', 1431655765)), core.int); - i = (dart.notNull(i) & 858993459)['+'](dart.dsend(JSInt[_shru](i, 2), '&', 858993459)); - i = 252645135 & i['+'](JSInt[_shru](i, 4)); + i = core.int['+'](dart.notNull(i) & 858993459, dart.dsend(JSInt[_shru](i, 2), '&', 858993459)); + i = 252645135 & core.int['+'](i, JSInt[_shru](i, 4)); i = dart.notNull(i) + dart.notNull(dart.as(JSInt[_shru](i, 8), core.int)); i = dart.notNull(i) + dart.notNull(dart.as(JSInt[_shru](i, 16), core.int)); return dart.notNull(i) & 63; @@ -740,7 +740,7 @@ var _interceptors; let delta = dart.notNull(width) - dart.notNull(this.length); if (dart.notNull(delta) <= 0) return this; - return core.String['+'](core.String['*'](padding, delta), this); + return core.String['*'](padding, delta) + dart.notNull(this); } padRight(width, padding) { if (padding === void 0) diff --git a/pkg/dev_compiler/lib/runtime/dart/_internal.js b/pkg/dev_compiler/lib/runtime/dart/_internal.js index 91b166257759..8e029e2e59a7 100644 --- a/pkg/dev_compiler/lib/runtime/dart/_internal.js +++ b/pkg/dev_compiler/lib/runtime/dart/_internal.js @@ -1846,7 +1846,7 @@ var _internal; this[_name] = Symbol.validatePublicSymbol(name); } ['=='](other) { - return dart.is(other, Symbol) && dart.notNull(dart.equals(this[_name], dart.dload(other, _name))); + return dart.is(other, Symbol) && dart.equals(this[_name], dart.dload(other, _name)); } get hashCode() { let arbitraryPrime = 664597; diff --git a/pkg/dev_compiler/lib/runtime/dart/_isolate_helper.js b/pkg/dev_compiler/lib/runtime/dart/_isolate_helper.js index d6086f141174..629495d63b4c 100644 --- a/pkg/dev_compiler/lib/runtime/dart/_isolate_helper.js +++ b/pkg/dev_compiler/lib/runtime/dart/_isolate_helper.js @@ -445,7 +445,7 @@ var _isolate_helper; let isWindowDefined = exports.globalWindow != null; let isWorkerDefined = exports.globalWorker != null; this.isWorker = !dart.notNull(isWindowDefined) && dart.notNull(exports.globalPostMessageDefined); - this.supportsWorkers = dart.notNull(this.isWorker) || dart.notNull(isWorkerDefined) && dart.notNull(IsolateNatives.thisScript != null); + this.supportsWorkers = dart.notNull(this.isWorker) || dart.notNull(isWorkerDefined) && IsolateNatives.thisScript != null; this.fromCommandLine = !dart.notNull(isWindowDefined) && !dart.notNull(this.isWorker); } [_nativeInitWorkerMessageHandler]() { @@ -1011,8 +1011,8 @@ var _isolate_helper; return IsolateNatives.spawn(null, uri.toString(), args, message, isLight, isSpawnUri, startPaused); } static spawn(functionName, uri, args, message, isLight, isSpawnUri, startPaused) { - if (dart.notNull(uri != null) && dart.notNull(uri.endsWith(".dart"))) { - uri = core.String['+'](uri, ".js"); + if (uri != null && dart.notNull(uri.endsWith(".dart"))) { + uri = dart.notNull(uri) + ".js"; } let port = new isolate.ReceivePort(); let completer = dart.as(new async.Completer(), async.Completer$(core.List)); diff --git a/pkg/dev_compiler/lib/runtime/dart/_js_helper.js b/pkg/dev_compiler/lib/runtime/dart/_js_helper.js index 1aa70ee7231b..5f4814105f04 100644 --- a/pkg/dev_compiler/lib/runtime/dart/_js_helper.js +++ b/pkg/dev_compiler/lib/runtime/dart/_js_helper.js @@ -93,7 +93,7 @@ var _js_helper; } forEach(f) { let keys = this[_keys]; - for (let i = 0; i['<'](dart.dload(keys, 'length')); i = dart.notNull(i) + 1) { + for (let i = 0; core.int['<'](i, dart.dload(keys, 'length')); i = dart.notNull(i) + 1) { let key = dart.dindex(keys, i); f(dart.as(key, K), dart.as(this[_fetch](key), V)); } @@ -377,7 +377,7 @@ var _js_helper; let context = window; let fun = function() { }; - for (let i = 0; i['<'](dart.dload(tags, 'length')); i = dart.notNull(i) + 1) { + for (let i = 0; core.int['<'](i, dart.dload(tags, 'length')); i = dart.notNull(i) + 1) { let tag = dart.dindex(tags, i); let proto = dart.dcall(exports.prototypeForTagFunction, tag); if (proto != null) { @@ -390,15 +390,15 @@ var _js_helper; } } } - for (let i = 0; i['<'](dart.dload(tags, 'length')); i = dart.notNull(i) + 1) { + for (let i = 0; core.int['<'](i, dart.dload(tags, 'length')); i = dart.notNull(i) + 1) { let tag = tags[i]; if (/^[A-Za-z_]/.test(tag)) { let interceptorClass = propertyGet(map, tag); - propertySet(map, core.String['+'](INSTANCE_CACHED_MARK, tag), interceptorClass); - propertySet(map, core.String['+'](UNCACHED_MARK, tag), interceptorClass); - propertySet(map, core.String['+'](LEAF_MARK, tag), interceptorClass); - propertySet(map, core.String['+'](INTERIOR_MARK, tag), interceptorClass); - propertySet(map, core.String['+'](DISCRIMINATED_MARK, tag), interceptorClass); + propertySet(map, dart.notNull(INSTANCE_CACHED_MARK) + dart.notNull(tag), interceptorClass); + propertySet(map, dart.notNull(UNCACHED_MARK) + dart.notNull(tag), interceptorClass); + propertySet(map, dart.notNull(LEAF_MARK) + dart.notNull(tag), interceptorClass); + propertySet(map, dart.notNull(INTERIOR_MARK) + dart.notNull(tag), interceptorClass); + propertySet(map, dart.notNull(DISCRIMINATED_MARK) + dart.notNull(tag), interceptorClass); } } } @@ -891,7 +891,7 @@ var _js_helper; return this[_typeName].hashCode; } ['=='](other) { - return dart.is(other, TypeImpl) && dart.notNull(dart.equals(this[_typeName], dart.dload(other, _typeName))); + return dart.is(other, TypeImpl) && dart.equals(this[_typeName], dart.dload(other, _typeName)); } } TypeImpl[dart.implements] = () => [core.Type]; @@ -1092,7 +1092,7 @@ var _js_helper; } // Function isSupertypeOfNull: (dynamic) → bool function isSupertypeOfNull(type) { - return dart.notNull(type == null) || dart.notNull(getConstructorName(type) == _foreign_helper.JS_OBJECT_CLASS_NAME()) || dart.notNull(getConstructorName(type) == _foreign_helper.JS_NULL_CLASS_NAME()); + return dart.notNull(type == null) || getConstructorName(type) == _foreign_helper.JS_OBJECT_CLASS_NAME() || getConstructorName(type) == _foreign_helper.JS_NULL_CLASS_NAME(); } // Function checkSubtypeOfRuntimeType: (dynamic, dynamic) → bool function checkSubtypeOfRuntimeType(o, t) { @@ -1724,8 +1724,8 @@ var _js_helper; let _mangledNameMatchesType = Symbol('_mangledNameMatchesType'); class Primitives extends core.Object { static initializeStatics(id) { - Primitives.mirrorFunctionCacheName = core.String['+'](Primitives.mirrorFunctionCacheName, `_${id}`); - Primitives.mirrorInvokeCacheName = core.String['+'](Primitives.mirrorInvokeCacheName, `_${id}`); + Primitives.mirrorFunctionCacheName = dart.notNull(Primitives.mirrorFunctionCacheName) + `_${id}`; + Primitives.mirrorInvokeCacheName = dart.notNull(Primitives.mirrorInvokeCacheName) + `_${id}`; } static objectHashCode(object) { let hash = dart.as(object.$identityHash, core.int); @@ -1799,7 +1799,7 @@ var _js_helper; let result = parseFloat(source); if (result.isNaN) { let trimmed = source.trim(); - if (dart.notNull(trimmed == 'NaN') || dart.notNull(trimmed == '+NaN') || dart.notNull(trimmed == '-NaN')) { + if (trimmed == 'NaN' || trimmed == '+NaN' || trimmed == '-NaN') { return result; } return handleError(source); @@ -1883,8 +1883,8 @@ var _js_helper; if (dart.dsend(i, '<=', 65535)) { a[core.$add](dart.as(i, core.int)); } else if (dart.dsend(i, '<=', 1114111)) { - a[core.$add](55296['+'](dart.dsend(dart.dsend(dart.dsend(i, '-', 65536), '>>', 10), '&', 1023))); - a[core.$add](56320['+'](dart.dsend(i, '&', 1023))); + a[core.$add](core.int['+'](55296, dart.dsend(dart.dsend(dart.dsend(i, '-', 65536), '>>', 10), '&', 1023))); + a[core.$add](core.int['+'](56320, dart.dsend(i, '&', 1023))); } else { throw new core.ArgumentError(i); } @@ -1903,14 +1903,14 @@ var _js_helper; return Primitives[_fromCharCodeApply](dart.as(charCodes, core.List$(core.int))); } static stringFromCharCode(charCode) { - if (0['<='](charCode)) { + if (core.int['<='](0, charCode)) { if (dart.dsend(charCode, '<=', 65535)) { return String.fromCharCode(charCode); } if (dart.dsend(charCode, '<=', 1114111)) { let bits = dart.dsend(charCode, '-', 65536); - let low = 56320['|'](dart.dsend(bits, '&', 1023)); - let high = 55296['|'](dart.dsend(bits, '>>', 10)); + let low = core.int['|'](56320, dart.dsend(bits, '&', 1023)); + let high = core.int['|'](55296, dart.dsend(bits, '>>', 10)); return String.fromCharCode(high, low); } } @@ -3382,7 +3382,7 @@ var _js_helper; static listToRti(list) { list = list; let result = []; - for (let i = 0; i['<'](dart.dload(list, 'length')); i = dart.notNull(i) + 1) { + for (let i = 0; core.int['<'](i, dart.dload(list, 'length')); i = dart.notNull(i) + 1) { result.push(dart.dsend(dart.dindex(list, i), 'toRti')); } return result; @@ -3394,46 +3394,46 @@ var _js_helper; for (let i = 0; dart.notNull(i) < dart.notNull(this.parameterTypes[core.$length]); i = dart.notNull(i) + 1) { let type = this.parameterTypes[core.$get](i); if (needsComma) { - result = core.String['+'](result, ', '); + result = dart.notNull(result) + ', '; } - result = core.String['+'](result, `${type}`); + result = dart.notNull(result) + `${type}`; needsComma = true; } } if (dart.notNull(this.optionalParameterTypes != null) && !dart.notNull(this.optionalParameterTypes[core.$isEmpty])) { if (needsComma) { - result = core.String['+'](result, ', '); + result = dart.notNull(result) + ', '; } needsComma = false; - result = core.String['+'](result, '['); + result = dart.notNull(result) + '['; for (let i = 0; dart.notNull(i) < dart.notNull(this.optionalParameterTypes[core.$length]); i = dart.notNull(i) + 1) { let type = this.optionalParameterTypes[core.$get](i); if (needsComma) { - result = core.String['+'](result, ', '); + result = dart.notNull(result) + ', '; } - result = core.String['+'](result, `${type}`); + result = dart.notNull(result) + `${type}`; needsComma = true; } - result = core.String['+'](result, ']'); + result = dart.notNull(result) + ']'; } else if (this.namedParameters != null) { if (needsComma) { - result = core.String['+'](result, ', '); + result = dart.notNull(result) + ', '; } needsComma = false; - result = core.String['+'](result, '{'); + result = dart.notNull(result) + '{'; let keys = _js_names.extractKeys(this.namedParameters); for (let i = 0; dart.notNull(i) < dart.notNull(keys[core.$length]); i = dart.notNull(i) + 1) { let name = keys[core.$get](i); if (needsComma) { - result = core.String['+'](result, ', '); + result = dart.notNull(result) + ', '; } let rti = dart.dsend(this.namedParameters[name], 'toRti'); - result = core.String['+'](result, `${rti} ${name}`); + result = dart.notNull(result) + `${rti} ${name}`; needsComma = true; } - result = core.String['+'](result, '}'); + result = dart.notNull(result) + '}'; } - result = core.String['+'](result, `) -> ${this.returnType}`); + result = dart.notNull(result) + `) -> ${this.returnType}`; return result; } } @@ -3625,39 +3625,39 @@ var _js_helper; let sep = ''; if (this[_hasArguments]) { for (let argument of this[_arguments]) { - s = core.String['+'](s, sep); - s = core.String['+'](s, this[_convert](argument)); + s = dart.notNull(s) + dart.notNull(sep); + s = dart.notNull(s) + dart.notNull(this[_convert](argument)); sep = ', '; } } if (this[_hasOptionalArguments]) { - s = core.String['+'](s, `${sep}[`); + s = dart.notNull(s) + `${sep}[`; sep = ''; for (let argument of this[_optionalArguments]) { - s = core.String['+'](s, sep); - s = core.String['+'](s, this[_convert](argument)); + s = dart.notNull(s) + dart.notNull(sep); + s = dart.notNull(s) + dart.notNull(this[_convert](argument)); sep = ', '; } - s = core.String['+'](s, ']'); + s = dart.notNull(s) + ']'; } if (this[_hasNamedArguments]) { - s = core.String['+'](s, `${sep}{`); + s = dart.notNull(s) + `${sep}{`; sep = ''; for (let name of _js_names.extractKeys(this[_namedArguments])) { - s = core.String['+'](s, sep); - s = core.String['+'](s, `${name}: `); - s = core.String['+'](s, this[_convert](this[_namedArguments][name])); + s = dart.notNull(s) + dart.notNull(sep); + s = dart.notNull(s) + `${name}: `; + s = dart.notNull(s) + dart.notNull(this[_convert](this[_namedArguments][name])); sep = ', '; } - s = core.String['+'](s, '}'); + s = dart.notNull(s) + '}'; } - s = core.String['+'](s, ') -> '); + s = dart.notNull(s) + ') -> '; if (this[_isVoid]) { - s = core.String['+'](s, 'void'); + s = dart.notNull(s) + 'void'; } else if (this[_hasReturnType]) { - s = core.String['+'](s, this[_convert](this[_returnType])); + s = dart.notNull(s) + dart.notNull(this[_convert](this[_returnType])); } else { - s = core.String['+'](s, 'dynamic'); + s = dart.notNull(s) + 'dynamic'; } return this[_cachedToString] = `${s}`; } diff --git a/pkg/dev_compiler/lib/runtime/dart/async.js b/pkg/dev_compiler/lib/runtime/dart/async.js index 550d08199986..fe1810d1928d 100644 --- a/pkg/dev_compiler/lib/runtime/dart/async.js +++ b/pkg/dev_compiler/lib/runtime/dart/async.js @@ -43,7 +43,7 @@ var async; toString() { let result = `Uncaught Error: ${this.error}`; if (this.stackTrace != null) { - result = core.String['+'](result, `\nStack Trace:\n${this.stackTrace}`); + result = dart.notNull(result) + `\nStack Trace:\n${this.stackTrace}`; } return result; } diff --git a/pkg/dev_compiler/lib/runtime/dart/collection.js b/pkg/dev_compiler/lib/runtime/dart/collection.js index 40357b4f38ab..0d83c67dfc0d 100644 --- a/pkg/dev_compiler/lib/runtime/dart/collection.js +++ b/pkg/dev_compiler/lib/runtime/dart/collection.js @@ -242,7 +242,7 @@ var collection; if (!dart.notNull(iterator.moveNext())) return ""; let buffer = new core.StringBuffer(); - if (dart.notNull(separator == null) || dart.notNull(separator == "")) { + if (separator == null || separator == "") { do { buffer.write(`${iterator.current}`); } while (iterator.moveNext()); @@ -488,7 +488,7 @@ var collection; if (!dart.notNull(iterator.moveNext())) return ""; let buffer = new core.StringBuffer(); - if (dart.notNull(separator == null) || dart.notNull(separator == "")) { + if (separator == null || separator == "") { do { buffer.write(`${iterator.current}`); } while (iterator.moveNext()); @@ -689,7 +689,7 @@ var collection; if (!dart.notNull(iterator.moveNext())) return ""; let buffer = new core.StringBuffer(); - if (dart.notNull(separator == null) || dart.notNull(separator == "")) { + if (separator == null || separator == "") { do { buffer.write(`${iterator.current}`); } while (iterator.moveNext()); @@ -833,7 +833,7 @@ var collection; if (rightDelimiter === void 0) rightDelimiter = ')'; if (IterableBase[_isToStringVisiting](iterable)) { - if (dart.notNull(leftDelimiter == "(") && dart.notNull(rightDelimiter == ")")) { + if (leftDelimiter == "(" && rightDelimiter == ")") { return "(...)"; } return `${leftDelimiter}...${rightDelimiter}`; diff --git a/pkg/dev_compiler/lib/runtime/dart/convert.js b/pkg/dev_compiler/lib/runtime/dart/convert.js index 85cdea784744..d3d297b4bddb 100644 --- a/pkg/dev_compiler/lib/runtime/dart/convert.js +++ b/pkg/dev_compiler/lib/runtime/dart/convert.js @@ -1400,7 +1400,7 @@ var convert; } addSlice(chunk, start, end, isLast) { if (this[_carry] != null) { - chunk = core.String['+'](this[_carry], chunk.substring(start, end)); + chunk = dart.notNull(this[_carry]) + dart.notNull(chunk.substring(start, end)); start = 0; end = chunk.length; this[_carry] = null; diff --git a/pkg/dev_compiler/lib/runtime/dart/core.js b/pkg/dev_compiler/lib/runtime/dart/core.js index 7f75328a9ad0..9c751d9a611d 100644 --- a/pkg/dev_compiler/lib/runtime/dart/core.js +++ b/pkg/dev_compiler/lib/runtime/dart/core.js @@ -938,23 +938,23 @@ var core; } toString() { let report = "FormatException"; - if (dart.notNull(this.message != null) && dart.notNull("" != this.message)) { + if (this.message != null && "" != this.message) { report = `${report}: ${this.message}`; } let offset = this.offset; if (!(typeof this.source == 'string')) { if (offset != -1) { - report = String['+'](report, ` (at offset ${offset})`); + report = dart.notNull(report) + ` (at offset ${offset})`; } return report; } - if (offset != -1 && (dart.notNull(offset) < 0 || offset['>'](dart.dload(this.source, 'length')))) { + if (offset != -1 && (dart.notNull(offset) < 0 || int['>'](offset, dart.dload(this.source, 'length')))) { offset = -1; } if (offset == -1) { let source = dart.as(this.source, String); if (dart.notNull(source.length) > 78) { - source = String['+'](source.substring(0, 75), "..."); + source = dart.notNull(source.substring(0, 75)) + "..."; } return `${report}\n${source}`; } @@ -976,12 +976,12 @@ var core; } } if (dart.notNull(lineNum) > 1) { - report = String['+'](report, ` (at line ${lineNum}, character ${dart.notNull(offset) - dart.notNull(lineStart) + 1})\n`); + report = dart.notNull(report) + ` (at line ${lineNum}, character ${dart.notNull(offset) - dart.notNull(lineStart) + 1})\n`; } else { - report = String['+'](report, ` (at character ${dart.notNull(offset) + 1})\n`); + report = dart.notNull(report) + ` (at character ${dart.notNull(offset) + 1})\n`; } let lineEnd = dart.as(dart.dload(this.source, 'length'), int); - for (let i = offset; i['<'](dart.dload(this.source, 'length')); i = dart.notNull(i) + 1) { + for (let i = offset; int['<'](i, dart.dload(this.source, 'length')); i = dart.notNull(i) + 1) { let char = dart.as(dart.dsend(this.source, 'codeUnitAt', i), int); if (char == 10 || char == 13) { lineEnd = i; @@ -1994,7 +1994,7 @@ var core; fragment = Uri[_makeFragment](fragment, 0, Uri[_stringOrNullLength](fragment)); port = Uri[_makePort](port, scheme); let isFile = scheme == "file"; - if (dart.notNull(host == null) && (dart.notNull(userInfo.isNotEmpty) || port != null || dart.notNull(isFile))) { + if (host == null && (dart.notNull(userInfo.isNotEmpty) || port != null || dart.notNull(isFile))) { host = ""; } let ensureLeadingSlash = host != null; @@ -2015,7 +2015,7 @@ var core; let userInfo = ""; let host = null; let port = null; - if (dart.notNull(authority != null) && dart.notNull(authority.isNotEmpty)) { + if (authority != null && dart.notNull(authority.isNotEmpty)) { let hostStart = 0; let hasUserInfo = false; for (let i = 0; dart.notNull(i) < dart.notNull(authority.length); i = dart.notNull(i) + 1) { @@ -2097,9 +2097,9 @@ var core; return; } if (argumentError) { - throw new ArgumentError(String['+']("Illegal drive letter ", new String.fromCharCode(charCode))); + throw new ArgumentError("Illegal drive letter " + dart.notNull(new String.fromCharCode(charCode))); } else { - throw new UnsupportedError(String['+']("Illegal drive letter ", new String.fromCharCode(charCode))); + throw new UnsupportedError("Illegal drive letter " + dart.notNull(new String.fromCharCode(charCode))); } } static [_makeFileUri](path) { @@ -2124,7 +2124,7 @@ var core; path = path.replaceAll("/", "\\"); } let sep = "\\"; - if (dart.notNull(path.length) > 1 && dart.notNull(String.get(path, 1) == ":")) { + if (dart.notNull(path.length) > 1 && String.get(path, 1) == ":") { Uri[_checkWindowsDriveLetter](path.codeUnitAt(0), true); if (path.length == 2 || path.codeUnitAt(2) != Uri[_BACKSLASH]) { throw new ArgumentError("Windows paths with drive letter must be absolute"); @@ -2133,8 +2133,8 @@ var core; Uri[_checkWindowsPathReservedCharacters](pathSegments, true, 1); return new Uri({scheme: "file", pathSegments: pathSegments}); } - if (dart.notNull(path.length) > 0 && dart.notNull(String.get(path, 0) == sep)) { - if (dart.notNull(path.length) > 1 && dart.notNull(String.get(path, 1) == sep)) { + if (dart.notNull(path.length) > 0 && String.get(path, 0) == sep) { + if (dart.notNull(path.length) > 1 && String.get(path, 1) == sep) { let pathStart = path.indexOf("\\", 2); let hostPart = pathStart == -1 ? path.substring(2) : path.substring(2, pathStart); let pathPart = pathStart == -1 ? "" : path.substring(dart.notNull(pathStart) + 1); @@ -2191,7 +2191,7 @@ var core; host = ""; } let ensureLeadingSlash = host != null; - if (dart.notNull(path != null) || dart.notNull(pathSegments != null)) { + if (path != null || dart.notNull(pathSegments != null)) { path = Uri[_makePath](path, 0, Uri[_stringOrNullLength](path), pathSegments, ensureLeadingSlash, isFile); } else { path = this.path; @@ -2199,7 +2199,7 @@ var core; path = `/${path}`; } } - if (dart.notNull(query != null) || dart.notNull(queryParameters != null)) { + if (query != null || dart.notNull(queryParameters != null)) { query = Uri[_makeQuery](query, 0, Uri[_stringOrNullLength](query), queryParameters); } else if (this.hasQuery) { query = this.query; @@ -2263,7 +2263,7 @@ var core; let char = host.codeUnitAt(index); if (char == Uri[_PERCENT]) { let replacement = Uri[_normalizeEscape](host, index, true); - if (dart.notNull(replacement == null) && dart.notNull(isNormalized)) { + if (replacement == null && dart.notNull(isNormalized)) { index = dart.notNull(index) + 3; continue; } @@ -2355,9 +2355,9 @@ var core; return Uri[_normalize](userInfo, start, end, dart.as(Uri[_userinfoTable], List$(int))); } static [_makePath](path, start, end, pathSegments, ensureLeadingSlash, isFile) { - if (dart.notNull(path == null) && dart.notNull(pathSegments == null)) + if (path == null && dart.notNull(pathSegments == null)) return isFile ? "/" : ""; - if (dart.notNull(path != null) && dart.notNull(pathSegments != null)) { + if (path != null && dart.notNull(pathSegments != null)) { throw new ArgumentError('Both path and pathSegments specified'); } let result = null; @@ -2375,9 +2375,9 @@ var core; return dart.as(result, String); } static [_makeQuery](query, start, end, queryParameters) { - if (dart.notNull(query == null) && dart.notNull(queryParameters == null)) + if (query == null && dart.notNull(queryParameters == null)) return null; - if (dart.notNull(query != null) && dart.notNull(queryParameters != null)) { + if (query != null && dart.notNull(queryParameters != null)) { throw new ArgumentError('Both query and queryParameters specified'); } if (query != null) @@ -2537,7 +2537,7 @@ var core; return dart.notNull(ch) <= dart.notNull(Uri[_RIGHT_BRACKET]) && dart.notNull(!dart.equals(dart.dsend(Uri[_genDelimitersTable][exports.$get](dart.notNull(ch) >> 4), '&', 1 << (dart.notNull(ch) & 15)), 0)); } get isAbsolute() { - return dart.notNull(this.scheme != "") && dart.notNull(this.fragment == ""); + return this.scheme != "" && this.fragment == ""; } [_merge](base, reference) { if (base.isEmpty) @@ -2561,7 +2561,7 @@ var core; baseEnd = newEnd; backCount = dart.notNull(backCount) - 1; } - return String['+'](base.substring(0, dart.notNull(baseEnd) + 1), reference.substring(dart.notNull(refStart) - 3 * dart.notNull(backCount))); + return dart.notNull(base.substring(0, dart.notNull(baseEnd) + 1)) + dart.notNull(reference.substring(dart.notNull(refStart) - 3 * dart.notNull(backCount))); } [_hasDotSegments](path) { if (dart.notNull(path.length) > 0 && path.codeUnitAt(0) == Uri[_DOT]) @@ -2577,7 +2577,7 @@ var core; for (let segment of path.split("/")) { appendSlash = false; if (segment == "..") { - if (!dart.notNull(output[exports.$isEmpty]) && (output[exports.$length] != 1 || dart.notNull(output[exports.$get](0) != ""))) + if (!dart.notNull(output[exports.$isEmpty]) && (output[exports.$length] != 1 || output[exports.$get](0) != "")) output[exports.$removeLast](); appendSlash = true; } else if ("." == segment) { @@ -2658,10 +2658,10 @@ var core; return this[_fragment] != null; } get origin() { - if (dart.notNull(this.scheme == "") || dart.notNull(this[_host] == null) || dart.notNull(this[_host] == "")) { + if (this.scheme == "" || this[_host] == null || this[_host] == "") { throw new StateError(`Cannot use origin without a scheme: ${this}`); } - if (dart.notNull(this.scheme != "http") && dart.notNull(this.scheme != "https")) { + if (this.scheme != "http" && this.scheme != "https") { throw new StateError(`Origin is only applicable schemes http and https: ${this}`); } if (this[_port] == null) @@ -2670,7 +2670,7 @@ var core; } toFilePath(opts) { let windows = opts && 'windows' in opts ? opts.windows : null; - if (dart.notNull(this.scheme != "") && dart.notNull(this.scheme != "file")) { + if (this.scheme != "" && this.scheme != "file") { throw new UnsupportedError(`Cannot extract a file path from a ${this.scheme} URI`); } if (this.query != "") { @@ -2718,7 +2718,7 @@ var core; return result.toString(); } get [_isPathAbsolute]() { - if (dart.notNull(this.path == null) || dart.notNull(this.path.isEmpty)) + if (this.path == null || dart.notNull(this.path.isEmpty)) return false; return this.path.startsWith('/'); } @@ -2737,7 +2737,7 @@ var core; toString() { let sb = new StringBuffer(); Uri[_addIfNonEmpty](sb, this.scheme, this.scheme, ':'); - if (dart.notNull(this.hasAuthority) || dart.notNull(this.path.startsWith("//")) || dart.notNull(this.scheme == "file")) { + if (dart.notNull(this.hasAuthority) || dart.notNull(this.path.startsWith("//")) || this.scheme == "file") { sb.write("//"); this[_writeAuthority](sb); } @@ -2756,7 +2756,7 @@ var core; if (!dart.is(other, Uri)) return false; let uri = dart.as(other, Uri); - return dart.notNull(this.scheme == uri.scheme) && this.hasAuthority == uri.hasAuthority && dart.notNull(this.userInfo == uri.userInfo) && dart.notNull(this.host == uri.host) && this.port == uri.port && dart.notNull(this.path == uri.path) && this.hasQuery == uri.hasQuery && dart.notNull(this.query == uri.query) && this.hasFragment == uri.hasFragment && dart.notNull(this.fragment == uri.fragment); + return this.scheme == uri.scheme && this.hasAuthority == uri.hasAuthority && this.userInfo == uri.userInfo && this.host == uri.host && this.port == uri.port && this.path == uri.path && this.hasQuery == uri.hasQuery && this.query == uri.query && this.hasFragment == uri.hasFragment && this.fragment == uri.fragment; } get hashCode() { // Function combine: (dynamic, dynamic) → int diff --git a/pkg/dev_compiler/lib/runtime/dart_runtime.js b/pkg/dev_compiler/lib/runtime/dart_runtime.js index 98ed2297dc9e..e80d4131cb47 100644 --- a/pkg/dev_compiler/lib/runtime/dart_runtime.js +++ b/pkg/dev_compiler/lib/runtime/dart_runtime.js @@ -54,6 +54,8 @@ var dart, _js_helper; throwNoSuchMethod(obj, method, args); } } + // TODO(jmesserly): enable this when we can fix => and methods. + /* let formals = formalParameterList(f); // TODO(vsm): Type check args! We need to encode sufficient type info on f. if (formals.length < args.length) { @@ -65,6 +67,7 @@ var dart, _js_helper; } } } + */ return f.apply(obj, args); } diff --git a/pkg/dev_compiler/lib/src/codegen/js_codegen.dart b/pkg/dev_compiler/lib/src/codegen/js_codegen.dart index dd157c8c59d8..ce49661dc4ad 100644 --- a/pkg/dev_compiler/lib/src/codegen/js_codegen.dart +++ b/pkg/dev_compiler/lib/src/codegen/js_codegen.dart @@ -1442,13 +1442,12 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor { /// "extension methods". This allows types to be extended without adding /// extensions directly on the prototype. bool _isJSBuiltinType(DartType t) => - rules.isNumType(t) || rules.isStringType(t) || rules.isBoolType(t); + typeIsPrimitiveInJS(t) || rules.isStringType(t); - bool typeIsPrimitiveInJS(DartType t) => !rules.isDynamic(t) && - (rules.isIntType(t) || - rules.isDoubleType(t) || - rules.isBoolType(t) || - rules.isNumType(t)); + bool typeIsPrimitiveInJS(DartType t) => rules.isIntType(t) || + rules.isDoubleType(t) || + rules.isBoolType(t) || + rules.isNumType(t); bool typeIsNonNullablePrimitiveInJS(DartType t) => typeIsPrimitiveInJS(t) && rules.isNonNullableType(t); @@ -1481,7 +1480,7 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor { } else if (expr is PostfixExpression) { type = getStaticType(expr.operand); } - if (type != null && typeIsPrimitiveInJS(type)) { + if (type != null && _isJSBuiltinType(type)) { return true; } if (expr is MethodInvocation) { @@ -1526,6 +1525,10 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor { var leftType = getStaticType(left); var rightType = getStaticType(right); + // TODO(jmesserly): this may not work correctly with options.ignoreTypes, + // because that results in unreliable type annotations. See issue #134, + // probably the checker/resolver is the right place to implement that, by + // replacing staticTypes with `dynamic` as needed, so codegen "just works". var code; if (op.type.isEqualityOperator) { // If we statically know LHS or RHS is null we can generate a clean check. @@ -1539,7 +1542,9 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor { return js.call(code, [_visit(left), _visit(right)]); } - if (binaryOperationIsPrimitive(leftType, rightType)) { + if (binaryOperationIsPrimitive(leftType, rightType) || + rules.isStringType(leftType) && op.type == TokenType.PLUS) { + // special cases where we inline the operation // these values are assumed to be non-null (determined by the checker) // TODO(jmesserly): it would be nice to just inline the method from core, diff --git a/pkg/dev_compiler/test/codegen/expect/fieldtest.js b/pkg/dev_compiler/test/codegen/expect/fieldtest.js index 81d970e72071..9354cf6742d7 100644 --- a/pkg/dev_compiler/test/codegen/expect/fieldtest.js +++ b/pkg/dev_compiler/test/codegen/expect/fieldtest.js @@ -43,7 +43,7 @@ var fieldtest; }); dart.copyProperties(exports, { get q() { - return core.String['+'](core.String['+']('life, ', 'the universe '), 'and everything'); + return 'life, ' + 'the universe ' + 'and everything'; }, get z() { return 42;