Skip to content
Permalink
Browse files
WebIDL generator should support the possibility for C++ classes to ha…
…ve a JS Builtin constructor

https://bugs.webkit.org/show_bug.cgi?id=152171

Reviewed by Darin Adler.

Reintroducing JSBuiltinConstructor keyword as a way to run automatically a JS builtin initialization function
to process the arguments passed to the DOM C++ constructor.

Specialized createJSObject for those classes.

Fixing typo in TestCustomConstructor.idl.

Covered by binding tests.

* bindings/scripts/CodeGeneratorJS.pm:
(GenerateConstructorDefinition):
(IsConstructable):
(IsJSBuiltinConstructor):
(AddJSBuiltinIncludesIfNeeded):
* bindings/scripts/test/GObject/WebKitDOMTestClassWithJSBuiltinConstructor.cpp: Added.
* bindings/scripts/test/GObject/WebKitDOMTestClassWithJSBuiltinConstructor.h: Added.
* bindings/scripts/test/GObject/WebKitDOMTestClassWithJSBuiltinConstructorPrivate.h: Added.
* bindings/scripts/test/JS/JSTestClassWithJSBuiltinConstructor.cpp: Added.
* bindings/scripts/test/JS/JSTestClassWithJSBuiltinConstructor.h: Added.
* bindings/scripts/test/ObjC/DOMTestClassWithJSBuiltinConstructor.h: Added.
* bindings/scripts/test/ObjC/DOMTestClassWithJSBuiltinConstructor.mm: Added.
* bindings/scripts/test/ObjC/DOMTestClassWithJSBuiltinConstructorInternal.h: Added.
* bindings/scripts/test/TestClassWithJSBuiltinConstructor.idl: Copied from Source/WebCore/bindings/scripts/test/TestCustomConstructor.idl.
* bindings/scripts/test/TestCustomConstructor.idl:


Canonical link: https://commits.webkit.org/170407@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@194100 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
youennf committed Dec 15, 2015
1 parent d401a70 commit a52ebf32eadb5a5a413cb3414f528ed7010abd16
@@ -1,3 +1,35 @@
2015-12-15 Youenn Fablet <youenn.fablet@crf.canon.fr>

WebIDL generator should support the possibility for C++ classes to have a JS Builtin constructor
https://bugs.webkit.org/show_bug.cgi?id=152171

Reviewed by Darin Adler.

Reintroducing JSBuiltinConstructor keyword as a way to run automatically a JS builtin initialization function
to process the arguments passed to the DOM C++ constructor.

Specialized createJSObject for those classes.

Fixing typo in TestCustomConstructor.idl.

Covered by binding tests.

* bindings/scripts/CodeGeneratorJS.pm:
(GenerateConstructorDefinition):
(IsConstructable):
(IsJSBuiltinConstructor):
(AddJSBuiltinIncludesIfNeeded):
* bindings/scripts/test/GObject/WebKitDOMTestClassWithJSBuiltinConstructor.cpp: Added.
* bindings/scripts/test/GObject/WebKitDOMTestClassWithJSBuiltinConstructor.h: Added.
* bindings/scripts/test/GObject/WebKitDOMTestClassWithJSBuiltinConstructorPrivate.h: Added.
* bindings/scripts/test/JS/JSTestClassWithJSBuiltinConstructor.cpp: Added.
* bindings/scripts/test/JS/JSTestClassWithJSBuiltinConstructor.h: Added.
* bindings/scripts/test/ObjC/DOMTestClassWithJSBuiltinConstructor.h: Added.
* bindings/scripts/test/ObjC/DOMTestClassWithJSBuiltinConstructor.mm: Added.
* bindings/scripts/test/ObjC/DOMTestClassWithJSBuiltinConstructorInternal.h: Added.
* bindings/scripts/test/TestClassWithJSBuiltinConstructor.idl: Copied from Source/WebCore/bindings/scripts/test/TestCustomConstructor.idl.
* bindings/scripts/test/TestCustomConstructor.idl:

