PageRenderTime 21ms CodeModel.GetById 1ms app.highlight 15ms RepoModel.GetById 1ms app.codeStats 0ms

/js/jetpack/tests/unit/impl.js

http://github.com/zpao/v8monkey
JavaScript | 87 lines | 68 code | 19 blank | 0 comment | 4 complexity | be00cae52b5a50eb7fb34d54adcb186c MD5 | raw file
 1function echo() {
 2  sendMessage.apply(this, arguments);
 3}
 4
 5registerReceiver("echo", echo);
 6
 7registerReceiver("callback",
 8                 function(msgName, data, handle) {
 9                   sendMessage("sendback",
10                               callMessage("callback", data)[0],
11                               handle);
12                 });
13
14registerReceiver("gimmeHandle",
15                 function(msgName) {
16                   sendMessage("recvHandle", "ok", createHandle());
17                 });
18
19registerReceiver("kthx",
20                 function(msgName, data, child) {
21                   sendMessage("recvHandleAgain", data + data, child.parent);
22                 });
23
24registerReceiver("echo2", echo);
25
26registerReceiver("multireturn begin",
27                 function() {
28                   var results = callMessage("multireturn");
29                   sendMessage.apply(null, ["multireturn check"].concat(results));
30                 });
31
32registerReceiver("testarray",
33                 function(msgName, array) {
34                   sendMessage("testarray", array.reverse());
35                 });
36
37registerReceiver("test primitive types", echo);
38
39registerReceiver("drop methods", echo);
40
41registerReceiver("exception coping", echo);
42
43registerReceiver("duplicate receivers", echo);
44
45function ok(c, msg)
46{
47  sendMessage("test result", c, msg);
48}
49
50registerReceiver("test sandbox", function() {
51  var addon = createSandbox();
52  ok(typeof(addon) == "object", "typeof(addon)");
53  ok("Date" in addon, "addon.Date exists");
54  ok(addon.Date !== Date, "Date objects are different");
55
56  var fn = "var x; var c = 3; function doit() { x = 12; return 4; }";
57  evalInSandbox(addon, fn);
58
59  ok(addon.x === undefined, "x is undefined");
60  ok(addon.c == 3, "c is 3");
61  ok(addon.doit() == 4, "doit called successfully");
62  ok(addon.x == 12, "x is now 12");
63
64  var fn2 = "let function barbar{}";
65  try {
66    evalInSandbox(addon, fn2);
67    ok(false, "bad syntax should throw");
68  }
69  catch(e) {
70    ok(true, "bad syntax should throw");
71  }
72
73  var fn3 = "throw new Error('just kidding')";
74  try {
75    evalInSandbox(addon, fn3);
76    ok(false, "thrown error should be caught");
77  }
78  catch(e) {
79    ok(true, "thrown error should be caught");
80  }
81
82  sendMessage("sandbox done");
83});
84
85registerReceiver("throw", function(msgName) {
86  throw new Error("throwing on request");
87});