enable es6 promise compatibility

This commit is contained in:
Leo Horie 2014-09-03 21:12:12 -04:00
parent d11087e9f6
commit 36999e6f4d
3 changed files with 89 additions and 32 deletions

View file

@ -1694,6 +1694,24 @@ function testMithril(mock) {
deferred.resolve("test")
return value1 === undefined && value2 instanceof Error
})
test(function() {
//Let unchecked exceptions bubble up in order to allow meaningful error messages in common cases like null reference exceptions due to typos
//An unchecked exception is defined as an object that is a subclass of Error (but not a direct instance of Error itself) - basically anything that can be thrown without an explicit `throw` keyword and that we'd never want to programmatically manipulate. In other words, an unchecked error is one where we only care about its line number and where the only reasonable way to deal with it is to change the buggy source code that caused the error to be thrown in the first place.
//By contrast, a checked exception is defined as anything that is explicitly thrown via the `throw` keyword and that can be programmatically handled, for example to display a validation error message on the UI. If an exception is a subclass of Error for whatever reason, but it is meant to be handled as a checked exception (i.e. follow the rejection rules for A+), it can be rethrown as an instance of Error
//This test tests two implementation details that differ from the Promises/A+ spec:
//1) A+ requires the `then` callback to be called in a different event loop from the resolve call, i.e. it must be asynchronous (this requires a setImmediate polyfill, which cannot be implemented in a reasonable way for Mithril's purpose - the possible polyfills are either too big or too slow)
//2) A+ swallows exceptions in a unrethrowable way, i.e. it's not possible to see default error messages on the console for runtime errors thrown from within a promise chain
var value1, value2, value3
var deferred = m.deferred()
try {
deferred.promise
.then(function(data) {foo.bar.baz}) //throws ReferenceError
.then(function(data) {value1 = 1}, function(data) {value2 = data})
deferred.resolve("test")
}
catch (e) {value3 = e}
return value1 === undefined && value2 === undefined && value3 instanceof ReferenceError
})
test(function() {
var deferred1 = m.deferred()
var deferred2 = m.deferred()