2015-12-14 Andreas Kling <akling@apple.com>

ResourceUsageOverlay should show GC timers.
@@ -4727,7 +4727,20 @@ sub GenerateConstructorDefinition
my $generatingNamedConstructor = shift;
my $function = shift;

return if IsJSBuiltinConstructor($interface);

if (IsJSBuiltinConstructor($interface)) {
if ($interface->extendedAttributes->{"JSBuiltinConstructor"}) {
# FIXME: Add support for ConstructorCallWith
push(@$outputArray, <<END);
template<> JSC::JSObject* ${className}Constructor::createJSObject()
{
return ${className}::create(getDOMStructure<${className}>(globalObject()->vm(), *globalObject()), globalObject(), ${interfaceName}::create());
}
END
}
return;
}

my $constructorClassName = $generatingNamedConstructor ? "${className}NamedConstructor" : "${className}Constructor";

@@ -5034,7 +5047,7 @@ sub IsConstructable
{
my $interface = shift;

return HasCustomConstructor($interface) || $interface->extendedAttributes->{"Constructor"} || $interface->extendedAttributes->{"NamedConstructor"} || $interface->extendedAttributes->{"ConstructorTemplate"};
return HasCustomConstructor($interface) || $interface->extendedAttributes->{"Constructor"} || $interface->extendedAttributes->{"NamedConstructor"} || $interface->extendedAttributes->{"ConstructorTemplate"} || $interface->extendedAttributes->{"JSBuiltinConstructor"};
}

sub HeaderNeedsPrototypeDeclaration
@@ -5082,6 +5095,7 @@ sub IsJSBuiltinConstructor

return 0 if $interface->extendedAttributes->{"CustomConstructor"};
return 1 if $interface->extendedAttributes->{"JSBuiltin"};
return 1 if $interface->extendedAttributes->{"JSBuiltinConstructor"};
return 0;
}

