https://bugs.webkit.org/show_bug.cgi?id=149263
<rdar://problem/
22545600>
Reviewed by Ryosuke Niwa.
LayoutTests/imported/w3c:
Rebaseline several W3C tests now that more NodeIterator / TreeWalker
checks are passing.
* web-platform-tests/dom/traversal/NodeIterator-expected.txt:
* web-platform-tests/dom/traversal/TreeWalker-basic-expected.txt:
Source/WebCore:
Add support for default parameter values to our Web IDL parser and JS
bindings generator. This allows the bindings to convert undefined to
the parameter's default value for optional parameters:
https://heycam.github.io/webidl/#dfn-optional-argument-default-value
Previously, our bindings generator would just convert undefined to
0 / false / "undefined" for optional parameters, depending on the
parameter type.
This patch uses the new default parameter support to fix a bug in
document.createNodeIterator() / document.createTreeWalker()'s handling
of the whatToShow parameter:
https://dom.spec.whatwg.org/#document
WebKit currently was undefined to 0 in this case, even though it should
use the parameter's default value: OxFFFFFFFF.
I am planning to go through other optional parameters in a follow-up
patch and add default values where needed.
No new tests, already covered by existing layout tests and
added bindings tests coverage.
* bindings/scripts/CodeGeneratorJS.pm:
(GenerateParametersCheck):
* bindings/scripts/IDLParser.pm:
(parseOptionalOrRequiredArgument):
* bindings/scripts/test/GObject/WebKitDOMTestObj.cpp:
(webkit_dom_test_obj_method_with_optional_arg_and_default_value):
(webkit_dom_test_obj_method_with_optional_string_and_default_value):
* bindings/scripts/test/GObject/WebKitDOMTestObj.h:
* bindings/scripts/test/JS/JSTestObj.cpp:
(WebCore::jsTestObjPrototypeFunctionMethodWithOptionalArgAndDefaultValue):
(WebCore::jsTestObjPrototypeFunctionMethodWithOptionalStringAndDefaultValue):
* bindings/scripts/test/ObjC/DOMTestObj.h:
* bindings/scripts/test/ObjC/DOMTestObj.mm:
(-[DOMTestObj methodWithOptionalArgAndDefaultValue:]):
(-[DOMTestObj methodWithOptionalStringAndDefaultValue:]):
* bindings/scripts/test/TestObj.idl:
* dom/Document.idl:
LayoutTests:
Rebaseline several NodeIterator / TreeWalker tests now that more checks
are passing.
* fast/dom/createNodeIterator-parameters-expected.txt:
* fast/dom/createTreeWalker-parameters-expected.txt:
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@189957
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2015-09-17 Chris Dumez <cdumez@apple.com>
+
+ [WebIDL] Add support for default parameter values
+ https://bugs.webkit.org/show_bug.cgi?id=149263
+ <rdar://problem/22545600>
+
+ Reviewed by Ryosuke Niwa.
+
+ Rebaseline several NodeIterator / TreeWalker tests now that more checks
+ are passing.
+
+ * fast/dom/createNodeIterator-parameters-expected.txt:
+ * fast/dom/createTreeWalker-parameters-expected.txt:
+
2015-09-17 Saam barati <sbarati@apple.com>
add a regress test for richards with try/catch.
iterator = document.createNodeIterator(document, undefined, undefined)
PASS iterator.root is document
PASS iterator.referenceNode is document
-FAIL iterator.whatToShow should be 4294967295. Was 0.
+PASS iterator.whatToShow is 0xFFFFFFFF
PASS iterator.filter is null
PASS iterator.pointerBeforeReferenceNode is true
PASS successfullyParsed is true
walker = document.createTreeWalker(document, undefined, undefined)
PASS walker.root is document
PASS walker.currentNode is document
-FAIL walker.whatToShow should be 4294967295. Was 0.
+PASS walker.whatToShow is 0xFFFFFFFF
PASS walker.filter is null
PASS successfullyParsed is true
+2015-09-17 Chris Dumez <cdumez@apple.com>
+
+ [WebIDL] Add support for default parameter values
+ https://bugs.webkit.org/show_bug.cgi?id=149263
+ <rdar://problem/22545600>
+
+ Reviewed by Ryosuke Niwa.
+
+ Rebaseline several W3C tests now that more NodeIterator / TreeWalker
+ checks are passing.
+
+ * web-platform-tests/dom/traversal/NodeIterator-expected.txt:
+ * web-platform-tests/dom/traversal/TreeWalker-basic-expected.txt:
+
2015-09-17 Zalan Bujtas <zalan@apple.com>
CSS WG multicol-1 tests failures with 1px differences due to baseline difference.
PASS detach() should be a no-op
PASS createNodeIterator() parameter defaults
PASS createNodeIterator() with null as arguments
-FAIL createNodeIterator() with undefined as arguments assert_equals: whatToShow expected 4294967295 but got 0
+PASS createNodeIterator() with undefined as arguments
PASS Propagate exception from filter function
PASS document.createNodeIterator(paras[0], 0, null)
PASS document.createNodeIterator(paras[0], 0, (function(node) { return true }))
PASS Construct a TreeWalker by document.createTreeWalker(root).
PASS Construct a TreeWalker by document.createTreeWalker(root, null, null).
-FAIL Construct a TreeWalker by document.createTreeWalker(root, undefined, undefined). assert_equals: whatToShow expected 4294967295 but got 0
+PASS Construct a TreeWalker by document.createTreeWalker(root, undefined, undefined).
PASS Give an invalid root node to document.createTreeWalker().
PASS Walk over nodes.
PASS Optional arguments to createTreeWalker should be optional (3 passed, null).
+2015-09-17 Chris Dumez <cdumez@apple.com>
+
+ [WebIDL] Add support for default parameter values
+ https://bugs.webkit.org/show_bug.cgi?id=149263
+ <rdar://problem/22545600>
+
+ Reviewed by Ryosuke Niwa.
+
+ Add support for default parameter values to our Web IDL parser and JS
+ bindings generator. This allows the bindings to convert undefined to
+ the parameter's default value for optional parameters:
+ https://heycam.github.io/webidl/#dfn-optional-argument-default-value
+
+ Previously, our bindings generator would just convert undefined to
+ 0 / false / "undefined" for optional parameters, depending on the
+ parameter type.
+
+ This patch uses the new default parameter support to fix a bug in
+ document.createNodeIterator() / document.createTreeWalker()'s handling
+ of the whatToShow parameter:
+ https://dom.spec.whatwg.org/#document
+
+ WebKit currently was undefined to 0 in this case, even though it should
+ use the parameter's default value: OxFFFFFFFF.
+
+ I am planning to go through other optional parameters in a follow-up
+ patch and add default values where needed.
+
+ No new tests, already covered by existing layout tests and
+ added bindings tests coverage.
+
+ * bindings/scripts/CodeGeneratorJS.pm:
+ (GenerateParametersCheck):
+ * bindings/scripts/IDLParser.pm:
+ (parseOptionalOrRequiredArgument):
+ * bindings/scripts/test/GObject/WebKitDOMTestObj.cpp:
+ (webkit_dom_test_obj_method_with_optional_arg_and_default_value):
+ (webkit_dom_test_obj_method_with_optional_string_and_default_value):
+ * bindings/scripts/test/GObject/WebKitDOMTestObj.h:
+ * bindings/scripts/test/JS/JSTestObj.cpp:
+ (WebCore::jsTestObjPrototypeFunctionMethodWithOptionalArgAndDefaultValue):
+ (WebCore::jsTestObjPrototypeFunctionMethodWithOptionalStringAndDefaultValue):
+ * bindings/scripts/test/ObjC/DOMTestObj.h:
+ * bindings/scripts/test/ObjC/DOMTestObj.mm:
+ (-[DOMTestObj methodWithOptionalArgAndDefaultValue:]):
+ (-[DOMTestObj methodWithOptionalStringAndDefaultValue:]):
+ * bindings/scripts/test/TestObj.idl:
+ * dom/Document.idl:
+
2015-09-17 Dean Jackson <dino@apple.com>
Multi-hop reference cycles not detected.
if ($optional && $defaultAttribute && $defaultAttribute eq "NullString") {
$outer = "exec->argument($argsIndex).isUndefined() ? String() : ";
$inner = "exec->uncheckedArgument($argsIndex)";
+ } elsif ($optional && $parameter->default) {
+ $outer = "exec->argument($argsIndex).isUndefined() ? " . $parameter->default . " : ";
+ $inner = "exec->uncheckedArgument($argsIndex)";
} else {
$outer = "";
$inner = "exec->argument($argsIndex)";
isNullable => '$', # Is variable type Nullable (T?)
isVariadic => '$', # Is variable variadic (long... numbers)
isOptional => '$', # Is variable optional (optional T)
+ default => '$', # Default value for parameters
});
# Used to represent string constants
$paramDataNode->type(identifierRemoveNullablePrefix(typeRemoveNullableSuffix($type)));
$paramDataNode->isOptional(1);
$paramDataNode->name($self->parseArgumentName());
- $self->parseDefault();
+ $paramDataNode->default($self->parseDefault());
return $paramDataNode;
}
if ($next->type() == IdentifierToken || $next->value() =~ /$nextExceptionField_1/) {
item->methodWithOptionalArg(opt);
}
+void webkit_dom_test_obj_method_with_optional_arg_and_default_value(WebKitDOMTestObj* self, glong opt)
+{
+ WebCore::JSMainThreadNullState state;
+ g_return_if_fail(WEBKIT_DOM_IS_TEST_OBJ(self));
+ WebCore::TestObj* item = WebKit::core(self);
+ item->methodWithOptionalArgAndDefaultValue(opt);
+}
+
void webkit_dom_test_obj_method_with_non_optional_arg_and_optional_arg(WebKitDOMTestObj* self, glong nonOpt, glong opt)
{
WebCore::JSMainThreadNullState state;
item->methodWithOptionalString(convertedStr);
}
+void webkit_dom_test_obj_method_with_optional_string_and_default_value(WebKitDOMTestObj* self, const gchar* str)
+{
+ WebCore::JSMainThreadNullState state;
+ g_return_if_fail(WEBKIT_DOM_IS_TEST_OBJ(self));
+ g_return_if_fail(str);
+ WebCore::TestObj* item = WebKit::core(self);
+ WTF::String convertedStr = WTF::String::fromUTF8(str);
+ item->methodWithOptionalStringAndDefaultValue(convertedStr);
+}
+
void webkit_dom_test_obj_method_with_optional_string_is_undefined(WebKitDOMTestObj* self, const gchar* str)
{
WebCore::JSMainThreadNullState state;
WEBKIT_API void
webkit_dom_test_obj_method_with_optional_arg(WebKitDOMTestObj* self, glong opt);
+/**
+ * webkit_dom_test_obj_method_with_optional_arg_and_default_value:
+ * @self: A #WebKitDOMTestObj
+ * @opt: A #glong
+ *
+ * Stability: Unstable
+**/
+WEBKIT_API void
+webkit_dom_test_obj_method_with_optional_arg_and_default_value(WebKitDOMTestObj* self, glong opt);
+
/**
* webkit_dom_test_obj_method_with_non_optional_arg_and_optional_arg:
* @self: A #WebKitDOMTestObj
WEBKIT_API void
webkit_dom_test_obj_method_with_optional_string(WebKitDOMTestObj* self, const gchar* str);
+/**
+ * webkit_dom_test_obj_method_with_optional_string_and_default_value:
+ * @self: A #WebKitDOMTestObj
+ * @str: A #gchar
+ *
+ * Stability: Unstable
+**/
+WEBKIT_API void
+webkit_dom_test_obj_method_with_optional_string_and_default_value(WebKitDOMTestObj* self, const gchar* str);
+
/**
* webkit_dom_test_obj_method_with_optional_string_is_undefined:
* @self: A #WebKitDOMTestObj
JSC::EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionWithScriptExecutionContextAndScriptStateWithSpaces(JSC::ExecState*);
JSC::EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionWithScriptArgumentsAndCallStack(JSC::ExecState*);
JSC::EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionMethodWithOptionalArg(JSC::ExecState*);
+JSC::EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionMethodWithOptionalArgAndDefaultValue(JSC::ExecState*);
JSC::EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionMethodWithNonOptionalArgAndOptionalArg(JSC::ExecState*);
JSC::EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionMethodWithNonOptionalArgAndTwoOptionalArgs(JSC::ExecState*);
JSC::EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionMethodWithOptionalString(JSC::ExecState*);
+JSC::EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionMethodWithOptionalStringAndDefaultValue(JSC::ExecState*);
JSC::EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionMethodWithOptionalStringIsUndefined(JSC::ExecState*);
JSC::EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionMethodWithOptionalStringIsNullString(JSC::ExecState*);
JSC::EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionMethodWithCallbackArg(JSC::ExecState*);
{ "withScriptExecutionContextAndScriptStateWithSpaces", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionWithScriptExecutionContextAndScriptStateWithSpaces), (intptr_t) (0) } },
{ "withScriptArgumentsAndCallStack", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionWithScriptArgumentsAndCallStack), (intptr_t) (0) } },
{ "methodWithOptionalArg", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionMethodWithOptionalArg), (intptr_t) (0) } },
+ { "methodWithOptionalArgAndDefaultValue", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionMethodWithOptionalArgAndDefaultValue), (intptr_t) (0) } },
{ "methodWithNonOptionalArgAndOptionalArg", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionMethodWithNonOptionalArgAndOptionalArg), (intptr_t) (1) } },
{ "methodWithNonOptionalArgAndTwoOptionalArgs", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionMethodWithNonOptionalArgAndTwoOptionalArgs), (intptr_t) (1) } },
{ "methodWithOptionalString", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionMethodWithOptionalString), (intptr_t) (0) } },
+ { "methodWithOptionalStringAndDefaultValue", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionMethodWithOptionalStringAndDefaultValue), (intptr_t) (0) } },
{ "methodWithOptionalStringIsUndefined", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionMethodWithOptionalStringIsUndefined), (intptr_t) (0) } },
{ "methodWithOptionalStringIsNullString", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionMethodWithOptionalStringIsNullString), (intptr_t) (0) } },
{ "methodWithCallbackArg", JSC::Function, NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestObjPrototypeFunctionMethodWithCallbackArg), (intptr_t) (1) } },
return JSValue::encode(jsUndefined());
}
+EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionMethodWithOptionalArgAndDefaultValue(ExecState* exec)
+{
+ JSValue thisValue = exec->thisValue();
+ JSTestObj* castedThis = jsDynamicCast<JSTestObj*>(thisValue);
+ if (UNLIKELY(!castedThis))
+ return throwThisTypeError(*exec, "TestObj", "methodWithOptionalArgAndDefaultValue");
+ ASSERT_GC_OBJECT_INHERITS(castedThis, JSTestObj::info());
+ auto& impl = castedThis->impl();
+
+ size_t argsCount = exec->argumentCount();
+ if (argsCount <= 0) {
+ impl.methodWithOptionalArgAndDefaultValue();
+ return JSValue::encode(jsUndefined());
+ }
+
+ int opt = exec->argument(0).isUndefined() ? 666 : toInt32(exec, exec->uncheckedArgument(0), NormalConversion);
+ if (UNLIKELY(exec->hadException()))
+ return JSValue::encode(jsUndefined());
+ impl.methodWithOptionalArgAndDefaultValue(opt);
+ return JSValue::encode(jsUndefined());
+}
+
EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionMethodWithNonOptionalArgAndOptionalArg(ExecState* exec)
{
JSValue thisValue = exec->thisValue();
return JSValue::encode(jsUndefined());
}
+EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionMethodWithOptionalStringAndDefaultValue(ExecState* exec)
+{
+ JSValue thisValue = exec->thisValue();
+ JSTestObj* castedThis = jsDynamicCast<JSTestObj*>(thisValue);
+ if (UNLIKELY(!castedThis))
+ return throwThisTypeError(*exec, "TestObj", "methodWithOptionalStringAndDefaultValue");
+ ASSERT_GC_OBJECT_INHERITS(castedThis, JSTestObj::info());
+ auto& impl = castedThis->impl();
+
+ size_t argsCount = exec->argumentCount();
+ if (argsCount <= 0) {
+ impl.methodWithOptionalStringAndDefaultValue();
+ return JSValue::encode(jsUndefined());
+ }
+
+ String str = exec->argument(0).isUndefined() ? "foo" : exec->uncheckedArgument(0).toString(exec)->value(exec);
+ if (UNLIKELY(exec->hadException()))
+ return JSValue::encode(jsUndefined());
+ impl.methodWithOptionalStringAndDefaultValue(str);
+ return JSValue::encode(jsUndefined());
+}
+
EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionMethodWithOptionalStringIsUndefined(ExecState* exec)
{
JSValue thisValue = exec->thisValue();
- (DOMTestObj *)withScriptExecutionContextAndScriptStateWithSpaces;
- (void)withScriptArgumentsAndCallStack;
- (void)methodWithOptionalArg:(int)opt;
+- (void)methodWithOptionalArgAndDefaultValue:(int)opt;
- (void)methodWithNonOptionalArgAndOptionalArg:(int)nonOpt opt:(int)opt;
- (void)methodWithNonOptionalArgAndTwoOptionalArgs:(int)nonOpt opt1:(int)opt1 opt2:(int)opt2;
- (void)methodWithOptionalString:(NSString *)str;
+- (void)methodWithOptionalStringAndDefaultValue:(NSString *)str;
- (void)methodWithOptionalStringIsUndefined:(NSString *)str;
- (void)methodWithOptionalStringIsNullString:(NSString *)str;
- (void)classMethod;
IMPL->methodWithOptionalArg(opt);
}
+- (void)methodWithOptionalArgAndDefaultValue:(int)opt
+{
+ WebCore::JSMainThreadNullState state;
+ IMPL->methodWithOptionalArgAndDefaultValue(opt);
+}
+
- (void)methodWithNonOptionalArgAndOptionalArg:(int)nonOpt opt:(int)opt
{
WebCore::JSMainThreadNullState state;
IMPL->methodWithOptionalString(str);
}
+- (void)methodWithOptionalStringAndDefaultValue:(NSString *)str
+{
+ WebCore::JSMainThreadNullState state;
+ IMPL->methodWithOptionalStringAndDefaultValue(str);
+}
+
- (void)methodWithOptionalStringIsUndefined:(NSString *)str
{
WebCore::JSMainThreadNullState state;
[CallWith= ScriptExecutionContext & ScriptState ] attribute TestObj withScriptExecutionContextAndScriptStateWithSpacesAttribute;
[CallWith=ScriptArguments&CallStack] attribute TestObj withScriptArgumentsAndCallStackAttribute;
- // 'Optional' extended attribute
+ // Optional parameters.
void methodWithOptionalArg(optional long opt);
+ void methodWithOptionalArgAndDefaultValue(optional long opt = 666);
void methodWithNonOptionalArgAndOptionalArg(long nonOpt, optional long opt);
void methodWithNonOptionalArgAndTwoOptionalArgs(long nonOpt, optional long opt1, optional long opt2);
void methodWithOptionalString(optional DOMString str);
+ void methodWithOptionalStringAndDefaultValue(optional DOMString str = "foo");
void methodWithOptionalStringIsUndefined([Default=Undefined] optional DOMString str);
void methodWithOptionalStringIsNullString([Default=NullString] optional DOMString str);
// DOM Level 2 Tranversal and Range (DocumentTraversal interface)
[ObjCLegacyUnnamedParameters, RaisesException, NewObject] NodeIterator createNodeIterator(Node root,
- optional unsigned long whatToShow,
+ optional unsigned long whatToShow = 0xFFFFFFFF,
optional NodeFilter? filter,
optional boolean expandEntityReferences);
[ObjCLegacyUnnamedParameters, RaisesException, NewObject] TreeWalker createTreeWalker(Node root,
- optional unsigned long whatToShow,
+ optional unsigned long whatToShow = 0xFFFFFFFF,
optional NodeFilter? filter,
optional boolean expandEntityReferences);