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

Fix prototypes of interface objects (fixes #2665) #8954

Merged
merged 8 commits into from Jan 12, 2016

Use the object prototype for callback interface objects

window.NodeFilter's prototype should be the object prototype.
  • Loading branch information
nox committed Jan 12, 2016
commit 7693aecf1521c17e59ca8f6863b91cd7ee1c4074
@@ -2374,7 +2374,7 @@ def definition_body(self):
if self.descriptor.interface.isCallback():
assert not self.descriptor.interface.ctor() and self.descriptor.interface.hasConstants()
return CGGeneric("""\
create_callback_interface_object(cx, receiver, throwing_constructor, 0, sConstants, %s);""" % str_to_const_array(name))
create_callback_interface_object(cx, receiver, sConstants, %s);""" % str_to_const_array(name))

protoChain = self.descriptor.prototypeChain
if len(protoChain) == 1:
@@ -5,10 +5,11 @@
//! Machinery to initialise interface prototype objects and interface objects.

use dom::bindings::utils::{ConstantSpec, NonNullJSNative, define_constants};
use js::jsapi::{HandleObject, JSClass, JSContext, JSFunctionSpec, JSObject};
use js::jsapi::{JSPropertySpec, JS_DefineProperty1, JS_GetFunctionObject};
use js::jsapi::{JS_LinkConstructorAndPrototype, JS_NewFunction};
use js::jsapi::{JS_NewObjectWithUniqueType, MutableHandleObject, RootedObject};
use js::jsapi::{HandleObject, JSClass, JSContext, JSFunctionSpec};
use js::jsapi::{JSObject, JSPropertySpec, JS_DefineProperty1, JS_DefineProperty2};
use js::jsapi::{JS_GetFunctionObject, JS_InternString, JS_LinkConstructorAndPrototype};
use js::jsapi::{JS_NewFunction, JS_NewObject, JS_NewObjectWithUniqueType};
use js::jsapi::{MutableHandleObject, RootedObject, RootedString};
use js::rust::{define_methods, define_properties};
use js::{JSFUN_CONSTRUCTOR, JSPROP_PERMANENT, JSPROP_READONLY};
use libc;
@@ -18,15 +19,13 @@ use std::ptr;
pub unsafe fn create_callback_interface_object(
cx: *mut JSContext,
receiver: HandleObject,
constructor_native: NonNullJSNative,
length: u32,
constants: &'static [ConstantSpec],
name: &'static [u8]) {
assert!(!constants.is_empty());
let interface_object =
RootedObject::new(cx, create_constructor(cx, constructor_native, length, name));
let interface_object = RootedObject::new(cx, JS_NewObject(cx, ptr::null()));
assert!(!interface_object.ptr.is_null());
define_constants(cx, interface_object.handle(), constants);
define_name(cx, interface_object.handle(), name);
define_on_global_object(cx, receiver, name, interface_object.handle());
}

@@ -140,6 +139,19 @@ unsafe fn create_object(
define_constants(cx, rval.handle(), constants);
}

unsafe fn define_name(cx: *mut JSContext, obj: HandleObject, name: &'static [u8]) {
assert!(*name.last().unwrap() == b'\0');
let name =
RootedString::new(cx, JS_InternString(cx, name.as_ptr() as *const libc::c_char));
assert!(!name.ptr.is_null());
assert!(JS_DefineProperty2(cx,
obj,
b"name\0".as_ptr() as *const libc::c_char,
name.handle(),
JSPROP_READONLY,
None, None));
}

unsafe fn define_on_global_object(
cx: *mut JSContext,
receiver: HandleObject,
@@ -195,9 +195,6 @@
[Range interface: stringifier]
expected: FAIL

[NodeFilter interface: existence and properties of interface object]
expected: FAIL

[DOMSettableTokenList interface: existence and properties of interface prototype object]
expected: FAIL

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.