mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Fix parser crash. Fix competing uses of JSContext's private slot.
This commit is contained in:
parent
e09f05d411
commit
d21d27e086
4 changed files with 17 additions and 16 deletions
|
@ -93,8 +93,8 @@ struct Content {
|
|||
fn Content(layout_task: LayoutTask,
|
||||
from_master: Port<ControlMsg>,
|
||||
resource_task: ResourceTask,
|
||||
img_cache_task: ImageCacheTask) -> Content {
|
||||
|
||||
img_cache_task: ImageCacheTask) -> @Content {
|
||||
|
||||
let jsrt = jsrt();
|
||||
let cx = jsrt.cx();
|
||||
let event_port = Port();
|
||||
|
@ -107,7 +107,7 @@ fn Content(layout_task: LayoutTask,
|
|||
Err(()) => None
|
||||
};
|
||||
|
||||
let content = Content {
|
||||
let content = @Content {
|
||||
layout_task : layout_task,
|
||||
image_cache_task : img_cache_task,
|
||||
from_master : from_master,
|
||||
|
@ -125,12 +125,12 @@ fn Content(layout_task: LayoutTask,
|
|||
compartment : compartment
|
||||
};
|
||||
|
||||
cx.set_cx_private(ptr::to_unsafe_ptr(&content) as *());
|
||||
cx.set_cx_private(ptr::to_unsafe_ptr(&*content) as *());
|
||||
|
||||
content
|
||||
}
|
||||
|
||||
fn task_from_context(cx: *JSContext) -> &Content unsafe {
|
||||
fn task_from_context(cx: *JSContext) -> *Content unsafe {
|
||||
cast::reinterpret_cast(&JS_GetContextPrivate(cx))
|
||||
}
|
||||
|
||||
|
|
|
@ -80,8 +80,8 @@ extern fn HTMLImageElement_getWidth(cx: *JSContext, _argc: c_uint, vp: *mut jsva
|
|||
~Element(ed) => {
|
||||
match ed.kind {
|
||||
~HTMLImageElement(*) => {
|
||||
let content : &Content = task_from_context(cx);
|
||||
match content.query_layout(layout_task::ContentBox(node)) {
|
||||
let content = task_from_context(cx);
|
||||
match (*content).query_layout(layout_task::ContentBox(node)) {
|
||||
Ok(rect) => rect.width,
|
||||
Err(()) => 0,
|
||||
}
|
||||
|
@ -171,8 +171,8 @@ pub fn create(cx: *JSContext, node: Node, scope: NodeScope) -> jsobj unsafe {
|
|||
//TODO error checking
|
||||
let compartment = utils::get_compartment(cx);
|
||||
let obj = result::unwrap(
|
||||
(*compartment).new_object_with_proto(~"GenericElementInstance", proto,
|
||||
(*compartment).global_obj.ptr));
|
||||
compartment.new_object_with_proto(~"GenericElementInstance", proto,
|
||||
compartment.global_obj.ptr));
|
||||
|
||||
unsafe {
|
||||
let raw_ptr: *libc::c_void =
|
||||
|
|
|
@ -10,6 +10,7 @@ use js::glue::{PROPERTY_STUB, STRICT_PROPERTY_STUB, ENUMERATE_STUB, CONVERT_STUB
|
|||
RESOLVE_STUB};
|
||||
use js::glue::bindgen::*;
|
||||
use ptr::null;
|
||||
use content::content_task::{Content, task_from_context};
|
||||
|
||||
enum DOMString {
|
||||
str(~str),
|
||||
|
@ -24,8 +25,6 @@ unsafe fn squirrel_away<T>(x: @T) -> *rust_box<T> {
|
|||
y
|
||||
}
|
||||
|
||||
type rust_unique<T> = {payload: T};
|
||||
|
||||
unsafe fn squirrel_away_unique<T>(x: ~T) -> *rust_box<T> {
|
||||
let y: *rust_box<T> = cast::reinterpret_cast(&x);
|
||||
cast::forget(x);
|
||||
|
@ -70,11 +69,13 @@ unsafe fn domstring_to_jsval(cx: *JSContext, str: &DOMString) -> jsval {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn get_compartment(cx: *JSContext) -> *bare_compartment {
|
||||
pub fn get_compartment(cx: *JSContext) -> compartment {
|
||||
unsafe {
|
||||
let privptr: *libc::c_void = JS_GetContextPrivate(cx);
|
||||
let compartment: *bare_compartment = cast::reinterpret_cast(&privptr);
|
||||
assert cx == (*compartment).cx.ptr;
|
||||
let content = task_from_context(cx);
|
||||
let compartment = option::expect(&(*content).compartment,
|
||||
~"Should always have compartment when \
|
||||
executing JS code");
|
||||
assert cx == compartment.cx.ptr;
|
||||
compartment
|
||||
}
|
||||
}
|
||||
|
|
|
@ -304,7 +304,7 @@ pub fn parse_html(scope: NodeScope,
|
|||
// A little function for holding this lint attr
|
||||
#[allow(non_implicitly_copyable_typarams)]
|
||||
fn complete_script(scope: &NodeScope, script: hubbub::Node, url: &Url, js_chan: &comm::Chan<JSMessage>) unsafe {
|
||||
do scope.read(reinterpret_cast(&script)) |node_contents| {
|
||||
do scope.read(&reinterpret_cast(&script)) |node_contents| {
|
||||
match *node_contents.kind {
|
||||
Element(element) if element.tag_name == ~"script" => {
|
||||
match element.get_attr(~"src") {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue