Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
integrate spidermonkey (it doesn't do anything yet)
- Loading branch information
1 parent
0571f51
commit 6d27ee5
Showing
7 changed files
with
194 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/bin/bash | ||
# | ||
# Handy tool for extracting #defines from jsapi.h. For example: | ||
# ./jsdefine %x JSCLASS_GLOBAL_FLAGS | ||
# outputs | ||
# 48000 | ||
|
||
ETCDIR=$(dirname $0) | ||
INCDIR=${ETCDIR}/../mozjs/dist/include | ||
|
||
echo > jsdefine.c | ||
echo '#include "jsapi.h"' >> jsdefine.c | ||
echo '' >> jsdefine.c | ||
echo 'int main() {' >> jsdefine.c | ||
echo ' printf(' >> jsdefine.c | ||
echo ' "'"$1"'\n"', >> jsdefine.c | ||
echo " $2);" >> jsdefine.c | ||
echo '}' >> jsdefine.c | ||
|
||
gcc -I ${INCDIR} jsdefine.c -o jsdefine.exe | ||
./jsdefine.exe |
Submodule mozjs
updated
from e8ffa4 to a971b9
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import jsapi::*; | ||
import jsapi::bindgen::*; | ||
import ptr::{null, addr_of}; | ||
import result::{result, ok, err, extensions}; | ||
|
||
export rt; | ||
export methods; | ||
export cx; | ||
export named_class; | ||
export jsobj; | ||
|
||
const default_heapsize: u32 = 8_u32 * 1024_u32 * 1024_u32; | ||
const default_stacksize: uint = 8192u; | ||
const ERR: JSBool = 0_i32; | ||
|
||
fn result(n: JSBool) -> result<(),()> { | ||
if n != ERR {ok(())} else {err(())} | ||
} | ||
|
||
type named_class = @{ | ||
name: str, | ||
jsclass: JSClass | ||
}; | ||
|
||
// ___________________________________________________________________________ | ||
// runtimes | ||
|
||
type rt = @rt_rsrc; | ||
|
||
resource rt_rsrc(self: {ptr: *JSRuntime}) { | ||
JS_Finish(self.ptr) | ||
} | ||
|
||
fn rt() -> rt { | ||
@rt_rsrc({ptr: JS_Init(default_heapsize)}) | ||
} | ||
|
||
impl methods for rt { | ||
fn cx() -> cx { | ||
@cx_rsrc({ptr: JS_NewContext(self.ptr, default_stacksize)}) | ||
} | ||
} | ||
|
||
// ___________________________________________________________________________ | ||
// contexts | ||
|
||
type cx = @cx_rsrc; | ||
resource cx_rsrc(self: {ptr: *JSContext}) { | ||
JS_DestroyContext(self.ptr); | ||
} | ||
|
||
impl methods for cx { | ||
fn rooted_obj(obj: *JSObject) -> jsobj { | ||
let jsobj = @jsobj_rsrc({cx: self.ptr, obj: obj}); | ||
JS_AddObjectRoot(self.ptr, ptr::addr_of(jsobj.obj)); | ||
jsobj | ||
} | ||
|
||
fn new_global(globcls: named_class) -> result<jsobj,()> { | ||
let globobj = | ||
JS_NewCompartmentAndGlobalObject( | ||
self.ptr, | ||
addr_of(globcls.jsclass), | ||
null()); | ||
result(JS_InitStandardClasses(self.ptr, globobj)).chain { |_ok| | ||
ok(self.rooted_obj(globobj)) | ||
} | ||
} | ||
} | ||
|
||
// ___________________________________________________________________________ | ||
// objects | ||
|
||
type jsobj = @jsobj_rsrc; | ||
|
||
resource jsobj_rsrc(self: {cx: *JSContext, obj: *JSObject}) { | ||
JS_RemoveObjectRoot(self.cx, ptr::addr_of(self.obj)); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Definition for the global object that we use: | ||
|
||
import jsapi::*; | ||
import jsapi::bindgen::*; | ||
import ptr::null; | ||
|
||
crust fn PropertyStub(++arg0: *JSContext, | ||
++arg1: *JSObject, | ||
++arg2: jsid, | ||
++arg3: *jsval) -> JSBool { | ||
JS_PropertyStub(arg0, arg1, arg2, arg3) | ||
} | ||
|
||
crust fn StrictPropertyStub(++arg0: *JSContext, | ||
++arg1: *JSObject, | ||
++arg2: jsid, | ||
++arg3: JSBool, | ||
++arg4: *jsval) -> JSBool { | ||
JS_StrictPropertyStub(arg0, arg1, arg2, arg3, arg4) | ||
} | ||
|
||
crust fn EnumerateStub(++arg0: *JSContext, ++arg1: *JSObject) -> JSBool { | ||
JS_EnumerateStub(arg0, arg1) | ||
} | ||
|
||
crust fn ResolveStub(++arg0: *JSContext, | ||
++arg1: *JSObject, | ||
++arg2: jsid) -> JSBool { | ||
JS_ResolveStub(arg0, arg1, arg2) | ||
} | ||
|
||
crust fn ConvertStub(++arg0: *JSContext, | ||
++arg1: *JSObject, | ||
++arg2: JSType, | ||
++arg3: *jsval) -> JSBool { | ||
JS_ConvertStub(arg0, arg1, arg2, arg3) | ||
} | ||
|
||
fn global_class() -> js::named_class { | ||
let name = "global"; | ||
let c_str = str::as_c_str(name) { |bytes| bytes }; | ||
@{name: name, // in theory, this should *move* the str in here.. | ||
jsclass: {name: c_str, // ...and so this ptr ought to be valid. | ||
flags: 0x48000_u32, | ||
addProperty: PropertyStub, | ||
delProperty: PropertyStub, | ||
getProperty: PropertyStub, | ||
setProperty: StrictPropertyStub, | ||
enumerate: EnumerateStub, | ||
resolve: ResolveStub, | ||
convert: ConvertStub, | ||
finalize: null(), | ||
reserved0: null(), | ||
checkAccess: null(), | ||
call: null(), | ||
construct: null(), | ||
xdrObject: null(), | ||
hasInstance: null(), | ||
trace: null(), | ||
reserved1: null(), | ||
reserved: (null(), null(), null(), null(), null(), // 05 | ||
null(), null(), null(), null(), null(), // 10 | ||
null(), null(), null(), null(), null(), // 15 | ||
null(), null(), null(), null(), null(), // 20 | ||
null(), null(), null(), null(), null(), // 25 | ||
null(), null(), null(), null(), null(), // 30 | ||
null(), null(), null(), null(), null(), // 35 | ||
null(), null(), null(), null(), null())}} // 40 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters