mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 974546 - SpecialPowers wrappers should catch, wrap, and rethrow exceptions for callables. r=mrbkap
This commit is contained in:
parent
c2040dc3c9
commit
37381cb9d4
@ -141,6 +141,24 @@ function starttest(){
|
||||
var returnsNull = function() { return null; }
|
||||
is(SpecialPowers.wrap(returnsNull)(), null, "Should be able to handle functions that return null.");
|
||||
|
||||
// Check a function that throws.
|
||||
var thrower = function() { throw new Error('hah'); }
|
||||
try {
|
||||
SpecialPowers.wrap(thrower)();
|
||||
ok(false, "Should have thrown");
|
||||
} catch (e) {
|
||||
ok(SpecialPowers.isWrapper(e), "Exceptions should be wrapped for call");
|
||||
is(e.message, 'hah', "Correct message");
|
||||
}
|
||||
try {
|
||||
var ctor = SpecialPowers.wrap(thrower);
|
||||
new ctor();
|
||||
ok(false, "Should have thrown");
|
||||
} catch (e) {
|
||||
ok(SpecialPowers.isWrapper(e), "Exceptions should be wrapped for construct");
|
||||
is(e.message, 'hah', "Correct message");
|
||||
}
|
||||
|
||||
// Play around with a JS object to check the non-xray path.
|
||||
var noxray_proto = {a: 3, b: 12};
|
||||
var noxray = {a: 5, c: 32};
|
||||
|
@ -115,7 +115,12 @@ function wrapPrivileged(obj) {
|
||||
var invocant = unwrapIfWrapped(this);
|
||||
var unwrappedArgs = Array.prototype.slice.call(arguments).map(unwrapIfWrapped);
|
||||
|
||||
return wrapPrivileged(doApply(obj, invocant, unwrappedArgs));
|
||||
try {
|
||||
return wrapPrivileged(doApply(obj, invocant, unwrappedArgs));
|
||||
} catch (e) {
|
||||
// Wrap exceptions and re-throw them.
|
||||
throw wrapIfUnwrapped(e);
|
||||
}
|
||||
};
|
||||
var constructTrap = function() {
|
||||
// The arguments may or may not be wrappers. Unwrap them if necessary.
|
||||
@ -129,7 +134,12 @@ function wrapPrivileged(obj) {
|
||||
// underlying constructor just be passing along its return value in our
|
||||
// constructor.
|
||||
var FakeConstructor = function() {
|
||||
return doApply(obj, this, unwrappedArgs);
|
||||
try {
|
||||
return doApply(obj, this, unwrappedArgs);
|
||||
} catch (e) {
|
||||
// Wrap exceptions and re-throw them.
|
||||
throw wrapIfUnwrapped(e);
|
||||
}
|
||||
};
|
||||
FakeConstructor.prototype = obj.prototype;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user