aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/script/dom/bindings
diff options
context:
space:
mode:
authorJosh Matthews <josh@joshmatthews.net>2013-07-30 14:51:16 -0400
committerJosh Matthews <josh@joshmatthews.net>2013-07-30 16:30:46 -0400
commita2bdab7989bf39fa5db4cdedc21884ca6018036f (patch)
tree74051c69466d57a603ae028a9e2dfbcd9fcab611 /src/components/script/dom/bindings
parent5546f2105bea0a3155a1090f3a9a8dfb65c7b47d (diff)
downloadservo-a2bdab7989bf39fa5db4cdedc21884ca6018036f.tar.gz
servo-a2bdab7989bf39fa5db4cdedc21884ca6018036f.zip
Generate bindings for Window.
Diffstat (limited to 'src/components/script/dom/bindings')
-rw-r--r--src/components/script/dom/bindings/codegen/Bindings.conf4
-rw-r--r--src/components/script/dom/bindings/codegen/CodegenRust.py30
-rw-r--r--src/components/script/dom/bindings/codegen/Window.webidl71
-rw-r--r--src/components/script/dom/bindings/domparser.rs4
-rw-r--r--src/components/script/dom/bindings/utils.rs27
-rw-r--r--src/components/script/dom/bindings/window.rs168
6 files changed, 100 insertions, 204 deletions
diff --git a/src/components/script/dom/bindings/codegen/Bindings.conf b/src/components/script/dom/bindings/codegen/Bindings.conf
index 6ab8feb11d8..b07e27c75a3 100644
--- a/src/components/script/dom/bindings/codegen/Bindings.conf
+++ b/src/components/script/dom/bindings/codegen/Bindings.conf
@@ -401,6 +401,9 @@ DOMInterfaces = {
'implicitJSContext': [ 'constructor' ]
}],
+'Window': {
+},
+
'WindowProxy': {
},
@@ -567,5 +570,4 @@ addExternalIface('WebGLShaderPrecisionFormat',
headerFile='WebGLContext.h')
addExternalIface('WebGLTexture', nativeType='mozilla::WebGLTexture',
headerFile='WebGLContext.h')
-addExternalIface('Window')
addExternalIface('XULElement')
diff --git a/src/components/script/dom/bindings/codegen/CodegenRust.py b/src/components/script/dom/bindings/codegen/CodegenRust.py
index 919673ac830..1c177e2e8ea 100644
--- a/src/components/script/dom/bindings/codegen/CodegenRust.py
+++ b/src/components/script/dom/bindings/codegen/CodegenRust.py
@@ -1158,8 +1158,8 @@ for (uint32_t i = 0; i < length; ++i) {
"rooting issues")
templateBody = "${declName} = ${val};"
templateBody = handleDefaultNull(templateBody,
- "${declName} = JS::NullValue()")
- return (templateBody, CGGeneric("JS::Value"), None, isOptional, None)
+ "${declName} = JSVAL_NULL")
+ return (templateBody, CGGeneric("JSVal"), None, isOptional, "JSVAL_NULL")
if type.isObject():
assert not isEnforceRange and not isClamp
@@ -1263,7 +1263,7 @@ for (uint32_t i = 0; i < length; ++i) {
" %s = %s;\n"
"}" % (dataLoc, defaultStr))).define()
- return (template, declType, None, isOptional, None)
+ return (template, declType, None, isOptional, "0 as %s" % typeName)
def instantiateJSToNativeConversionTemplate(templateTuple, replacements,
argcAndIndex=None):
@@ -1308,11 +1308,7 @@ def instantiateJSToNativeConversionTemplate(templateTuple, replacements,
originalDeclName = replacements["declName"]
if declType is not None:
if dealWithOptional:
- replacements["declName"] = (
- "const_cast< %s & >(%s.Value())" %
- (declType.define(), originalDeclName))
- mutableDeclType = CGWrapper(declType, pre="Optional< ", post=" >")
- declType = CGWrapper(mutableDeclType, pre="const ")
+ mutableDeclType = CGWrapper(declType, pre="Option< ", post=" >")
newDecl = [CGGeneric("let mut "),
CGGeneric(originalDeclName),
CGGeneric(": "),
@@ -1327,19 +1323,8 @@ def instantiateJSToNativeConversionTemplate(templateTuple, replacements,
)
if argcAndIndex is not None:
- if dealWithOptional:
- declConstruct = CGIndenter(
- CGGeneric("const_cast< %s &>(%s).Construct();" %
- (mutableDeclType.define(), originalDeclName)))
- if holderType is not None:
- holderConstruct = CGIndenter(
- CGGeneric("const_cast< %s &>(%s).Construct();" %
- (mutableHolderType.define(), originalHolderName)))
- else:
- holderConstruct = None
- else:
- declConstruct = None
- holderConstruct = None
+ declConstruct = None
+ holderConstruct = None
conversion = CGList(
[CGGeneric(
@@ -2155,7 +2140,7 @@ class CGImports(CGWrapper):
# TODO imports to cover descriptors, etc.
def _useString(imports):
- return '#[allow(non_uppercase_statics,unused_imports,unused_variable,unused_unsafe,unused_mut)];' + ''.join(['use %s;\n' % i for i in imports]) + '\n'
+ return '#[allow(non_uppercase_statics,unused_imports,unused_variable,unused_unsafe,unused_mut,dead_assignment)];\n' + ''.join(['use %s;\n' % i for i in imports]) + '\n'
CGWrapper.__init__(self, child,
declarePre=_useString(sorted(declareImports)))
@@ -4373,6 +4358,7 @@ class CGBindingRoot(CGThing):
'dom::mouseevent::*', #XXXjdm
'dom::uievent::*', #XXXjdm
'dom::windowproxy::*', #XXXjdm
+ 'dom::window::Window', #XXXjdm
'dom::bindings::codegen::*', #XXXjdm
'script_task::{JSPageInfo, page_from_context}',
'dom::bindings::utils::EnumEntry',
diff --git a/src/components/script/dom/bindings/codegen/Window.webidl b/src/components/script/dom/bindings/codegen/Window.webidl
new file mode 100644
index 00000000000..6240365be94
--- /dev/null
+++ b/src/components/script/dom/bindings/codegen/Window.webidl
@@ -0,0 +1,71 @@
+/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * 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/.
+ *
+ * The origin of this IDL file is:
+ * http://www.w3.org/html/wg/drafts/html/master/browsers.html#the-window-object
+ */
+
+[NamedPropertiesObject]
+/*sealed*/ interface Window /*: EventTarget*/ {
+ // the current browsing context
+ /*[Unforgeable] readonly attribute WindowProxy window;
+ [Replaceable] readonly attribute WindowProxy self;*/
+ [Unforgeable] readonly attribute Document document;
+ attribute DOMString name;
+ /*[PutForwards=href, Unforgeable] readonly attribute Location location;
+ readonly attribute History history;
+ [Replaceable] readonly attribute BarProp locationbar;
+ [Replaceable] readonly attribute BarProp menubar;
+ [Replaceable] readonly attribute BarProp personalbar;
+ [Replaceable] readonly attribute BarProp scrollbars;
+ [Replaceable] readonly attribute BarProp statusbar;
+ [Replaceable] readonly attribute BarProp toolbar;*/
+ attribute DOMString status;
+ void close();
+ readonly attribute boolean closed;
+ void stop();
+ void focus();
+ void blur();
+
+ // other browsing contexts
+ /*[Replaceable] readonly attribute WindowProxy frames;
+ [Replaceable] readonly attribute unsigned long length;
+ [Unforgeable] readonly attribute WindowProxy top;
+ attribute WindowProxy? opener;
+ readonly attribute WindowProxy parent;*/
+ readonly attribute Element? frameElement;
+ /*WindowProxy open(optional DOMString url = "about:blank", optional DOMString target = "_blank", optional DOMString features = "", optional boolean replace = false);
+ getter WindowProxy (unsigned long index);*/
+ getter object (DOMString name);
+
+ // the user agent
+ /*readonly attribute Navigator navigator;
+ readonly attribute External external;
+ readonly attribute ApplicationCache applicationCache;*/
+
+ // user prompts
+ void alert(optional DOMString message = "");
+ boolean confirm(optional DOMString message = "");
+ DOMString? prompt(optional DOMString message = "", optional DOMString default = "");
+ void print();
+ any showModalDialog(DOMString url, optional any argument);
+
+
+};
+/*Window implements GlobalEventHandlers;
+ Window implements WindowEventHandlers;*/
+
+[NoInterfaceObject]
+interface WindowTimers {
+ //long setTimeout(Function handler, optional long timeout, any... arguments);
+ //XXXjdm No support for Function or variadic arguments yet
+ long setTimeout(any handler, optional long timeout/*, any... arguments*/);
+ /*long setTimeout(DOMString handler, optional long timeout, any... arguments);
+ void clearTimeout(long handle);
+ long setInterval(Function handler, optional long timeout, any... arguments);
+ long setInterval(DOMString handler, optional long timeout, any... arguments);
+ void clearInterval(long handle);*/
+};
+Window implements WindowTimers;
diff --git a/src/components/script/dom/bindings/domparser.rs b/src/components/script/dom/bindings/domparser.rs
index 4e38e7d0f61..f54e7be4d88 100644
--- a/src/components/script/dom/bindings/domparser.rs
+++ b/src/components/script/dom/bindings/domparser.rs
@@ -24,8 +24,8 @@ impl CacheableWrapper for DOMParser {
}
impl BindingObject for DOMParser {
- fn GetParentObject(&self, _cx: *JSContext) -> @mut CacheableWrapper {
- return self.owner as @mut CacheableWrapper;
+ fn GetParentObject(&self, _cx: *JSContext) -> Option<@mut CacheableWrapper> {
+ Some(self.owner as @mut CacheableWrapper)
}
}
diff --git a/src/components/script/dom/bindings/utils.rs b/src/components/script/dom/bindings/utils.rs
index 47ab4633e60..40f0f89ee4d 100644
--- a/src/components/script/dom/bindings/utils.rs
+++ b/src/components/script/dom/bindings/utils.rs
@@ -20,7 +20,7 @@ use js::glue::*;
use js::glue::{DefineFunctionWithReserved, GetObjectJSClass, RUST_OBJECT_TO_JSVAL};
use js::glue::{js_IsObjectProxyClass, js_IsFunctionProxyClass, IsProxyHandlerFamily};
use js::glue::{PROPERTY_STUB, STRICT_PROPERTY_STUB, ENUMERATE_STUB, CONVERT_STUB, RESOLVE_STUB};
-use js::jsapi::{JS_AlreadyHasOwnProperty, JS_NewObject, JS_NewFunction};
+use js::jsapi::{JS_AlreadyHasOwnProperty, JS_NewObject, JS_NewFunction, JS_GetGlobalObject};
use js::jsapi::{JS_DefineProperties, JS_WrapValue, JS_ForwardGetPropertyTo};
use js::jsapi::{JS_EncodeString, JS_free, JS_GetStringCharsAndLength};
use js::jsapi::{JS_GetClass, JS_LinkConstructorAndPrototype};
@@ -616,7 +616,7 @@ pub extern fn ThrowingConstructor(_cx: *JSContext, _argc: uint, _vp: *JSVal) ->
}
pub fn initialize_global(global: *JSObject) {
- let protoArray = @mut ([0 as *JSObject, ..24]); //XXXjdm PrototyepList::id::_ID_Count
+ let protoArray = @mut ([0 as *JSObject, ..25]); //XXXjdm PrototyepList::id::_ID_Count
unsafe {
//XXXjdm we should be storing the box pointer instead of the inner
let box = squirrel_away(protoArray);
@@ -679,19 +679,24 @@ pub fn WrapNewBindingObject(cx: *JSContext, scope: *JSObject,
}
}
-pub fn WrapNativeParent(cx: *JSContext, scope: *JSObject, mut p: @mut CacheableWrapper) -> *JSObject {
- let cache = p.get_wrappercache();
- let wrapper = cache.get_wrapper();
- if wrapper.is_not_null() {
- return wrapper;
+pub fn WrapNativeParent(cx: *JSContext, scope: *JSObject, mut p: Option<@mut CacheableWrapper>) -> *JSObject {
+ match p {
+ Some(ref mut p) => {
+ let cache = p.get_wrappercache();
+ let wrapper = cache.get_wrapper();
+ if wrapper.is_not_null() {
+ return wrapper;
+ }
+ let wrapper = p.wrap_object_shared(cx, scope);
+ cache.set_wrapper(wrapper);
+ wrapper
+ }
+ None => unsafe { JS_GetGlobalObject(cx) }
}
- let wrapper = p.wrap_object_shared(cx, scope);
- cache.set_wrapper(wrapper);
- wrapper
}
pub trait BindingObject {
- fn GetParentObject(&self, cx: *JSContext) -> @mut CacheableWrapper;
+ fn GetParentObject(&self, cx: *JSContext) -> Option<@mut CacheableWrapper>;
}
pub fn GetPropertyOnPrototype(cx: *JSContext, proxy: *JSObject, id: jsid, found: *mut bool,
diff --git a/src/components/script/dom/bindings/window.rs b/src/components/script/dom/bindings/window.rs
deleted file mode 100644
index 6bcb8466cde..00000000000
--- a/src/components/script/dom/bindings/window.rs
+++ /dev/null
@@ -1,168 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * 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/. */
-
-// DOM bindings for the Window object.
-
-use dom::bindings::utils::{rust_box, squirrel_away, CacheableWrapper};
-use dom::bindings::utils::{WrapperCache};
-use dom::window::Window;
-use super::utils;
-
-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::*;
-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;
-use js::{JS_ARGV, JSPROP_ENUMERATE, JSVAL_NULL};
-use js::{JS_THIS_OBJECT, JS_SET_RVAL};
-
-extern fn alert(cx: *JSContext, argc: c_uint, vp: *JSVal) -> JSBool {
- unsafe {
- let argv = JS_ARGV(cx, vp);
- assert!(argc == 1);
- // Abstract this pattern and use it in debug, too?
- let jsstr = JS_ValueToString(cx, *ptr::offset(argv, 0));
- if jsstr.is_null() {
- return 0;
- }
-
- (*unwrap(JS_THIS_OBJECT(cx, vp))).payload.alert(jsval_to_rust_str(cx, jsstr));
-
- JS_SET_RVAL(cx, vp, JSVAL_NULL);
- return 1;
- }
-}
-
-extern fn setTimeout(cx: *JSContext, argc: c_uint, vp: *JSVal) -> JSBool {
- unsafe {
- let argv = JS_ARGV(cx, vp);
- assert!(argc >= 2);
-
- //TODO: don't crash when passed a non-integer value for the timeout
-
- (*unwrap(JS_THIS_OBJECT(cx, vp))).payload.setTimeout(
- RUST_JSVAL_TO_INT(*ptr::offset(argv, 1)) as int,
- argc, argv);
-
- JS_SET_RVAL(cx, vp, JSVAL_NULL);
- return 1;
- }
-}
-
-extern fn close(cx: *JSContext, _argc: c_uint, vp: *JSVal) -> JSBool {
- unsafe {
- (*unwrap(JS_THIS_OBJECT(cx, vp))).payload.close();
- JS_SET_RVAL(cx, vp, JSVAL_NULL);
- return 1;
- }
-}
-
-extern fn gc(cx: *JSContext, _argc: c_uint, _vp: *JSVal) -> JSBool {
- unsafe {
- let runtime = JS_GetRuntime(cx);
- JS_GC(runtime);
- return 1;
- }
-}
-
-unsafe fn unwrap(obj: *JSObject) -> *rust_box<Window> {
- let val = JS_GetReservedSlot(obj, 0);
- cast::transmute(RUST_JSVAL_TO_PRIVATE(val))
-}
-
-extern fn finalize(_fop: *JSFreeOp, obj: *JSObject) {
- debug!("finalize!");
- unsafe {
- let val = JS_GetReservedSlot(obj, 0);
- let _: @Window = cast::transmute(RUST_JSVAL_TO_PRIVATE(val));
- }
-}
-
-pub fn init(compartment: @mut Compartment) {
- let proto = utils::define_empty_prototype(~"Window", None, compartment);
- compartment.register_class(utils::instance_jsclass(~"WindowInstance", finalize, null()));
-
- /* Define methods on a window */
- let methods = [
- JSFunctionSpec {
- name: compartment.add_name(~"alert"),
- call: JSNativeWrapper { op: alert, info: null() },
- nargs: 1,
- flags: 0,
- selfHostedName: null()
- },
- JSFunctionSpec {
- name: compartment.add_name(~"setTimeout"),
- call: JSNativeWrapper { op: setTimeout, info: null() },
- nargs: 2,
- flags: 0,
- selfHostedName: null()
- },
- JSFunctionSpec {
- name: compartment.add_name(~"close"),
- call: JSNativeWrapper { op: close, info: null() },
- nargs: 0,
- flags: 0,
- selfHostedName: null()
- },
- JSFunctionSpec {
- name: compartment.add_name(~"_trigger_gc"),
- call: JSNativeWrapper { op: gc, info: null() },
- nargs: 0,
- flags: 0,
- selfHostedName: null()
- },
- JSFunctionSpec {
- name: null(),
- call: JSNativeWrapper { op: null(), info: null() },
- nargs: 0,
- flags: 0,
- selfHostedName: null()
- }
- ];
-
- unsafe {
- JS_DefineFunctions(compartment.cx.ptr, proto.ptr, &methods[0]);
- }
-}
-
-pub fn create(compartment: @mut Compartment, win: @mut Window) {
- let obj = result::unwrap(
- compartment.new_object_with_proto(~"WindowInstance",
- ~"Window", null()));
-
- win.get_wrappercache().set_wrapper(obj.ptr);
-
- 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);
- }
-}
-
-impl CacheableWrapper for Window {
- fn get_wrappercache(&mut self) -> &mut WrapperCache {
- unsafe { cast::transmute(&self.wrapper) }
- }
-
- fn wrap_object_shared(@mut self, _cx: *JSContext, _scope: *JSObject) -> *JSObject {
- fail!(~"should this be called?");
- }
-}