Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[js] Implement nqp::setmessage, nqp::setpayload, nqp::getpayload, nqp…
…::throw and VMException REPR.
  • Loading branch information
pmurias committed Mar 8, 2016
1 parent d8dab2f commit 66d0ca2
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/vm/js/Operations.nqp
Expand Up @@ -662,6 +662,12 @@ class QAST::OperationsJS {
add_simple_op('exception', $T_OBJ, [], sub () {"$*CTX.exception"});
add_simple_op('rethrow', $T_VOID, [$T_OBJ], sub ($exception) {"$*CTX.rethrow($exception)"}, :sideffects);
add_simple_op('resume', $T_VOID, [$T_OBJ], sub ($exception) {"$*CTX.resume($exception)"}, :sideffects);
add_simple_op('throw', $T_VOID, [$T_OBJ], :sideffects, sub ($exception) {"{$*CTX}.throw($exception)"});

add_simple_op('setpayload', $T_OBJ, [$T_OBJ, $T_OBJ], :sideffects);
add_simple_op('getpayload', $T_OBJ, [$T_OBJ, $T_OBJ]);

add_simple_op('setmessage', $T_OBJ, [$T_OBJ, $T_OBJ], :sideffects);
add_simple_op('getmessage', $T_STR, [$T_OBJ]);

add_simple_op('findmethod', $T_OBJ, [$T_OBJ, $T_STR], :sideffects);
Expand Down
12 changes: 12 additions & 0 deletions src/vm/js/nqp-runtime/core.js
Expand Up @@ -592,6 +592,18 @@ op.getmessage = function(exception) {
return exception.message;
};

op.setmessage = function(exception, message) {
return (exception.message = message);
};

op.getpayload = function(exception) {
return exception.payload;
};

op.setpayload = function(exception, payload) {
return (exception.payload = payload);
};

op.unshift = function(target, value) {
if (target.$$unshift) return target.$$unshift(value);
target.unshift(value);
Expand Down
8 changes: 8 additions & 0 deletions src/vm/js/nqp-runtime/reprs.js
Expand Up @@ -991,3 +991,11 @@ MultiDimArray.prototype.deserialize_finish = function(obj, data) {
};

module.exports.MultiDimArray = MultiDimArray;

function VMException() {
}
VMException.prototype.create_obj_constructor = basic_constructor;
VMException.prototype.allocate = basic_allocate;
VMException.prototype.type_object_for = basic_type_object_for;

module.exports.VMException = VMException;
4 changes: 4 additions & 0 deletions src/vm/js/nqp-runtime/runtime.js
Expand Up @@ -231,6 +231,10 @@ Ctx.prototype.resume = function(exception) {
exception.resume = true;
};

Ctx.prototype.throw = function(exception) {
this.propagateException(exception);
};

Ctx.prototype.lookup_dynamic = function(name) {
var ctx = this;
while (ctx) {
Expand Down

0 comments on commit 66d0ca2

Please sign in to comment.