зеркало из https://github.com/mozilla/gecko-dev.git
servo: make it possible for content to (successfully) invoke JS
Source-Repo: https://github.com/servo/servo Source-Revision: b7315ad9d010257d19995f00a9457f3d0e8d9e75
This commit is contained in:
Родитель
00f91c4c08
Коммит
de8c710ec0
|
@ -63,7 +63,10 @@ fn content(to_layout: chan<layout::msg>) -> chan<msg> {
|
|||
}
|
||||
result::ok(bytes) {
|
||||
let cx = rt.cx();
|
||||
cx.set_default_options_and_version();
|
||||
cx.set_logging_error_reporter();
|
||||
cx.new_compartment(jsglobal::global_class).chain { |comp|
|
||||
comp.define_functions(jsglobal::global_fns);
|
||||
cx.evaluate_script(comp.global_obj, bytes, filename, 1u)
|
||||
};
|
||||
}
|
||||
|
|
|
@ -74,6 +74,10 @@ impl methods for cx {
|
|||
JS_SetVersion(self.ptr, v);
|
||||
}
|
||||
|
||||
fn set_logging_error_reporter() {
|
||||
JS_SetErrorReporter(self.ptr, reportError);
|
||||
}
|
||||
|
||||
fn set_error_reporter(reportfn: *u8) {
|
||||
JS_SetErrorReporter(self.ptr, reportfn);
|
||||
}
|
||||
|
@ -119,6 +123,18 @@ impl methods for cx {
|
|||
}
|
||||
}
|
||||
|
||||
crust fn reportError(_cx: *JSContext,
|
||||
msg: *c_char,
|
||||
report: *JSErrorReport) {
|
||||
unsafe {
|
||||
let fnptr = (*report).filename;
|
||||
let fname = if fnptr.is_not_null() {from_c_str(fnptr)} else {"none"};
|
||||
let lineno = (*report).lineno;
|
||||
let msg = from_c_str(msg);
|
||||
#error["Error at %s:%?: %s\n", fname, lineno, msg];
|
||||
}
|
||||
}
|
||||
|
||||
// ___________________________________________________________________________
|
||||
// compartment
|
||||
|
||||
|
@ -152,24 +168,12 @@ resource jsobj_rsrc(self: {cx: cx, cxptr: *JSContext, ptr: *JSObject}) {
|
|||
#[cfg(test)]
|
||||
mod test {
|
||||
|
||||
crust fn reportError(_cx: *JSContext,
|
||||
msg: *c_char,
|
||||
report: *JSErrorReport) {
|
||||
unsafe {
|
||||
let fnptr = (*report).filename;
|
||||
let fname = if fnptr.is_not_null() {from_c_str(fnptr)} else {"none"};
|
||||
let lineno = (*report).lineno;
|
||||
let msg = from_c_str(msg);
|
||||
#error["Error at %s:%?: %s\n", fname, lineno, msg];
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dummy() {
|
||||
let rt = rt();
|
||||
let cx = rt.cx();
|
||||
cx.set_default_options_and_version();
|
||||
cx.set_error_reporter(reportError);
|
||||
cx.set_logging_error_reporter();
|
||||
cx.new_compartment(jsglobal::global_class).chain { |comp|
|
||||
comp.define_functions(jsglobal::global_fns);
|
||||
|
||||
|
|
|
@ -63,7 +63,7 @@ fn global_class(np: name_pool) -> JSClass {
|
|||
null(), null(), null(), null(), null())} // 40
|
||||
}
|
||||
|
||||
crust fn debug(cx: *JSContext, argc: uintN, vp: *jsval) {
|
||||
crust fn debug(cx: *JSContext, argc: uintN, vp: *jsval) -> JSBool {
|
||||
import io::writer_util;
|
||||
|
||||
#debug["debug() called with %? arguments", argc];
|
||||
|
@ -78,6 +78,7 @@ crust fn debug(cx: *JSContext, argc: uintN, vp: *jsval) {
|
|||
#debug["%s", str];
|
||||
}
|
||||
JS_SET_RVAL(cx, vp, JSVAL_NULL);
|
||||
ret 1_i32;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
print("Hello, world!");
|
||||
debug("Hello, world!");
|
||||
|
|
Загрузка…
Ссылка в новой задаче