Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Implement the simplest possible way of calling JavaScript call.
  • Loading branch information
pmurias committed Aug 16, 2014
1 parent ae2122e commit e65d7e1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/vm/js/QAST/Compiler.nqp
Expand Up @@ -285,6 +285,12 @@ class QAST::OperationsJS {
Chunk.new($T_OBJ, "null" , [], :$node);
});

QAST::OperationsJS.add_op('getcomp', sub ($comp, $node, :$want) {
my $arg := $comp.as_js($node[0], :want($T_STR));
my $tmp := $*BLOCK.add_tmp();
Chunk.new($T_OBJ, $tmp , [$arg, "$tmp = nqp.op.getcomp({$arg.expr});\n"], :$node);
});

QAST::OperationsJS.add_op('say', sub ($comp, $node, :$want) {
my $arg := $comp.as_js($node[0], :want($T_STR));
Chunk.new($T_VOID, "" , [$arg, "nqp.op.say({$arg.expr});\n"], :$node);
Expand Down
2 changes: 1 addition & 1 deletion src/vm/js/bin/run_tests
@@ -1,5 +1,5 @@
#!/bin/bash
# 19 and 30 where moved out as they were parrot specific, 52,54 is missing, we can't pass 49 till we are bootstraped
#echo 'No tests pass as we are in the early stages of a rewrite/refactor'
prove -e './nqp-js-with-setting' t/nqp/{01..05}* t/nqp/{07..08}* t/nqp/{10,16}*
prove -e './nqp-js-with-setting' t/nqp/{01..05}* t/nqp/{07..08}* t/nqp/{10,16}* t/js/getcomp-js.t
#prove -e './nqp-js' t/nqp/{01..29}*.t t/nqp/{31..48}* t/nqp/{50,51,53}* t/nqp/{55..81}* t/nqp/83* t/serialization/0{2,3}*.t
8 changes: 8 additions & 0 deletions src/vm/js/nqp-runtime/runtime.js
Expand Up @@ -13,6 +13,14 @@ op.say = function(arg) {
}
};

op.getcomp = function(lang) {
if (lang == 'JavaScript') {
return function(ctx, named, code) {
return eval(code);
};
}
};

op.isinvokable = function(obj) {
return (typeof obj == 'function' ? 1 : 0);
};
Expand Down
4 changes: 4 additions & 0 deletions t/js/getcomp-js.t
@@ -0,0 +1,4 @@
plan(1);
my $comp := nqp::getcomp('JavaScript');
my $helloworld := $comp('"Hello " + "World"');
ok($helloworld eq 'Hello World',"getting a simple string from JavaScript");

0 comments on commit e65d7e1

Please sign in to comment.