Diff
Modified: trunk/Source/WebCore/ChangeLog (189062 => 189063)
--- trunk/Source/WebCore/ChangeLog 2015-08-27 22:33:40 UTC (rev 189062)
+++ trunk/Source/WebCore/ChangeLog 2015-08-27 22:35:46 UTC (rev 189063)
@@ -1,5 +1,50 @@
2015-08-27 Chris Dumez <[email protected]>
+ A WebIDL callback interface is allowed to have constants
+ https://bugs.webkit.org/show_bug.cgi?id=148449
+
+ Reviewed by Geoffrey Garen.
+
+ Our JS bindings generator is now able to:
+ 1. Handle IDL constants [1] on a callback interfaces [2] and generate
+ a DOMConstructorObject subclass with static properties for
+ these constants [3].
+ 2. Generate a property on the global object for callback interfaces
+ that have constants and do not have the [NoInterfaceObject] IDL
+ extended attribute [4].
+
+ This is a pre-requirement for Bug 148415 as NodeFilter [5] has constants
+ and should be a callback interface. Once NodeFilter is ported to be
+ a callback interface, the JS still needs to be able to access
+ window.NodeFilter.SHOW_ALL for e.g.
+
+ [1] https://heycam.github.io/webidl/#dfn-constant
+ [2] https://heycam.github.io/webidl/#dfn-callback-interface
+ [3] https://heycam.github.io/webidl/#NoInterfaceObject
+ [4] https://heycam.github.io/webidl/#es-interfaces
+ [5] https://dom.spec.whatwg.org/#interface-nodefilter
+
+ * bindings/scripts/CodeGeneratorJS.pm:
+ (GenerateCallbackHeader):
+ (GenerateCallbackImplementation):
+ (GenerateConstructorHelperMethods):
+ (ConstructorHasProperties): Deleted.
+ * bindings/scripts/preprocess-idls.pl:
+ (getInterfaceExtendedAttributesFromIDL):
+ (interfaceHasConstantAttribute):
+ * bindings/scripts/test/GObject/WebKitDOMTestCallback.h:
+ * bindings/scripts/test/JS/JSTestCallback.cpp:
+ (WebCore::JSTestCallbackConstructor::create):
+ (WebCore::JSTestCallbackConstructor::createStructure):
+ (WebCore::JSTestCallbackConstructor::JSTestCallbackConstructor):
+ (WebCore::JSTestCallbackConstructor::finishCreation):
+ (WebCore::JSTestCallback::getConstructor):
+ * bindings/scripts/test/JS/JSTestCallback.h:
+ * bindings/scripts/test/ObjC/DOMTestCallback.h:
+ * bindings/scripts/test/TestCallback.idl:
+
+2015-08-27 Chris Dumez <[email protected]>
+
Range.compareBoundaryPoints() should throw a NotSupportedError for invalid compareHow values
https://bugs.webkit.org/show_bug.cgi?id=148483
Modified: trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm (189062 => 189063)
--- trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm 2015-08-27 22:33:40 UTC (rev 189062)
+++ trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm 2015-08-27 22:35:46 UTC (rev 189063)
@@ -3475,6 +3475,11 @@
# Destructor
push(@headerContent, " virtual ~$className();\n");
+ # Constructor object getter.
+ if (@{$interface->constants}) {
+ push(@headerContent, " static JSC::JSValue getConstructor(JSC::VM&, JSC::JSGlobalObject*);\n");
+ }
+
if ($interface->extendedAttributes->{"CallbackNeedsOperatorEqual"}) {
push(@headerContent, " virtual bool operator==(const $interfaceName&) const;\n\n")
}
@@ -3522,6 +3527,7 @@
my ($object, $interface) = @_;
my $interfaceName = $interface->name;
+ my $visibleInterfaceName = $codeGenerator->GetVisibleInterfaceName($interface);
my $className = "JS$interfaceName";
# - Add default header template
@@ -3570,7 +3576,54 @@
push(@implContent, " return static_cast<const ${className}*>(&other)->m_data->callback() == m_data->callback();\n");
push(@implContent, "}\n\n");
}
- # Functions
+
+ # Constants.
+ my $numConstants = @{$interface->constants};
+ if ($numConstants > 0) {
+ GenerateConstructorDeclaration(\@implContent, $className, $interface, $interfaceName);
+
+ my $hashSize = 0;
+ my $hashName = $className . "ConstructorTable";
+
+ my @hashKeys = ();
+ my @hashValue1 = ();
+ my @hashValue2 = ();
+ my @hashSpecials = ();
+ my %conditionals = ();
+
+ foreach my $constant (@{$interface->constants}) {
+ my $name = $constant->name;
+ push(@hashKeys, $name);
+ push(@hashValue1, $constant->value);
+ push(@hashValue2, "0");
+ push(@hashSpecials, "DontDelete | ReadOnly | ConstantInteger");
+
+ my $implementedBy = $constant->extendedAttributes->{"ImplementedBy"};
+ if ($implementedBy) {
+ $implIncludes{"${implementedBy}.h"} = 1;
+ }
+ my $conditional = $constant->extendedAttributes->{"Conditional"};
+ if ($conditional) {
+ $conditionals{$name} = $conditional;
+ }
+
+ $hashSize++;
+ }
+ $object->GenerateHashTable($hashName, $hashSize,
+ \@hashKeys, \@hashSpecials,
+ \@hashValue1, \@hashValue2,
+ \%conditionals, 1) if $hashSize > 0;
+
+ push(@implContent, $codeGenerator->GenerateCompileTimeCheckForEnumsIfNeeded($interface));
+
+ GenerateConstructorDefinitions(\@implContent, $className, "", $interfaceName, $visibleInterfaceName, $interface);
+
+ push(@implContent, "JSValue ${className}::getConstructor(VM& vm, JSGlobalObject* globalObject)\n{\n");
+ push(@implContent, " return getDOMConstructor<${className}Constructor>(vm, jsCast<JSDOMGlobalObject*>(globalObject));\n");
+ push(@implContent, "}\n\n");
+ }
+
+ # Functions.
my $numFunctions = @{$interface->functions};
if ($numFunctions > 0) {
push(@implContent, "\n// Functions\n");
@@ -4779,20 +4832,25 @@
push(@$outputArray, "void ${constructorClassName}::finishCreation(VM& vm, JSDOMGlobalObject* globalObject)\n");
push(@$outputArray, "{\n");
- if (IsDOMGlobalObject($interface)) {
- push(@$outputArray, " Base::finishCreation(vm);\n");
- push(@$outputArray, " ASSERT(inherits(info()));\n");
- push(@$outputArray, " putDirect(vm, vm.propertyNames->prototype, globalObject->prototype(), DontDelete | ReadOnly | DontEnum);\n");
- } elsif ($generatingNamedConstructor) {
+
+ if ($generatingNamedConstructor) {
push(@$outputArray, " Base::finishCreation(globalObject);\n");
- push(@$outputArray, " ASSERT(inherits(info()));\n");
- push(@$outputArray, " putDirect(vm, vm.propertyNames->prototype, ${className}::getPrototype(vm, globalObject), DontDelete | ReadOnly | DontEnum);\n");
} else {
push(@$outputArray, " Base::finishCreation(vm);\n");
- push(@$outputArray, " ASSERT(inherits(info()));\n");
- push(@$outputArray, " putDirect(vm, vm.propertyNames->prototype, ${className}::getPrototype(vm, globalObject), DontDelete | ReadOnly | DontEnum);\n");
}
+ push(@$outputArray, " ASSERT(inherits(info()));\n");
+ # There must exist an interface prototype object for every non-callback interface defined, regardless
+ # of whether the interface was declared with the [NoInterfaceObject] extended attribute.
+ # https://heycam.github.io/webidl/#interface-prototype-object
+ if (IsDOMGlobalObject($interface)) {
+ push(@$outputArray, " putDirect(vm, vm.propertyNames->prototype, globalObject->prototype(), DontDelete | ReadOnly | DontEnum);\n");
+ } elsif ($interface->isCallback) {
+ push(@$outputArray, " UNUSED_PARAM(globalObject);\n");
+ } else {
+ push(@$outputArray, " putDirect(vm, vm.propertyNames->prototype, ${className}::getPrototype(vm, globalObject), DontDelete | ReadOnly | DontEnum);\n");
+ }
+
push(@$outputArray, " putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String(ASCIILiteral(\"$visibleInterfaceName\"))), ReadOnly | DontEnum);\n");
if (defined $leastConstructorLength) {
Modified: trunk/Source/WebCore/bindings/scripts/preprocess-idls.pl (189062 => 189063)
--- trunk/Source/WebCore/bindings/scripts/preprocess-idls.pl 2015-08-27 22:33:40 UTC (rev 189062)
+++ trunk/Source/WebCore/bindings/scripts/preprocess-idls.pl 2015-08-27 22:35:46 UTC (rev 189063)
@@ -95,10 +95,15 @@
$supplementalDependencies{$implementedIdlFile} = [$interfaceName];
}
}
- # Handle [NoInterfaceObject].
- unless (isCallbackInterfaceFromIDL($idlFileContents)) {
- my $extendedAttributes = getInterfaceExtendedAttributesFromIDL($idlFileContents);
- unless ($extendedAttributes->{"NoInterfaceObject"}) {
+
+ # For every interface that is exposed in a given ECMAScript global environment and:
+ # - is a callback interface that has constants declared on it, or
+ # - is a non-callback interface that is not declared with the [NoInterfaceObject] extended attribute, a corresponding
+ # property must exist on the ECMAScript environment's global object.
+ # See https://heycam.github.io/webidl/#es-interfaces
+ my $extendedAttributes = getInterfaceExtendedAttributesFromIDL($idlFileContents);
+ unless ($extendedAttributes->{"NoInterfaceObject"}) {
+ if (!isCallbackInterfaceFromIDL($idlFileContents) || interfaceHasConstantAttribute($idlFileContents)) {
my @globalContexts = split("&", $extendedAttributes->{"GlobalContext"} || "DOMWindow");
my $attributeCode = GenerateConstructorAttribute($interfaceName, $extendedAttributes);
$windowConstructorsCode .= $attributeCode if grep(/^DOMWindow$/, @globalContexts);
@@ -277,7 +282,7 @@
my $extendedAttributes = {};
- if ($fileContents =~ /\[(.*)\]\s+(interface|exception)\s+(\w+)/gs) {
+ if ($fileContents =~ /\[(.*)\]\s+(callback interface|interface|exception)\s+(\w+)/gs) {
my @parts = split(',', $1);
foreach my $part (@parts) {
my @keyValue = split('=', $part);
@@ -291,3 +296,10 @@
return $extendedAttributes;
}
+
+sub interfaceHasConstantAttribute
+{
+ my $fileContents = shift;
+
+ return $fileContents =~ /\s+const[\s\w]+=\s+[\w]+;/gs;
+}
Modified: trunk/Source/WebCore/bindings/scripts/test/GObject/WebKitDOMTestCallback.h (189062 => 189063)
--- trunk/Source/WebCore/bindings/scripts/test/GObject/WebKitDOMTestCallback.h 2015-08-27 22:33:40 UTC (rev 189062)
+++ trunk/Source/WebCore/bindings/scripts/test/GObject/WebKitDOMTestCallback.h 2015-08-27 22:35:46 UTC (rev 189063)
@@ -36,6 +36,16 @@
#define WEBKIT_DOM_IS_TEST_CALLBACK_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), WEBKIT_DOM_TYPE_TEST_CALLBACK))
#define WEBKIT_DOM_TEST_CALLBACK_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), WEBKIT_DOM_TYPE_TEST_CALLBACK, WebKitDOMTestCallbackClass))
+/**
+ * WEBKIT_DOM_TEST_CALLBACK_CONSTANT1:
+ */
+#define WEBKIT_DOM_TEST_CALLBACK_CONSTANT1 1
+
+/**
+ * WEBKIT_DOM_TEST_CALLBACK_CONSTANT2:
+ */
+#define WEBKIT_DOM_TEST_CALLBACK_CONSTANT2 2
+
struct _WebKitDOMTestCallback {
WebKitDOMObject parent_instance;
};
Modified: trunk/Source/WebCore/bindings/scripts/test/JS/JSTestCallback.cpp (189062 => 189063)
--- trunk/Source/WebCore/bindings/scripts/test/JS/JSTestCallback.cpp 2015-08-27 22:33:40 UTC (rev 189062)
+++ trunk/Source/WebCore/bindings/scripts/test/JS/JSTestCallback.cpp 2015-08-27 22:35:46 UTC (rev 189063)
@@ -59,7 +59,62 @@
#endif
}
+class JSTestCallbackConstructor : public DOMConstructorObject {
+private:
+ JSTestCallbackConstructor(JSC::Structure*, JSDOMGlobalObject*);
+ void finishCreation(JSC::VM&, JSDOMGlobalObject*);
+public:
+ typedef DOMConstructorObject Base;
+ static JSTestCallbackConstructor* create(JSC::VM& vm, JSC::Structure* structure, JSDOMGlobalObject* globalObject)
+ {
+ JSTestCallbackConstructor* ptr = new (NotNull, JSC::allocateCell<JSTestCallbackConstructor>(vm.heap)) JSTestCallbackConstructor(structure, globalObject);
+ ptr->finishCreation(vm, globalObject);
+ return ptr;
+ }
+
+ DECLARE_INFO;
+ static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
+ {
+ return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
+ }
+};
+
+/* Hash table for constructor */
+
+static const HashTableValue JSTestCallbackConstructorTableValues[] =
+{
+ { "CONSTANT1", DontDelete | ReadOnly | ConstantInteger, NoIntrinsic, (intptr_t)(1), (intptr_t) (0) },
+ { "CONSTANT2", DontDelete | ReadOnly | ConstantInteger, NoIntrinsic, (intptr_t)(2), (intptr_t) (0) },
+};
+
+
+COMPILE_ASSERT(1 == TestCallback::CONSTANT1, TestCallbackEnumCONSTANT1IsWrongUseDoNotCheckConstants);
+COMPILE_ASSERT(2 == TestCallback::CONSTANT2, TestCallbackEnumCONSTANT2IsWrongUseDoNotCheckConstants);
+
+const ClassInfo JSTestCallbackConstructor::s_info = { "TestCallbackConstructor", &Base::s_info, 0, CREATE_METHOD_TABLE(JSTestCallbackConstructor) };
+
+JSTestCallbackConstructor::JSTestCallbackConstructor(Structure* structure, JSDOMGlobalObject* globalObject)
+ : DOMConstructorObject(structure, globalObject)
+{
+}
+
+void JSTestCallbackConstructor::finishCreation(VM& vm, JSDOMGlobalObject* globalObject)
+{
+ Base::finishCreation(vm);
+ ASSERT(inherits(info()));
+ UNUSED_PARAM(globalObject);
+ putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String(ASCIILiteral("TestCallback"))), ReadOnly | DontEnum);
+ putDirect(vm, vm.propertyNames->length, jsNumber(0), ReadOnly | DontEnum);
+ reifyStaticProperties(vm, JSTestCallbackConstructorTableValues, *this);
+}
+
+JSValue JSTestCallback::getConstructor(VM& vm, JSGlobalObject* globalObject)
+{
+ return getDOMConstructor<JSTestCallbackConstructor>(vm, jsCast<JSDOMGlobalObject*>(globalObject));
+}
+
+
// Functions
bool JSTestCallback::callbackWithNoParam()
Modified: trunk/Source/WebCore/bindings/scripts/test/JS/JSTestCallback.h (189062 => 189063)
--- trunk/Source/WebCore/bindings/scripts/test/JS/JSTestCallback.h 2015-08-27 22:33:40 UTC (rev 189062)
+++ trunk/Source/WebCore/bindings/scripts/test/JS/JSTestCallback.h 2015-08-27 22:35:46 UTC (rev 189063)
@@ -40,6 +40,7 @@
virtual ScriptExecutionContext* scriptExecutionContext() const { return ContextDestructionObserver::scriptExecutionContext(); }
virtual ~JSTestCallback();
+ static JSC::JSValue getConstructor(JSC::VM&, JSC::JSGlobalObject*);
// Functions
virtual bool callbackWithNoParam();
Modified: trunk/Source/WebCore/bindings/scripts/test/ObjC/DOMTestCallback.h (189062 => 189063)
--- trunk/Source/WebCore/bindings/scripts/test/ObjC/DOMTestCallback.h 2015-08-27 22:33:40 UTC (rev 189062)
+++ trunk/Source/WebCore/bindings/scripts/test/ObjC/DOMTestCallback.h 2015-08-27 22:35:46 UTC (rev 189063)
@@ -33,6 +33,11 @@
@class DOMTestNode;
@class NSString;
+enum {
+ DOM_CONSTANT1 = 1,
+ DOM_CONSTANT2 = 2
+} WEBKIT_ENUM_AVAILABLE_MAC(9876_5);
+
WEBKIT_CLASS_AVAILABLE_MAC(9876_5)
WEBCORE_EXPORT @interface DOMTestCallback : DOMObject
- (BOOL)callbackWithNoParam;
Modified: trunk/Source/WebCore/bindings/scripts/test/TestCallback.idl (189062 => 189063)
--- trunk/Source/WebCore/bindings/scripts/test/TestCallback.idl 2015-08-27 22:33:40 UTC (rev 189062)
+++ trunk/Source/WebCore/bindings/scripts/test/TestCallback.idl 2015-08-27 22:35:46 UTC (rev 189063)
@@ -31,6 +31,11 @@
[
Conditional=SPEECH_SYNTHESIS,
] callback interface TestCallback {
+ // Constants
+ const unsigned short CONSTANT1 = 1;
+ const unsigned short CONSTANT2 = 2;
+
+ // Operations.
boolean callbackWithNoParam();
boolean callbackWithArrayParam(Float32Array arrayParam);
boolean callbackWithSerializedScriptValueParam(SerializedScriptValue srzParam, DOMString strArg);