annotate tcb.cpp @ 71:e4aec93c1e3c

Added license blocks.
author Atul Varma <varmaa@toolness.com>
date Thu, 25 Jun 2009 18:12:23 -0700
parents f6e3733eac01
children b87b6ebb6e86
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
71
e4aec93c1e3c Added license blocks.
Atul Varma <varmaa@toolness.com>
parents: 70
diff changeset
1 /* ***** BEGIN LICENSE BLOCK *****
e4aec93c1e3c Added license blocks.
Atul Varma <varmaa@toolness.com>
parents: 70
diff changeset
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
e4aec93c1e3c Added license blocks.
Atul Varma <varmaa@toolness.com>
parents: 70
diff changeset
3 *
e4aec93c1e3c Added license blocks.
Atul Varma <varmaa@toolness.com>
parents: 70
diff changeset
4 * The contents of this file are subject to the Mozilla Public License Version
e4aec93c1e3c Added license blocks.
Atul Varma <varmaa@toolness.com>
parents: 70
diff changeset
5 * 1.1 (the "License"); you may not use this file except in compliance with
e4aec93c1e3c Added license blocks.
Atul Varma <varmaa@toolness.com>
parents: 70
diff changeset
6 * the License. You may obtain a copy of the License at
e4aec93c1e3c Added license blocks.
Atul Varma <varmaa@toolness.com>
parents: 70
diff changeset
7 * http://www.mozilla.org/MPL/
e4aec93c1e3c Added license blocks.
Atul Varma <varmaa@toolness.com>
parents: 70
diff changeset
8 *
e4aec93c1e3c Added license blocks.
Atul Varma <varmaa@toolness.com>
parents: 70
diff changeset
9 * Software distributed under the License is distributed on an "AS IS" basis,
e4aec93c1e3c Added license blocks.
Atul Varma <varmaa@toolness.com>
parents: 70
diff changeset
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
e4aec93c1e3c Added license blocks.
Atul Varma <varmaa@toolness.com>
parents: 70
diff changeset
11 * for the specific language governing rights and limitations under the
e4aec93c1e3c Added license blocks.
Atul Varma <varmaa@toolness.com>
parents: 70
diff changeset
12 * License.
e4aec93c1e3c Added license blocks.
Atul Varma <varmaa@toolness.com>
parents: 70
diff changeset
13 *
e4aec93c1e3c Added license blocks.
Atul Varma <varmaa@toolness.com>
parents: 70
diff changeset
14 * The Original Code is Ubiquity.
e4aec93c1e3c Added license blocks.
Atul Varma <varmaa@toolness.com>
parents: 70
diff changeset
15 *
e4aec93c1e3c Added license blocks.
Atul Varma <varmaa@toolness.com>
parents: 70
diff changeset
16 * The Initial Developer of the Original Code is Mozilla.
e4aec93c1e3c Added license blocks.
Atul Varma <varmaa@toolness.com>
parents: 70
diff changeset
17 * Portions created by the Initial Developer are Copyright (C) 2007
e4aec93c1e3c Added license blocks.
Atul Varma <varmaa@toolness.com>
parents: 70
diff changeset
18 * the Initial Developer. All Rights Reserved.
e4aec93c1e3c Added license blocks.
Atul Varma <varmaa@toolness.com>
parents: 70
diff changeset
19 *
e4aec93c1e3c Added license blocks.
Atul Varma <varmaa@toolness.com>
parents: 70
diff changeset
20 * Contributor(s):
e4aec93c1e3c Added license blocks.
Atul Varma <varmaa@toolness.com>
parents: 70
diff changeset
21 * Atul Varma <atul@mozilla.com>
e4aec93c1e3c Added license blocks.
Atul Varma <varmaa@toolness.com>
parents: 70
diff changeset
22 *
e4aec93c1e3c Added license blocks.
Atul Varma <varmaa@toolness.com>
parents: 70
diff changeset
23 * Alternatively, the contents of this file may be used under the terms of
e4aec93c1e3c Added license blocks.
Atul Varma <varmaa@toolness.com>
parents: 70
diff changeset
24 * either the GNU General Public License Version 2 or later (the "GPL"), or
e4aec93c1e3c Added license blocks.
Atul Varma <varmaa@toolness.com>
parents: 70
diff changeset
25 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
e4aec93c1e3c Added license blocks.
Atul Varma <varmaa@toolness.com>
parents: 70
diff changeset
26 * in which case the provisions of the GPL or the LGPL are applicable instead
e4aec93c1e3c Added license blocks.
Atul Varma <varmaa@toolness.com>
parents: 70
diff changeset
27 * of those above. If you wish to allow use of your version of this file only
e4aec93c1e3c Added license blocks.
Atul Varma <varmaa@toolness.com>
parents: 70
diff changeset
28 * under the terms of either the GPL or the LGPL, and not to allow others to
e4aec93c1e3c Added license blocks.
Atul Varma <varmaa@toolness.com>
parents: 70
diff changeset
29 * use your version of this file under the terms of the MPL, indicate your
e4aec93c1e3c Added license blocks.
Atul Varma <varmaa@toolness.com>
parents: 70
diff changeset
30 * decision by deleting the provisions above and replace them with the notice
e4aec93c1e3c Added license blocks.
Atul Varma <varmaa@toolness.com>
parents: 70
diff changeset
31 * and other provisions required by the GPL or the LGPL. If you do not delete
e4aec93c1e3c Added license blocks.
Atul Varma <varmaa@toolness.com>
parents: 70
diff changeset
32 * the provisions above, a recipient may use your version of this file under
e4aec93c1e3c Added license blocks.
Atul Varma <varmaa@toolness.com>
parents: 70
diff changeset
33 * the terms of any one of the MPL, the GPL or the LGPL.
e4aec93c1e3c Added license blocks.
Atul Varma <varmaa@toolness.com>
parents: 70
diff changeset
34 *
e4aec93c1e3c Added license blocks.
Atul Varma <varmaa@toolness.com>
parents: 70
diff changeset
35 * ***** END LICENSE BLOCK ***** */
e4aec93c1e3c Added license blocks.
Atul Varma <varmaa@toolness.com>
parents: 70
diff changeset
36
69
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
37 #include "tcb.h"
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
38
70
f6e3733eac01 Refactored some code, fixed some TODOs.
Atul Varma <varmaa@toolness.com>
parents: 69
diff changeset
39 static JSFunctionSpec TCB_global_functions[] = {
f6e3733eac01 Refactored some code, fixed some TODOs.
Atul Varma <varmaa@toolness.com>
parents: 69
diff changeset
40 JS_FS("print", TCB_print, 1, 0, 0),
f6e3733eac01 Refactored some code, fixed some TODOs.
Atul Varma <varmaa@toolness.com>
parents: 69
diff changeset
41 JS_FS("stack", TCB_stack, 0, 0, 0),
f6e3733eac01 Refactored some code, fixed some TODOs.
Atul Varma <varmaa@toolness.com>
parents: 69
diff changeset
42 JS_FS("lookupProperty", TCB_lookupProperty, 2, 0, 0),
f6e3733eac01 Refactored some code, fixed some TODOs.
Atul Varma <varmaa@toolness.com>
parents: 69
diff changeset
43 JS_FS("functionInfo", TCB_functionInfo, 1, 0, 0),
f6e3733eac01 Refactored some code, fixed some TODOs.
Atul Varma <varmaa@toolness.com>
parents: 69
diff changeset
44 JS_FS("enumerate", TCB_enumerate, 1, 0, 0),
f6e3733eac01 Refactored some code, fixed some TODOs.
Atul Varma <varmaa@toolness.com>
parents: 69
diff changeset
45 JS_FS("forceGC", TCB_forceGC, 0, 0, 0),
f6e3733eac01 Refactored some code, fixed some TODOs.
Atul Varma <varmaa@toolness.com>
parents: 69
diff changeset
46 JS_FS_END
f6e3733eac01 Refactored some code, fixed some TODOs.
Atul Varma <varmaa@toolness.com>
parents: 69
diff changeset
47 };
f6e3733eac01 Refactored some code, fixed some TODOs.
Atul Varma <varmaa@toolness.com>
parents: 69
diff changeset
48
69
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
49 // The class of the global object.
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
50 JSClass TCB_global_class = {
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
51 "TCBGlobal", JSCLASS_GLOBAL_FLAGS,
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
52 JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub,
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
53 JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub,
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
54 JSCLASS_NO_OPTIONAL_MEMBERS
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
55 };
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
56
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
57 // This native JS function prints the given string to the console.
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
58
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
59 JSBool TCB_print(JSContext *cx, JSObject *obj, uintN argc,
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
60 jsval *argv, jsval *rval)
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
61 {
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
62 char *str;
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
63
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
64 if (!JS_ConvertArguments(cx, argc, argv, "s", &str))
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
65 return JS_FALSE;
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
66
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
67 printf("%s\n", str);
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
68
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
69 return JS_TRUE;
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
70 }
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
71
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
72 // This native JS function forces garbage collection.
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
73
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
74 JSBool TCB_forceGC(JSContext *cx, JSObject *obj, uintN argc,
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
75 jsval *argv, jsval *rval)
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
76 {
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
77 JS_GC(cx);
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
78 return JS_TRUE;
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
79 }
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
80
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
81 // This native JS function is a wrapper for JS_Enumerate().
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
82
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
83 JSBool TCB_enumerate(JSContext *cx, JSObject *obj, uintN argc,
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
84 jsval *argv, jsval *rval)
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
85 {
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
86 JSObject *target;
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
87
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
88 if (!JS_ConvertArguments(cx, argc, argv, "o", &target))
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
89 return JS_FALSE;
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
90
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
91 JSIdArray *ids = JS_Enumerate(cx, target);
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
92
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
93 if (ids == NULL)
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
94 return JS_FALSE;
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
95
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
96 JSObject *array = JS_NewArrayObject(cx, ids->length, ids->vector);
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
97 *rval = OBJECT_TO_JSVAL(array);
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
98 return JS_TRUE;
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
99 }
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
100
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
101 // This native JS function looks up the property of an object, bypassing
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
102 // security checks and getters/setters.
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
103
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
104 JSBool TCB_lookupProperty(JSContext *cx, JSObject *obj, uintN argc,
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
105 jsval *argv, jsval *rval)
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
106 {
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
107 JSObject *target;
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
108
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
109 if (argc < 2) {
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
110 JS_ReportError(cx, "Must provide id to lookup.");
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
111 return JS_FALSE;
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
112 }
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
113
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
114 if (!JS_ConvertArguments(cx, argc, argv, "o", &target))
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
115 return JS_FALSE;
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
116
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
117 return JS_LookupPropertyById(cx, target, argv[1], rval);
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
118 }
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
119
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
120 // This native JS function returns a JS object containing metadata about
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
121 // the given function.
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
122
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
123 JSBool TCB_functionInfo(JSContext *cx, JSObject *obj, uintN argc,
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
124 jsval *argv, jsval *rval)
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
125 {
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
126 JSFunction *func;
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
127
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
128 if (!JS_ConvertArguments(cx, argc, argv, "f", &func))
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
129 return JS_FALSE;
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
130
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
131 JSScript *script = JS_GetFunctionScript(cx, func);
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
132
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
133 if (script == NULL) {
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
134 *rval = JSVAL_NULL;
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
135 return JS_TRUE;
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
136 }
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
137
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
138 jsval filenameVal = JSVAL_NULL;
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
139
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
140 const char *filename = JS_GetScriptFilename(cx, script);
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
141 if (filename) {
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
142 JSString *filenameStr = JS_NewStringCopyZ(cx, filename);
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
143 filenameVal = STRING_TO_JSVAL(filenameStr);
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
144 }
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
145
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
146 // TODO: Check for return values here.
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
147 JSObject *funcInfo = JS_NewObject(cx, NULL, NULL, NULL);
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
148 JS_DefineProperty(cx, funcInfo, "filename", filenameVal,
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
149 NULL, NULL, 0);
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
150
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
151 *rval = OBJECT_TO_JSVAL(funcInfo);
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
152 return JS_TRUE;
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
153 }
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
154
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
155 // This native JS function returns a JS representation of the current
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
156 // state of the stack, starting with the callee's stack frame and going
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
157 // up from there.
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
158
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
159 JSBool TCB_stack(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
160 jsval *rval)
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
161 {
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
162 JSAutoLocalRootScope autoScope(cx);
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
163
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
164 JSStackFrame *iterator = NULL;
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
165 JSStackFrame *frame;
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
166 JSObject *prevFrameInfo = NULL;
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
167 JSObject *firstFrameInfo = NULL;
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
168 bool skippedMyFrame = false;
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
169
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
170 if (obj == NULL)
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
171 // We're being called from native code, don't skip the topmost frame.
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
172 skippedMyFrame = true;
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
173
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
174 while ((frame = JS_FrameIterator(cx, &iterator)) != NULL) {
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
175 if (!skippedMyFrame) {
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
176 skippedMyFrame = true;
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
177 continue;
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
178 }
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
179
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
180 jsval functionNameVal = JSVAL_NULL;
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
181 jsval filenameVal = JSVAL_NULL;
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
182 jsval lineNoVal = JSVAL_ZERO;
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
183 jsval functionObjectVal = JSVAL_NULL;
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
184 jsval scopeChainVal = JSVAL_NULL;
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
185
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
186 JSFunction *func = JS_GetFrameFunction(cx, frame);
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
187 if (func) {
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
188 JSString *functionName = JS_GetFunctionId(func);
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
189 if (functionName)
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
190 functionNameVal = STRING_TO_JSVAL(functionName);
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
191 }
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
192
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
193 if (!JS_IsNativeFrame(cx, frame)) {
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
194 JSScript *script = JS_GetFrameScript(cx, frame);
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
195 jsbytecode *bytecode = JS_GetFramePC(cx, frame);
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
196
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
197 const char *filename = JS_GetScriptFilename(cx, script);
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
198 if (filename) {
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
199 JSString *filenameStr = JS_NewStringCopyZ(cx, filename);
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
200 filenameVal = STRING_TO_JSVAL(filenameStr);
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
201 }
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
202
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
203 uintN lineNo = JS_PCToLineNumber(cx, script, bytecode);
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
204 lineNoVal = INT_TO_JSVAL(lineNo);
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
205
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
206 JSObject *functionObject = JS_GetFrameFunctionObject(cx, frame);
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
207 functionObjectVal = OBJECT_TO_JSVAL(functionObject);
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
208
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
209 JSObject *scopeChain = JS_GetFrameScopeChain(cx, frame);
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
210 scopeChainVal = OBJECT_TO_JSVAL(scopeChain);
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
211 }
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
212
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
213 // TODO: Check for return values here.
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
214 JSObject *frameInfo = JS_NewObject(cx, NULL, NULL, NULL);
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
215 JS_DefineProperty(cx, frameInfo, "filename", filenameVal,
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
216 NULL, NULL, 0);
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
217 JS_DefineProperty(cx, frameInfo, "lineNo", lineNoVal,
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
218 NULL, NULL, 0);
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
219 JS_DefineProperty(cx, frameInfo, "functionName", functionNameVal,
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
220 NULL, NULL, 0);
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
221 JS_DefineProperty(cx, frameInfo, "functionObject", functionObjectVal,
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
222 NULL, NULL, 0);
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
223 JS_DefineProperty(cx, frameInfo, "scopeChain", scopeChainVal,
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
224 NULL, NULL, 0);
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
225
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
226 if (prevFrameInfo)
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
227 JS_DefineProperty(cx, prevFrameInfo, "caller",
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
228 OBJECT_TO_JSVAL(frameInfo), NULL, NULL, 0);
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
229 else
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
230 firstFrameInfo = frameInfo;
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
231
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
232 prevFrameInfo = frameInfo;
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
233 }
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
234
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
235 if (firstFrameInfo)
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
236 *rval = OBJECT_TO_JSVAL(firstFrameInfo);
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
237 else
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
238 *rval = JSVAL_NULL;
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
239
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
240 return JS_TRUE;
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
241 }
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
242
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
243 // Our global hook called whenever an exception is thrown saves the current
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
244 // exception and stack information to the 'lastException' and
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
245 // 'lastExceptionTraceback' globals of the TCB, respectively, much like
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
246 // Python's sys.exc_info().
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
247
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
248 JSTrapStatus TCB_throwHook(JSContext *cx, JSScript *script, jsbytecode *pc,
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
249 jsval *rval, void *closure)
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
250 {
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
251 JSObject *tcb_global = (JSObject *) closure;
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
252 jsval lastExceptionTraceback;
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
253 jsval lastException;
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
254
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
255 jsval exception = *rval;
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
256 if (JS_IsExceptionPending(cx))
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
257 if (!JS_GetPendingException(cx, &exception))
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
258 printf("Getting exception failed.\n");
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
259
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
260 if (!JS_GetProperty(cx, tcb_global, "lastException", &lastException))
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
261 printf("Unable to retrieve last exception.");
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
262
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
263 if (lastException == exception)
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
264 // The same exception is just propagating through the stack; keep
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
265 // our existing last-exception info.
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
266 return JSTRAP_CONTINUE;
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
267
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
268 if (!TCB_stack(cx, NULL, 0, NULL, &lastExceptionTraceback)) {
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
269 printf("Generation of exception info failed.");
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
270 lastExceptionTraceback = JSVAL_NULL;
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
271 }
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
272
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
273 if (!JS_SetProperty(cx, tcb_global, "lastExceptionTraceback",
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
274 &lastExceptionTraceback) ||
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
275 !JS_SetProperty(cx, tcb_global, "lastException", &exception))
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
276 printf("Setting of exception info failed.");
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
277
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
278 return JSTRAP_CONTINUE;
be61430630ab Separated out some of the TCB-specific code into tcb.cpp/h.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
279 }
70
f6e3733eac01 Refactored some code, fixed some TODOs.
Atul Varma <varmaa@toolness.com>
parents: 69
diff changeset
280
f6e3733eac01 Refactored some code, fixed some TODOs.
Atul Varma <varmaa@toolness.com>
parents: 69
diff changeset
281 JSBool TCB_init(JSContext *cx, jsval *rval)
f6e3733eac01 Refactored some code, fixed some TODOs.
Atul Varma <varmaa@toolness.com>
parents: 69
diff changeset
282 {
f6e3733eac01 Refactored some code, fixed some TODOs.
Atul Varma <varmaa@toolness.com>
parents: 69
diff changeset
283 #ifdef DEBUG
f6e3733eac01 Refactored some code, fixed some TODOs.
Atul Varma <varmaa@toolness.com>
parents: 69
diff changeset
284 JS_SetGCZeal(cx, 2);
f6e3733eac01 Refactored some code, fixed some TODOs.
Atul Varma <varmaa@toolness.com>
parents: 69
diff changeset
285 #endif
f6e3733eac01 Refactored some code, fixed some TODOs.
Atul Varma <varmaa@toolness.com>
parents: 69
diff changeset
286
f6e3733eac01 Refactored some code, fixed some TODOs.
Atul Varma <varmaa@toolness.com>
parents: 69
diff changeset
287 JSRuntime *rt = JS_GetRuntime(cx);
f6e3733eac01 Refactored some code, fixed some TODOs.
Atul Varma <varmaa@toolness.com>
parents: 69
diff changeset
288
71
e4aec93c1e3c Added license blocks.
Atul Varma <varmaa@toolness.com>
parents: 70
diff changeset
289 // Create the TCB's global object.
70
f6e3733eac01 Refactored some code, fixed some TODOs.
Atul Varma <varmaa@toolness.com>
parents: 69
diff changeset
290 JSObject *global = JS_NewObject(cx, &TCB_global_class, NULL, NULL);
f6e3733eac01 Refactored some code, fixed some TODOs.
Atul Varma <varmaa@toolness.com>
parents: 69
diff changeset
291 if (global == NULL) {
f6e3733eac01 Refactored some code, fixed some TODOs.
Atul Varma <varmaa@toolness.com>
parents: 69
diff changeset
292 JS_ReportOutOfMemory(cx);
f6e3733eac01 Refactored some code, fixed some TODOs.
Atul Varma <varmaa@toolness.com>
parents: 69
diff changeset
293 return JS_FALSE;
f6e3733eac01 Refactored some code, fixed some TODOs.
Atul Varma <varmaa@toolness.com>
parents: 69
diff changeset
294 }
f6e3733eac01 Refactored some code, fixed some TODOs.
Atul Varma <varmaa@toolness.com>
parents: 69
diff changeset
295
f6e3733eac01 Refactored some code, fixed some TODOs.
Atul Varma <varmaa@toolness.com>
parents: 69
diff changeset
296 if (!JS_InitStandardClasses(cx, global) ||
f6e3733eac01 Refactored some code, fixed some TODOs.
Atul Varma <varmaa@toolness.com>
parents: 69
diff changeset
297 !JS_DefineFunctions(cx, global, TCB_global_functions))
f6e3733eac01 Refactored some code, fixed some TODOs.
Atul Varma <varmaa@toolness.com>
parents: 69
diff changeset
298 return JS_FALSE;
f6e3733eac01 Refactored some code, fixed some TODOs.
Atul Varma <varmaa@toolness.com>
parents: 69
diff changeset
299
f6e3733eac01 Refactored some code, fixed some TODOs.
Atul Varma <varmaa@toolness.com>
parents: 69
diff changeset
300 if (!JS_SetThrowHook(rt, TCB_throwHook, global) ||
f6e3733eac01 Refactored some code, fixed some TODOs.
Atul Varma <varmaa@toolness.com>
parents: 69
diff changeset
301 !JS_DefineProperty(cx, global, "lastExceptionTraceback", JSVAL_NULL,
f6e3733eac01 Refactored some code, fixed some TODOs.
Atul Varma <varmaa@toolness.com>
parents: 69
diff changeset
302 NULL, NULL, 0) ||
f6e3733eac01 Refactored some code, fixed some TODOs.
Atul Varma <varmaa@toolness.com>
parents: 69
diff changeset
303 !JS_DefineProperty(cx, global, "lastException", JSVAL_NULL,
f6e3733eac01 Refactored some code, fixed some TODOs.
Atul Varma <varmaa@toolness.com>
parents: 69
diff changeset
304 NULL, NULL, 0))
f6e3733eac01 Refactored some code, fixed some TODOs.
Atul Varma <varmaa@toolness.com>
parents: 69
diff changeset
305 return JS_FALSE;
f6e3733eac01 Refactored some code, fixed some TODOs.
Atul Varma <varmaa@toolness.com>
parents: 69
diff changeset
306
f6e3733eac01 Refactored some code, fixed some TODOs.
Atul Varma <varmaa@toolness.com>
parents: 69
diff changeset
307 *rval = OBJECT_TO_JSVAL(global);
f6e3733eac01 Refactored some code, fixed some TODOs.
Atul Varma <varmaa@toolness.com>
parents: 69
diff changeset
308 return JS_TRUE;
f6e3733eac01 Refactored some code, fixed some TODOs.
Atul Varma <varmaa@toolness.com>
parents: 69
diff changeset
309 }