Merge "fix: the incorrect version of tarball generated by gbs export" into tizen
[platform/upstream/js.git] / js / src / jsapi-tests / testCloneScript.cpp
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2  * vim: set ts=8 sw=4 et tw=99:
3  *
4  * Test script cloning.
5  */
6
7 #include "tests.h"
8 #include "jsapi.h"
9
10 BEGIN_TEST(test_cloneScript)
11 {
12     JSObject *A, *B;
13
14     CHECK(A = createGlobal());
15     CHECK(B = createGlobal());
16
17     const char *source = 
18         "var i = 0;\n"
19         "var sum = 0;\n"
20         "while (i < 10) {\n"
21         "    sum += i;\n"
22         "    ++i;\n"
23         "}\n"
24         "(sum);\n";
25
26     JSObject *obj;
27
28     // compile for A
29     {
30         JSAutoEnterCompartment a;
31         if (!a.enter(cx, A))
32             return false;
33
34         JSFunction *fun;
35         CHECK(fun = JS_CompileFunction(cx, A, "f", 0, NULL, source, strlen(source), __FILE__, 1));
36         CHECK(obj = JS_GetFunctionObject(fun));
37     }
38
39     // clone into B
40     {
41         JSAutoEnterCompartment b;
42         if (!b.enter(cx, B))
43             return false;
44
45         CHECK(JS_CloneFunctionObject(cx, obj, B));
46     }
47
48     return true;
49 }
50 END_TEST(test_cloneScript)