mirror of
https://github.com/servo/servo.git
synced 2025-08-05 05:30:08 +01:00
Implement [Inline] interfaces
Inline interfaces just appear as a Rust type and in the TypeId hierarchy. They are completely invisible on the JS side.
This commit is contained in:
parent
b745866a4d
commit
5a42bb58f9
12 changed files with 91 additions and 36 deletions
|
@ -1929,8 +1929,8 @@ class CGImports(CGWrapper):
|
||||||
if t.isInterface() or t.isNamespace():
|
if t.isInterface() or t.isNamespace():
|
||||||
descriptor = descriptorProvider.getDescriptor(getIdentifier(t).name)
|
descriptor = descriptorProvider.getDescriptor(getIdentifier(t).name)
|
||||||
extras += [descriptor.path]
|
extras += [descriptor.path]
|
||||||
if descriptor.interface.parent:
|
parentName = descriptor.getParentName()
|
||||||
parentName = getIdentifier(descriptor.interface.parent).name
|
if parentName:
|
||||||
descriptor = descriptorProvider.getDescriptor(parentName)
|
descriptor = descriptorProvider.getDescriptor(parentName)
|
||||||
extras += [descriptor.path, descriptor.bindingPath]
|
extras += [descriptor.path, descriptor.bindingPath]
|
||||||
elif t.isType() and t.isMozMap():
|
elif t.isType() and t.isMozMap():
|
||||||
|
@ -2754,7 +2754,7 @@ assert!((*cache)[PrototypeList::Constructor::%(id)s as usize].is_null());
|
||||||
getPrototypeProto = "prototype_proto.set(JS_GetObjectPrototype(cx, global))"
|
getPrototypeProto = "prototype_proto.set(JS_GetObjectPrototype(cx, global))"
|
||||||
else:
|
else:
|
||||||
getPrototypeProto = ("%s::GetProtoObject(cx, global, prototype_proto.handle_mut())" %
|
getPrototypeProto = ("%s::GetProtoObject(cx, global, prototype_proto.handle_mut())" %
|
||||||
toBindingNamespace(self.descriptor.prototypeChain[-2]))
|
toBindingNamespace(self.descriptor.getParentName()))
|
||||||
|
|
||||||
code = [CGGeneric("""\
|
code = [CGGeneric("""\
|
||||||
rooted!(in(cx) let mut prototype_proto = ptr::null_mut());
|
rooted!(in(cx) let mut prototype_proto = ptr::null_mut());
|
||||||
|
@ -2808,8 +2808,9 @@ assert!((*cache)[PrototypeList::ID::%(id)s as usize].is_null());
|
||||||
properties["length"] = methodLength(self.descriptor.interface.ctor())
|
properties["length"] = methodLength(self.descriptor.interface.ctor())
|
||||||
else:
|
else:
|
||||||
properties["length"] = 0
|
properties["length"] = 0
|
||||||
if self.descriptor.interface.parent:
|
parentName = self.descriptor.getParentName()
|
||||||
parentName = toBindingNamespace(self.descriptor.getParentName())
|
if parentName:
|
||||||
|
parentName = toBindingNamespace(parentName)
|
||||||
code.append(CGGeneric("""
|
code.append(CGGeneric("""
|
||||||
rooted!(in(cx) let mut interface_proto = ptr::null_mut());
|
rooted!(in(cx) let mut interface_proto = ptr::null_mut());
|
||||||
%s::GetConstructorObject(cx, global, interface_proto.handle_mut());""" % parentName))
|
%s::GetConstructorObject(cx, global, interface_proto.handle_mut());""" % parentName))
|
||||||
|
@ -5744,25 +5745,26 @@ class CGDescriptor(CGThing):
|
||||||
|
|
||||||
cgThings.append(CGGeneric(str(properties)))
|
cgThings.append(CGGeneric(str(properties)))
|
||||||
|
|
||||||
if not descriptor.interface.isCallback() and not descriptor.interface.isNamespace():
|
if not descriptor.interface.getExtendedAttribute("Inline"):
|
||||||
cgThings.append(CGGetProtoObjectMethod(descriptor))
|
if not descriptor.interface.isCallback() and not descriptor.interface.isNamespace():
|
||||||
reexports.append('GetProtoObject')
|
cgThings.append(CGGetProtoObjectMethod(descriptor))
|
||||||
cgThings.append(CGPrototypeJSClass(descriptor))
|
reexports.append('GetProtoObject')
|
||||||
if descriptor.interface.hasInterfaceObject():
|
cgThings.append(CGPrototypeJSClass(descriptor))
|
||||||
if descriptor.interface.ctor():
|
if descriptor.interface.hasInterfaceObject():
|
||||||
cgThings.append(CGClassConstructHook(descriptor))
|
if descriptor.interface.ctor():
|
||||||
for ctor in descriptor.interface.namedConstructors:
|
cgThings.append(CGClassConstructHook(descriptor))
|
||||||
cgThings.append(CGClassConstructHook(descriptor, ctor))
|
for ctor in descriptor.interface.namedConstructors:
|
||||||
if not descriptor.interface.isCallback():
|
cgThings.append(CGClassConstructHook(descriptor, ctor))
|
||||||
cgThings.append(CGInterfaceObjectJSClass(descriptor))
|
if not descriptor.interface.isCallback():
|
||||||
if descriptor.shouldHaveGetConstructorObjectMethod():
|
cgThings.append(CGInterfaceObjectJSClass(descriptor))
|
||||||
cgThings.append(CGGetConstructorObjectMethod(descriptor))
|
if descriptor.shouldHaveGetConstructorObjectMethod():
|
||||||
reexports.append('GetConstructorObject')
|
cgThings.append(CGGetConstructorObjectMethod(descriptor))
|
||||||
if descriptor.register:
|
reexports.append('GetConstructorObject')
|
||||||
cgThings.append(CGDefineDOMInterfaceMethod(descriptor))
|
if descriptor.register:
|
||||||
reexports.append('DefineDOMInterface')
|
cgThings.append(CGDefineDOMInterfaceMethod(descriptor))
|
||||||
cgThings.append(CGConstructorEnabled(descriptor))
|
reexports.append('DefineDOMInterface')
|
||||||
cgThings.append(CGCreateInterfaceObjectsMethod(descriptor, properties, haveUnscopables))
|
cgThings.append(CGConstructorEnabled(descriptor))
|
||||||
|
cgThings.append(CGCreateInterfaceObjectsMethod(descriptor, properties, haveUnscopables))
|
||||||
|
|
||||||
cgThings = generate_imports(config, CGList(cgThings, '\n'), [descriptor])
|
cgThings = generate_imports(config, CGList(cgThings, '\n'), [descriptor])
|
||||||
cgThings = CGWrapper(CGNamespace(toBindingNamespace(descriptor.name),
|
cgThings = CGWrapper(CGNamespace(toBindingNamespace(descriptor.name),
|
||||||
|
@ -6803,7 +6805,7 @@ class GlobalGenRoots():
|
||||||
globals_ = CGWrapper(CGIndenter(global_flags), pre="bitflags! {\n", post="\n}")
|
globals_ = CGWrapper(CGIndenter(global_flags), pre="bitflags! {\n", post="\n}")
|
||||||
|
|
||||||
pairs = []
|
pairs = []
|
||||||
for d in config.getDescriptors(hasInterfaceObject=True):
|
for d in config.getDescriptors(hasInterfaceObject=True, isInline=False):
|
||||||
binding = toBindingNamespace(d.name)
|
binding = toBindingNamespace(d.name)
|
||||||
pairs.append((d.name, binding, binding))
|
pairs.append((d.name, binding, binding))
|
||||||
for ctor in d.interface.namedConstructors:
|
for ctor in d.interface.namedConstructors:
|
||||||
|
@ -6931,7 +6933,7 @@ class GlobalGenRoots():
|
||||||
allprotos.append(CGGeneric("\n"))
|
allprotos.append(CGGeneric("\n"))
|
||||||
|
|
||||||
if downcast:
|
if downcast:
|
||||||
hierarchy[descriptor.getParentName()].append(name)
|
hierarchy[descriptor.interface.parent.identifier.name].append(name)
|
||||||
|
|
||||||
typeIdCode = []
|
typeIdCode = []
|
||||||
topTypeVariants = [
|
topTypeVariants = [
|
||||||
|
@ -6955,7 +6957,7 @@ class GlobalGenRoots():
|
||||||
|
|
||||||
for base, derived in hierarchy.iteritems():
|
for base, derived in hierarchy.iteritems():
|
||||||
variants = []
|
variants = []
|
||||||
if not config.getInterface(base).getExtendedAttribute("Abstract"):
|
if config.getDescriptor(base).concrete:
|
||||||
variants.append(CGGeneric(base))
|
variants.append(CGGeneric(base))
|
||||||
variants += [CGGeneric(type_id_variant(derivedName)) for derivedName in derived]
|
variants += [CGGeneric(type_id_variant(derivedName)) for derivedName in derived]
|
||||||
derives = "Clone, Copy, Debug, PartialEq"
|
derives = "Clone, Copy, Debug, PartialEq"
|
||||||
|
|
|
@ -88,6 +88,8 @@ class Configuration:
|
||||||
getter = lambda x: x.interface.isJSImplemented()
|
getter = lambda x: x.interface.isJSImplemented()
|
||||||
elif key == 'isGlobal':
|
elif key == 'isGlobal':
|
||||||
getter = lambda x: x.isGlobal()
|
getter = lambda x: x.isGlobal()
|
||||||
|
elif key == 'isInline':
|
||||||
|
getter = lambda x: x.interface.getExtendedAttribute('Inline') is not None
|
||||||
elif key == 'isExposedConditionally':
|
elif key == 'isExposedConditionally':
|
||||||
getter = lambda x: x.interface.isExposedConditionally()
|
getter = lambda x: x.interface.isExposedConditionally()
|
||||||
elif key == 'isIteratorInterface':
|
elif key == 'isIteratorInterface':
|
||||||
|
@ -234,6 +236,7 @@ class Descriptor(DescriptorProvider):
|
||||||
self.concrete = (not self.interface.isCallback() and
|
self.concrete = (not self.interface.isCallback() and
|
||||||
not self.interface.isNamespace() and
|
not self.interface.isNamespace() and
|
||||||
not self.interface.getExtendedAttribute("Abstract") and
|
not self.interface.getExtendedAttribute("Abstract") and
|
||||||
|
not self.interface.getExtendedAttribute("Inline") and
|
||||||
not spiderMonkeyInterface)
|
not spiderMonkeyInterface)
|
||||||
self.hasUnforgeableMembers = (self.concrete and
|
self.hasUnforgeableMembers = (self.concrete and
|
||||||
any(MemberIsUnforgeable(m, self) for m in
|
any(MemberIsUnforgeable(m, self) for m in
|
||||||
|
@ -383,8 +386,12 @@ class Descriptor(DescriptorProvider):
|
||||||
return attrs
|
return attrs
|
||||||
|
|
||||||
def getParentName(self):
|
def getParentName(self):
|
||||||
assert self.interface.parent is not None
|
parent = self.interface.parent
|
||||||
return self.interface.parent.identifier.name
|
while parent:
|
||||||
|
if not parent.getExtendedAttribute("Inline"):
|
||||||
|
return parent.identifier.name
|
||||||
|
parent = parent.parent
|
||||||
|
return None
|
||||||
|
|
||||||
def hasDescendants(self):
|
def hasDescendants(self):
|
||||||
return (self.interface.getUserData("hasConcreteDescendant", False) or
|
return (self.interface.getUserData("hasConcreteDescendant", False) or
|
||||||
|
|
|
@ -1695,7 +1695,8 @@ class IDLInterface(IDLInterfaceOrNamespace):
|
||||||
identifier == "ProbablyShortLivingObject" or
|
identifier == "ProbablyShortLivingObject" or
|
||||||
identifier == "LegacyUnenumerableNamedProperties" or
|
identifier == "LegacyUnenumerableNamedProperties" or
|
||||||
identifier == "NonOrdinaryGetPrototypeOf" or
|
identifier == "NonOrdinaryGetPrototypeOf" or
|
||||||
identifier == "Abstract"):
|
identifier == "Abstract" or
|
||||||
|
identifier == "Inline"):
|
||||||
# Known extended attributes that do not take values
|
# Known extended attributes that do not take values
|
||||||
if not attr.noArguments():
|
if not attr.noArguments():
|
||||||
raise WebIDLError("[%s] must take no arguments" % identifier,
|
raise WebIDLError("[%s] must take no arguments" % identifier,
|
||||||
|
|
12
components/script/dom/bindings/codegen/parser/inline.patch
Normal file
12
components/script/dom/bindings/codegen/parser/inline.patch
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
--- WebIDL.py
|
||||||
|
+++ WebIDL.py
|
||||||
|
@@ -1695,7 +1695,8 @@ class IDLInterface(IDLInterfaceOrNamespace):
|
||||||
|
identifier == "ProbablyShortLivingObject" or
|
||||||
|
identifier == "LegacyUnenumerableNamedProperties" or
|
||||||
|
identifier == "NonOrdinaryGetPrototypeOf" or
|
||||||
|
- identifier == "Abstract"):
|
||||||
|
+ identifier == "Abstract" or
|
||||||
|
+ identifier == "Inline"):
|
||||||
|
# Known extended attributes that do not take values
|
||||||
|
if not attr.noArguments():
|
||||||
|
raise WebIDLError("[%s] must take no arguments" % identifier,
|
|
@ -4,6 +4,7 @@ patch < debug.patch
|
||||||
patch < pref-main-thread.patch
|
patch < pref-main-thread.patch
|
||||||
patch < callback-location.patch
|
patch < callback-location.patch
|
||||||
patch < union-typedef.patch
|
patch < union-typedef.patch
|
||||||
|
patch < inline.patch
|
||||||
|
|
||||||
wget https://hg.mozilla.org/mozilla-central/archive/tip.tar.gz/dom/bindings/parser/tests/ -O tests.tar.gz
|
wget https://hg.mozilla.org/mozilla-central/archive/tip.tar.gz/dom/bindings/parser/tests/ -O tests.tar.gz
|
||||||
rm -r tests
|
rm -r tests
|
||||||
|
|
18
components/script/dom/globalscope.rs
Normal file
18
components/script/dom/globalscope.rs
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
/* 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/. */
|
||||||
|
|
||||||
|
use dom::eventtarget::EventTarget;
|
||||||
|
|
||||||
|
#[dom_struct]
|
||||||
|
pub struct GlobalScope {
|
||||||
|
eventtarget: EventTarget,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GlobalScope {
|
||||||
|
pub fn new_inherited() -> GlobalScope {
|
||||||
|
GlobalScope {
|
||||||
|
eventtarget: EventTarget::new_inherited(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -276,6 +276,7 @@ pub mod filereadersync;
|
||||||
pub mod focusevent;
|
pub mod focusevent;
|
||||||
pub mod forcetouchevent;
|
pub mod forcetouchevent;
|
||||||
pub mod formdata;
|
pub mod formdata;
|
||||||
|
pub mod globalscope;
|
||||||
pub mod hashchangeevent;
|
pub mod hashchangeevent;
|
||||||
pub mod headers;
|
pub mod headers;
|
||||||
pub mod history;
|
pub mod history;
|
||||||
|
|
10
components/script/dom/webidls/GlobalScope.webidl
Normal file
10
components/script/dom/webidls/GlobalScope.webidl
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
/* 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/. */
|
||||||
|
|
||||||
|
// This interface is entirely internal to Servo, and should not be accessible to
|
||||||
|
// web pages.
|
||||||
|
|
||||||
|
[Exposed=(Window,Worker),
|
||||||
|
Inline]
|
||||||
|
interface GlobalScope : EventTarget {};
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#window
|
// https://html.spec.whatwg.org/multipage/#window
|
||||||
[PrimaryGlobal, Exposed=(Window,Worker)]
|
[PrimaryGlobal, Exposed=(Window,Worker)]
|
||||||
/*sealed*/ interface Window : EventTarget {
|
/*sealed*/ interface Window : GlobalScope {
|
||||||
// the current browsing context
|
// the current browsing context
|
||||||
[Unforgeable] readonly attribute WindowProxy window;
|
[Unforgeable] readonly attribute WindowProxy window;
|
||||||
[BinaryName="Self_", Replaceable] readonly attribute WindowProxy self;
|
[BinaryName="Self_", Replaceable] readonly attribute WindowProxy self;
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#workerglobalscope
|
// https://html.spec.whatwg.org/multipage/#workerglobalscope
|
||||||
[Abstract, Exposed=Worker]
|
[Abstract, Exposed=Worker]
|
||||||
interface WorkerGlobalScope : EventTarget {
|
interface WorkerGlobalScope : GlobalScope {
|
||||||
[BinaryName="Self_"] readonly attribute WorkerGlobalScope self;
|
[BinaryName="Self_"] readonly attribute WorkerGlobalScope self;
|
||||||
readonly attribute WorkerLocation location;
|
readonly attribute WorkerLocation location;
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,7 @@ use dom::element::Element;
|
||||||
use dom::errorevent::ErrorEvent;
|
use dom::errorevent::ErrorEvent;
|
||||||
use dom::event::{Event, EventBubbles, EventCancelable};
|
use dom::event::{Event, EventBubbles, EventCancelable};
|
||||||
use dom::eventtarget::EventTarget;
|
use dom::eventtarget::EventTarget;
|
||||||
|
use dom::globalscope::GlobalScope;
|
||||||
use dom::history::History;
|
use dom::history::History;
|
||||||
use dom::htmliframeelement::build_mozbrowser_custom_event;
|
use dom::htmliframeelement::build_mozbrowser_custom_event;
|
||||||
use dom::location::Location;
|
use dom::location::Location;
|
||||||
|
@ -143,7 +144,7 @@ pub type ScrollPoint = Point2D<Au>;
|
||||||
|
|
||||||
#[dom_struct]
|
#[dom_struct]
|
||||||
pub struct Window {
|
pub struct Window {
|
||||||
eventtarget: EventTarget,
|
globalscope: GlobalScope,
|
||||||
#[ignore_heap_size_of = "trait objects are hard"]
|
#[ignore_heap_size_of = "trait objects are hard"]
|
||||||
script_chan: MainThreadScriptChan,
|
script_chan: MainThreadScriptChan,
|
||||||
#[ignore_heap_size_of = "task sources are hard"]
|
#[ignore_heap_size_of = "task sources are hard"]
|
||||||
|
@ -1629,7 +1630,7 @@ impl Window {
|
||||||
};
|
};
|
||||||
let current_time = time::get_time();
|
let current_time = time::get_time();
|
||||||
let win = box Window {
|
let win = box Window {
|
||||||
eventtarget: EventTarget::new_inherited(),
|
globalscope: GlobalScope::new_inherited(),
|
||||||
script_chan: script_chan,
|
script_chan: script_chan,
|
||||||
dom_manipulation_task_source: dom_task_source,
|
dom_manipulation_task_source: dom_task_source,
|
||||||
user_interaction_task_source: user_task_source,
|
user_interaction_task_source: user_task_source,
|
||||||
|
|
|
@ -22,6 +22,7 @@ use dom::errorevent::ErrorEvent;
|
||||||
use dom::event::{Event, EventBubbles, EventCancelable};
|
use dom::event::{Event, EventBubbles, EventCancelable};
|
||||||
use dom::eventdispatcher::EventStatus;
|
use dom::eventdispatcher::EventStatus;
|
||||||
use dom::eventtarget::EventTarget;
|
use dom::eventtarget::EventTarget;
|
||||||
|
use dom::globalscope::GlobalScope;
|
||||||
use dom::promise::Promise;
|
use dom::promise::Promise;
|
||||||
use dom::serviceworkerglobalscope::ServiceWorkerGlobalScope;
|
use dom::serviceworkerglobalscope::ServiceWorkerGlobalScope;
|
||||||
use dom::window::{base64_atob, base64_btoa};
|
use dom::window::{base64_atob, base64_btoa};
|
||||||
|
@ -79,7 +80,8 @@ pub fn prepare_workerscope_init(global: GlobalRef,
|
||||||
// https://html.spec.whatwg.org/multipage/#the-workerglobalscope-common-interface
|
// https://html.spec.whatwg.org/multipage/#the-workerglobalscope-common-interface
|
||||||
#[dom_struct]
|
#[dom_struct]
|
||||||
pub struct WorkerGlobalScope {
|
pub struct WorkerGlobalScope {
|
||||||
eventtarget: EventTarget,
|
globalscope: GlobalScope,
|
||||||
|
|
||||||
worker_id: WorkerId,
|
worker_id: WorkerId,
|
||||||
pipeline_id: PipelineId,
|
pipeline_id: PipelineId,
|
||||||
worker_url: Url,
|
worker_url: Url,
|
||||||
|
@ -140,7 +142,7 @@ impl WorkerGlobalScope {
|
||||||
closing: Option<Arc<AtomicBool>>)
|
closing: Option<Arc<AtomicBool>>)
|
||||||
-> WorkerGlobalScope {
|
-> WorkerGlobalScope {
|
||||||
WorkerGlobalScope {
|
WorkerGlobalScope {
|
||||||
eventtarget: EventTarget::new_inherited(),
|
globalscope: GlobalScope::new_inherited(),
|
||||||
next_worker_id: Cell::new(WorkerId(0)),
|
next_worker_id: Cell::new(WorkerId(0)),
|
||||||
worker_id: init.worker_id,
|
worker_id: init.worker_id,
|
||||||
pipeline_id: init.pipeline_id,
|
pipeline_id: init.pipeline_id,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue