Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add WindowProxy support and basic browsing context concept. #1818

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -112,14 +112,23 @@ DOMInterfaces = {
'ValidityState': {},
'Window': {
'createGlobal': True,
'classHooks': {
'outerObject': 'Some(bindings::utils::outerize_global)',
'thisObject': 'Some(bindings::utils::outerize_global)',
},
'needsAbstract': [
'console',
'location',
'navigator',
],
},

'WindowProxy': {},
'WindowProxy': {
'nativeType': 'JSObject',
'pointerType': '*',
'concrete': False,
'register': False
},

'TestBinding': {},

@@ -129,7 +138,6 @@ DOMInterfaces = {
def addHTMLElement(element, concrete=None, needsAbstract=[]):
DOMInterfaces[element] = {
'nativeType': 'JS<%s>' % element,
'pointerType': '',
'concreteType': concrete if concrete else element,
'needsAbstract': needsAbstract
}
@@ -571,6 +571,22 @@ def wrapObjectTemplate(templateBody, isDefinitelyObject, type,

return templateBody

# A helper function for converting things that look like a JSObject*.
def handleJSObjectType(type, isMember, failureCode):
if not isMember:
declType = CGGeneric('Option<*JSObject>')
declArgs="cx"
else:
#assert (isMember == "Sequence" or isMember == "Variadic" or
# isMember == "Dictionary" or isMember == "OwningUnion")
# We'll get traced by the sequence or dictionary or union tracer
declType = CGGeneric("Option<*JSObject>")
declArgs = None
templateBody = "${declName} = Some(${val}.to_object());"
setToNullCode = "${declName} = None;"
template = wrapObjectTemplate(templateBody, False, type, failureCode)
return (template, declType, None, isOptional, None) #XXX declArgs

assert not (isEnforceRange and isClamp) # These are mutually exclusive

if type.isArray():
@@ -621,6 +637,9 @@ def wrapObjectTemplate(templateBody, isDefinitelyObject, type,
failureCode)
return (template, declType, None, isOptional, None)

if descriptor.nativeType == 'JSObject':
return handleJSObjectType(type, isMember, failureCode)

# Sequences and callbacks have to hold a strong ref to the thing being
# passed down.
forceOwningType = descriptor.interface.isCallback() or isMember
@@ -1090,7 +1109,7 @@ def getRetvalDeclarationForType(returnType, descriptorProvider):
if returnType.isGeckoInterface():
descriptor = descriptorProvider.getDescriptor(
returnType.unroll().inner.identifier.name)
result = CGGeneric(descriptor.nativeType)
result = CGGeneric(descriptor.pointerType + descriptor.nativeType)
if returnType.nullable():
result = CGWrapper(result, pre="Option<", post=">")
return result
@@ -1526,7 +1545,8 @@ def define(self):
return """
static Class_name: [u8, ..%i] = %s;
static Class: DOMJSClass = DOMJSClass {
base: JSClass { name: &Class_name as *u8 as *libc::c_char,
base: js::Class {
name: &Class_name as *u8 as *libc::c_char,
flags: JSCLASS_IS_DOMJSCLASS | %s | (((%s) & JSCLASS_RESERVED_SLOTS_MASK) << JSCLASS_RESERVED_SLOTS_SHIFT), //JSCLASS_HAS_RESERVED_SLOTS(%s),
addProperty: Some(JS_PropertyStub),
delProperty: Some(JS_PropertyStub),
@@ -1541,21 +1561,60 @@ def define(self):
hasInstance: None,
construct: None,
trace: %s,
reserved: (0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void, // 05
0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void, // 10
0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void, // 15
0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void, // 20
0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void, // 25
0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void, // 30
0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void, // 35
0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void, 0 as *libc::c_void) // 40
ext: js::ClassExtension {
equality: 0 as *u8,
outerObject: %s,
innerObject: None,
iteratorObject: 0 as *u8,
unused: 0 as *u8,
isWrappedNative: 0 as *u8,
},
ops: js::ObjectOps {
lookupGeneric: 0 as *u8,
lookupProperty: 0 as *u8,
lookupElement: 0 as *u8,
lookupSpecial: 0 as *u8,
defineGeneric: 0 as *u8,
defineProperty: 0 as *u8,
defineElement: 0 as *u8,
defineSpecial: 0 as *u8,
getGeneric: 0 as *u8,
getProperty: 0 as *u8,
getElement: 0 as *u8,
getElementIfPresent: 0 as *u8,
getSpecial: 0 as *u8,
setGeneric: 0 as *u8,
setProperty: 0 as *u8,
setElement: 0 as *u8,
setSpecial: 0 as *u8,
getGenericAttributes: 0 as *u8,
getPropertyAttributes: 0 as *u8,
getElementAttributes: 0 as *u8,
getSpecialAttributes: 0 as *u8,
setGenericAttributes: 0 as *u8,
setPropertyAttributes: 0 as *u8,
setElementAttributes: 0 as *u8,
setSpecialAttributes: 0 as *u8,
deleteProperty: 0 as *u8,
deleteElement: 0 as *u8,
deleteSpecial: 0 as *u8,
enumerate: 0 as *u8,
typeOf: 0 as *u8,
thisObject: %s,
clear: 0 as *u8,
},
},
dom_class: %s
};
""" % (len(self.descriptor.interface.identifier.name) + 1,
str_to_const_array(self.descriptor.interface.identifier.name),
flags, slots, slots,
FINALIZE_HOOK_NAME, traceHook,
self.descriptor.classHooks['outerObject'],
self.descriptor.classHooks['thisObject'],
CGIndenter(CGGeneric(DOMClass(self.descriptor))).define())

def str_to_const_array(s):
@@ -1874,9 +1933,9 @@ def CreateBindingJSObject(descriptor, parent=None):
""" % (parent)
else:
if descriptor.createGlobal:
create += " let obj = CreateDOMGlobal(aCx, &Class.base);\n"
create += " let obj = CreateDOMGlobal(aCx, &Class.base as *js::Class as *JSClass);\n"
else:
create += " let obj = JS_NewObject(aCx, &Class.base, proto, %s);\n" % parent
create += " let obj = JS_NewObject(aCx, &Class.base as *js::Class as *JSClass, proto, %s);\n" % parent
create += """ assert!(obj.is_not_null());
JS_SetReservedSlot(obj, DOM_OBJECT_SLOT as u32,
@@ -2140,41 +2199,41 @@ def definition_body(self):
#XXXjdm This self.descriptor.concrete check shouldn't be necessary
if not self.descriptor.concrete or self.descriptor.proxy:
body += """ let traps = ProxyTraps {
getPropertyDescriptor: getPropertyDescriptor,
getOwnPropertyDescriptor: getOwnPropertyDescriptor,
defineProperty: defineProperty,
getOwnPropertyNames: ptr::null(),
delete_: ptr::null(),
enumerate: ptr::null(),
has: ptr::null(),
hasOwn: hasOwn,
get: get,
set: ptr::null(),
keys: ptr::null(),
iterate: ptr::null(),
call: ptr::null(),
construct: ptr::null(),
getPropertyDescriptor: Some(getPropertyDescriptor),
getOwnPropertyDescriptor: Some(getOwnPropertyDescriptor),
defineProperty: Some(defineProperty),
getOwnPropertyNames: 0 as *u8,
delete_: None,
enumerate: 0 as *u8,
has: None,
hasOwn: Some(hasOwn),
get: Some(get),
set: None,
keys: 0 as *u8,
iterate: None,
call: None,
construct: None,
nativeCall: ptr::null(),
hasInstance: ptr::null(),
typeOf: ptr::null(),
objectClassIs: ptr::null(),
obj_toString: obj_toString,
fun_toString: ptr::null(),
hasInstance: None,
typeOf: None,
objectClassIs: None,
obj_toString: Some(obj_toString),
fun_toString: None,
//regexp_toShared: ptr::null(),
defaultValue: ptr::null(),
iteratorNext: ptr::null(),
finalize: %s,
getElementIfPresent: ptr::null(),
getPrototypeOf: ptr::null(),
trace: %s
defaultValue: None,
iteratorNext: None,
finalize: Some(%s),
getElementIfPresent: None,
getPrototypeOf: None,
trace: Some(%s)
};
js_info.dom_static.proxy_handlers.insert(PrototypeList::id::%s as uint,
CreateProxyHandler(&traps, cast::transmute(&Class)));
""" % (FINALIZE_HOOK_NAME,
('Some(%s)' % TRACE_HOOK_NAME),
TRACE_HOOK_NAME,
self.descriptor.name)

return (body + """ let cx = js_info.js_context.deref().ptr;
@@ -4209,6 +4268,8 @@ def defaultValue(ty):
return '~""'
elif ty.startswith("Option"):
return "None"
elif ty == '*JSObject':
return "ptr::null()"
else:
return "/* uh oh: %s */" % ty

@@ -4451,6 +4512,7 @@ def __init__(self, config, prefix, webIDLFile):
#XXXjdm This should only import the namespace for the current binding,
# not every binding ever.
curr = CGImports(curr, [
'js',
'js::{JS_ARGV, JS_CALLEE, JS_THIS_OBJECT}',
'js::{JSCLASS_GLOBAL_SLOT_COUNT, JSCLASS_IS_DOMJSCLASS}',
'js::{JSCLASS_IS_GLOBAL, JSCLASS_RESERVED_SLOTS_SHIFT}',
@@ -4476,6 +4538,7 @@ def __init__(self, config, prefix, webIDLFile):
'js::glue::{RUST_FUNCTION_VALUE_TO_JITINFO}',
'js::glue::{RUST_JS_NumberValue, RUST_JSID_IS_STRING}',
'dom::types::*',
'dom::bindings',
'dom::bindings::js::JS',
'dom::bindings::utils::{CreateDOMGlobal, CreateInterfaceObjects2}',
'dom::bindings::utils::{ConstantSpec, cx_for_dom_object, Default}',
@@ -2,6 +2,8 @@
# 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/.

from collections import defaultdict

autogenerated_comment = "/* THIS FILE IS AUTOGENERATED - DO NOT EDIT */\n"

class Configuration:
@@ -133,11 +135,13 @@ def __init__(self, config, interface, desc):
else:
nativeTypeDefault = 'JS<%s>' % ifaceName

self.pointerType = desc.get('pointerType', '')
self.nativeType = desc.get('nativeType', nativeTypeDefault)
self.concreteType = desc.get('concreteType', ifaceName)
self.needsAbstract = desc.get('needsAbstract', [])
self.createGlobal = desc.get('createGlobal', False)
self.register = desc.get('register', True)
self.classHooks = desc.get('classHooks', defaultdict(lambda: 'None'))

# If we're concrete, we need to crawl our ancestor interfaces and mark
# them as having a concrete descendant.
@@ -7,15 +7,15 @@ use dom::bindings::utils::Reflectable;
use dom::bindings::utils::jsstring_to_str;
use servo_util::str::DOMString;

use js::jsapi::{JSBool, JSContext};
use js::jsapi::{JSBool, JSContext, JSObject};
use js::jsapi::{JS_ValueToUint64, JS_ValueToInt64};
use js::jsapi::{JS_ValueToECMAUint32, JS_ValueToECMAInt32};
use js::jsapi::{JS_ValueToUint16, JS_ValueToNumber, JS_ValueToBoolean};
use js::jsapi::{JS_NewUCStringCopyN, JS_ValueToString};
use js::jsapi::{JS_WrapValue};
use js::jsval::JSVal;
use js::jsval::{UndefinedValue, NullValue, BooleanValue, Int32Value, UInt32Value};
use js::jsval::{StringValue, ObjectValue};
use js::jsval::{StringValue, ObjectValue, ObjectOrNullValue};
use js::glue::RUST_JS_NumberValue;
use std::default::Default;
use std::libc;
@@ -202,6 +202,12 @@ impl FromJSValConvertible<()> for f64 {
}
}

impl ToJSValConvertible for *JSObject {
fn to_jsval(&self, _cx: *JSContext) -> JSVal {
ObjectOrNullValue(*self)
}
}

impl ToJSValConvertible for DOMString {
fn to_jsval(&self, cx: *JSContext) -> JSVal {
unsafe {
@@ -5,7 +5,7 @@
use dom::bindings::js::JS;
use dom::bindings::utils::{Reflectable, Reflector};

use js::jsapi::{JSTracer, JS_CallTracer, JSTRACE_OBJECT};
use js::jsapi::{JSObject, JSTracer, JS_CallTracer, JSTRACE_OBJECT};

use std::cast;
use std::libc;
@@ -35,14 +35,17 @@ pub trait Traceable {
}

pub fn trace_reflector(tracer: *mut JSTracer, description: &str, reflector: &Reflector) {
trace_object(tracer, description, reflector.get_jsobject())
}

pub fn trace_object(tracer: *mut JSTracer, description: &str, obj: *JSObject) {
unsafe {
description.to_c_str().with_ref(|name| {
(*tracer).debugPrinter = ptr::null();
(*tracer).debugPrintIndex = -1;
(*tracer).debugPrintArg = name as *libc::c_void;
debug!("tracing {:s}", description);
JS_CallTracer(tracer as *JSTracer, reflector.get_jsobject(),
JSTRACE_OBJECT as u32);
JS_CallTracer(tracer as *JSTracer, obj, JSTRACE_OBJECT as u32);
});
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.