Index: lib/runtime/dart_runtime.js |
diff --git a/lib/runtime/dart_runtime.js b/lib/runtime/dart_runtime.js |
index 200d187f7e01a6436d27ab56f7eb53e6aa172304..6683bc9768f592cd7a23fdb418d30fcae633d72c 100644 |
--- a/lib/runtime/dart_runtime.js |
+++ b/lib/runtime/dart_runtime.js |
@@ -50,6 +50,11 @@ var dart, _js_helper, _js_primitives; |
} |
dart.dput = dput; |
+ function throwRuntimeError(message) { |
+ console.error(message); |
Jennifer Messerly
2015/06/05 16:22:27
what's the benefit of logging and throwing? Don't
vsm
2015/06/05 17:01:04
removed
|
+ throw new _js_helper.RuntimeError(message); |
Jennifer Messerly
2015/06/05 16:22:27
what happens if this isn't loaded? don't we have b
vsm
2015/06/05 17:01:04
Done.
|
+ } |
+ |
// TODO(jmesserly): this should call noSuchMethod, not throw. |
function throwNoSuchMethod(obj, name, args, opt_func) { |
if (obj === void 0) obj = opt_func; |
@@ -431,15 +436,15 @@ var dart, _js_helper, _js_primitives; |
/** Checks that `x` is not null or undefined. */ |
function notNull(x) { |
- if (x == null) throw 'expected not-null value'; |
+ if (x == null) throwRuntimeError('expected not-null value'); |
return x; |
} |
dart.notNull = notNull; |
function _typeName(type) { |
- if (type === void 0) throw "Undefined type"; |
+ if (type === void 0) throwRuntimeError('Undefined type'); |
var name = type.name; |
- if (!name) throw 'Unexpected type: ' + type; |
+ if (!name) throwRuntimeError('Unexpected type: ' + type); |
return name; |
} |
@@ -727,7 +732,7 @@ var dart, _js_helper, _js_primitives; |
function lazyGetter() { |
// Clear the init function to detect circular initialization. |
let f = init; |
- if (f === null) throw 'circular initialization for field ' + name; |
+ if (f === null) throwRuntimeError('circular initialization for field ' + name); |
init = null; |
// Compute and store the value. |
@@ -906,8 +911,7 @@ var dart, _js_helper, _js_primitives; |
dart.map = map; |
function assert(condition) { |
- // TODO(jmesserly): throw assertion error. |
- if (!condition) throw 'assertion failed'; |
+ if (!condition) throw new core.AssertionError(); |
} |
dart.assert = assert; |
@@ -941,12 +945,12 @@ var dart, _js_helper, _js_primitives; |
/** Memoize a generic type constructor function. */ |
function generic(typeConstructor) { |
let length = typeConstructor.length; |
- if (length < 1) throw Error('must have at least one generic type argument'); |
+ if (length < 1) throwRuntimeError('must have at least one generic type argument'); |
let resultMap = new Map(); |
function makeGenericType(/*...arguments*/) { |
if (arguments.length != length && arguments.length != 0) { |
- throw Error('requires ' + length + ' or 0 type arguments'); |
+ throwRuntimeError('requires ' + length + ' or 0 type arguments'); |
} |
let args = Array.prototype.slice.call(arguments); |
// TODO(leafp): This should really be core.Object for |
@@ -959,7 +963,7 @@ var dart, _js_helper, _js_primitives; |
for (let i = 0; i < length; i++) { |
let arg = args[i]; |
if (arg == null) { |
- throw Error('type arguments should not be null: ' + typeConstructor); |
+ throwRuntimeError('type arguments should not be null: ' + typeConstructor); |
} |
let map = value; |
value = map.get(arg); |
@@ -1230,24 +1234,51 @@ var dart, _js_helper, _js_primitives; |
dart.global = window || global; |
dart.JsSymbol = Symbol; |
- function import_(value) { |
+ var loadedLibraries = {}; |
Jennifer Messerly
2015/06/05 16:22:27
How will this work with JS interop? It seems we ar
vsm
2015/06/05 17:01:04
Not really assuming a closed world. For JS code,
|
+ |
+ function import_(name) { |
+ let value = loadedLibraries[name]; |
// TODO(vsm): Change this to a hard throw. |
// For now, we're missing some libraries. E.g., dart:js: |
// https://github.com/dart-lang/dev_compiler/issues/168 |
if (!value) { |
- console.log('missing required module'); |
+ console.warn('Missing required module: ' + name); |
+ } else if (value != dart.global[name]) { |
+ throwRuntimeError('Library name mismatch: ' + name) |
} |
return value; |
} |
dart.import = import_; |
+ |
+ function initializeLibraryStub(name) { |
+ // Create the library object if necessary. |
+ if (!dart.global[name]) { |
+ dart.global[name] = {}; |
+ } |
+ return dart.global[name]; |
+ } |
- function lazyImport(value) { |
- return defineLibrary(value, {}); |
+ function lazyImport(name) { |
+ return initializeLibraryStub(name); |
} |
dart.lazyImport = lazyImport; |
- function defineLibrary(value, defaultValue) { |
- return value ? value : defaultValue; |
+ function defineLibrary(name, defaultValue) { |
+ if (loadedLibraries[name]) { |
+ throwRuntimeError('Library is already defined: ' + name); |
+ } |
+ var value; |
+ if (defaultValue) { |
+ var oldValue = dart.global[name]; |
+ if (oldValue && oldValue != defaultValue) { |
+ throwRuntimeError('Library ' + name + ' cannot be redefined to ' + defaultValue); |
Jennifer Messerly
2015/06/05 16:22:27
long line.
also could use interpolation:
`Library
vsm
2015/06/05 17:01:04
Done.
|
+ } |
+ dart.global[name] = value = defaultValue; |
+ } else { |
+ value = initializeLibraryStub(name); |
+ } |
+ loadedLibraries[name] = value; |
+ return value; |
} |
dart.defineLibrary = defineLibrary; |