mirror of
https://github.com/servo/servo.git
synced 2025-06-24 17:14:33 +01:00
Merge branch 'spiderup'
This commit is contained in:
commit
04d18d128a
10 changed files with 107 additions and 53 deletions
|
@ -1 +1 @@
|
|||
Subproject commit 8cf5c9b76a84e1304acd09523facaa1a30e3ba57
|
||||
Subproject commit 4fc39c96b0f121f1b61c7541aaa3de2a84246aad
|
|
@ -1 +1 @@
|
|||
Subproject commit 9bf630c5f2035a29e7ccee0ca94e9c4568815f7b
|
||||
Subproject commit 1dbbc2ee587634bda13d4c32957c2b1a0ce167cc
|
|
@ -1,6 +1,6 @@
|
|||
import js::rust::{compartment, bare_compartment, methods, jsobj};
|
||||
import js::{JS_ARGV, JSCLASS_HAS_RESERVED_SLOTS, JSPROP_ENUMERATE, JSPROP_SHARED, JSVAL_NULL, JS_THIS_OBJECT,
|
||||
JS_SET_RVAL};
|
||||
import js::{JS_ARGV, JSCLASS_HAS_RESERVED_SLOTS, JSPROP_ENUMERATE, JSPROP_SHARED,
|
||||
JSVAL_NULL, JS_THIS_OBJECT, JS_SET_RVAL, JSPROP_NATIVE_ACCESSORS};
|
||||
import js::jsapi::{JSContext, jsval, JSObject, JSBool, jsid, JSClass, JSFreeOp};
|
||||
import js::jsapi::bindgen::{JS_ValueToString, JS_GetStringCharsZAndLength, JS_ReportError,
|
||||
JS_GetReservedSlot, JS_SetReservedSlot, JS_NewStringCopyN,
|
||||
|
@ -60,11 +60,17 @@ enum Element = int;
|
|||
return 1;
|
||||
}*/
|
||||
|
||||
extern fn getDocumentElement(cx: *JSContext, obj: *JSObject, _id: jsid, rval: *mut jsval) -> JSBool unsafe {
|
||||
extern fn getDocumentElement(cx: *JSContext, _argc: c_uint, vp: *mut jsval)
|
||||
-> JSBool unsafe {
|
||||
let obj = JS_THIS_OBJECT(cx, unsafe::reinterpret_cast(vp));
|
||||
if obj.is_null() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
let box = unwrap(obj);
|
||||
let node = (*box).payload.root;
|
||||
let scope = (*box).payload.scope;
|
||||
*rval = RUST_OBJECT_TO_JSVAL(node::create(cx, node, scope).ptr);
|
||||
*vp = RUST_OBJECT_TO_JSVAL(node::create(cx, node, scope).ptr);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -88,12 +94,12 @@ fn init(compartment: bare_compartment, doc: @Document) {
|
|||
let attrs = @~[
|
||||
{name: compartment.add_name(~"documentElement"),
|
||||
tinyid: 0,
|
||||
flags: 0,
|
||||
getter: getDocumentElement,
|
||||
setter: null()}];
|
||||
flags: (JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_NATIVE_ACCESSORS) as u8,
|
||||
getter: {op: getDocumentElement, info: null()},
|
||||
setter: {op: null(), info: null()}}];
|
||||
vec::push(compartment.global_props, attrs);
|
||||
vec::as_buf(*attrs, |specs, _len| {
|
||||
JS_DefineProperties(compartment.cx.ptr, obj.ptr, specs);
|
||||
assert JS_DefineProperties(compartment.cx.ptr, obj.ptr, specs) == 1;
|
||||
});
|
||||
|
||||
compartment.register_class(utils::instance_jsclass(~"DocumentInstance", finalize));
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import js::rust::{bare_compartment, methods, jsobj};
|
||||
import js::{JS_ARGV, JSCLASS_HAS_RESERVED_SLOTS, JSPROP_ENUMERATE, JSPROP_SHARED, JSVAL_NULL,
|
||||
JS_THIS_OBJECT, JS_SET_RVAL};
|
||||
JS_THIS_OBJECT, JS_SET_RVAL, JSPROP_NATIVE_ACCESSORS};
|
||||
import js::jsapi::{JSContext, jsval, JSObject, JSBool, jsid, JSClass, JSFreeOp, JSPropertySpec};
|
||||
import js::jsapi::bindgen::{JS_ValueToString, JS_GetStringCharsZAndLength, JS_ReportError,
|
||||
JS_GetReservedSlot, JS_SetReservedSlot, JS_NewStringCopyN,
|
||||
|
@ -32,9 +32,9 @@ fn init(compartment: bare_compartment) {
|
|||
let attrs = @~[
|
||||
{name: compartment.add_name(~"tagName"),
|
||||
tinyid: 0,
|
||||
flags: 0,
|
||||
getter: getTagName,
|
||||
setter: null()}];
|
||||
flags: (JSPROP_ENUMERATE | JSPROP_SHARED | JSPROP_NATIVE_ACCESSORS) as u8,
|
||||
getter: {op: getTagName, info: null()},
|
||||
setter: {op: null(), info: null()}}];
|
||||
vec::push(compartment.global_props, attrs);
|
||||
vec::as_buf(*attrs, |specs, _len| {
|
||||
JS_DefineProperties(compartment.cx.ptr, obj.ptr, specs);
|
||||
|
@ -52,17 +52,22 @@ fn init(compartment: bare_compartment) {
|
|||
let attrs = @~[
|
||||
{name: compartment.add_name(~"width"),
|
||||
tinyid: 0,
|
||||
flags: (JSPROP_SHARED | JSPROP_ENUMERATE) as u8,
|
||||
getter: HTMLImageElement_getWidth,
|
||||
setter: HTMLImageElement_setWidth}];
|
||||
flags: (JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_NATIVE_ACCESSORS) as u8,
|
||||
getter: {op: HTMLImageElement_getWidth, info: null()},
|
||||
setter: {op: HTMLImageElement_setWidth, info: null()}}];
|
||||
vec::push(compartment.global_props, attrs);
|
||||
vec::as_buf(*attrs, |specs, _len| {
|
||||
JS_DefineProperties(compartment.cx.ptr, obj.ptr, specs);
|
||||
});
|
||||
}
|
||||
|
||||
extern fn HTMLImageElement_getWidth(_cx: *JSContext, obj: *JSObject, _id: jsid,
|
||||
rval: *mut jsval) -> JSBool unsafe {
|
||||
extern fn HTMLImageElement_getWidth(cx: *JSContext, _argc: c_uint, vp: *mut jsval)
|
||||
-> JSBool unsafe {
|
||||
let obj = JS_THIS_OBJECT(cx, unsafe::reinterpret_cast(vp));
|
||||
if obj.is_null() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
let bundle = unwrap(obj);
|
||||
let width = (*bundle).payload.scope.write((*bundle).payload.node, |nd| {
|
||||
match nd.kind {
|
||||
|
@ -75,13 +80,18 @@ extern fn HTMLImageElement_getWidth(_cx: *JSContext, obj: *JSObject, _id: jsid,
|
|||
_ => fail ~"why is this not an element?"
|
||||
}
|
||||
});
|
||||
*rval = RUST_INT_TO_JSVAL(
|
||||
*vp = RUST_INT_TO_JSVAL(
|
||||
(au_to_px(width) & (i32::max_value as int)) as libc::c_int);
|
||||
return 1;
|
||||
}
|
||||
|
||||
extern fn HTMLImageElement_setWidth(_cx: *JSContext, obj: *JSObject, _id: jsid,
|
||||
_strict: JSBool, vp: *jsval) -> JSBool unsafe {
|
||||
extern fn HTMLImageElement_setWidth(cx: *JSContext, _argc: c_uint, vp: *mut jsval)
|
||||
-> JSBool unsafe {
|
||||
let obj = JS_THIS_OBJECT(cx, unsafe::reinterpret_cast(vp));
|
||||
if obj.is_null() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
let bundle = unwrap(obj);
|
||||
do (*bundle).payload.scope.write((*bundle).payload.node) |nd| {
|
||||
match nd.kind {
|
||||
|
@ -98,19 +108,24 @@ extern fn HTMLImageElement_setWidth(_cx: *JSContext, obj: *JSObject, _id: jsid,
|
|||
return 1;
|
||||
}
|
||||
|
||||
extern fn getTagName(cx: *JSContext, obj: *JSObject, _id: jsid, rval: *mut jsval)
|
||||
extern fn getTagName(cx: *JSContext, _argc: c_uint, vp: *mut jsval)
|
||||
-> JSBool {
|
||||
unsafe {
|
||||
let obj = JS_THIS_OBJECT(cx, unsafe::reinterpret_cast(vp));
|
||||
if obj.is_null() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
let bundle = unwrap(obj);
|
||||
do (*bundle).payload.scope.write((*bundle).payload.node) |nd| {
|
||||
match nd.kind {
|
||||
~Element(ed) => {
|
||||
let s = str(copy ed.tag_name);
|
||||
*rval = domstring_to_jsval(cx, s);
|
||||
*vp = domstring_to_jsval(cx, s);
|
||||
}
|
||||
_ => {
|
||||
//XXXjdm should probably read the spec to figure out what to do here
|
||||
*rval = JSVAL_NULL;
|
||||
*vp = JSVAL_NULL;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import js::rust::{bare_compartment, methods, jsobj};
|
||||
import js::{JS_ARGV, JSCLASS_HAS_RESERVED_SLOTS, JSPROP_ENUMERATE, JSPROP_SHARED, JSVAL_NULL,
|
||||
JS_THIS_OBJECT, JS_SET_RVAL};
|
||||
JS_THIS_OBJECT, JS_SET_RVAL, JSPROP_NATIVE_ACCESSORS};
|
||||
import js::jsapi::{JSContext, jsval, JSObject, JSBool, jsid, JSClass, JSFreeOp, JSPropertySpec};
|
||||
import js::jsapi::bindgen::{JS_ValueToString, JS_GetStringCharsZAndLength, JS_ReportError,
|
||||
JS_GetReservedSlot, JS_SetReservedSlot, JS_NewStringCopyN,
|
||||
|
@ -20,15 +20,15 @@ fn init(compartment: bare_compartment) {
|
|||
let attrs = @~[
|
||||
{name: compartment.add_name(~"firstChild"),
|
||||
tinyid: 0,
|
||||
flags: 0,
|
||||
getter: getFirstChild,
|
||||
setter: null()},
|
||||
flags: (JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_NATIVE_ACCESSORS) as u8,
|
||||
getter: {op: getFirstChild, info: null()},
|
||||
setter: {op: null(), info: null()}},
|
||||
|
||||
{name: compartment.add_name(~"nextSibling"),
|
||||
tinyid: 0,
|
||||
flags: 0,
|
||||
getter: getNextSibling,
|
||||
setter: null()}];
|
||||
flags: (JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_NATIVE_ACCESSORS) as u8,
|
||||
getter: {op: getNextSibling, info: null()},
|
||||
setter: {op: null(), info: null()}}];
|
||||
vec::push(compartment.global_props, attrs);
|
||||
vec::as_buf(*attrs, |specs, _len| {
|
||||
JS_DefineProperties(compartment.cx.ptr, obj.ptr, specs);
|
||||
|
@ -64,17 +64,22 @@ unsafe fn unwrap(obj: *JSObject) -> *rust_box<NodeBundle> {
|
|||
unsafe::reinterpret_cast(RUST_JSVAL_TO_PRIVATE(val))
|
||||
}
|
||||
|
||||
extern fn getFirstChild(cx: *JSContext, obj: *JSObject, _id: jsid, rval: *mut jsval) -> JSBool {
|
||||
extern fn getFirstChild(cx: *JSContext, _argc: c_uint, vp: *mut jsval) -> JSBool {
|
||||
unsafe {
|
||||
let obj = JS_THIS_OBJECT(cx, unsafe::reinterpret_cast(vp));
|
||||
if obj.is_null() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
let bundle = unwrap(obj);
|
||||
do (*bundle).payload.scope.write((*bundle).payload.node) |nd| {
|
||||
match nd.tree.first_child {
|
||||
some(n) => {
|
||||
let obj = create(cx, n, (*bundle).payload.scope).ptr;
|
||||
*rval = RUST_OBJECT_TO_JSVAL(obj);
|
||||
*vp = RUST_OBJECT_TO_JSVAL(obj);
|
||||
}
|
||||
none => {
|
||||
*rval = JSVAL_NULL;
|
||||
*vp = JSVAL_NULL;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -82,20 +87,44 @@ extern fn getFirstChild(cx: *JSContext, obj: *JSObject, _id: jsid, rval: *mut js
|
|||
return 1;
|
||||
}
|
||||
|
||||
extern fn getNextSibling(cx: *JSContext, obj: *JSObject, _id: jsid, rval: *mut jsval) -> JSBool {
|
||||
extern fn getNextSibling(cx: *JSContext, _argc: c_uint, vp: *mut jsval) -> JSBool {
|
||||
unsafe {
|
||||
let obj = JS_THIS_OBJECT(cx, unsafe::reinterpret_cast(vp));
|
||||
if obj.is_null() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
let bundle = unwrap(obj);
|
||||
do (*bundle).payload.scope.write((*bundle).payload.node) |nd| {
|
||||
match nd.tree.next_sibling {
|
||||
some(n) => {
|
||||
let obj = create(cx, n, (*bundle).payload.scope).ptr;
|
||||
*rval = RUST_OBJECT_TO_JSVAL(obj);
|
||||
*vp = RUST_OBJECT_TO_JSVAL(obj);
|
||||
}
|
||||
none => {
|
||||
*rval = JSVAL_NULL;
|
||||
*vp = JSVAL_NULL;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
extern fn getNodeType(cx: *JSContext, _argc: c_uint, vp: *mut jsval) -> JSBool {
|
||||
unsafe {
|
||||
let obj = JS_THIS_OBJECT(cx, unsafe::reinterpret_cast(vp));
|
||||
if obj.is_null() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
let bundle = unwrap(obj);
|
||||
let nodeType = do (*bundle).payload.node.read |nd| {
|
||||
match nd.kind {
|
||||
~Element(*) => 1,
|
||||
~Text(*) => 3
|
||||
}
|
||||
};
|
||||
*vp = RUST_INT_TO_JSVAL(nodeType);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -109,8 +109,8 @@ fn prototype_jsclass(name: ~str) -> fn(bare_compartment) -> JSClass {
|
|||
finalize: null(),
|
||||
checkAccess: null(),
|
||||
call: null(),
|
||||
construct: null(),
|
||||
hasInstance: has_instance,
|
||||
construct: null(),
|
||||
trace: null(),
|
||||
reserved: (null(), null(), null(), null(), null(), // 05
|
||||
null(), null(), null(), null(), null(), // 10
|
||||
|
@ -138,8 +138,8 @@ fn instance_jsclass(name: ~str, finalize: *u8)
|
|||
finalize: finalize,
|
||||
checkAccess: null(),
|
||||
call: null(),
|
||||
construct: null(),
|
||||
hasInstance: has_instance,
|
||||
construct: null(),
|
||||
trace: null(),
|
||||
reserved: (null(), null(), null(), null(), null(), // 05
|
||||
null(), null(), null(), null(), null(), // 10
|
||||
|
|
|
@ -87,17 +87,19 @@ fn init(compartment: bare_compartment, win: @Window) {
|
|||
|
||||
/* Define methods on a window */
|
||||
let methods = ~[{name: compartment.add_name(~"alert"),
|
||||
call: alert,
|
||||
call: {op: alert, info: null()},
|
||||
nargs: 1,
|
||||
flags: 0},
|
||||
flags: 0,
|
||||
selfHostedName: null()},
|
||||
{name: compartment.add_name(~"setTimeout"),
|
||||
call: setTimeout,
|
||||
call: {op: setTimeout, info: null()},
|
||||
nargs: 2,
|
||||
flags: 0}];
|
||||
flags: 0,
|
||||
selfHostedName: null()}];
|
||||
|
||||
vec::as_buf(methods, |fns, _len| {
|
||||
JS_DefineFunctions(compartment.cx.ptr, proto.ptr, fns);
|
||||
});
|
||||
});
|
||||
|
||||
unsafe {
|
||||
let raw_ptr: *libc::c_void = unsafe::reinterpret_cast(squirrel_away(win));
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
<img src="test.jpeg"></img>
|
||||
<div></div>
|
||||
<script src="test_getter_time.js"></script>
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
var elem = document.documentElement.firstChild;
|
||||
var start = new Date().getTime();
|
||||
for (var i = 0; i < 10000; i++)
|
||||
var a = elem.width;
|
||||
window.alert(new Date().getTime() - start);
|
||||
start = new Date().getTime();
|
||||
|
||||
var start = (new Date()).getTime();
|
||||
for (var i = 0; i < 100000; i++)
|
||||
var a = elem.nodeType;
|
||||
window.alert((new Date()).getTime() - start);
|
||||
|
||||
/*start = new Date().getTime();
|
||||
for (i = 0; i < 10000; i++)
|
||||
elem.width = i;
|
||||
window.alert(new Date().getTime() - start);
|
||||
window.alert(new Date().getTime() - start);*/
|
Loading…
Add table
Add a link
Reference in a new issue