Use IDL sequence default value

This commit is contained in:
Kagami Sascha Rosylight 2019-11-04 22:42:10 +09:00
parent 4ad08fff04
commit 01e0b2cb5e
13 changed files with 40 additions and 65 deletions

View file

@ -6388,8 +6388,11 @@ class CGDictionary(CGThing):
def struct(self):
d = self.dictionary
if d.parent:
inheritance = " pub parent: %s::%s,\n" % (self.makeModuleName(d.parent),
self.makeClassName(d.parent))
typeName = "%s::%s" % (self.makeModuleName(d.parent),
self.makeClassName(d.parent))
if type_needs_tracing(d.parent):
typeName = "RootedTraceableBox<%s>" % typeName
inheritance = " pub parent: %s,\n" % typeName
else:
inheritance = ""
memberDecls = [" pub %s: %s," %
@ -6520,10 +6523,7 @@ class CGDictionary(CGThing):
})
def membersNeedTracing(self):
for member, _ in self.memberInfo:
if type_needs_tracing(member.type):
return True
return False
return type_needs_tracing(self.dictionary)
@staticmethod
def makeDictionaryName(dictionary):

View file

@ -164,7 +164,7 @@ impl Bluetooth {
&self,
p: &Rc<Promise>,
filters: &Option<Vec<BluetoothLEScanFilterInit>>,
optional_services: &Option<Vec<BluetoothServiceUUID>>,
optional_services: &[BluetoothServiceUUID],
sender: IpcSender<BluetoothResponseResult>,
) {
// TODO: Step 1: Triggered by user activation.
@ -197,23 +197,21 @@ impl Bluetooth {
}
let mut optional_services_uuids = vec![];
if let &Some(ref opt_services) = optional_services {
for opt_service in opt_services {
// Step 2.5 - 2.6.
let uuid = match BluetoothUUID::service(opt_service.clone()) {
Ok(u) => u.to_string(),
Err(e) => {
p.reject_error(e);
return;
},
};
for opt_service in optional_services {
// Step 2.5 - 2.6.
let uuid = match BluetoothUUID::service(opt_service.clone()) {
Ok(u) => u.to_string(),
Err(e) => {
p.reject_error(e);
return;
},
};
// Step 2.7.
// Note: What we are doing here, is adding the not blocklisted UUIDs to the result vector,
// instead of removing them from an already filled vector.
if !uuid_is_blocklisted(uuid.as_ref(), Blocklist::All) {
optional_services_uuids.push(uuid);
}
// Step 2.7.
// Note: What we are doing here, is adding the not blocklisted UUIDs to the result vector,
// instead of removing them from an already filled vector.
if !uuid_is_blocklisted(uuid.as_ref(), Blocklist::All) {
optional_services_uuids.push(uuid);
}
}

View file

@ -619,8 +619,6 @@ impl DedicatedWorkerGlobalScopeMethods for DedicatedWorkerGlobalScope {
let mut rooted = CustomAutoRooter::new(
options
.transfer
.as_ref()
.unwrap_or(&Vec::with_capacity(0))
.iter()
.map(|js: &RootedTraceableBox<Heap<*mut JSObject>>| js.get())
.collect(),

View file

@ -141,15 +141,9 @@ impl DissimilarOriginWindowMethods for DissimilarOriginWindow {
cx: JSContext,
message: HandleValue,
target_origin: USVString,
mut transfer: CustomAutoRooterGuard<Option<Vec<*mut JSObject>>>,
transfer: CustomAutoRooterGuard<Vec<*mut JSObject>>,
) -> ErrorResult {
if transfer.is_some() {
let mut rooted = CustomAutoRooter::new(transfer.take().unwrap());
let transfer = Some(CustomAutoRooterGuard::new(*cx, &mut rooted));
self.post_message_impl(&target_origin, cx, message, transfer)
} else {
self.post_message_impl(&target_origin, cx, message, None)
}
self.post_message_impl(&target_origin, cx, message, transfer)
}
/// https://html.spec.whatwg.org/multipage/#dom-window-postmessage-options
@ -161,14 +155,13 @@ impl DissimilarOriginWindowMethods for DissimilarOriginWindow {
) -> ErrorResult {
let mut rooted = CustomAutoRooter::new(
options
.parent
.transfer
.as_ref()
.unwrap_or(&Vec::with_capacity(0))
.iter()
.map(|js: &RootedTraceableBox<Heap<*mut JSObject>>| js.get())
.collect(),
);
let transfer = Some(CustomAutoRooterGuard::new(*cx, &mut rooted));
let transfer = CustomAutoRooterGuard::new(*cx, &mut rooted);
self.post_message_impl(&options.targetOrigin, cx, message, transfer)
}
@ -208,10 +201,10 @@ impl DissimilarOriginWindow {
target_origin: &USVString,
cx: JSContext,
message: HandleValue,
transfer: Option<CustomAutoRooterGuard<Vec<*mut JSObject>>>,
transfer: CustomAutoRooterGuard<Vec<*mut JSObject>>,
) -> ErrorResult {
// Step 6-7.
let data = structuredclone::write(cx, message, transfer)?;
let data = structuredclone::write(cx, message, Some(transfer))?;
self.post_message(target_origin, data)
}

View file

@ -294,8 +294,6 @@ impl MessagePortMethods for MessagePort {
let mut rooted = CustomAutoRooter::new(
options
.transfer
.as_ref()
.unwrap_or(&Vec::with_capacity(0))
.iter()
.map(|js: &RootedTraceableBox<Heap<*mut JSObject>>| js.get())
.collect(),

View file

@ -141,8 +141,6 @@ impl ServiceWorkerMethods for ServiceWorker {
let mut rooted = CustomAutoRooter::new(
options
.transfer
.as_ref()
.unwrap_or(&Vec::with_capacity(0))
.iter()
.map(|js: &RootedTraceableBox<Heap<*mut JSObject>>| js.get())
.collect(),

View file

@ -21,7 +21,7 @@ dictionary BluetoothLEScanFilterInit {
dictionary RequestDeviceOptions {
sequence<BluetoothLEScanFilterInit> filters;
sequence<BluetoothServiceUUID> optionalServices /*= []*/;
sequence<BluetoothServiceUUID> optionalServices = [];
boolean acceptAllDevices = false;
};

View file

@ -8,7 +8,7 @@ dictionary BluetoothPermissionDescriptor : PermissionDescriptor {
DOMString deviceId;
// These match RequestDeviceOptions.
sequence<BluetoothLEScanFilterInit> filters;
sequence<BluetoothServiceUUID> optionalServices/* = []*/;
sequence<BluetoothServiceUUID> optionalServices = [];
boolean acceptAllDevices = false;
};

View file

@ -25,7 +25,7 @@ interface DissimilarOriginWindow : GlobalScope {
void close();
readonly attribute boolean closed;
[Throws] void postMessage(any message, USVString targetOrigin, optional sequence<object> transfer /*= []*/);
[Throws] void postMessage(any message, USVString targetOrigin, optional sequence<object> transfer = []);
[Throws] void postMessage(any message, optional WindowPostMessageOptions options = {});
attribute any opener;
void blur();

View file

@ -8,7 +8,7 @@
[Exposed=(Window,Worker)]
interface MessagePort : EventTarget {
[Throws] void postMessage(any message, sequence<object> transfer /*= []*/);
[Throws] void postMessage(any message, sequence<object> transfer);
[Throws] void postMessage(any message, optional PostMessageOptions options = {});
void start();
void close();
@ -19,5 +19,5 @@ interface MessagePort : EventTarget {
};
dictionary PostMessageOptions {
sequence<object> transfer;
sequence<object> transfer = [];
};

View file

@ -64,7 +64,7 @@
void cancelAnimationFrame(unsigned long handle);
[Throws]
void postMessage(any message, USVString targetOrigin, optional sequence<object> transfer /*= []*/);
void postMessage(any message, USVString targetOrigin, optional sequence<object> transfer = []);
[Throws]
void postMessage(any message, optional WindowPostMessageOptions options = {});
@ -175,7 +175,6 @@ partial interface Window {
readonly attribute unsigned long runningAnimationCount;
};
dictionary WindowPostMessageOptions {
dictionary WindowPostMessageOptions : PostMessageOptions {
USVString targetOrigin = "/";
sequence<object> transfer;
};

View file

@ -979,19 +979,13 @@ impl WindowMethods for Window {
cx: JSContext,
message: HandleValue,
target_origin: USVString,
mut transfer: CustomAutoRooterGuard<Option<Vec<*mut JSObject>>>,
transfer: CustomAutoRooterGuard<Vec<*mut JSObject>>,
) -> ErrorResult {
let incumbent = GlobalScope::incumbent().expect("no incumbent global?");
let source = incumbent.as_window();
let source_origin = source.Document().origin().immutable().clone();
if transfer.is_some() {
let mut rooted = CustomAutoRooter::new(transfer.take().unwrap());
let transfer = Some(CustomAutoRooterGuard::new(*cx, &mut rooted));
self.post_message_impl(&target_origin, source_origin, source, cx, message, transfer)
} else {
self.post_message_impl(&target_origin, source_origin, source, cx, message, None)
}
self.post_message_impl(&target_origin, source_origin, source, cx, message, transfer)
}
/// <https://html.spec.whatwg.org/multipage/#dom-messageport-postmessage>
@ -1003,14 +997,13 @@ impl WindowMethods for Window {
) -> ErrorResult {
let mut rooted = CustomAutoRooter::new(
options
.parent
.transfer
.as_ref()
.unwrap_or(&Vec::with_capacity(0))
.iter()
.map(|js: &RootedTraceableBox<Heap<*mut JSObject>>| js.get())
.collect(),
);
let transfer = Some(CustomAutoRooterGuard::new(*cx, &mut rooted));
let transfer = CustomAutoRooterGuard::new(*cx, &mut rooted);
let incumbent = GlobalScope::incumbent().expect("no incumbent global?");
let source = incumbent.as_window();
@ -1330,10 +1323,10 @@ impl Window {
source: &Window,
cx: JSContext,
message: HandleValue,
transfer: Option<CustomAutoRooterGuard<Vec<*mut JSObject>>>,
transfer: CustomAutoRooterGuard<Vec<*mut JSObject>>,
) -> ErrorResult {
// Step 1-2, 6-8.
let data = structuredclone::write(cx, message, transfer)?;
let data = structuredclone::write(cx, message, Some(transfer))?;
// Step 3-5.
let target_origin = match target_origin.0[..].as_ref() {

View file

@ -218,8 +218,6 @@ impl WorkerMethods for Worker {
let mut rooted = CustomAutoRooter::new(
options
.transfer
.as_ref()
.unwrap_or(&Vec::with_capacity(0))
.iter()
.map(|js: &RootedTraceableBox<Heap<*mut JSObject>>| js.get())
.collect(),