diff --git a/tests/ecmascript/test-err-callstack-headroom.js b/tests/ecmascript/test-err-callstack-headroom-1.js similarity index 98% rename from tests/ecmascript/test-err-callstack-headroom.js rename to tests/ecmascript/test-err-callstack-headroom-1.js index 00e57e29..cefa8852 100644 --- a/tests/ecmascript/test-err-callstack-headroom.js +++ b/tests/ecmascript/test-err-callstack-headroom-1.js @@ -41,7 +41,6 @@ try { function f() { f(); } f(); -} -catch(e) { +} catch(e) { print(e); } diff --git a/tests/ecmascript/test-err-callstack-headroom-2.js b/tests/ecmascript/test-err-callstack-headroom-2.js new file mode 100644 index 00000000..5456e9b1 --- /dev/null +++ b/tests/ecmascript/test-err-callstack-headroom-2.js @@ -0,0 +1,35 @@ +/* + * Error handling callstack headroom (GH-191) + * + * Check that relaxed callstack limit during error creation is still bounded + * so that an errCreate callback doing unbounded recursion is caught. The + * result is a DoubleError. + */ + +/*--- +{ + "custom": true +} +---*/ + +/*=== +DoubleError: error in error handling +===*/ + +try { + function recurse() { + var dummy; + recurse(); + dummy = 1; + } + + Duktape.errCreate = function(e) { + recurse(); + return e; + }; + + function f() { f(); } + f(); +} catch(e) { + print(e); +} diff --git a/tests/ecmascript/test-err-errcreate-error.js b/tests/ecmascript/test-err-errcreate-error.js new file mode 100644 index 00000000..5dc66b04 --- /dev/null +++ b/tests/ecmascript/test-err-errcreate-error.js @@ -0,0 +1,37 @@ +/* + * Errors thrown by Duktape internals during an errCreate() will work + * normally except they won't be augmented to avoid recursion. + */ + +/*=== +errCreate: RangeError +internal error: URIError +internal error: EvalError +errThrow: RangeError +RangeError +===*/ + +try { + Duktape.errCreate = function (e) { + print('errCreate:', e.name); + try { + decodeURIComponent('%ff%ff'); + } catch (e2) { + print('internal error:', e2.name); + } + try { + throw new EvalError('user error'); // created but not augmented + } catch (e2) { + print('internal error:', e2.name); + } + return e; + }; + Duktape.errThrow = function (e) { + print('errThrow:', e.name); + return e; + }; + + throw new RangeError('aiee'); +} catch (e) { + print(e.name); +} diff --git a/tests/ecmascript/test-err-errthrow-error.js b/tests/ecmascript/test-err-errthrow-error.js new file mode 100644 index 00000000..dda34504 --- /dev/null +++ b/tests/ecmascript/test-err-errthrow-error.js @@ -0,0 +1,37 @@ +/* + * Errors thrown by Duktape internals during an errThrow() will work + * normally except they won't be augmented to avoid recursion. + */ + +/*=== +errCreate: RangeError +errThrow: RangeError +internal error: URIError +internal error: EvalError +RangeError +===*/ + +try { + Duktape.errCreate = function (e) { + print('errCreate:', e.name); + return e; + }; + Duktape.errThrow = function (e) { + print('errThrow:', e.name); + try { + decodeURIComponent('%ff%ff'); + } catch (e2) { + print('internal error:', e2.name); + } + try { + throw new EvalError('user error'); // created but not augmented + } catch (e2) { + print('internal error:', e2.name); + } + return e; + }; + + throw new RangeError('aiee'); +} catch (e) { + print(e.name); +}