aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/script/dom
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2013-06-24 18:42:17 -0700
committerBrian Anderson <banderson@mozilla.com>2013-06-26 13:44:26 -0700
commit56e5ba1b825b77eaf56db7211ba7bf9549421c0b (patch)
tree008ba1ffb9fe69cf189c3cc461d65f41dd0fec9b /src/components/script/dom
parenta01f6b97f23b06dda6587f9b1c3d4e2ec3cf1f82 (diff)
downloadservo-56e5ba1b825b77eaf56db7211ba7bf9549421c0b.tar.gz
servo-56e5ba1b825b77eaf56db7211ba7bf9549421c0b.zip
Update for language changes
Diffstat (limited to 'src/components/script/dom')
-rw-r--r--src/components/script/dom/bindings/clientrect.rs6
-rw-r--r--src/components/script/dom/bindings/clientrectlist.rs6
-rw-r--r--src/components/script/dom/bindings/codegen/CodegenRust.py31
-rw-r--r--src/components/script/dom/bindings/conversions.rs10
-rw-r--r--src/components/script/dom/bindings/document.rs35
-rw-r--r--src/components/script/dom/bindings/domparser.rs4
-rw-r--r--src/components/script/dom/bindings/element.rs33
-rw-r--r--src/components/script/dom/bindings/event.rs5
-rw-r--r--src/components/script/dom/bindings/eventtarget.rs5
-rw-r--r--src/components/script/dom/bindings/htmlcollection.rs6
-rw-r--r--src/components/script/dom/bindings/node.rs13
-rw-r--r--src/components/script/dom/bindings/proxyhandler.rs14
-rw-r--r--src/components/script/dom/bindings/text.rs14
-rw-r--r--src/components/script/dom/bindings/utils.rs372
-rw-r--r--src/components/script/dom/bindings/window.rs43
-rw-r--r--src/components/script/dom/characterdata.rs4
-rw-r--r--src/components/script/dom/clientrect.rs2
-rw-r--r--src/components/script/dom/clientrectlist.rs10
-rw-r--r--src/components/script/dom/document.rs50
-rw-r--r--src/components/script/dom/element.rs19
-rw-r--r--src/components/script/dom/event.rs2
-rw-r--r--src/components/script/dom/eventtarget.rs4
-rw-r--r--src/components/script/dom/htmlcollection.rs14
-rw-r--r--src/components/script/dom/node.rs6
-rw-r--r--src/components/script/dom/window.rs21
25 files changed, 419 insertions, 310 deletions
diff --git a/src/components/script/dom/bindings/clientrect.rs b/src/components/script/dom/bindings/clientrect.rs
index a21b12cc049..b910ff1f41c 100644
--- a/src/components/script/dom/bindings/clientrect.rs
+++ b/src/components/script/dom/bindings/clientrect.rs
@@ -8,9 +8,11 @@ use dom::clientrect::ClientRect;
use script_task::{task_from_context, global_script_context};
use js::jsapi::{JSObject, JSContext, JSVal};
-use js::glue::bindgen::RUST_OBJECT_TO_JSVAL;
+use js::glue::RUST_OBJECT_TO_JSVAL;
-pub impl ClientRect {
+use std::cast;
+
+impl ClientRect {
pub fn init_wrapper(@mut self) {
let script_context = global_script_context();
let cx = script_context.js_compartment.cx.ptr;
diff --git a/src/components/script/dom/bindings/clientrectlist.rs b/src/components/script/dom/bindings/clientrectlist.rs
index aca6d85d1f4..a6d19a73a10 100644
--- a/src/components/script/dom/bindings/clientrectlist.rs
+++ b/src/components/script/dom/bindings/clientrectlist.rs
@@ -9,8 +9,10 @@ use script_task::{task_from_context, global_script_context};
use js::jsapi::{JSObject, JSContext};
-pub impl ClientRectList {
- fn init_wrapper(@mut self) {
+use std::cast;
+
+impl ClientRectList {
+ pub fn init_wrapper(@mut self) {
let script_context = global_script_context();
let cx = script_context.js_compartment.cx.ptr;
let owner = script_context.root_frame.get_ref().window;
diff --git a/src/components/script/dom/bindings/codegen/CodegenRust.py b/src/components/script/dom/bindings/codegen/CodegenRust.py
index 3c0c07d5ab5..59eca2a2e18 100644
--- a/src/components/script/dom/bindings/codegen/CodegenRust.py
+++ b/src/components/script/dom/bindings/codegen/CodegenRust.py
@@ -2853,7 +2853,7 @@ class CGCallGenerator(CGThing):
"""
def __init__(self, errorReport, arguments, argsPre, returnType,
extendedAttributes, descriptorProvider, nativeMethodName,
- static, object="self", declareResult=True):
+ static, object="this", declareResult=True):
CGThing.__init__(self)
assert errorReport is None or isinstance(errorReport, CGThing)
@@ -3070,7 +3070,7 @@ class CGAbstractBindingMethod(CGAbstractExternMethod):
unwrapThis = CGIndenter(CGGeneric(
str(CastableObjectUnwrapper(
FakeCastableDescriptor(self.descriptor),
- "obj", "self", self.unwrapFailureCode))))
+ "obj", "this", self.unwrapFailureCode))))
return CGList([ self.getThis(), unwrapThis,
self.generate_code() ], "\n").define()
@@ -3081,7 +3081,7 @@ class CGAbstractBindingMethod(CGAbstractExternMethod):
" return false as JSBool;\n"
"}\n"
"\n"
- "let self: *rust_box<%s>;" % self.descriptor.nativeType))
+ "let this: *rust_box<%s>;" % self.descriptor.nativeType))
def generate_code(self):
assert(False) # Override me
@@ -3098,7 +3098,7 @@ class CGGenericMethod(CGAbstractBindingMethod):
def generate_code(self):
return CGIndenter(CGGeneric(
"let _info: *JSJitInfo = RUST_FUNCTION_VALUE_TO_JITINFO(JS_CALLEE(cx, vp));\n"
- "return CallJitMethodOp(_info, cx, obj, ptr::to_unsafe_ptr(&(*self).payload) as *libc::c_void, argc, vp);"))
+ "return CallJitMethodOp(_info, cx, obj, ptr::to_unsafe_ptr(&(*this).payload) as *libc::c_void, argc, vp);"))
class CGAbstractStaticMethod(CGAbstractMethod):
"""
@@ -3121,7 +3121,7 @@ class CGSpecializedMethod(CGAbstractExternMethod):
self.method = method
name = method.identifier.name
args = [Argument('*JSContext', 'cx'), Argument('JSHandleObject', 'obj'),
- Argument('*mut %s' % descriptor.nativeType, 'self'),
+ Argument('*mut %s' % descriptor.nativeType, 'this'),
Argument('libc::c_uint', 'argc'), Argument('*mut JSVal', 'vp')]
CGAbstractExternMethod.__init__(self, descriptor, name, 'JSBool', args)
@@ -3154,7 +3154,7 @@ class CGGenericGetter(CGAbstractBindingMethod):
def generate_code(self):
return CGIndenter(CGGeneric(
"let _info: *JSJitInfo = RUST_FUNCTION_VALUE_TO_JITINFO(JS_CALLEE(cx, vp));\n"
- "return CallJitPropertyOp(_info, cx, obj, ptr::to_unsafe_ptr(&(*self).payload) as *libc::c_void, vp);"))
+ "return CallJitPropertyOp(_info, cx, obj, ptr::to_unsafe_ptr(&(*this).payload) as *libc::c_void, vp);"))
class CGSpecializedGetter(CGAbstractExternMethod):
"""
@@ -3166,7 +3166,7 @@ class CGSpecializedGetter(CGAbstractExternMethod):
name = 'get_' + attr.identifier.name
args = [ Argument('*JSContext', 'cx'),
Argument('JSHandleObject', 'obj'),
- Argument('*%s' % descriptor.nativeType, 'self'),
+ Argument('*%s' % descriptor.nativeType, 'this'),
Argument('*mut JSVal', 'vp') ]
CGAbstractExternMethod.__init__(self, descriptor, name, "JSBool", args)
@@ -3466,7 +3466,7 @@ if expando.is_not_null() {
getIndexedOrExpando = ("let index = GetArrayIndexFromId(cx, id);\n" +
"if index.is_some() {\n" +
" let index = index.get();\n" +
- " let self = UnwrapProxy(proxy);\n" +
+ " let this = UnwrapProxy(proxy);\n" +
CGIndenter(CGProxyIndexedGetter(self.descriptor, templateValues)).define())
getIndexedOrExpando += """
// Even if we don't have this index, we don't forward the
@@ -3488,7 +3488,7 @@ if expando.is_not_null() {
" return false;\n" +
" }\n" +
"\n" +
- " let self = UnwrapProxy(proxy);\n" +
+ " let this = UnwrapProxy(proxy);\n" +
CGIndenter(CGProxyNamedGetter(self.descriptor, templateValues)).define() +
"}\n") % (self.descriptor.nativeType)
else:
@@ -3558,7 +3558,7 @@ class CGAbstractClassHook(CGAbstractExternMethod):
def definition_body_prologue(self):
return "" #XXXjdm we may want to do a proper unwrap here
return """
- let self: *%s = &(unwrap::<*rust_box<%s>>(obj).payload);
+ let this: *%s = &(unwrap::<*rust_box<%s>>(obj).payload);
""" % (self.descriptor.nativeType, self.descriptor.nativeType)
def definition_body(self):
@@ -3570,8 +3570,8 @@ class CGAbstractClassHook(CGAbstractExternMethod):
def finalizeHook(descriptor, hookName, context):
if descriptor.customFinalize:
- return """if (self) {
- self->%s(%s);
+ return """if (this) {
+ this->%s(%s);
}""" % (hookName, context)
#clearWrapper = "ClearWrapper(self, self);\n" if descriptor.wrapperCache else ""
if descriptor.workers:
@@ -4132,9 +4132,7 @@ class CGBindingRoot(CGThing):
dictionaries,
['js::*',
'js::jsapi::*',
- 'js::jsapi::bindgen::*',
'js::jsfriendapi::bindgen::*',
- 'js::glue::bindgen::*',
'js::glue::*',
'dom::node::AbstractNode', #XXXjdm
'dom::document::Document', #XXXjdm
@@ -4150,6 +4148,11 @@ class CGBindingRoot(CGThing):
'script_task::task_from_context',
'dom::bindings::utils::EnumEntry',
'dom::node::ScriptView',
+ 'std::cast',
+ 'std::libc',
+ 'std::ptr',
+ 'std::vec',
+ 'std::str'
],
[],
curr)
diff --git a/src/components/script/dom/bindings/conversions.rs b/src/components/script/dom/bindings/conversions.rs
index 7350427a95e..48839401bcd 100644
--- a/src/components/script/dom/bindings/conversions.rs
+++ b/src/components/script/dom/bindings/conversions.rs
@@ -4,7 +4,7 @@
use js::jsapi::JSVal;
use js::{JSVAL_FALSE, JSVAL_TRUE};
-use js::glue::bindgen::{RUST_UINT_TO_JSVAL, RUST_JSVAL_TO_INT};
+use js::glue::{RUST_UINT_TO_JSVAL, RUST_JSVAL_TO_INT};
pub trait JSValConvertible {
fn to_jsval(&self) -> JSVal;
@@ -13,11 +13,15 @@ pub trait JSValConvertible {
impl JSValConvertible for u32 {
fn to_jsval(&self) -> JSVal {
- RUST_UINT_TO_JSVAL(*self)
+ unsafe {
+ RUST_UINT_TO_JSVAL(*self)
+ }
}
fn from_jsval(val: JSVal) -> Option<u32> {
- Some(RUST_JSVAL_TO_INT(val) as u32)
+ unsafe {
+ Some(RUST_JSVAL_TO_INT(val) as u32)
+ }
}
}
diff --git a/src/components/script/dom/bindings/document.rs b/src/components/script/dom/bindings/document.rs
index 87889f52ff9..731e6619bd9 100644
--- a/src/components/script/dom/bindings/document.rs
+++ b/src/components/script/dom/bindings/document.rs
@@ -2,16 +2,21 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+use std::cast;
+use std::libc;
+use std::ptr;
+use std::result;
+use std::vec;
use dom::bindings::utils::{DOMString, rust_box, squirrel_away, str};
use dom::bindings::utils::{WrapperCache, DerivedWrapper};
use dom::bindings::utils::{jsval_to_str, WrapNewBindingObject, CacheableWrapper};
use dom::bindings::utils;
use dom::document::Document;
use dom::htmlcollection::HTMLCollection;
-use js::glue::bindgen::*;
+use js::glue::*;
use js::glue::{PROPERTY_STUB, STRICT_PROPERTY_STUB};
-use js::jsapi::bindgen::{JS_DefineProperties};
-use js::jsapi::bindgen::{JS_GetReservedSlot, JS_SetReservedSlot, JS_DefineFunctions};
+use js::jsapi::{JS_DefineProperties};
+use js::jsapi::{JS_GetReservedSlot, JS_SetReservedSlot, JS_DefineFunctions};
use js::jsapi::{JSContext, JSVal, JSObject, JSBool, JSFreeOp, JSPropertySpec, JSPropertyOpWrapper};
use js::jsapi::{JSStrictPropertyOpWrapper, JSNativeWrapper, JSFunctionSpec};
use js::rust::{Compartment, jsobj};
@@ -19,8 +24,8 @@ use js::{JSPROP_NATIVE_ACCESSORS};
use js::{JS_ARGV, JSPROP_ENUMERATE, JSPROP_SHARED, JSVAL_NULL, JS_THIS_OBJECT, JS_SET_RVAL};
use script_task::task_from_context;
-use core::libc::c_uint;
-use core::ptr::null;
+use std::libc::c_uint;
+use std::ptr::null;
extern fn getDocumentElement(cx: *JSContext, _argc: c_uint, vp: *mut JSVal) -> JSBool {
unsafe {
@@ -96,9 +101,11 @@ pub fn init(compartment: @mut Compartment) {
flags: (JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_NATIVE_ACCESSORS) as u8,
getter: JSPropertyOpWrapper {op: null(), info: null()},
setter: JSStrictPropertyOpWrapper {op: null(), info: null()}}];
- vec::push(&mut compartment.global_props, attrs);
+ compartment.global_props.push(attrs);
vec::as_imm_buf(*attrs, |specs, _len| {
- assert!(JS_DefineProperties(compartment.cx.ptr, obj.ptr, specs) == 1);
+ unsafe {
+ assert!(JS_DefineProperties(compartment.cx.ptr, obj.ptr, specs) == 1);
+ }
});
let methods = @~[JSFunctionSpec {name: compartment.add_name(~"getElementsByTagName"),
@@ -112,7 +119,9 @@ pub fn init(compartment: @mut Compartment) {
flags: 0,
selfHostedName: null()}];
vec::as_imm_buf(*methods, |fns, _len| {
- JS_DefineFunctions(compartment.cx.ptr, obj.ptr, fns);
+ unsafe {
+ JS_DefineFunctions(compartment.cx.ptr, obj.ptr, fns);
+ }
});
compartment.register_class(utils::instance_jsclass(~"DocumentInstance",
@@ -129,12 +138,12 @@ pub fn create(compartment: @mut Compartment, doc: @mut Document) -> *JSObject {
unsafe {
let raw_ptr: *libc::c_void = cast::transmute(squirrel_away(doc));
JS_SetReservedSlot(instance.ptr, 0, RUST_PRIVATE_TO_JSVAL(raw_ptr));
- }
- compartment.define_property(~"document", RUST_OBJECT_TO_JSVAL(instance.ptr),
- GetJSClassHookStubPointer(PROPERTY_STUB) as *u8,
- GetJSClassHookStubPointer(STRICT_PROPERTY_STUB) as *u8,
- JSPROP_ENUMERATE);
+ compartment.define_property(~"document", RUST_OBJECT_TO_JSVAL(instance.ptr),
+ GetJSClassHookStubPointer(PROPERTY_STUB) as *u8,
+ GetJSClassHookStubPointer(STRICT_PROPERTY_STUB) as *u8,
+ JSPROP_ENUMERATE);
+ }
instance.ptr
}
diff --git a/src/components/script/dom/bindings/domparser.rs b/src/components/script/dom/bindings/domparser.rs
index 21744e43eb2..4e38e7d0f61 100644
--- a/src/components/script/dom/bindings/domparser.rs
+++ b/src/components/script/dom/bindings/domparser.rs
@@ -8,7 +8,9 @@ use dom::bindings::utils::{BindingObject, DerivedWrapper};
use dom::domparser::DOMParser;
use js::jsapi::{JSContext, JSObject, JSVal};
-use js::glue::bindgen::{RUST_OBJECT_TO_JSVAL};
+use js::glue::{RUST_OBJECT_TO_JSVAL};
+
+use std::cast;
impl CacheableWrapper for DOMParser {
fn get_wrappercache(&mut self) -> &mut WrapperCache {
diff --git a/src/components/script/dom/bindings/element.rs b/src/components/script/dom/bindings/element.rs
index 4e296e3bb6f..9a34f7c5dc6 100644
--- a/src/components/script/dom/bindings/element.rs
+++ b/src/components/script/dom/bindings/element.rs
@@ -12,10 +12,17 @@ use layout_interface::{ContentBoxQuery, ContentBoxResponse};
use script_task::task_from_context;
use super::utils;
-use core::libc::c_uint;
-use core::ptr::null;
-use js::glue::bindgen::*;
-use js::jsapi::bindgen::*;
+use std::cast;
+use std::i32;
+use std::libc;
+use std::libc::c_uint;
+use std::ptr;
+use std::ptr::null;
+use std::result;
+use std::str;
+use std::vec;
+use js::glue::*;
+use js::jsapi::*;
use js::jsapi::{JSContext, JSVal, JSObject, JSBool, JSFreeOp, JSPropertySpec};
use js::jsapi::{JSNativeWrapper, JSTracer, JSTRACE_OBJECT};
use js::jsapi::{JSPropertyOpWrapper, JSStrictPropertyOpWrapper, JSFunctionSpec};
@@ -78,7 +85,9 @@ pub fn init(compartment: @mut Compartment) {
setter: JSStrictPropertyOpWrapper {op: null(), info: null()}}];
vec::push(&mut compartment.global_props, attrs);
vec::as_imm_buf(*attrs, |specs, _len| {
- JS_DefineProperties(compartment.cx.ptr, obj.ptr, specs);
+ unsafe {
+ JS_DefineProperties(compartment.cx.ptr, obj.ptr, specs);
+ }
});
let methods = @~[JSFunctionSpec {name: compartment.add_name(~"getClientRects"),
@@ -102,7 +111,9 @@ pub fn init(compartment: @mut Compartment) {
flags: 0,
selfHostedName: null()}];
vec::as_imm_buf(*methods, |fns, _len| {
- JS_DefineFunctions(compartment.cx.ptr, obj.ptr, fns);
+ unsafe {
+ JS_DefineFunctions(compartment.cx.ptr, obj.ptr, fns);
+ }
});
compartment.register_class(utils::instance_jsclass(~"GenericElementInstance",
@@ -127,7 +138,9 @@ pub fn init(compartment: @mut Compartment) {
setter: JSStrictPropertyOpWrapper {op: null(), info: null()}}];
vec::push(&mut compartment.global_props, attrs);
vec::as_imm_buf(*attrs, |specs, _len| {
- JS_DefineProperties(compartment.cx.ptr, obj.ptr, specs);
+ unsafe {
+ JS_DefineProperties(compartment.cx.ptr, obj.ptr, specs);
+ }
});
}
@@ -299,8 +312,10 @@ pub fn create(cx: *JSContext, node: &mut AbstractNode<ScriptView>) -> jsobj {
assert!(cache.get_wrapper().is_null());
cache.set_wrapper(obj.ptr);
- let raw_ptr = node.raw_object() as *libc::c_void;
- JS_SetReservedSlot(obj.ptr, DOM_OBJECT_SLOT as u32, RUST_PRIVATE_TO_JSVAL(raw_ptr));
+ unsafe {
+ let raw_ptr = node.raw_object() as *libc::c_void;
+ JS_SetReservedSlot(obj.ptr, DOM_OBJECT_SLOT as u32, RUST_PRIVATE_TO_JSVAL(raw_ptr));
+ }
return obj;
}
diff --git a/src/components/script/dom/bindings/event.rs b/src/components/script/dom/bindings/event.rs
index 432dee40838..2197646e188 100644
--- a/src/components/script/dom/bindings/event.rs
+++ b/src/components/script/dom/bindings/event.rs
@@ -2,15 +2,16 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+use std::cast;
use dom::bindings::codegen::EventBinding;
use dom::bindings::utils::{CacheableWrapper, WrapperCache, BindingObject, DerivedWrapper};
use dom::event::Event_;
use script_task::{task_from_context, global_script_context};
-use js::glue::bindgen::RUST_OBJECT_TO_JSVAL;
+use js::glue::RUST_OBJECT_TO_JSVAL;
use js::jsapi::{JSObject, JSContext, JSVal};
-pub impl Event_ {
+impl Event_ {
pub fn init_wrapper(@mut self) {
let script_context = global_script_context();
let cx = script_context.js_compartment.cx.ptr;
diff --git a/src/components/script/dom/bindings/eventtarget.rs b/src/components/script/dom/bindings/eventtarget.rs
index 7b82f915791..ffb804d905c 100644
--- a/src/components/script/dom/bindings/eventtarget.rs
+++ b/src/components/script/dom/bindings/eventtarget.rs
@@ -2,15 +2,16 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+use std::cast;
use dom::bindings::codegen::EventTargetBinding;
use dom::bindings::utils::{CacheableWrapper, WrapperCache, BindingObject, DerivedWrapper};
use dom::eventtarget::EventTarget;
use script_task::{task_from_context, global_script_context};
-use js::glue::bindgen::RUST_OBJECT_TO_JSVAL;
+use js::glue::RUST_OBJECT_TO_JSVAL;
use js::jsapi::{JSObject, JSContext, JSVal};
-pub impl EventTarget {
+impl EventTarget {
pub fn init_wrapper(@mut self) {
let script_context = global_script_context();
let cx = script_context.js_compartment.cx.ptr;
diff --git a/src/components/script/dom/bindings/htmlcollection.rs b/src/components/script/dom/bindings/htmlcollection.rs
index 866e7634ada..fe7ddf3dfe0 100644
--- a/src/components/script/dom/bindings/htmlcollection.rs
+++ b/src/components/script/dom/bindings/htmlcollection.rs
@@ -9,8 +9,10 @@ use script_task::{task_from_context, global_script_context};
use js::jsapi::{JSObject, JSContext};
-pub impl HTMLCollection {
- fn init_wrapper(@mut self) {
+use std::cast;
+
+impl HTMLCollection {
+ pub fn init_wrapper(@mut self) {
let script_context = global_script_context();
let cx = script_context.js_compartment.cx.ptr;
let owner = script_context.root_frame.get_ref().window;
diff --git a/src/components/script/dom/bindings/node.rs b/src/components/script/dom/bindings/node.rs
index 36e1984d0ca..49a857405a9 100644
--- a/src/components/script/dom/bindings/node.rs
+++ b/src/components/script/dom/bindings/node.rs
@@ -9,9 +9,12 @@ use dom::bindings::utils::{CacheableWrapper, WrapperCache, DerivedWrapper};
use dom::node::{AbstractNode, Node, ElementNodeTypeId, TextNodeTypeId, CommentNodeTypeId};
use dom::node::{DoctypeNodeTypeId, ScriptView};
-use core::libc::c_uint;
-use core::ptr::null;
-use js::jsapi::bindgen::*;
+use std::cast;
+use std::libc::c_uint;
+use std::ptr;
+use std::ptr::null;
+use std::vec;
+use js::jsapi::*;
use js::jsapi::{JSContext, JSVal, JSObject, JSBool, JSPropertySpec};
use js::jsapi::{JSPropertyOpWrapper, JSStrictPropertyOpWrapper};
use js::jsval::{INT_TO_JSVAL};
@@ -53,7 +56,9 @@ pub fn init(compartment: @mut Compartment) {
setter: JSStrictPropertyOpWrapper {op: null(), info: null()}}];
vec::push(&mut compartment.global_props, attrs);
vec::as_imm_buf(*attrs, |specs, _len| {
- JS_DefineProperties(compartment.cx.ptr, obj.ptr, specs);
+ unsafe {
+ JS_DefineProperties(compartment.cx.ptr, obj.ptr, specs);
+ }
});
}
diff --git a/src/components/script/dom/bindings/proxyhandler.rs b/src/components/script/dom/bindings/proxyhandler.rs
index f073f54d8c1..2780a969eb2 100644
--- a/src/components/script/dom/bindings/proxyhandler.rs
+++ b/src/components/script/dom/bindings/proxyhandler.rs
@@ -3,11 +3,15 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use js::jsapi::{JSContext, jsid, JSPropertyDescriptor, JSObject, JSString, jschar};
-use js::jsapi::bindgen::{JS_GetPropertyDescriptorById, JS_NewUCString, JS_malloc, JS_free};
-use js::glue::bindgen::{RUST_JSVAL_IS_VOID, RUST_JSVAL_TO_OBJECT, GetProxyExtra};
-use js::glue::bindgen::{GetObjectProto};
+use js::jsapi::{JS_GetPropertyDescriptorById, JS_NewUCString, JS_malloc, JS_free};
+use js::glue::{RUST_JSVAL_IS_VOID, RUST_JSVAL_TO_OBJECT, GetProxyExtra};
+use js::glue::{GetObjectProto};
-use core::sys::size_of;
+use std::cast;
+use std::libc;
+use std::ptr;
+use std::str;
+use std::sys::size_of;
type c_bool = libc::c_int;
@@ -68,7 +72,7 @@ pub fn _obj_toString(cx: *JSContext, className: *libc::c_char) -> *JSString {
}
let result = ~"[object " + name + ~"]";
- for result.each_chari |i, c| {
+ for result.iter().enumerate().advance |(i, c)| {
*chars.offset(i) = c as jschar;
}
*chars.offset(nchars) = 0;
diff --git a/src/components/script/dom/bindings/text.rs b/src/components/script/dom/bindings/text.rs
index 5067896a6e2..2ec4a6a69df 100644
--- a/src/components/script/dom/bindings/text.rs
+++ b/src/components/script/dom/bindings/text.rs
@@ -10,10 +10,14 @@ use dom::node::{AbstractNode, Text, Comment, Doctype, TextNodeTypeId, CommentNod
use dom::node::{DoctypeNodeTypeId, ScriptView};
use js::jsapi::{JSFreeOp, JSObject, JSContext};
-use js::jsapi::bindgen::{JS_SetReservedSlot};
-use js::glue::bindgen::{RUST_PRIVATE_TO_JSVAL};
+use js::jsapi::{JS_SetReservedSlot};
+use js::glue::{RUST_PRIVATE_TO_JSVAL};
use js::rust::{Compartment, jsobj};
+use std::cast;
+use std::libc;
+use std::result;
+
extern fn finalize_text(_fop: *JSFreeOp, obj: *JSObject) {
debug!("text finalize: %?!", obj as uint);
unsafe {
@@ -83,8 +87,10 @@ pub fn create(cx: *JSContext, node: &mut AbstractNode<ScriptView>) -> jsobj {
assert!(cache.get_wrapper().is_null());
cache.set_wrapper(obj.ptr);
- let raw_ptr = node.raw_object() as *libc::c_void;
- JS_SetReservedSlot(obj.ptr, DOM_OBJECT_SLOT as u32, RUST_PRIVATE_TO_JSVAL(raw_ptr));
+ unsafe {
+ let raw_ptr = node.raw_object() as *libc::c_void;
+ JS_SetReservedSlot(obj.ptr, DOM_OBJECT_SLOT as u32, RUST_PRIVATE_TO_JSVAL(raw_ptr));
+ }
return obj;
}
diff --git a/src/components/script/dom/bindings/utils.rs b/src/components/script/dom/bindings/utils.rs
index 206cc4224ba..9d3105fefca 100644
--- a/src/components/script/dom/bindings/utils.rs
+++ b/src/components/script/dom/bindings/utils.rs
@@ -6,20 +6,26 @@ use dom::bindings::node;
use dom::node::{AbstractNode, ScriptView};
use script_task::task_from_context;
-use core::cast;
-use core::hashmap::HashMap;
-use core::ptr::{null, to_unsafe_ptr};
-use js::glue::bindgen::*;
-use js::glue::bindgen::{DefineFunctionWithReserved, GetObjectJSClass, RUST_OBJECT_TO_JSVAL};
+use std::cast;
+use std::hashmap::HashMap;
+use std::libc;
+use std::ptr;
+use std::ptr::{null, to_unsafe_ptr};
+use std::result;
+use std::str;
+use std::sys;
+use std::uint;
+use js::glue::*;
+use js::glue::{DefineFunctionWithReserved, GetObjectJSClass, RUST_OBJECT_TO_JSVAL};
use js::glue::{PROPERTY_STUB, STRICT_PROPERTY_STUB, ENUMERATE_STUB, CONVERT_STUB, RESOLVE_STUB};
-use js::jsapi::bindgen::{JS_AlreadyHasOwnProperty, JS_NewObject, JS_NewFunction};
-use js::jsapi::bindgen::{JS_DefineProperties, JS_WrapValue, JS_ForwardGetPropertyTo};
-use js::jsapi::bindgen::{JS_EncodeString, JS_free, JS_GetStringCharsAndLength};
-use js::jsapi::bindgen::{JS_GetClass, JS_GetPrototype, JS_LinkConstructorAndPrototype};
-use js::jsapi::bindgen::{JS_GetFunctionPrototype, JS_InternString, JS_GetFunctionObject};
-use js::jsapi::bindgen::{JS_HasPropertyById, JS_GetPrototype, JS_GetGlobalForObject};
-use js::jsapi::bindgen::{JS_NewStringCopyN, JS_DefineFunctions, JS_DefineProperty};
-use js::jsapi::bindgen::{JS_ValueToString, JS_GetReservedSlot, JS_SetReservedSlot};
+use js::jsapi::{JS_AlreadyHasOwnProperty, JS_NewObject, JS_NewFunction};
+use js::jsapi::{JS_DefineProperties, JS_WrapValue, JS_ForwardGetPropertyTo};
+use js::jsapi::{JS_EncodeString, JS_free, JS_GetStringCharsAndLength};
+use js::jsapi::{JS_GetClass, JS_GetPrototype, JS_LinkConstructorAndPrototype};
+use js::jsapi::{JS_GetFunctionPrototype, JS_InternString, JS_GetFunctionObject};
+use js::jsapi::{JS_HasPropertyById, JS_GetPrototype, JS_GetGlobalForObject};
+use js::jsapi::{JS_NewStringCopyN, JS_DefineFunctions, JS_DefineProperty};
+use js::jsapi::{JS_ValueToString, JS_GetReservedSlot, JS_SetReservedSlot};
use js::jsapi::{JSContext, JSVal, JSObject, JSBool, jsid, JSClass, JSNative};
use js::jsapi::{JSFunctionSpec, JSPropertySpec, JSVal, JSPropertyDescriptor};
use js::jsfriendapi::bindgen::JS_NewObjectWithUniqueType;
@@ -88,8 +94,8 @@ pub enum DOMString {
null_string
}
-pub impl DOMString {
- fn to_str(&self) -> ~str {
+impl DOMString {
+ pub fn to_str(&self) -> ~str {
match *self {
str(ref s) => s.clone(),
null_string => ~""
@@ -129,17 +135,17 @@ pub unsafe fn squirrel_away<T>(x: @mut T) -> *rust_box<T> {
//XXX very incomplete
pub fn jsval_to_str(cx: *JSContext, v: JSVal) -> Result<~str, ()> {
- let jsstr;
- if RUST_JSVAL_IS_STRING(v) == 1 {
- jsstr = RUST_JSVAL_TO_STRING(v)
- } else {
- jsstr = JS_ValueToString(cx, v);
- if jsstr.is_null() {
- return Err(());
+ unsafe {
+ let jsstr;
+ if RUST_JSVAL_IS_STRING(v) == 1 {
+ jsstr = RUST_JSVAL_TO_STRING(v)
+ } else {
+ jsstr = JS_ValueToString(cx, v);
+ if jsstr.is_null() {
+ return Err(());
+ }
}
- }
- unsafe {
let strbuf = JS_EncodeString(cx, jsstr);
let buf = str::raw::from_buf(strbuf as *u8);
JS_free(cx, strbuf as *libc::c_void);
@@ -172,45 +178,49 @@ pub fn get_compartment(cx: *JSContext) -> @mut Compartment {
extern fn has_instance(_cx: *JSContext, obj: **JSObject, v: *JSVal, bp: *mut JSBool) -> JSBool {
//XXXjdm this is totally broken for non-object values
- let mut o = RUST_JSVAL_TO_OBJECT(unsafe {*v});
- let obj = unsafe {*obj};
- unsafe { *bp = 0; }
- while o.is_not_null() {
- if o == obj {
- unsafe { *bp = 1; }
- break;
+ unsafe {
+ let mut o = RUST_JSVAL_TO_OBJECT(unsafe {*v});
+ let obj = unsafe {*obj};
+ unsafe { *bp = 0; }
+ while o.is_not_null() {
+ if o == obj {
+ unsafe { *bp = 1; }
+ break;
+ }
+ o = JS_GetPrototype(o);
}
- o = JS_GetPrototype(o);
+ return 1;
}
- return 1;
}
pub fn prototype_jsclass(name: ~str) -> @fn(compartment: @mut Compartment) -> JSClass {
let f: @fn(@mut Compartment) -> JSClass = |compartment: @mut Compartment| {
- JSClass {
- name: compartment.add_name(copy name),
- flags: 0,
- addProperty: GetJSClassHookStubPointer(PROPERTY_STUB) as *u8,
- delProperty: GetJSClassHookStubPointer(PROPERTY_STUB) as *u8,
- getProperty: GetJSClassHookStubPointer(PROPERTY_STUB) as *u8,
- setProperty: GetJSClassHookStubPointer(STRICT_PROPERTY_STUB) as *u8,
- enumerate: GetJSClassHookStubPointer(ENUMERATE_STUB) as *u8,
- resolve: GetJSClassHookStubPointer(RESOLVE_STUB) as *u8,
- convert: GetJSClassHookStubPointer(CONVERT_STUB) as *u8,
- finalize: null(),
- checkAccess: null(),
- call: null(),
- hasInstance: has_instance,
- construct: null(),
- trace: 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
+ unsafe {
+ JSClass {
+ name: compartment.add_name(copy name),
+ flags: 0,
+ addProperty: GetJSClassHookStubPointer(PROPERTY_STUB) as *u8,
+ delProperty: GetJSClassHookStubPointer(PROPERTY_STUB) as *u8,
+ getProperty: GetJSClassHookStubPointer(PROPERTY_STUB) as *u8,
+ setProperty: GetJSClassHookStubPointer(STRICT_PROPERTY_STUB) as *u8,
+ enumerate: GetJSClassHookStubPointer(ENUMERATE_STUB) as *u8,
+ resolve: GetJSClassHookStubPointer(RESOLVE_STUB) as *u8,
+ convert: GetJSClassHookStubPointer(CONVERT_STUB) as *u8,
+ finalize: null(),
+ checkAccess: null(),
+ call: null(),
+ hasInstance: has_instance,
+ construct: null(),
+ trace: 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
+ }
}
};
return f;
@@ -219,30 +229,32 @@ pub fn prototype_jsclass(name: ~str) -> @fn(compartment: @mut Compartment) -> JS
pub fn instance_jsclass(name: ~str, finalize: *u8, trace: *u8)
-> @fn(compartment: @mut Compartment) -> JSClass {
let f: @fn(@mut Compartment) -> JSClass = |compartment: @mut Compartment| {
- JSClass {
- name: compartment.add_name(copy name),
- flags: JSCLASS_HAS_RESERVED_SLOTS(1) | js::JSCLASS_IS_DOMJSCLASS,
- addProperty: GetJSClassHookStubPointer(PROPERTY_STUB) as *u8,
- delProperty: GetJSClassHookStubPointer(PROPERTY_STUB) as *u8,
- getProperty: GetJSClassHookStubPointer(PROPERTY_STUB) as *u8,
- setProperty: GetJSClassHookStubPointer(STRICT_PROPERTY_STUB) as *u8,
- enumerate: GetJSClassHookStubPointer(ENUMERATE_STUB) as *u8,
- resolve: GetJSClassHookStubPointer(RESOLVE_STUB) as *u8,
- convert: GetJSClassHookStubPointer(CONVERT_STUB) as *u8,
- finalize: finalize,
- checkAccess: null(),
- call: null(),
- hasInstance: has_instance,
- construct: null(),
- trace: trace,
- 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
+ unsafe {
+ JSClass {
+ name: compartment.add_name(copy name),
+ flags: JSCLASS_HAS_RESERVED_SLOTS(1) | js::JSCLASS_IS_DOMJSCLASS,
+ addProperty: GetJSClassHookStubPointer(PROPERTY_STUB) as *u8,
+ delProperty: GetJSClassHookStubPointer(PROPERTY_STUB) as *u8,
+ getProperty: GetJSClassHookStubPointer(PROPERTY_STUB) as *u8,
+ setProperty: GetJSClassHookStubPointer(STRICT_PROPERTY_STUB) as *u8,
+ enumerate: GetJSClassHookStubPointer(ENUMERATE_STUB) as *u8,
+ resolve: GetJSClassHookStubPointer(RESOLVE_STUB) as *u8,
+ convert: GetJSClassHookStubPointer(CONVERT_STUB) as *u8,
+ finalize: finalize,
+ checkAccess: null(),
+ call: null(),
+ hasInstance: has_instance,
+ construct: null(),
+ trace: trace,
+ 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
+ }
}
};
return f;
@@ -262,12 +274,14 @@ pub fn define_empty_prototype(name: ~str, proto: Option<~str>, compartment: @mut
None => compartment.new_object(copy name, null(), compartment.global_obj.ptr)
});
- compartment.define_property(copy name, RUST_OBJECT_TO_JSVAL(obj.ptr),
- GetJSClassHookStubPointer(PROPERTY_STUB) as *u8,
- GetJSClassHookStubPointer(STRICT_PROPERTY_STUB) as *u8,
- JSPROP_ENUMERATE);
- compartment.stash_global_proto(name, obj);
- return obj;
+ unsafe {
+ compartment.define_property(copy name, RUST_OBJECT_TO_JSVAL(obj.ptr),
+ GetJSClassHookStubPointer(PROPERTY_STUB) as *u8,
+ GetJSClassHookStubPointer(STRICT_PROPERTY_STUB) as *u8,
+ JSPROP_ENUMERATE);
+ compartment.stash_global_proto(name, obj);
+ return obj;
+ }
}
// We use slot 0 for holding the raw object. This is safe for both
@@ -390,8 +404,10 @@ pub fn CreateInterfaceObjects2(cx: *JSContext, global: *JSObject, receiver: *JSO
return ptr::null();
}
- JS_SetReservedSlot(proto, DOM_PROTO_INSTANCE_CLASS_SLOT,
- RUST_PRIVATE_TO_JSVAL(domClass as *libc::c_void));
+ unsafe {
+ JS_SetReservedSlot(proto, DOM_PROTO_INSTANCE_CLASS_SLOT,
+ RUST_PRIVATE_TO_JSVAL(domClass as *libc::c_void));
+ }
}
let mut interface = ptr::null();
@@ -419,75 +435,77 @@ fn CreateInterfaceObject(cx: *JSContext, global: *JSObject, receiver: *JSObject,
staticMethods: *JSFunctionSpec,
constants: *ConstantSpec,
name: *libc::c_char) -> *JSObject {
- let constructor = if constructorClass.is_not_null() {
- let functionProto = JS_GetFunctionPrototype(cx, global);
- if functionProto.is_null() {
- ptr::null()
+ unsafe {
+ let constructor = if constructorClass.is_not_null() {
+ let functionProto = JS_GetFunctionPrototype(cx, global);
+ if functionProto.is_null() {
+ ptr::null()
+ } else {
+ JS_NewObject(cx, constructorClass, functionProto, global)
+ }
} else {
- JS_NewObject(cx, constructorClass, functionProto, global)
+ assert!(constructorNative.is_not_null());
+ let fun = JS_NewFunction(cx, constructorNative, ctorNargs,
+ JSFUN_CONSTRUCTOR, global, name);
+ if fun.is_null() {
+ ptr::null()
+ } else {
+ JS_GetFunctionObject(fun)
+ }
+ };
+
+ if constructor.is_null() {
+ return ptr::null();
}
- } else {
- assert!(constructorNative.is_not_null());
- let fun = JS_NewFunction(cx, constructorNative, ctorNargs,
- JSFUN_CONSTRUCTOR, global, name);
- if fun.is_null() {
- ptr::null()
- } else {
- JS_GetFunctionObject(fun)
+
+ if staticMethods.is_not_null() &&
+ !DefineMethods(cx, constructor, staticMethods) {
+ return ptr::null();
}
- };
- if constructor.is_null() {
- return ptr::null();
- }
+ if constructorClass.is_not_null() {
+ let toString = do str::as_c_str("toString") |s| {
+ DefineFunctionWithReserved(cx, constructor, s,
+ InterfaceObjectToString,
+ 0, 0)
+ };
+ if toString.is_null() {
+ return ptr::null();
+ }
- if staticMethods.is_not_null() &&
- !DefineMethods(cx, constructor, staticMethods) {
- return ptr::null();
- }
+ let toStringObj = JS_GetFunctionObject(toString);
+ SetFunctionNativeReserved(toStringObj, TOSTRING_CLASS_RESERVED_SLOT,
+ &RUST_PRIVATE_TO_JSVAL(constructorClass as *libc::c_void));
+ let s = JS_InternString(cx, name);
+ if s.is_null() {
+ return ptr::null();
+ }
+ SetFunctionNativeReserved(toStringObj, TOSTRING_NAME_RESERVED_SLOT,
+ &RUST_STRING_TO_JSVAL(s));
+ }
- if constructorClass.is_not_null() {
- let toString = do str::as_c_str("toString") |s| {
- DefineFunctionWithReserved(cx, constructor, s,
- InterfaceObjectToString,
- 0, 0)
- };
- if toString.is_null() {
+ if constants.is_not_null() &&
+ !DefineConstants(cx, constructor, constants) {
return ptr::null();
}
- let toStringObj = JS_GetFunctionObject(toString);
- SetFunctionNativeReserved(toStringObj, TOSTRING_CLASS_RESERVED_SLOT,
- &RUST_PRIVATE_TO_JSVAL(constructorClass as *libc::c_void));
- let s = JS_InternString(cx, name);
- if s.is_null() {
+ if proto.is_not_null() && JS_LinkConstructorAndPrototype(cx, constructor, proto) == 0 {
return ptr::null();
}
- SetFunctionNativeReserved(toStringObj, TOSTRING_NAME_RESERVED_SLOT,
- &RUST_STRING_TO_JSVAL(s));
- }
-
- if constants.is_not_null() &&
- !DefineConstants(cx, constructor, constants) {
- return ptr::null();
- }
- if proto.is_not_null() && JS_LinkConstructorAndPrototype(cx, constructor, proto) == 0 {
- return ptr::null();
- }
+ let alreadyDefined = 0;
+ if JS_AlreadyHasOwnProperty(cx, receiver, name, &alreadyDefined) == 0 {
+ return ptr::null();
+ }
- let alreadyDefined = 0;
- if JS_AlreadyHasOwnProperty(cx, receiver, name, &alreadyDefined) == 0 {
- return ptr::null();
- }
+ if alreadyDefined == 0 &&
+ JS_DefineProperty(cx, receiver, name, RUST_OBJECT_TO_JSVAL(constructor),
+ ptr::null(), ptr::null(), 0) == 0 {
+ return ptr::null();
+ }
- if alreadyDefined == 0 &&
- JS_DefineProperty(cx, receiver, name, RUST_OBJECT_TO_JSVAL(constructor),
- ptr::null(), ptr::null(), 0) == 0 {
- return ptr::null();
+ return constructor;
}
-
- return constructor;
}
fn DefineConstants(cx: *JSContext, obj: *JSObject, constants: *ConstantSpec) -> bool {
@@ -520,11 +538,15 @@ fn DefineConstants(cx: *JSContext, obj: *JSObject, constants: *ConstantSpec) ->
}
fn DefineMethods(cx: *JSContext, obj: *JSObject, methods: *JSFunctionSpec) -> bool {
- JS_DefineFunctions(cx, obj, methods) != 0
+ unsafe {
+ JS_DefineFunctions(cx, obj, methods) != 0
+ }
}
fn DefineProperties(cx: *JSContext, obj: *JSObject, properties: *JSPropertySpec) -> bool {
- JS_DefineProperties(cx, obj, properties) != 0
+ unsafe {
+ JS_DefineProperties(cx, obj, properties) != 0
+ }
}
fn CreateInterfacePrototypeObject(cx: *JSContext, global: *JSObject,
@@ -532,24 +554,26 @@ fn CreateInterfacePrototypeObject(cx: *JSContext, global: *JSObject,
methods: *JSFunctionSpec,
properties: *JSPropertySpec,
constants: *ConstantSpec) -> *JSObject {
- let ourProto = JS_NewObjectWithUniqueType(cx, protoClass, parentProto, global);
- if ourProto.is_null() {
- return ptr::null();
- }
+ unsafe {
+ let ourProto = JS_NewObjectWithUniqueType(cx, protoClass, parentProto, global);
+ if ourProto.is_null() {
+ return ptr::null();
+ }
- if methods.is_not_null() && !DefineMethods(cx, ourProto, methods) {
- return ptr::null();
- }
+ if methods.is_not_null() && !DefineMethods(cx, ourProto, methods) {
+ return ptr::null();
+ }
- if properties.is_not_null() && !DefineProperties(cx, ourProto, properties) {
- return ptr::null();
- }
+ if properties.is_not_null() && !DefineProperties(cx, ourProto, properties) {
+ return ptr::null();
+ }
- if constants.is_not_null() && !DefineConstants(cx, ourProto, constants) {
- return ptr::null();
- }
+ if constants.is_not_null() && !DefineConstants(cx, ourProto, constants) {
+ return ptr::null();
+ }
- return ourProto;
+ return ourProto;
+ }
}
pub extern fn ThrowingConstructor(_cx: *JSContext, _argc: uint, _vp: *JSVal) -> JSBool {
@@ -578,20 +602,20 @@ pub struct WrapperCache {
wrapper: *JSObject
}
-pub impl WrapperCache {
- fn get_wrapper(&self) -> *JSObject {
+impl WrapperCache {
+ pub fn get_wrapper(&self) -> *JSObject {
unsafe { cast::transmute(self.wrapper) }
}
- fn set_wrapper(&mut self, wrapper: *JSObject) {
+ pub fn set_wrapper(&mut self, wrapper: *JSObject) {
self.wrapper = wrapper;
}
- fn get_rootable(&self) -> **JSObject {
+ pub fn get_rootable(&self) -> **JSObject {
return to_unsafe_ptr(&self.wrapper);
}
- fn new() -> WrapperCache {
+ pub fn new() -> WrapperCache {
WrapperCache {
wrapper: ptr::null()
}
@@ -660,10 +684,12 @@ pub fn GetPropertyOnPrototype(cx: *JSContext, proxy: *JSObject, id: jsid, found:
}
pub fn GetArrayIndexFromId(_cx: *JSContext, id: jsid) -> Option<u32> {
- if RUST_JSID_IS_INT(id) != 0 {
- return Some(RUST_JSID_TO_INT(id) as u32);
+ unsafe {
+ if RUST_JSID_IS_INT(id) != 0 {
+ return Some(RUST_JSID_TO_INT(id) as u32);
+ }
+ return None;
}
- return None;
// if id is length atom, -1, otherwise
/*return if JSID_IS_ATOM(id) {
let atom = JSID_TO_ATOM(id);
@@ -730,11 +756,13 @@ pub fn XrayResolveProperty(cx: *JSContext,
}
fn InternJSString(cx: *JSContext, chars: *libc::c_char) -> Option<jsid> {
- let s = JS_InternString(cx, chars);
- if s.is_not_null() {
- Some(RUST_INTERNED_STRING_TO_JSID(cx, s))
- } else {
- None
+ unsafe {
+ let s = JS_InternString(cx, chars);
+ if s.is_not_null() {
+ Some(RUST_INTERNED_STRING_TO_JSID(cx, s))
+ } else {
+ None
+ }
}
}
diff --git a/src/components/script/dom/bindings/window.rs b/src/components/script/dom/bindings/window.rs
index 27d55ff1475..6bcb8466cde 100644
--- a/src/components/script/dom/bindings/window.rs
+++ b/src/components/script/dom/bindings/window.rs
@@ -9,16 +9,19 @@ use dom::bindings::utils::{WrapperCache};
use dom::window::Window;
use super::utils;
-use core::libc::c_uint;
-use core::ptr::null;
-use core::ptr;
+use std::cast;
+use std::libc;
+use std::libc::c_uint;
+use std::ptr::null;
+use std::ptr;
+use std::result;
use js::crust::{JS_PropertyStub, JS_StrictPropertyStub};
use js::global::jsval_to_rust_str;
-use js::glue::bindgen::*;
-use js::glue::bindgen::RUST_JSVAL_TO_INT;
-use js::jsapi::bindgen::{JS_DefineFunctions, JS_GC, JS_GetRuntime};
-use js::jsapi::bindgen::{JS_GetReservedSlot, JS_SetReservedSlot};
-use js::jsapi::bindgen::{JS_ValueToString};
+use js::glue::*;
+use js::glue::RUST_JSVAL_TO_INT;
+use js::jsapi::{JS_DefineFunctions, JS_GC, JS_GetRuntime};
+use js::jsapi::{JS_GetReservedSlot, JS_SetReservedSlot};
+use js::jsapi::{JS_ValueToString};
use js::jsapi::{JSContext, JSVal, JSObject, JSBool, JSFreeOp, JSFunctionSpec};
use js::jsapi::{JSNativeWrapper};
use js::rust::Compartment;
@@ -67,9 +70,11 @@ extern fn close(cx: *JSContext, _argc: c_uint, vp: *JSVal) -> JSBool {
}
extern fn gc(cx: *JSContext, _argc: c_uint, _vp: *JSVal) -> JSBool {
- let runtime = JS_GetRuntime(cx);
- JS_GC(runtime);
- return 1;
+ unsafe {
+ let runtime = JS_GetRuntime(cx);
+ JS_GC(runtime);
+ return 1;
+ }
}
unsafe fn unwrap(obj: *JSObject) -> *rust_box<Window> {
@@ -128,7 +133,9 @@ pub fn init(compartment: @mut Compartment) {
}
];
- JS_DefineFunctions(compartment.cx.ptr, proto.ptr, &methods[0]);
+ unsafe {
+ JS_DefineFunctions(compartment.cx.ptr, proto.ptr, &methods[0]);
+ }
}
pub fn create(compartment: @mut Compartment, win: @mut Window) {
@@ -141,13 +148,13 @@ pub fn create(compartment: @mut Compartment, win: @mut Window) {
unsafe {
let raw_ptr: *libc::c_void = cast::transmute(squirrel_away(win));
JS_SetReservedSlot(obj.ptr, 0, RUST_PRIVATE_TO_JSVAL(raw_ptr));
- }
- //TODO: All properties/methods on Window need to be available on the global
- // object as well. We probably want a special JSClass with a resolve hook.
- compartment.define_property(~"window", RUST_OBJECT_TO_JSVAL(obj.ptr),
- JS_PropertyStub, JS_StrictPropertyStub,
- JSPROP_ENUMERATE);
+ //TODO: All properties/methods on Window need to be available on the global
+ // object as well. We probably want a special JSClass with a resolve hook.
+ compartment.define_property(~"window", RUST_OBJECT_TO_JSVAL(obj.ptr),
+ JS_PropertyStub, JS_StrictPropertyStub,
+ JSPROP_ENUMERATE);
+ }
}
impl CacheableWrapper for Window {
diff --git a/src/components/script/dom/characterdata.rs b/src/components/script/dom/characterdata.rs
index 4108868d8d4..91838432f6b 100644
--- a/src/components/script/dom/characterdata.rs
+++ b/src/components/script/dom/characterdata.rs
@@ -7,7 +7,7 @@
use dom::bindings::utils::{DOMString, null_string, str};
use dom::node::{Node, NodeTypeId, ScriptView};
-use core::str;
+use std::str;
pub struct CharacterData {
parent: Node<ScriptView>,
@@ -46,7 +46,7 @@ impl CharacterData {
pub fn AppendData(&mut self, arg: DOMString) {
let s = self.data.to_str();
- self.data = str(str::append(s, arg.to_str()));
+ self.data = str(s.append(arg.to_str()));
}
pub fn InsertData(&mut self, _offset: u32, _arg: DOMString) {
diff --git a/src/components/script/dom/clientrect.rs b/src/components/script/dom/clientrect.rs
index 3c9f6f9dca9..ccddcff788f 100644
--- a/src/components/script/dom/clientrect.rs
+++ b/src/components/script/dom/clientrect.rs
@@ -4,6 +4,8 @@
use dom::bindings::utils::WrapperCache;
+use std::f32;
+
pub struct ClientRect {
wrapper: WrapperCache,
top: f32,
diff --git a/src/components/script/dom/clientrectlist.rs b/src/components/script/dom/clientrectlist.rs
index ff48e6623be..6165f13e6e3 100644
--- a/src/components/script/dom/clientrectlist.rs
+++ b/src/components/script/dom/clientrectlist.rs
@@ -10,8 +10,8 @@ pub struct ClientRectList {
rects: ~[@mut ClientRect]
}
-pub impl ClientRectList {
- fn new(rects: ~[@mut ClientRect]) -> @mut ClientRectList {
+impl ClientRectList {
+ pub fn new(rects: ~[@mut ClientRect]) -> @mut ClientRectList {
let list = @mut ClientRectList {
wrapper: WrapperCache::new(),
rects: rects
@@ -20,11 +20,11 @@ pub impl ClientRectList {
list
}
- fn Length(&self) -> u32 {
+ pub fn Length(&self) -> u32 {
self.rects.len() as u32
}
- fn Item(&self, index: u32) -> Option<@mut ClientRect> {
+ pub fn Item(&self, index: u32) -> Option<@mut ClientRect> {
if index < self.rects.len() as u32 {
Some(self.rects[index])
} else {
@@ -32,7 +32,7 @@ pub impl ClientRectList {
}
}
- fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option<@mut ClientRect> {
+ pub fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option<@mut ClientRect> {
*found = index < self.rects.len() as u32;
self.Item(index)
}
diff --git a/src/components/script/dom/document.rs b/src/components/script/dom/document.rs
index ba52025362f..2a0afc0010e 100644
--- a/src/components/script/dom/document.rs
+++ b/src/components/script/dom/document.rs
@@ -9,7 +9,7 @@ use dom::node::{AbstractNode, ScriptView};
use dom::window::Window;
use script_task::global_script_context;
-use js::jsapi::bindgen::{JS_AddObjectRoot, JS_RemoveObjectRoot};
+use js::jsapi::{JS_AddObjectRoot, JS_RemoveObjectRoot};
use servo_util::tree::{TreeNodeRef, TreeUtils};
pub struct Document {
@@ -19,23 +19,25 @@ pub struct Document {
}
pub fn Document(root: AbstractNode<ScriptView>, window: Option<@mut Window>) -> @mut Document {
- let doc = @mut Document {
- root: root,
- wrapper: WrapperCache::new(),
- window: window
- };
- let compartment = global_script_context().js_compartment;
- do root.with_base |base| {
- assert!(base.wrapper.get_wrapper().is_not_null());
- let rootable = base.wrapper.get_rootable();
- JS_AddObjectRoot(compartment.cx.ptr, rootable);
+ unsafe {
+ let doc = @mut Document {
+ root: root,
+ wrapper: WrapperCache::new(),
+ window: window
+ };
+ let compartment = global_script_context().js_compartment;
+ do root.with_base |base| {
+ assert!(base.wrapper.get_wrapper().is_not_null());
+ let rootable = base.wrapper.get_rootable();
+ JS_AddObjectRoot(compartment.cx.ptr, rootable);
+ }
+ document::create(compartment, doc);
+ doc
}
- document::create(compartment, doc);
- doc
}
-pub impl Document {
- fn getElementsByTagName(&self, tag: DOMString) -> Option<@mut HTMLCollection> {
+impl Document {
+ pub fn getElementsByTagName(&self, tag: DOMString) -> Option<@mut HTMLCollection> {
let mut elements = ~[];
let tag = tag.to_str();
let _ = for self.root.traverse_preorder |child| {
@@ -50,18 +52,20 @@ pub impl Document {
Some(HTMLCollection::new(elements))
}
- fn content_changed(&self) {
- for self.window.each |window| {
+ pub fn content_changed(&self) {
+ for self.window.iter().advance |window| {
window.content_changed()
}
}
- fn teardown(&self) {
- let compartment = global_script_context().js_compartment;
- do self.root.with_base |node| {
- assert!(node.wrapper.get_wrapper().is_not_null());
- let rootable = node.wrapper.get_rootable();
- JS_RemoveObjectRoot(compartment.cx.ptr, rootable);
+ pub fn teardown(&self) {
+ unsafe {
+ let compartment = global_script_context().js_compartment;
+ do self.root.with_base |node| {
+ assert!(node.wrapper.get_wrapper().is_not_null());
+ let rootable = node.wrapper.get_rootable();
+ JS_RemoveObjectRoot(compartment.cx.ptr, rootable);
+ }
}
}
}
diff --git a/src/components/script/dom/element.rs b/src/components/script/dom/element.rs
index 742fdb46682..e707a95ebb9 100644
--- a/src/components/script/dom/element.rs
+++ b/src/components/script/dom/element.rs
@@ -11,9 +11,10 @@ use dom::node::{ElementNodeTypeId, Node, ScriptView};
use layout_interface::{ContentBoxQuery, ContentBoxResponse, ContentBoxesQuery};
use layout_interface::{ContentBoxesResponse};
-use core::cell::Cell;
-use core::str::eq_slice;
-use std::net::url::Url;
+use std::cell::Cell;
+use std::uint;
+use std::str::eq_slice;
+use extra::net::url::Url;
pub struct Element {
parent: Node<ScriptView>,
@@ -114,7 +115,7 @@ pub struct HTMLImageElement {
// Element methods
//
-pub impl<'self> Element {
+impl<'self> Element {
pub fn new(type_id: ElementTypeId, tag_name: ~str) -> Element {
Element {
parent: Node::new(ElementNodeTypeId(type_id)),
@@ -123,7 +124,7 @@ pub impl<'self> Element {
}
}
- fn get_attr(&'self self, name: &str) -> Option<&'self str> {
+ pub fn get_attr(&'self self, name: &str) -> Option<&'self str> {
// FIXME: Need an each() that links lifetimes in Rust.
for uint::range(0, self.attrs.len()) |i| {
if eq_slice(self.attrs[i].name, name) {
@@ -134,11 +135,11 @@ pub impl<'self> Element {
return None;
}
- fn set_attr(&mut self, name: &DOMString, value: &DOMString) {
+ pub fn set_attr(&mut self, name: &DOMString, value: &DOMString) {
let name = name.to_str();
let value = value.to_str();
// FIXME: We need a better each_mut in Rust; this is ugly.
- let value_cell = Cell(value);
+ let value_cell = Cell::new(value);
let mut found = false;
for uint::range(0, self.attrs.len()) |i| {
if eq_slice(self.attrs[i].name, name) {
@@ -157,7 +158,7 @@ pub impl<'self> Element {
}
}
- fn getClientRects(&self) -> Option<@mut ClientRectList> {
+ pub fn getClientRects(&self) -> Option<@mut ClientRectList> {
let rects = match self.parent.owner_doc {
Some(doc) => {
match doc.window {
@@ -199,7 +200,7 @@ pub impl<'self> Element {
Some(ClientRectList::new(rects))
}
- fn getBoundingClientRect(&self) -> Option<@mut ClientRect> {
+ pub fn getBoundingClientRect(&self) -> Option<@mut ClientRect> {
match self.parent.owner_doc {
Some(doc) => {
match doc.window {
diff --git a/src/components/script/dom/event.rs b/src/components/script/dom/event.rs
index 6b4be15b701..047b734e6b4 100644
--- a/src/components/script/dom/event.rs
+++ b/src/components/script/dom/event.rs
@@ -9,6 +9,8 @@ use dom::bindings::utils::{DOMString, ErrorResult, WrapperCache};
use geom::point::Point2D;
+use std::comm;
+
pub enum Event {
ResizeEvent(uint, uint),
ReflowEvent,
diff --git a/src/components/script/dom/eventtarget.rs b/src/components/script/dom/eventtarget.rs
index b216b7d0cca..e4066ccb8d4 100644
--- a/src/components/script/dom/eventtarget.rs
+++ b/src/components/script/dom/eventtarget.rs
@@ -8,8 +8,8 @@ pub struct EventTarget {
wrapper: WrapperCache
}
-pub impl EventTarget {
- fn new() -> ~EventTarget {
+impl EventTarget {
+ pub fn new() -> ~EventTarget {
~EventTarget {
wrapper: WrapperCache::new()
}
diff --git a/src/components/script/dom/htmlcollection.rs b/src/components/script/dom/htmlcollection.rs
index 762504a7002..403469061b8 100644
--- a/src/components/script/dom/htmlcollection.rs
+++ b/src/components/script/dom/htmlcollection.rs
@@ -8,13 +8,15 @@ use dom::node::{AbstractNode, ScriptView};
use js::jsapi::{JSObject, JSContext};
+use std::ptr;
+
pub struct HTMLCollection {
elements: ~[AbstractNode<ScriptView>],
wrapper: WrapperCache
}
-pub impl HTMLCollection {
- fn new(elements: ~[AbstractNode<ScriptView>]) -> @mut HTMLCollection {
+impl HTMLCollection {
+ pub fn new(elements: ~[AbstractNode<ScriptView>]) -> @mut HTMLCollection {
let collection = @mut HTMLCollection {
elements: elements,
wrapper: WrapperCache::new()
@@ -23,11 +25,11 @@ pub impl HTMLCollection {
collection
}
- fn Length(&self) -> u32 {
+ pub fn Length(&self) -> u32 {
self.elements.len() as u32
}
- fn Item(&self, index: u32) -> Option<AbstractNode<ScriptView>> {
+ pub fn Item(&self, index: u32) -> Option<AbstractNode<ScriptView>> {
if index < self.Length() {
Some(self.elements[index])
} else {
@@ -35,12 +37,12 @@ pub impl HTMLCollection {
}
}
- fn NamedItem(&self, _cx: *JSContext, _name: DOMString, rv: &mut ErrorResult) -> *JSObject {
+ pub fn NamedItem(&self, _cx: *JSContext, _name: DOMString, rv: &mut ErrorResult) -> *JSObject {
*rv = Ok(());
ptr::null()
}
- fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option<AbstractNode<ScriptView>> {
+ pub fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option<AbstractNode<ScriptView>> {
*found = true;
self.Item(index)
}
diff --git a/src/components/script/dom/node.rs b/src/components/script/dom/node.rs
index 875c31f8322..d415288bfa2 100644
--- a/src/components/script/dom/node.rs
+++ b/src/components/script/dom/node.rs
@@ -14,8 +14,10 @@ use dom::element::{Element, ElementTypeId, HTMLImageElement, HTMLImageElementTyp
use dom::element::{HTMLStyleElementTypeId};
use script_task::global_script_context;
-use core::cast::transmute;
-use core::libc::c_void;
+use std::cast;
+use std::cast::transmute;
+use std::libc::c_void;
+use std::uint;
use js::rust::Compartment;
use netsurfcss::util::VoidPtrLike;
use servo_util::tree::{TreeNode, TreeNodeRef, TreeUtils};
diff --git a/src/components/script/dom/window.rs b/src/components/script/dom/window.rs
index 0c48008827d..5fb07c66f07 100644
--- a/src/components/script/dom/window.rs
+++ b/src/components/script/dom/window.rs
@@ -8,10 +8,15 @@ use dom::bindings::window;
use layout_interface::ReflowForScriptQuery;
use script_task::{ExitMsg, FireTimerMsg, ScriptChan, ScriptContext};
-use core::comm::Chan;
+use std::comm;
+use std::comm::Chan;
+use std::libc;
+use std::int;
+use std::io;
+use std::ptr;
use js::jsapi::JSVal;
-use std::timer;
-use std::uv_global_loop;
+use extra::timer;
+use extra::uv_global_loop;
pub enum TimerControlMsg {
TimerMessage_Fire(~TimerData),
@@ -61,17 +66,17 @@ pub fn TimerData(argc: libc::c_uint, argv: *JSVal) -> TimerData {
// FIXME: delayed_send shouldn't require Copy
#[allow(non_implicitly_copyable_typarams)]
-pub impl Window {
- fn alert(&self, s: &str) {
+impl Window {
+ pub fn alert(&self, s: &str) {
// Right now, just print to the console
io::println(fmt!("ALERT: %s", s));
}
- fn close(&self) {
+ pub fn close(&self) {
self.timer_chan.send(TimerMessage_TriggerExit);
}
- fn setTimeout(&self, timeout: int, argc: libc::c_uint, argv: *JSVal) {
+ pub fn setTimeout(&self, timeout: int, argc: libc::c_uint, argv: *JSVal) {
let timeout = int::max(0, timeout) as uint;
// Post a delayed message to the per-window timer task; it will dispatch it
@@ -82,7 +87,7 @@ pub impl Window {
TimerMessage_Fire(~TimerData(argc, argv)));
}
- fn content_changed(&self) {
+ pub fn content_changed(&self) {
unsafe {
(*self.script_context).reflow_all(ReflowForScriptQuery)
}