@@ -5112,7 +5126,7 @@ sub AddJSBuiltinIncludesIfNeeded()
{
my $interface = shift;

if ($interface->extendedAttributes->{"JSBuiltin"}) {
if ($interface->extendedAttributes->{"JSBuiltin"} || $interface->extendedAttributes->{"JSBuiltinConstructor"}) {
AddToImplIncludes($interface->name . "Builtins.h");
return;
}
@@ -0,0 +1,104 @@
/*
* This file is part of the WebKit open source project.
* This file has been generated by generate-bindings.pl. DO NOT MODIFY!
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/

#include "config.h"
#include "WebKitDOMTestClassWithJSBuiltinConstructor.h"

#include "CSSImportRule.h"
#include "DOMObjectCache.h"
#include "Document.h"
#include "ExceptionCode.h"
#include "ExceptionCodeDescription.h"
#include "JSMainThreadExecState.h"
#include "WebKitDOMPrivate.h"
#include "WebKitDOMTestClassWithJSBuiltinConstructorPrivate.h"
#include "gobject/ConvertToUTF8String.h"
#include <wtf/GetPtr.h>
#include <wtf/RefPtr.h>

#define WEBKIT_DOM_TEST_CLASS_WITH_JS_BUILTIN_CONSTRUCTOR_GET_PRIVATE(obj) G_TYPE_INSTANCE_GET_PRIVATE(obj, WEBKIT_DOM_TYPE_TEST_CLASS_WITH_JS_BUILTIN_CONSTRUCTOR, WebKitDOMTestClassWithJSBuiltinConstructorPrivate)

typedef struct _WebKitDOMTestClassWithJSBuiltinConstructorPrivate {
RefPtr<WebCore::TestClassWithJSBuiltinConstructor> coreObject;
} WebKitDOMTestClassWithJSBuiltinConstructorPrivate;

namespace WebKit {

WebKitDOMTestClassWithJSBuiltinConstructor* kit(WebCore::TestClassWithJSBuiltinConstructor* obj)
{
if (!obj)
return 0;

if (gpointer ret = DOMObjectCache::get(obj))
return WEBKIT_DOM_TEST_CLASS_WITH_JS_BUILTIN_CONSTRUCTOR(ret);

return wrapTestClassWithJSBuiltinConstructor(obj);
}

WebCore::TestClassWithJSBuiltinConstructor* core(WebKitDOMTestClassWithJSBuiltinConstructor* request)
{
return request ? static_cast<WebCore::TestClassWithJSBuiltinConstructor*>(WEBKIT_DOM_OBJECT(request)->coreObject) : 0;
}

WebKitDOMTestClassWithJSBuiltinConstructor* wrapTestClassWithJSBuiltinConstructor(WebCore::TestClassWithJSBuiltinConstructor* coreObject)
{
ASSERT(coreObject);
return WEBKIT_DOM_TEST_CLASS_WITH_JS_BUILTIN_CONSTRUCTOR(g_object_new(WEBKIT_DOM_TYPE_TEST_CLASS_WITH_JS_BUILTIN_CONSTRUCTOR, "core-object", coreObject, nullptr));
}

} // namespace WebKit

G_DEFINE_TYPE(WebKitDOMTestClassWithJSBuiltinConstructor, webkit_dom_test_class_with_js_builtin_constructor, WEBKIT_DOM_TYPE_OBJECT)

static void webkit_dom_test_class_with_js_builtin_constructor_finalize(GObject* object)
{
WebKitDOMTestClassWithJSBuiltinConstructorPrivate* priv = WEBKIT_DOM_TEST_CLASS_WITH_JS_BUILTIN_CONSTRUCTOR_GET_PRIVATE(object);

WebKit::DOMObjectCache::forget(priv->coreObject.get());

priv->~WebKitDOMTestClassWithJSBuiltinConstructorPrivate();
G_OBJECT_CLASS(webkit_dom_test_class_with_js_builtin_constructor_parent_class)->finalize(object);
}

static GObject* webkit_dom_test_class_with_js_builtin_constructor_constructor(GType type, guint constructPropertiesCount, GObjectConstructParam* constructProperties)
{
GObject* object = G_OBJECT_CLASS(webkit_dom_test_class_with_js_builtin_constructor_parent_class)->constructor(type, constructPropertiesCount, constructProperties);

WebKitDOMTestClassWithJSBuiltinConstructorPrivate* priv = WEBKIT_DOM_TEST_CLASS_WITH_JS_BUILTIN_CONSTRUCTOR_GET_PRIVATE(object);
priv->coreObject = static_cast<WebCore::TestClassWithJSBuiltinConstructor*>(WEBKIT_DOM_OBJECT(object)->coreObject);
WebKit::DOMObjectCache::put(priv->coreObject.get(), object);

return object;
}

static void webkit_dom_test_class_with_js_builtin_constructor_class_init(WebKitDOMTestClassWithJSBuiltinConstructorClass* requestClass)
{
GObjectClass* gobjectClass = G_OBJECT_CLASS(requestClass);
g_type_class_add_private(gobjectClass, sizeof(WebKitDOMTestClassWithJSBuiltinConstructorPrivate));
gobjectClass->constructor = webkit_dom_test_class_with_js_builtin_constructor_constructor;
gobjectClass->finalize = webkit_dom_test_class_with_js_builtin_constructor_finalize;
}

static void webkit_dom_test_class_with_js_builtin_constructor_init(WebKitDOMTestClassWithJSBuiltinConstructor* request)
{
WebKitDOMTestClassWithJSBuiltinConstructorPrivate* priv = WEBKIT_DOM_TEST_CLASS_WITH_JS_BUILTIN_CONSTRUCTOR_GET_PRIVATE(request);
new (priv) WebKitDOMTestClassWithJSBuiltinConstructorPrivate();
}

@@ -0,0 +1,53 @@
/*
* This file is part of the WebKit open source project.
* This file has been generated by generate-bindings.pl. DO NOT MODIFY!
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/

#ifndef WebKitDOMTestClassWithJSBuiltinConstructor_h
#define WebKitDOMTestClassWithJSBuiltinConstructor_h

#ifdef WEBKIT_DOM_USE_UNSTABLE_API

#include <glib-object.h>
#include <webkitdom/WebKitDOMObject.h>
#include <webkitdom/webkitdomdefines-unstable.h>

G_BEGIN_DECLS

#define WEBKIT_DOM_TYPE_TEST_CLASS_WITH_JS_BUILTIN_CONSTRUCTOR (webkit_dom_test_class_with_js_builtin_constructor_get_type())
#define WEBKIT_DOM_TEST_CLASS_WITH_JS_BUILTIN_CONSTRUCTOR(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_DOM_TYPE_TEST_CLASS_WITH_JS_BUILTIN_CONSTRUCTOR, WebKitDOMTestClassWithJSBuiltinConstructor))
#define WEBKIT_DOM_TEST_CLASS_WITH_JS_BUILTIN_CONSTRUCTOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), WEBKIT_DOM_TYPE_TEST_CLASS_WITH_JS_BUILTIN_CONSTRUCTOR, WebKitDOMTestClassWithJSBuiltinConstructorClass)
#define WEBKIT_DOM_IS_TEST_CLASS_WITH_JS_BUILTIN_CONSTRUCTOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_DOM_TYPE_TEST_CLASS_WITH_JS_BUILTIN_CONSTRUCTOR))
#define WEBKIT_DOM_IS_TEST_CLASS_WITH_JS_BUILTIN_CONSTRUCTOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), WEBKIT_DOM_TYPE_TEST_CLASS_WITH_JS_BUILTIN_CONSTRUCTOR))
#define WEBKIT_DOM_TEST_CLASS_WITH_JS_BUILTIN_CONSTRUCTOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), WEBKIT_DOM_TYPE_TEST_CLASS_WITH_JS_BUILTIN_CONSTRUCTOR, WebKitDOMTestClassWithJSBuiltinConstructorClass))

struct _WebKitDOMTestClassWithJSBuiltinConstructor {
WebKitDOMObject parent_instance;
};

struct _WebKitDOMTestClassWithJSBuiltinConstructorClass {
WebKitDOMObjectClass parent_class;
};

WEBKIT_API GType
webkit_dom_test_class_with_js_builtin_constructor_get_type(void);

G_END_DECLS

#endif /* WEBKIT_DOM_USE_UNSTABLE_API */
#endif /* WebKitDOMTestClassWithJSBuiltinConstructor_h */
@@ -0,0 +1,33 @@
/*
* This file is part of the WebKit open source project.
* This file has been generated by generate-bindings.pl. DO NOT MODIFY!
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/

#ifndef WebKitDOMTestClassWithJSBuiltinConstructorPrivate_h
#define WebKitDOMTestClassWithJSBuiltinConstructorPrivate_h

#include "TestClassWithJSBuiltinConstructor.h"
#include <webkitdom/WebKitDOMTestClassWithJSBuiltinConstructor.h>

namespace WebKit {
WebKitDOMTestClassWithJSBuiltinConstructor* wrapTestClassWithJSBuiltinConstructor(WebCore::TestClassWithJSBuiltinConstructor*);
WebKitDOMTestClassWithJSBuiltinConstructor* kit(WebCore::TestClassWithJSBuiltinConstructor*);
WebCore::TestClassWithJSBuiltinConstructor* core(WebKitDOMTestClassWithJSBuiltinConstructor*);
} // namespace WebKit

#endif /* WebKitDOMTestClassWithJSBuiltinConstructorPrivate_h */

0 comments on commit a52ebf3

Please sign in to comment.