Commit ebe6cd0e authored by Romain Courteaud's avatar Romain Courteaud

Add toJSON method on the Error object

Improve the verbosity of error when using iframe.
parent 8bf6b773
......@@ -27,6 +27,27 @@
Event, URL) {
"use strict";
// Error propagation in jschannel uses JSON.stringify
// Sadly, ...
// JSON.stringify(new TypeError('lala')) -> '{}'
// Change the browser default behaviour to propagate at least the message
// See https://stackoverflow.com/a/18391400
if (!Error.prototype.hasOwnProperty('toJSON')) {
Object.defineProperty(Error.prototype, 'toJSON', {
value: function () {
var alt = {};
Object.getOwnPropertyNames(this).forEach(function (key) {
alt[key] = this[key];
}, this);
return alt;
},
configurable: true,
writable: true
});
}
/////////////////////////////////////////////////////////////////
// Error
/////////////////////////////////////////////////////////////////
......
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<!--
Copyright 2014, Nexedi SA
This program is free software: you can Use, Study, Modify and Redistribute
it under the terms of the GNU General Public License version 3, or (at your
option) any later version, as published by the Free Software Foundation.
You can also Link and Combine this program with other software covered by
the terms of any of the Free Software licenses or any of the Open Source
Initiative approved licenses and Convey the resulting work. Corresponding
source of such a combination shall include the source code for all other
software used.
This program is distributed WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See COPYING file for full licensing terms.
See https://www.nexedi.com/licensing for rationale and options.
-->
<html>
<head>
<title>Embedded page for renderJS test</title>
<meta name="viewport" content="width=device-width, height=device-height"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script src="../node_modules/rsvp/dist/rsvp-2.0.4.js" type="text/javascript"></script>
<script src="../dist/renderjs-latest.js" type="text/javascript"></script>
<script src="./embedded_crashing_service.js" type="text/javascript"></script>
</head>
<body>
</body>
</html>
/*
* Copyright 2014, Nexedi SA
*
* This program is free software: you can Use, Study, Modify and Redistribute
* it under the terms of the GNU General Public License version 3, or (at your
* option) any later version, as published by the Free Software Foundation.
*
* You can also Link and Combine this program with other software covered by
* the terms of any of the Free Software licenses or any of the Open Source
* Initiative approved licenses and Convey the resulting work. Corresponding
* source of such a combination shall include the source code for all other
* software used.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* See COPYING file for full licensing terms.
* See https://www.nexedi.com/licensing for rationale and options.
*/
(function (window, rJS) {
"use strict";
rJS(window)
.declareService(function () {
throw new TypeError("Cannot read property 'bar' of undefined");
});
}(window, rJS));
......@@ -3034,6 +3034,55 @@
});
});
test('Service error from iframe are reported to parent gadget', function () {
// Subclass RenderJSGadget to not pollute its namespace
var ParentKlass = function () {
RenderJSGadget.call(this);
},
gadget,
defer = RSVP.defer();
ParentKlass.prototype = new RenderJSGadget();
ParentKlass.prototype.constructor = ParentKlass;
ParentKlass.prototype.__acquired_method_dict = {};
ParentKlass.allowPublicAcquisition = RenderJSGadget.allowPublicAcquisition;
ParentKlass.allowPublicAcquisition('reportServiceError',
function (argument_list) {
defer.resolve(argument_list[0]);
});
gadget = new ParentKlass();
gadget.__sub_gadget_dict = {};
document.getElementById('qunit-fixture').innerHTML = "<div></div>";
stop();
expect(3);
return gadget.declareGadget(
'embedded_crashing_service.html',
{element: document.getElementById('qunit-fixture')
.querySelector("div"),
sandbox: 'iframe'}
)
.then(function () {
return defer.promise;
})
.then(function (catched_error) {
ok(catched_error instanceof Object);
ok(!(catched_error instanceof Error));
equal(
catched_error.message,
"Cannot read property 'bar' of undefined"
);
})
.fail(function (e) {
ok(false, e);
})
.always(function () {
start();
});
});
test('Service error stops the other services', function () {
// Subclass RenderJSGadget to not pollute its namespace
var ParentKlass = function () {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment