mirror of
https://github.com/servo/servo.git
synced 2025-08-09 07:25:35 +01:00
Update web-platform-tests to revision 8a2ceb5f18911302b7a5c1cd2791f4ab50ad4326
This commit is contained in:
parent
462c272380
commit
1f531f66ea
5377 changed files with 174916 additions and 84369 deletions
|
@ -1,12 +1,5 @@
|
|||
<!doctype html>
|
||||
<meta charset=utf-8>
|
||||
<title>DOMException constants</title>
|
||||
<link rel=help href="https://heycam.github.io/webidl/#es-DOMException-constructor-object">
|
||||
<link rel=help href="https://heycam.github.io/webidl/#es-DOMException-prototype-object">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
'use strict';
|
||||
|
||||
test(function() {
|
||||
// https://www.w3.org/Bugs/Public/show_bug.cgi?id=27732
|
||||
var constants = [
|
||||
|
@ -47,13 +40,12 @@ test(function() {
|
|||
assert_equals(object[name], i + 1, name)
|
||||
assert_own_property(object, name)
|
||||
var pd = Object.getOwnPropertyDescriptor(object, name)
|
||||
assert_false("get" in pd, "property has getter")
|
||||
assert_false("set" in pd, "property has setter")
|
||||
assert_false(pd.writable, "not writable")
|
||||
assert_false("get" in pd, "get")
|
||||
assert_false("set" in pd, "set")
|
||||
assert_false(pd.writable, "writable")
|
||||
assert_true(pd.enumerable, "enumerable")
|
||||
assert_false(pd.configurable, "not configurable")
|
||||
assert_false(pd.configurable, "configurable")
|
||||
}, "Constant " + name + " on " + description)
|
||||
})
|
||||
})
|
||||
})
|
||||
</script>
|
|
@ -0,0 +1,32 @@
|
|||
test(function() {
|
||||
assert_own_property(self, "DOMException", "property of global");
|
||||
|
||||
var desc = Object.getOwnPropertyDescriptor(self, "DOMException");
|
||||
assert_false("get" in desc, "get");
|
||||
assert_false("set" in desc, "set");
|
||||
assert_true(desc.writable, "writable");
|
||||
assert_false(desc.enumerable, "enumerable");
|
||||
assert_true(desc.configurable, "configurable");
|
||||
}, "existence and property descriptor of DOMException");
|
||||
|
||||
test(function() {
|
||||
assert_own_property(self.DOMException, "prototype", "prototype property");
|
||||
|
||||
var desc = Object.getOwnPropertyDescriptor(self.DOMException, "prototype");
|
||||
assert_false("get" in desc, "get");
|
||||
assert_false("set" in desc, "set");
|
||||
assert_false(desc.writable, "writable");
|
||||
assert_false(desc.enumerable, "enumerable");
|
||||
assert_false(desc.configurable, "configurable");
|
||||
}, "existence and property descriptor of DOMException.prototype");
|
||||
|
||||
test(function() {
|
||||
assert_own_property(self.DOMException.prototype, "constructor", "property of prototype");
|
||||
var desc = Object.getOwnPropertyDescriptor(self.DOMException.prototype, "constructor");
|
||||
assert_false("get" in desc, "get");
|
||||
assert_false("set" in desc, "set");
|
||||
assert_true(desc.writable, "writable");
|
||||
assert_false(desc.enumerable, "enumerable");
|
||||
assert_true(desc.configurable, "configurable");
|
||||
assert_equals(self.DOMException.prototype.constructor, self.DOMException, "equality with actual constructor");
|
||||
}, "existence and property descriptor of DOMException.prototype.constructor");
|
|
@ -1,13 +1,5 @@
|
|||
<!doctype html>
|
||||
<meta charset=utf-8>
|
||||
<title>DOMException constructor</title>
|
||||
<link rel=help href="https://heycam.github.io/webidl/#es-DOMException-constructor-object">
|
||||
<link rel=help href="https://people.mozilla.org/~jorendorff/es6-draft.html#sec-error.prototype.message">
|
||||
<link rel=help href="https://people.mozilla.org/~jorendorff/es6-draft.html#sec-error.prototype.name">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
'use strict';
|
||||
|
||||
test(function() {
|
||||
var ex = new DOMException();
|
||||
assert_equals(ex.name, "Error",
|
||||
|
@ -22,7 +14,7 @@ test(function() {
|
|||
"The name property should be inherited");
|
||||
assert_false(ex.hasOwnProperty("message"),
|
||||
"The message property should be inherited");
|
||||
}, 'new DOMException(): own-ness');
|
||||
}, 'new DOMException(): inherited-ness');
|
||||
|
||||
test(function() {
|
||||
var ex = new DOMException(null);
|
||||
|
@ -46,7 +38,7 @@ test(function() {
|
|||
"The name property should be inherited");
|
||||
assert_false(ex.hasOwnProperty("message"),
|
||||
"The message property should be inherited");
|
||||
}, 'new DOMException(undefined): own-ness');
|
||||
}, 'new DOMException(undefined): inherited-ness');
|
||||
|
||||
test(function() {
|
||||
var ex = new DOMException("foo");
|
||||
|
@ -59,9 +51,9 @@ test(function() {
|
|||
var ex = new DOMException("foo");
|
||||
assert_false(ex.hasOwnProperty("name"),
|
||||
"The name property should be inherited");
|
||||
assert_true(ex.hasOwnProperty("message"),
|
||||
"The message property should be own");
|
||||
}, 'new DOMException("foo"): own-ness');
|
||||
assert_false(ex.hasOwnProperty("message"),
|
||||
"The message property should be inherited");
|
||||
}, 'new DOMException("foo"): inherited-ness');
|
||||
|
||||
test(function() {
|
||||
var ex = new DOMException("bar", undefined);
|
||||
|
@ -80,11 +72,11 @@ test(function() {
|
|||
|
||||
test(function() {
|
||||
var ex = new DOMException("bar", "NotSupportedError");
|
||||
assert_true(ex.hasOwnProperty("name"),
|
||||
"The name property should be own");
|
||||
assert_true(ex.hasOwnProperty("message"),
|
||||
"The message property should be own");
|
||||
}, 'new DOMException("bar", "NotSupportedError"): own-ness');
|
||||
assert_false(ex.hasOwnProperty("name"),
|
||||
"The name property should be inherited");
|
||||
assert_false(ex.hasOwnProperty("message"),
|
||||
"The message property should be inherited");
|
||||
}, 'new DOMException("bar", "NotSupportedError"): inherited-ness');
|
||||
|
||||
test(function() {
|
||||
var ex = new DOMException("bar", "foo");
|
||||
|
@ -127,13 +119,3 @@ test(function() {
|
|||
"Should have matching legacy code from error names table");
|
||||
},'new DOMexception("msg", "' + test_case.name + '")');
|
||||
});
|
||||
|
||||
test(function() {
|
||||
var ex = new DOMException("bar", "UnknownError");
|
||||
assert_equals(ex.name, "UnknownError", "Should be using the passed-in name");
|
||||
assert_equals(ex.message, "bar", "Should still be using passed-in message");
|
||||
assert_equals(ex.code, 0,
|
||||
"Should have 0 for code for a name in the exception names table with no legacy code");
|
||||
}, 'new DOMException("bar", "UnknownError")');
|
||||
|
||||
</script>
|
|
@ -0,0 +1,120 @@
|
|||
"use strict";
|
||||
|
||||
test(() => {
|
||||
assert_throws(new TypeError(), () => DOMException());
|
||||
}, "Cannot construct without new");
|
||||
|
||||
test(() => {
|
||||
assert_equals(Object.getPrototypeOf(DOMException.prototype), Error.prototype);
|
||||
}, "inherits from Error: prototype-side");
|
||||
|
||||
test(() => {
|
||||
assert_equals(Object.getPrototypeOf(DOMException), Function.prototype);
|
||||
}, "does not inherit from Error: class-side");
|
||||
|
||||
test(() => {
|
||||
const e = new DOMException("message", "name");
|
||||
assert_false(e.hasOwnProperty("message"), "property is not own");
|
||||
|
||||
const propDesc = Object.getOwnPropertyDescriptor(DOMException.prototype, "message");
|
||||
assert_equals(typeof propDesc.get, "function", "property descriptor is a getter");
|
||||
assert_equals(propDesc.set, undefined, "property descriptor is not a setter");
|
||||
assert_true(propDesc.enumerable, "property descriptor enumerable");
|
||||
assert_true(propDesc.configurable, "property descriptor configurable");
|
||||
}, "message property descriptor");
|
||||
|
||||
test(() => {
|
||||
const getter = Object.getOwnPropertyDescriptor(DOMException.prototype, "message").get;
|
||||
|
||||
assert_throws(new TypeError(), () => getter.apply({}));
|
||||
}, "message getter performs brand checks (i.e. is not [LenientThis]");
|
||||
|
||||
test(() => {
|
||||
const e = new DOMException("message", "name");
|
||||
assert_false(e.hasOwnProperty("name"), "property is not own");
|
||||
|
||||
const propDesc = Object.getOwnPropertyDescriptor(DOMException.prototype, "name");
|
||||
assert_equals(typeof propDesc.get, "function", "property descriptor is a getter");
|
||||
assert_equals(propDesc.set, undefined, "property descriptor is not a setter");
|
||||
assert_true(propDesc.enumerable, "property descriptor enumerable");
|
||||
assert_true(propDesc.configurable, "property descriptor configurable");
|
||||
}, "name property descriptor");
|
||||
|
||||
test(() => {
|
||||
const getter = Object.getOwnPropertyDescriptor(DOMException.prototype, "name").get;
|
||||
|
||||
assert_throws(new TypeError(), () => getter.apply({}));
|
||||
}, "name getter performs brand checks (i.e. is not [LenientThis]");
|
||||
|
||||
test(() => {
|
||||
const e = new DOMException("message", "name");
|
||||
assert_false(e.hasOwnProperty("code"), "property is not own");
|
||||
|
||||
const propDesc = Object.getOwnPropertyDescriptor(DOMException.prototype, "code");
|
||||
assert_equals(typeof propDesc.get, "function", "property descriptor is a getter");
|
||||
assert_equals(propDesc.set, undefined, "property descriptor is not a setter");
|
||||
assert_true(propDesc.enumerable, "property descriptor enumerable");
|
||||
assert_true(propDesc.configurable, "property descriptor configurable");
|
||||
}, "code property descriptor");
|
||||
|
||||
test(() => {
|
||||
const getter = Object.getOwnPropertyDescriptor(DOMException.prototype, "code").get;
|
||||
|
||||
assert_throws(new TypeError(), () => getter.apply({}));
|
||||
}, "code getter performs brand checks (i.e. is not [LenientThis]");
|
||||
|
||||
test(() => {
|
||||
const e = new DOMException("message", "InvalidCharacterError");
|
||||
assert_equals(e.code, 5, "Initially the code is set to 5");
|
||||
|
||||
Object.defineProperty(e, "name", {
|
||||
value: "WrongDocumentError"
|
||||
});
|
||||
|
||||
assert_equals(e.code, 5, "The code is still set to 5");
|
||||
}, "code property is not affected by shadowing the name property");
|
||||
|
||||
test(() => {
|
||||
const e = new DOMException("message", "name");
|
||||
assert_equals(Object.prototype.toString.call(e), "[object DOMException]");
|
||||
}, "Object.prototype.toString behavior is like other interfaces");
|
||||
|
||||
test(() => {
|
||||
const e = new DOMException("message", "name");
|
||||
assert_false(e.hasOwnProperty("toString"), "toString must not exist on the instance");
|
||||
assert_false(DOMException.prototype.hasOwnProperty("toString"), "toString must not exist on DOMException.prototype");
|
||||
assert_equals(typeof e.toString, "function", "toString must still exist (via Error.prototype)");
|
||||
}, "Inherits its toString() from Error.prototype");
|
||||
|
||||
test(() => {
|
||||
const e = new DOMException("message", "name");
|
||||
assert_equals(e.toString(), "name: message",
|
||||
"The default Error.prototype.toString() behavior must work on supplied name and message");
|
||||
|
||||
Object.defineProperty(e, "name", { value: "new name" });
|
||||
Object.defineProperty(e, "message", { value: "new message" });
|
||||
assert_equals(e.toString(), "new name: new message",
|
||||
"The default Error.prototype.toString() behavior must work on shadowed names and messages");
|
||||
}, "toString() behavior from Error.prototype applies as expected");
|
||||
|
||||
test(() => {
|
||||
assert_throws(new TypeError(), () => DOMException.prototype.toString());
|
||||
}, "DOMException.prototype.toString() applied to DOMException.prototype throws because of name/message brand checks");
|
||||
|
||||
test(() => {
|
||||
let stackOnNormalErrors;
|
||||
try {
|
||||
throw new Error("normal error");
|
||||
} catch (e) {
|
||||
stackOnNormalErrors = e.stack;
|
||||
}
|
||||
|
||||
let stackOnDOMException;
|
||||
try {
|
||||
throw new DOMException("message", "name");
|
||||
} catch (e) {
|
||||
stackOnDOMException = e.stack;
|
||||
}
|
||||
|
||||
assert_equals(typeof stackOnDOMException, typeof stackOnNormalErrors, "The typeof values must match");
|
||||
}, "If the implementation has a stack property on normal errors, it also does on DOMExceptions");
|
|
@ -1,11 +0,0 @@
|
|||
<!doctype html>
|
||||
<meta charset=utf-8>
|
||||
<title>DOMException constructor and prototype object</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src=constructor-object.js></script>
|
||||
<div id="log"></div>
|
||||
<script>
|
||||
setup({ explicit_done: true })
|
||||
run_test()
|
||||
</script>
|
|
@ -1,111 +0,0 @@
|
|||
function run_test() {
|
||||
test(function() {
|
||||
// "There MUST exist a property on the ECMAScript global object whose
|
||||
// name is “DOMException” and value is an object called the
|
||||
// DOMException constructor object, which provides access to legacy
|
||||
// DOMException code constants. The property has the attributes
|
||||
// { [[Writable]]: true, [[Enumerable]]: false,
|
||||
// [[Configurable]]: true }."
|
||||
assert_own_property(self, "DOMException",
|
||||
"self does not have own property \"DOMException\"");
|
||||
var desc = Object.getOwnPropertyDescriptor(self, "DOMException");
|
||||
assert_false("get" in desc, "self's property \"DOMException\" has getter");
|
||||
assert_false("set" in desc, "self's property \"DOMException\" has setter");
|
||||
assert_true(desc.writable, "self's property \"DOMException\" is not writable");
|
||||
assert_false(desc.enumerable, "self's property \"DOMException\" is enumerable");
|
||||
assert_true(desc.configurable, "self's property \"DOMException\" is not configurable");
|
||||
|
||||
// "The DOMException constructor object MUST be a function object but
|
||||
// with a [[Prototype]] value of %Error% ([ECMA-262], section 6.1.7.4)."
|
||||
assert_equals(Object.getPrototypeOf(self.DOMException), Error,
|
||||
"prototype of self's property \"DOMException\" is not Error");
|
||||
|
||||
// "Its [[Get]] internal property is set as described in ECMA-262
|
||||
// section 9.1.8."
|
||||
// Not much to test for this.
|
||||
// "Its [[Construct]] internal property is set as described in ECMA-262
|
||||
// section 19.2.2.3."
|
||||
// "Its @@hasInstance property is set as described in ECMA-262 section
|
||||
// 19.2.3.8, unless otherwise specified."
|
||||
|
||||
// String() returns something implementation-dependent, because it
|
||||
// calls Function#toString.
|
||||
assert_class_string(self.DOMException, "Function",
|
||||
"class string of DOMException");
|
||||
|
||||
// "For every legacy code listed in the error names table, there MUST
|
||||
// be a property on the DOMException constructor object whose name and
|
||||
// value are as indicated in the table. The property has attributes
|
||||
// { [[Writable]]: false, [[Enumerable]]: true,
|
||||
// [[Configurable]]: false }."
|
||||
// See DOMException-constants.html.
|
||||
}, "existence and properties of DOMException");
|
||||
|
||||
test(function() {
|
||||
assert_own_property(self, "DOMException",
|
||||
"self does not have own property \"DOMException\"");
|
||||
|
||||
// "The DOMException constructor object MUST also have a property named
|
||||
// “prototype” with attributes { [[Writable]]: false,
|
||||
// [[Enumerable]]: false, [[Configurable]]: false } whose value is an
|
||||
// object called the DOMException prototype object. This object also
|
||||
// provides access to the legacy code values."
|
||||
assert_own_property(self.DOMException, "prototype",
|
||||
'exception "DOMException" does not have own property "prototype"');
|
||||
var desc = Object.getOwnPropertyDescriptor(self.DOMException, "prototype");
|
||||
assert_false("get" in desc, "DOMException.prototype has getter");
|
||||
assert_false("set" in desc, "DOMException.prototype has setter");
|
||||
assert_false(desc.writable, "DOMException.prototype is writable");
|
||||
assert_false(desc.enumerable, "DOMException.prototype is enumerable");
|
||||
assert_false(desc.configurable, "DOMException.prototype is configurable");
|
||||
|
||||
// "The DOMException prototype object MUST have an internal
|
||||
// [[Prototype]] property whose value is %ErrorPrototype% ([ECMA-262],
|
||||
// section 6.1.7.4)."
|
||||
assert_own_property(self, "Error",
|
||||
'should inherit from Error, but self has no such property');
|
||||
assert_own_property(self.Error, "prototype",
|
||||
'should inherit from Error, but that object has no "prototype" property');
|
||||
assert_equals(Object.getPrototypeOf(self.DOMException.prototype),
|
||||
self.Error.prototype,
|
||||
'prototype of DOMException.prototype is not Error.prototype');
|
||||
|
||||
// "The class string of the DOMException prototype object is
|
||||
// “DOMExceptionPrototype”."
|
||||
assert_class_string(self.DOMException.prototype, "DOMExceptionPrototype",
|
||||
"class string of DOMException.prototype");
|
||||
}, "existence and properties of DOMException.prototype");
|
||||
|
||||
test(function() {
|
||||
assert_false(self.DOMException.prototype.hasOwnProperty("name"),
|
||||
"DOMException.prototype should not have an own \"name\" " +
|
||||
"property.");
|
||||
assert_false(self.DOMException.prototype.hasOwnProperty("code"),
|
||||
"DOMException.prototype should not have an own \"name\" " +
|
||||
"property.");
|
||||
}, "existence of name and code properties on DOMException.prototype");
|
||||
|
||||
test(function() {
|
||||
assert_own_property(self, "DOMException",
|
||||
"self does not have own property \"DOMException\"");
|
||||
assert_own_property(self.DOMException, "prototype",
|
||||
'interface "DOMException" does not have own property "prototype"');
|
||||
|
||||
// "There MUST be a property named “constructor” on the DOMException
|
||||
// prototype object with attributes { [[Writable]]: true,
|
||||
// [[Enumerable]]: false, [[Configurable]]: true } and whose value is
|
||||
// the DOMException constructor object."
|
||||
assert_own_property(self.DOMException.prototype, "constructor",
|
||||
"DOMException" + '.prototype does not have own property "constructor"');
|
||||
var desc = Object.getOwnPropertyDescriptor(self.DOMException.prototype, "constructor");
|
||||
assert_false("get" in desc, "DOMException.prototype.constructor has getter");
|
||||
assert_false("set" in desc, "DOMException.prototype.constructor has setter");
|
||||
assert_true(desc.writable, "DOMException.prototype.constructor is not writable");
|
||||
assert_false(desc.enumerable, "DOMException.prototype.constructor is enumerable");
|
||||
assert_true(desc.configurable, "DOMException.prototype.constructor in not configurable");
|
||||
assert_equals(self.DOMException.prototype.constructor, self.DOMException,
|
||||
"DOMException.prototype.constructor is not the same object as DOMException");
|
||||
}, "existence and properties of exception interface prototype object's \"constructor\" property");
|
||||
|
||||
done();
|
||||
}
|
|
@ -1,3 +0,0 @@
|
|||
importScripts("/resources/testharness.js")
|
||||
importScripts("constructor-object.js")
|
||||
run_test();
|
|
@ -20,90 +20,31 @@
|
|||
setup({explicit_done: true});
|
||||
|
||||
function testException(exception, global, desc) {
|
||||
// https://heycam.github.io/webidl/#es-exception-objects
|
||||
// (as of 2015-01-03): "The value of the internal [[Prototype]] property of a
|
||||
// DOMException object MUST be the DOMException prototype object from the
|
||||
// global environment the exception object is associated with."
|
||||
test(function() {
|
||||
assert_equals(global.Object.getPrototypeOf(exception),
|
||||
global.DOMException.prototype);
|
||||
}, desc + "Object.getPrototypeOf(exception) === DOMException.prototype");
|
||||
|
||||
|
||||
// https://heycam.github.io/webidl/#es-creating-throwing-exceptions
|
||||
// (as of 2015-01-03): "Call the [[DefineOwnProperty]] internal method of /O/
|
||||
// passing “name”, Property Descriptor { [[Value]]: /N/, [[Writable]]: true,
|
||||
// [[Enumerable]]: true, [[Configurable]]: true }, and false as arguments."
|
||||
test(function() {
|
||||
assert_true(exception.hasOwnProperty("name"));
|
||||
assert_false(exception.hasOwnProperty("name"));
|
||||
}, desc + "exception.hasOwnProperty(\"name\")");
|
||||
test(function() {
|
||||
assert_false(exception.hasOwnProperty("message"));
|
||||
}, desc + "exception.hasOwnProperty(\"message\")");
|
||||
|
||||
test(function() {
|
||||
assert_equals(exception.name, "HierarchyRequestError");
|
||||
}, desc + "exception.name === \"HierarchyRequestError\"");
|
||||
|
||||
test(function() {
|
||||
var desc = global.Object.getOwnPropertyDescriptor(exception, "name");
|
||||
assert_true(desc.writable, "must be writable");
|
||||
assert_true(desc.enumerable, "must be enumerable");
|
||||
assert_true(desc.configurable, "must be configurable");
|
||||
}, desc + "Object.getOwnPropertyDescriptor(exception, \"name\")");
|
||||
|
||||
|
||||
// https://heycam.github.io/webidl/#es-creating-throwing-exceptions
|
||||
// (as of 2015-01-03): "If the optional user agent-defined message /M/ was
|
||||
// specified, then this list has a single element whose value is the result
|
||||
// of converting /M/ to a String value. Otherwise, the list is empty."
|
||||
//
|
||||
// https://heycam.github.io/webidl/#es-DOMException-constructor-object
|
||||
// (as of 2015-01-03): "Call the [[DefineOwnProperty]] internal method of /O/
|
||||
// passing “message”, Property Descriptor { [[Value]]: /S/,
|
||||
// [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true }, and
|
||||
// false as arguments."
|
||||
test(function() {
|
||||
if (exception.hasOwnProperty("message")) {
|
||||
var desc = global.Object.getOwnPropertyDescriptor(exception, "message");
|
||||
assert_true(desc.writable, "must be writable");
|
||||
assert_false(desc.enumerable, "must not be enumerable");
|
||||
assert_true(desc.configurable, "must be configurable");
|
||||
}
|
||||
}, desc + "Object.getOwnPropertyDescriptor(exception, \"message\")");
|
||||
|
||||
test(function() {
|
||||
if (exception.hasOwnProperty("message")) {
|
||||
// Can't test anything more specific, since it's implementation-defined :(
|
||||
assert_equals(typeof exception.message, "string");
|
||||
} else {
|
||||
// Error.prototype.message
|
||||
assert_equals(exception.message, "");
|
||||
}
|
||||
}, desc + "typeof exception.message === \"string\"");
|
||||
|
||||
|
||||
// https://heycam.github.io/webidl/#es-exception-objects
|
||||
// (as of 2015-01-03): "The class string of a DOMException object MUST be
|
||||
// “DOMException”."
|
||||
test(function() {
|
||||
assert_equals(global.Object.prototype.toString.call(exception),
|
||||
"[object DOMException]");
|
||||
}, desc + "Object.prototype.toString.call(exception) === \"[object DOMException]\"");
|
||||
|
||||
|
||||
// https://heycam.github.io/webidl/#es-creating-throwing-exceptions
|
||||
// (as of 2015-01-03): "Call the [[DefineOwnProperty]] internal method of /O/
|
||||
// passing “code”, Property Descriptor { [[Value]]: /code/,
|
||||
// [[Writable]]: true, [[Enumerable]]: true, [[Configurable]]: true }, and
|
||||
// false as arguments."
|
||||
test(function() {
|
||||
assert_equals(exception.code, global.DOMException.HIERARCHY_REQUEST_ERR);
|
||||
}, desc + "exception.code === DOMException.HIERARCHY_REQUEST_ERR");
|
||||
|
||||
test(function() {
|
||||
var desc = global.Object.getOwnPropertyDescriptor(exception, "name");
|
||||
assert_true(desc.writable, "must be writable");
|
||||
assert_true(desc.enumerable, "must be enumerable");
|
||||
assert_true(desc.configurable, "must be configurable");
|
||||
}, desc + "Object.getOwnPropertyDescriptor(exception, \"code\")");
|
||||
assert_equals(global.Object.prototype.toString.call(exception),
|
||||
"[object DOMException]");
|
||||
}, desc + "Object.prototype.toString.call(exception) === \"[object DOMException]\"");
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,191 @@
|
|||
<!DOCTYPE html>
|
||||
<meta charset="utf-8">
|
||||
<title>Legacy platform objects</title>
|
||||
<link rel="help" href="https://heycam.github.io/webidl/#es-legacy-platform-objects">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script>
|
||||
function assert_prop_desc_equals(object, property_key, expected) {
|
||||
let actual = Object.getOwnPropertyDescriptor(object, property_key);
|
||||
if (expected === undefined) {
|
||||
assert_equals(
|
||||
actual, undefined,
|
||||
"(assert_prop_desc_equals: no property descriptor expected)");
|
||||
return;
|
||||
}
|
||||
for (p in actual) {
|
||||
assert_true(
|
||||
expected.hasOwnProperty(p),
|
||||
"(assert_prop_desc_equals: property '" + p + "' is not expected)");
|
||||
assert_equals(
|
||||
actual[p], expected[p],
|
||||
"(assert_prop_desc_equals: property '" + p + "')");
|
||||
}
|
||||
for (p in expected) {
|
||||
assert_true(
|
||||
actual.hasOwnProperty(p),
|
||||
"(assert_prop_desc_equals: expected property '" + p + "' missing)");
|
||||
}
|
||||
}
|
||||
|
||||
// https://heycam.github.io/webidl/#legacy-platform-object-getownproperty
|
||||
// https://heycam.github.io/webidl/#LegacyPlatformObjectGetOwnProperty
|
||||
|
||||
test(function() {
|
||||
// DOMTokenList has an indexed property getter, no indexed property setter
|
||||
// and no named property handlers.
|
||||
let div = document.createElement("div");
|
||||
div.classList.add("baz", "quux");
|
||||
const domTokenList = div.classList;
|
||||
assert_prop_desc_equals(
|
||||
domTokenList, "1",
|
||||
{value: "quux", writable: false, enumerable: true, configurable: true},
|
||||
"[[GetOwnProperty]] for indexed properties returns the right descriptor");
|
||||
assert_prop_desc_equals(
|
||||
domTokenList, "42", undefined,
|
||||
"[[GetOwnProperty]] with invalid index returns undefined");
|
||||
assert_array_equals(Object.keys(domTokenList), ["0", "1"]);
|
||||
assert_array_equals(Object.values(domTokenList), ["baz", "quux"]);
|
||||
|
||||
// getElementsByTagName() returns an HTMLCollection.
|
||||
// HTMLCollection has indexed and named property getters, no setters. Its IDL
|
||||
// interface declaration has [LegacyUnenumerableNamedProperties] so its named
|
||||
// properties are not enumerable.
|
||||
let span1 = document.createElement("span");
|
||||
span1.id = "foo";
|
||||
let span2 = document.createElement("span");
|
||||
span2.id = "bar";
|
||||
document.head.appendChild(span1);
|
||||
document.head.appendChild(span2);
|
||||
const elementList = document.getElementsByTagName("span");
|
||||
assert_prop_desc_equals(
|
||||
elementList, "foo",
|
||||
{value: span1, writable: false, enumerable: false, configurable: true},
|
||||
"[[GetOwnProperty]] for named properties returns the right descriptor");
|
||||
assert_prop_desc_equals(
|
||||
elementList, "1",
|
||||
{value: span2, writable: false, enumerable: true, configurable: true},
|
||||
"[[GetOwnProperty]] for indexed properties returns the right descriptor");
|
||||
assert_prop_desc_equals(
|
||||
elementList, "unknown", undefined,
|
||||
"[[GetOwnProperty]] with invalid property name returns undefined");
|
||||
assert_array_equals(Object.keys(elementList), ["0", "1"]);
|
||||
assert_array_equals(Object.values(elementList), [span1, span2]);
|
||||
}, "[[GetOwnProperty]] with getters and no setters");
|
||||
|
||||
test(function() {
|
||||
// DOMStringMap supports named property getters and setters, but not indexed
|
||||
// properties.
|
||||
let span = document.createElement("span");
|
||||
span.dataset.foo = "bar";
|
||||
assert_prop_desc_equals(
|
||||
span.dataset, "foo",
|
||||
{value: "bar", writable: true, enumerable: true, configurable: true},
|
||||
"[[GetOwnProperty]] for named properties returns the right descriptor");
|
||||
assert_prop_desc_equals(
|
||||
span.dataset, "unknown", undefined,
|
||||
"[[GetOwnProperty]] with invalid property name returns undefined");
|
||||
assert_array_equals(Object.keys(span.dataset), ["foo"]);
|
||||
assert_array_equals(Object.values(span.dataset), ["bar"]);
|
||||
}, "[[GetOwnProperty]] with named property getters and setters");
|
||||
|
||||
test(function() {
|
||||
// HTMLSelectElement has indexed property getters and setters, but no support
|
||||
// for named properties.
|
||||
let selectElement = document.createElement("select");
|
||||
assert_prop_desc_equals(
|
||||
selectElement, "0", undefined,
|
||||
"[[GetOwnProperty]] with invalid property index returns undefined");
|
||||
let optionElement = document.createElement("option");
|
||||
selectElement.appendChild(optionElement);
|
||||
assert_prop_desc_equals(
|
||||
selectElement, "0",
|
||||
{value: optionElement, writable: true, enumerable: true, configurable: true},
|
||||
"[[GetOwnProperty]] for indexed properties returns the right descriptor");
|
||||
assert_array_equals(Object.keys(selectElement), ["0"]);
|
||||
assert_array_equals(Object.values(selectElement), [optionElement]);
|
||||
}, "[[GetOwnProperty]] with indexed property getters and setters");
|
||||
|
||||
// https://heycam.github.io/webidl/#legacy-platform-object-defineownproperty
|
||||
// 3.9.3. [[DefineOwnProperty]]
|
||||
|
||||
test(function() {
|
||||
let span = document.createElement("span");
|
||||
span.className = "foo";
|
||||
// DOMTokenList supports an indexed property getter but not a setter.
|
||||
let domTokenList = span.classList;
|
||||
// Confirm the test settings.
|
||||
assert_equals(domTokenList.length, 1);
|
||||
assert_prop_desc_equals(domTokenList, "0",
|
||||
{value: "foo", writable: false, enumerable: true,
|
||||
configurable: true});
|
||||
assert_prop_desc_equals(domTokenList, "1", undefined);
|
||||
// Actual test
|
||||
assert_throws(new TypeError(), () =>
|
||||
Object.defineProperty(domTokenList, "0", {value: true, writable: true}));
|
||||
assert_throws(new TypeError(), () =>
|
||||
Object.defineProperty(domTokenList, "1", {value: true, writable: true}));
|
||||
assert_throws(new TypeError(), () =>
|
||||
Object.defineProperty(domTokenList, "0", {get: () => {}}));
|
||||
assert_throws(new TypeError(), () =>
|
||||
Object.defineProperty(domTokenList, "0", {set: () => {}}));
|
||||
assert_throws(new TypeError(), () =>
|
||||
Object.defineProperty(domTokenList, "1", {get: () => {}}));
|
||||
assert_throws(new TypeError(), () =>
|
||||
Object.defineProperty(domTokenList, "1", {set: () => {}}));
|
||||
assert_equals(domTokenList[0], "foo");
|
||||
assert_equals(domTokenList[1], undefined);
|
||||
domTokenList[0] = "bar";
|
||||
domTokenList[1] = "bar";
|
||||
assert_equals(domTokenList[0], "foo");
|
||||
assert_equals(domTokenList[1], undefined);
|
||||
assert_throws(new TypeError(), () => {
|
||||
"use strict";
|
||||
domTokenList[0] = "bar";
|
||||
});
|
||||
assert_throws(new TypeError(), () => {
|
||||
"use strict";
|
||||
domTokenList[1] = "bar";
|
||||
});
|
||||
// Nothing must change after all.
|
||||
assert_equals(domTokenList.length, 1);
|
||||
assert_prop_desc_equals(domTokenList, "0",
|
||||
{value: "foo", writable: false, enumerable: true,
|
||||
configurable: true});
|
||||
assert_prop_desc_equals(domTokenList, "1", undefined);
|
||||
}, "Test [[DefineOwnProperty]] with no indexed property setter support.");
|
||||
|
||||
test(function() {
|
||||
// HTMLSelectElement supports an indexed property setter.
|
||||
let select = document.createElement("select");
|
||||
let option0 = document.createElement("option");
|
||||
let option1 = document.createElement("option");
|
||||
// Confirm the test settings.
|
||||
assert_equals(select.length, 0);
|
||||
assert_prop_desc_equals(select, "0", undefined);
|
||||
// Try to define an accessor property with non supported property index.
|
||||
assert_throws(new TypeError(), () =>
|
||||
Object.defineProperty(select, "0", {get: () => {}}));
|
||||
assert_throws(new TypeError(), () =>
|
||||
Object.defineProperty(select, "0", {set: () => {}}));
|
||||
assert_prop_desc_equals(select, "0", undefined);
|
||||
// writable, enumerable, configurable will be ignored.
|
||||
Object.defineProperty(select, "0", {value: option0, writable: false,
|
||||
enumerable: false, configurable: false});
|
||||
assert_prop_desc_equals(select, "0",
|
||||
{value: option0, writable: true, enumerable: true,
|
||||
configurable: true});
|
||||
select[1] = option1;
|
||||
assert_prop_desc_equals(select, "1",
|
||||
{value: option1, writable: true, enumerable: true,
|
||||
configurable: true});
|
||||
// Try to define an accessor property with a supported property index.
|
||||
assert_throws(new TypeError(), () =>
|
||||
Object.defineProperty(select, "0", {get: () => {}}));
|
||||
assert_throws(new TypeError(), () =>
|
||||
Object.defineProperty(select, "0", {set: () => {}}));
|
||||
assert_prop_desc_equals(select, "0",
|
||||
{value: option0, writable: true, enumerable: true,
|
||||
configurable: true});
|
||||
}, "Test [[DefineOwnProperty]] with indexed property setter support.");
|
||||
</script>
|
Loading…
Add table
Add a link
Reference in a new issue