annotate memory_profiler.cpp @ 55:1aba1b7a0a2c

Added a 'nativeClass' property to object info method.
author Atul Varma <varmaa@toolness.com>
date Wed, 24 Jun 2009 18:32:14 -0700
parents c451579bf83c
children b36c15de56f6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
50
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
1 #include "jsdhash.h"
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
2
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
3 #include "memory_profiler.h"
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
4 #include "server_socket.h"
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
5
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
6 #define SERVER_FILENAME "memory_profiler_server.js"
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
7
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
8 // TODO: Lots of code here is copied from spidermonkey-playground.cpp; we should
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
9 // consolidate it.
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
10
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
11 /* The error reporter callback. */
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
12 static void reportError(JSContext *cx, const char *message, JSErrorReport *report)
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
13 {
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
14 fprintf(stderr, "%s:%u:%s\n",
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
15 report->filename ? report->filename : "<no filename>",
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
16 (unsigned int) report->lineno,
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
17 message);
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
18 }
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
19
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
20 static JSClass global_class = {
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
21 "serverGlobal", JSCLASS_GLOBAL_FLAGS,
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
22 JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub,
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
23 JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub,
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
24 JSCLASS_NO_OPTIONAL_MEMBERS
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
25 };
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
26
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
27 // This native JS function prints the given string to the console.
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
28
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
29 static JSBool print(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
30 jsval *rval)
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
31 {
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
32 char *str;
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
33
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
34 if (!JS_ConvertArguments(cx, argc, argv, "s", &str))
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
35 return JS_FALSE;
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
36
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
37 printf("%s\n", str);
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
38
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
39 return JS_TRUE;
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
40 }
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
41
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
42 // Private structure to track the state of tracing the JS heap.
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
43
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
44 typedef struct TracingState {
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
45 // Keeps track of what objects we've visited so far.
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
46 JSDHashTable visited;
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
47
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
48 // Whether the tracing operation is successful or failed.
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
49 JSBool result;
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
50
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
51 // Class to look for.
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
52 JSClass *classp;
51
8750e9ecf3af Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents: 50
diff changeset
53
8750e9ecf3af Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents: 50
diff changeset
54 // Runtime that we're tracing.
8750e9ecf3af Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents: 50
diff changeset
55 JSRuntime *runtime;
8750e9ecf3af Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents: 50
diff changeset
56
8750e9ecf3af Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents: 50
diff changeset
57 // Structure required to use JS tracing functions.
8750e9ecf3af Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents: 50
diff changeset
58 JSTracer tracer;
50
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
59 };
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
60
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
61 // Static singleton for tracking the state of tracing the JS heap.
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
62 static TracingState tracingState;
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
63
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
64 // JSTraceCallback for heap dumping and other operations.
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
65
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
66 static void traceCallback(JSTracer *trc, void *thing, uint32 kind)
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
67 {
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
68 switch (kind) {
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
69 case JSTRACE_OBJECT:
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
70 JSDHashEntryStub *entry = (JSDHashEntryStub *)
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
71 JS_DHashTableOperate(&tracingState.visited,
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
72 thing,
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
73 JS_DHASH_LOOKUP);
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
74 if (JS_DHASH_ENTRY_IS_FREE((JSDHashEntryHdr *)entry)) {
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
75 entry = (JSDHashEntryStub *) JS_DHashTableOperate(&tracingState.visited,
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
76 thing,
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
77 JS_DHASH_ADD);
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
78 if (entry == NULL) {
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
79 JS_ReportOutOfMemory(trc->context);
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
80 tracingState.result = JS_FALSE;
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
81 return;
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
82 }
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
83 entry->key = thing;
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
84 JS_TraceChildren(trc, thing, kind);
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
85 }
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
86 break;
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
87 case JSTRACE_DOUBLE:
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
88 break;
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
89 case JSTRACE_STRING:
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
90 break;
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
91 }
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
92 }
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
93
51
8750e9ecf3af Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents: 50
diff changeset
94 static intN countRoots(void *rp, const char *name, void *data)
8750e9ecf3af Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents: 50
diff changeset
95 {
8750e9ecf3af Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents: 50
diff changeset
96 return JS_MAP_GCROOT_NEXT;
8750e9ecf3af Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents: 50
diff changeset
97 }
8750e9ecf3af Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents: 50
diff changeset
98
8750e9ecf3af Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents: 50
diff changeset
99 static intN rootMapFun(void *rp, const char *name, void *data)
8750e9ecf3af Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents: 50
diff changeset
100 {
8750e9ecf3af Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents: 50
diff changeset
101 jsval **currIndex = (jsval **) data;
8750e9ecf3af Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents: 50
diff changeset
102 **currIndex = INT_TO_JSVAL((unsigned int) rp);
8750e9ecf3af Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents: 50
diff changeset
103 *currIndex++;
8750e9ecf3af Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents: 50
diff changeset
104 return JS_MAP_GCROOT_NEXT;
8750e9ecf3af Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents: 50
diff changeset
105 }
8750e9ecf3af Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents: 50
diff changeset
106
54
c451579bf83c Built out more of the /objects/ method.
Atul Varma <varmaa@toolness.com>
parents: 51
diff changeset
107 static JSBool getObjInfo(JSContext *cx, JSObject *obj, uintN argc,
c451579bf83c Built out more of the /objects/ method.
Atul Varma <varmaa@toolness.com>
parents: 51
diff changeset
108 jsval *argv, jsval *rval)
c451579bf83c Built out more of the /objects/ method.
Atul Varma <varmaa@toolness.com>
parents: 51
diff changeset
109 {
c451579bf83c Built out more of the /objects/ method.
Atul Varma <varmaa@toolness.com>
parents: 51
diff changeset
110 uint32 id;
c451579bf83c Built out more of the /objects/ method.
Atul Varma <varmaa@toolness.com>
parents: 51
diff changeset
111
c451579bf83c Built out more of the /objects/ method.
Atul Varma <varmaa@toolness.com>
parents: 51
diff changeset
112 if (!JS_ConvertArguments(cx, argc, argv, "u", &id))
c451579bf83c Built out more of the /objects/ method.
Atul Varma <varmaa@toolness.com>
parents: 51
diff changeset
113 return JS_FALSE;
c451579bf83c Built out more of the /objects/ method.
Atul Varma <varmaa@toolness.com>
parents: 51
diff changeset
114
c451579bf83c Built out more of the /objects/ method.
Atul Varma <varmaa@toolness.com>
parents: 51
diff changeset
115 JSDHashEntryStub *entry = (JSDHashEntryStub *)
c451579bf83c Built out more of the /objects/ method.
Atul Varma <varmaa@toolness.com>
parents: 51
diff changeset
116 JS_DHashTableOperate(&tracingState.visited,
c451579bf83c Built out more of the /objects/ method.
Atul Varma <varmaa@toolness.com>
parents: 51
diff changeset
117 (void *) id,
c451579bf83c Built out more of the /objects/ method.
Atul Varma <varmaa@toolness.com>
parents: 51
diff changeset
118 JS_DHASH_LOOKUP);
c451579bf83c Built out more of the /objects/ method.
Atul Varma <varmaa@toolness.com>
parents: 51
diff changeset
119 if (entry == NULL) {
c451579bf83c Built out more of the /objects/ method.
Atul Varma <varmaa@toolness.com>
parents: 51
diff changeset
120 JS_ReportOutOfMemory(cx);
c451579bf83c Built out more of the /objects/ method.
Atul Varma <varmaa@toolness.com>
parents: 51
diff changeset
121 return JS_FALSE;
c451579bf83c Built out more of the /objects/ method.
Atul Varma <varmaa@toolness.com>
parents: 51
diff changeset
122 }
c451579bf83c Built out more of the /objects/ method.
Atul Varma <varmaa@toolness.com>
parents: 51
diff changeset
123
c451579bf83c Built out more of the /objects/ method.
Atul Varma <varmaa@toolness.com>
parents: 51
diff changeset
124 if (JS_DHASH_ENTRY_IS_BUSY((JSDHashEntryHdr *)entry)) {
c451579bf83c Built out more of the /objects/ method.
Atul Varma <varmaa@toolness.com>
parents: 51
diff changeset
125 JSObject *info = JS_NewObject(cx, NULL, NULL, NULL);
55
1aba1b7a0a2c Added a 'nativeClass' property to object info method.
Atul Varma <varmaa@toolness.com>
parents: 54
diff changeset
126
1aba1b7a0a2c Added a 'nativeClass' property to object info method.
Atul Varma <varmaa@toolness.com>
parents: 54
diff changeset
127 JSObject *target = (JSObject *) id;
1aba1b7a0a2c Added a 'nativeClass' property to object info method.
Atul Varma <varmaa@toolness.com>
parents: 54
diff changeset
128 JSClass *classp = JS_GET_CLASS(tracingState.tracer.context, target);
1aba1b7a0a2c Added a 'nativeClass' property to object info method.
Atul Varma <varmaa@toolness.com>
parents: 54
diff changeset
129 if (classp != NULL) {
1aba1b7a0a2c Added a 'nativeClass' property to object info method.
Atul Varma <varmaa@toolness.com>
parents: 54
diff changeset
130 // TODO: Should really be using an interned string here or something.
1aba1b7a0a2c Added a 'nativeClass' property to object info method.
Atul Varma <varmaa@toolness.com>
parents: 54
diff changeset
131 JSString *name = JS_NewStringCopyZ(cx, classp->name);
1aba1b7a0a2c Added a 'nativeClass' property to object info method.
Atul Varma <varmaa@toolness.com>
parents: 54
diff changeset
132 if (name == NULL) {
1aba1b7a0a2c Added a 'nativeClass' property to object info method.
Atul Varma <varmaa@toolness.com>
parents: 54
diff changeset
133 JS_ReportOutOfMemory(cx);
1aba1b7a0a2c Added a 'nativeClass' property to object info method.
Atul Varma <varmaa@toolness.com>
parents: 54
diff changeset
134 return JS_FALSE;
1aba1b7a0a2c Added a 'nativeClass' property to object info method.
Atul Varma <varmaa@toolness.com>
parents: 54
diff changeset
135 }
1aba1b7a0a2c Added a 'nativeClass' property to object info method.
Atul Varma <varmaa@toolness.com>
parents: 54
diff changeset
136 if (!JS_DefineProperty(cx, info, "nativeClass", STRING_TO_JSVAL(name),
1aba1b7a0a2c Added a 'nativeClass' property to object info method.
Atul Varma <varmaa@toolness.com>
parents: 54
diff changeset
137 NULL, NULL, JSPROP_ENUMERATE)) {
1aba1b7a0a2c Added a 'nativeClass' property to object info method.
Atul Varma <varmaa@toolness.com>
parents: 54
diff changeset
138 JS_ReportOutOfMemory(cx);
1aba1b7a0a2c Added a 'nativeClass' property to object info method.
Atul Varma <varmaa@toolness.com>
parents: 54
diff changeset
139 return JS_FALSE;
1aba1b7a0a2c Added a 'nativeClass' property to object info method.
Atul Varma <varmaa@toolness.com>
parents: 54
diff changeset
140 }
1aba1b7a0a2c Added a 'nativeClass' property to object info method.
Atul Varma <varmaa@toolness.com>
parents: 54
diff changeset
141 }
1aba1b7a0a2c Added a 'nativeClass' property to object info method.
Atul Varma <varmaa@toolness.com>
parents: 54
diff changeset
142
54
c451579bf83c Built out more of the /objects/ method.
Atul Varma <varmaa@toolness.com>
parents: 51
diff changeset
143 *rval = OBJECT_TO_JSVAL(info);
c451579bf83c Built out more of the /objects/ method.
Atul Varma <varmaa@toolness.com>
parents: 51
diff changeset
144 } else
c451579bf83c Built out more of the /objects/ method.
Atul Varma <varmaa@toolness.com>
parents: 51
diff changeset
145 *rval = JSVAL_NULL;
c451579bf83c Built out more of the /objects/ method.
Atul Varma <varmaa@toolness.com>
parents: 51
diff changeset
146
c451579bf83c Built out more of the /objects/ method.
Atul Varma <varmaa@toolness.com>
parents: 51
diff changeset
147 return JS_TRUE;
c451579bf83c Built out more of the /objects/ method.
Atul Varma <varmaa@toolness.com>
parents: 51
diff changeset
148 }
c451579bf83c Built out more of the /objects/ method.
Atul Varma <varmaa@toolness.com>
parents: 51
diff changeset
149
51
8750e9ecf3af Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents: 50
diff changeset
150 static JSBool getGCRoots(JSContext *cx, JSObject *obj, uintN argc,
8750e9ecf3af Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents: 50
diff changeset
151 jsval *argv, jsval *rval)
8750e9ecf3af Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents: 50
diff changeset
152 {
8750e9ecf3af Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents: 50
diff changeset
153 uint32 numRoots = JS_MapGCRoots(tracingState.runtime, countRoots, NULL);
8750e9ecf3af Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents: 50
diff changeset
154 jsval rootList[numRoots];
8750e9ecf3af Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents: 50
diff changeset
155 jsval *currIndex = rootList;
8750e9ecf3af Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents: 50
diff changeset
156
8750e9ecf3af Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents: 50
diff changeset
157 JS_MapGCRoots(tracingState.runtime, rootMapFun, &currIndex);
8750e9ecf3af Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents: 50
diff changeset
158
8750e9ecf3af Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents: 50
diff changeset
159 JSObject *roots = JS_NewArrayObject(cx, numRoots, rootList);
8750e9ecf3af Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents: 50
diff changeset
160 if (roots == NULL) {
8750e9ecf3af Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents: 50
diff changeset
161 JS_ReportError(cx, "Creating array failed.");
8750e9ecf3af Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents: 50
diff changeset
162 return JS_FALSE;
8750e9ecf3af Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents: 50
diff changeset
163 }
8750e9ecf3af Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents: 50
diff changeset
164
8750e9ecf3af Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents: 50
diff changeset
165 *rval = OBJECT_TO_JSVAL(roots);
8750e9ecf3af Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents: 50
diff changeset
166 return JS_TRUE;
8750e9ecf3af Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents: 50
diff changeset
167 }
8750e9ecf3af Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents: 50
diff changeset
168
50
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
169 static JSFunctionSpec server_global_functions[] = {
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
170 JS_FS("print", print, 1, 0, 0),
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
171 JS_FS("ServerSocket", createServerSocket, 0, 0, 0),
51
8750e9ecf3af Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents: 50
diff changeset
172 JS_FS("getGCRoots", getGCRoots, 0, 0, 0),
54
c451579bf83c Built out more of the /objects/ method.
Atul Varma <varmaa@toolness.com>
parents: 51
diff changeset
173 JS_FS("getObjectInfo", getObjInfo, 1, 0, 0),
50
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
174 JS_FS_END
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
175 };
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
176
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
177 JSBool profileMemory(JSContext *cx, JSObject *obj, uintN argc,
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
178 jsval *argv, jsval *rval)
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
179 {
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
180 if (!JS_DHashTableInit(&tracingState.visited, JS_DHashGetStubOps(),
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
181 NULL, sizeof(JSDHashEntryStub),
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
182 JS_DHASH_DEFAULT_CAPACITY(100))) {
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
183 JS_ReportOutOfMemory(cx);
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
184 return JS_FALSE;
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
185 }
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
186
51
8750e9ecf3af Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents: 50
diff changeset
187 tracingState.runtime = JS_GetRuntime(cx);
50
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
188 tracingState.result = JS_TRUE;
51
8750e9ecf3af Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents: 50
diff changeset
189 tracingState.tracer.context = cx;
8750e9ecf3af Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents: 50
diff changeset
190 tracingState.tracer.callback = traceCallback;
8750e9ecf3af Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents: 50
diff changeset
191 JS_TraceRuntime(&tracingState.tracer);
50
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
192
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
193 if (!tracingState.result)
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
194 return JS_FALSE;
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
195
51
8750e9ecf3af Added a getGCRoots() function.
Atul Varma <varmaa@toolness.com>
parents: 50
diff changeset
196 JSRuntime *serverRuntime = JS_NewRuntime(8L * 1024L * 1024L);
50
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
197 if (serverRuntime == NULL) {
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
198 JS_ReportError(cx, "Couldn't create server JS runtime.");
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
199 return JS_FALSE;
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
200 }
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
201
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
202 JSContext *serverCx = JS_NewContext(serverRuntime, 8192);
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
203 if (serverCx == NULL) {
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
204 JS_ReportError(cx, "Couldn't create server JS context.");
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
205 return JS_FALSE;
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
206 }
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
207 JS_SetOptions(serverCx, JSOPTION_VAROBJFIX);
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
208 JS_SetVersion(serverCx, JSVERSION_LATEST);
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
209 JS_SetErrorReporter(serverCx, reportError);
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
210
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
211 JSObject *serverGlobal = JS_NewObject(serverCx, &global_class, NULL, NULL);
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
212 if (serverGlobal == NULL) {
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
213 JS_ReportError(cx, "Couldn't create server JS global.");
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
214 return JS_FALSE;
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
215 }
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
216
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
217 if (!JS_InitStandardClasses(serverCx, serverGlobal)) {
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
218 JS_ReportError(cx, "Couldn't init standard classes on server JS global.");
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
219 return JS_FALSE;
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
220 }
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
221
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
222 if (!JS_DefineFunctions(serverCx, serverGlobal, server_global_functions)) {
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
223 JS_ReportError(cx, "Couldn't define functions on server JS global.");
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
224 return JS_FALSE;
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
225 }
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
226
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
227 FILE *f = fopen(SERVER_FILENAME, "r");
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
228 if (!f) {
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
229 JS_ReportError(cx, "Couldn't open " SERVER_FILENAME);
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
230 return JS_FALSE;
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
231 }
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
232
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
233 fseek(f, 0, SEEK_END);
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
234 long fileSize = ftell(f);
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
235 fseek(f, 0, SEEK_SET);
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
236
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
237 char source[fileSize];
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
238 fread(source, fileSize, 1, f);
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
239 fclose(f);
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
240
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
241 jsval serverRval;
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
242 if (!JS_EvaluateScript(serverCx, serverGlobal, source,
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
243 fileSize, SERVER_FILENAME, 1,
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
244 &serverRval)) {
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
245 JS_ReportError(cx, "Server failed.");
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
246 return JS_FALSE;
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
247 }
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
248
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
249 /* Cleanup. */
54
c451579bf83c Built out more of the /objects/ method.
Atul Varma <varmaa@toolness.com>
parents: 51
diff changeset
250 JS_DHashTableFinish(&tracingState.visited);
50
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
251 JS_DestroyContext(serverCx);
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
252 JS_DestroyRuntime(serverRuntime);
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
253
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
254 *rval = JSVAL_VOID;
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
255 return JS_TRUE;
853f80bd3b4b Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
256 }