[gjs/wip/ptomato/classes: 3/4] Revert "js: Workaround for function with custom prototype"
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs/wip/ptomato/classes: 3/4] Revert "js: Workaround for function with custom prototype"
- Date: Tue, 18 Jul 2017 00:29:15 +0000 (UTC)
commit e1ef120cf7b2d905a2994d2e903016467af66990
Author: Philip Chimento <philip chimento gmail com>
Date: Thu Jul 6 19:31:51 2017 -0700
Revert "js: Workaround for function with custom prototype"
This reverts commit 72c0298c5f9df9036ed67fd504db84cbc028daaa.
The warning that was the reason for this code in the first place was
removed in SpiderMonkey 52. According to
https://bugzilla.mozilla.org/show_bug.cgi?id=1049041 the warning was out
of date, and there are only performance effects "if the object escapes to
somewhere interesting before getting its final __proto__".
In addition, client code should move to ES6 classes which do not have
this performance problem.
Edited to resolve conflicts due to code being moved around in the
meantime, and to use Object.setPrototypeOf() instead of the deprecated
__proto__ property.
gjs-srcs.mk | 2 -
gjs/global.cpp | 4 +-
gjs/jsapi-constructor-proxy.cpp | 190 ---------------------------------------
gjs/jsapi-constructor-proxy.h | 38 --------
gjs/jsapi-wrapper.h | 2 +-
gjs/mem.cpp | 4 +-
gjs/mem.h | 1 -
modules/lang.js | 19 ++--
modules/overrides/GObject.js | 18 ++--
util/log.cpp | 3 -
util/log.h | 1 -
11 files changed, 21 insertions(+), 261 deletions(-)
---
diff --git a/gjs-srcs.mk b/gjs-srcs.mk
index 5d41951..ce37c81 100644
--- a/gjs-srcs.mk
+++ b/gjs-srcs.mk
@@ -61,8 +61,6 @@ gjs_srcs = \
gjs/importer.cpp \
gjs/importer.h \
gjs/jsapi-class.h \
- gjs/jsapi-constructor-proxy.cpp \
- gjs/jsapi-constructor-proxy.h \
gjs/jsapi-dynamic-class.cpp \
gjs/jsapi-private.cpp \
gjs/jsapi-private.h \
diff --git a/gjs/global.cpp b/gjs/global.cpp
index 16dd5bd..1beaabb 100644
--- a/gjs/global.cpp
+++ b/gjs/global.cpp
@@ -27,7 +27,6 @@
#include "global.h"
#include "importer.h"
-#include "jsapi-constructor-proxy.h"
#include "jsapi-util.h"
#include "jsapi-wrapper.h"
@@ -230,8 +229,7 @@ public:
{
if (!JS_DefineProperty(cx, global, "window", global,
JSPROP_READONLY | JSPROP_PERMANENT) ||
- !JS_DefineFunctions(cx, global, GjsGlobal::static_funcs) ||
- !gjs_define_constructor_proxy_factory(cx, global))
+ !JS_DefineFunctions(cx, global, GjsGlobal::static_funcs))
return false;
JS::Value v_importer = gjs_get_global_slot(cx, GJS_GLOBAL_SLOT_IMPORTS);
diff --git a/gjs/jsapi-wrapper.h b/gjs/jsapi-wrapper.h
index 11bdadb..bdc7245 100644
--- a/gjs/jsapi-wrapper.h
+++ b/gjs/jsapi-wrapper.h
@@ -40,7 +40,7 @@
#endif
#include <mozilla/Maybe.h>
#include <jsapi.h>
+#include <jsfriendapi.h>
#include <js/Conversions.h>
-#include <js/Proxy.h> /* For jsapi-constructor-proxy */
#endif /* GJS_JSAPI_WRAPPER_H */
diff --git a/gjs/mem.cpp b/gjs/mem.cpp
index 77adeff..1ed251b 100644
--- a/gjs/mem.cpp
+++ b/gjs/mem.cpp
@@ -48,7 +48,6 @@ GJS_DEFINE_COUNTER(repo)
GJS_DEFINE_COUNTER(resultset)
GJS_DEFINE_COUNTER(weakhash)
GJS_DEFINE_COUNTER(interface)
-GJS_DEFINE_COUNTER(constructor_proxy)
#define GJS_LIST_COUNTER(name) \
& gjs_counter_ ## name
@@ -67,8 +66,7 @@ static GjsMemCounter* counters[] = {
GJS_LIST_COUNTER(repo),
GJS_LIST_COUNTER(resultset),
GJS_LIST_COUNTER(weakhash),
- GJS_LIST_COUNTER(interface),
- GJS_LIST_COUNTER(constructor_proxy),
+ GJS_LIST_COUNTER(interface)
};
void
diff --git a/gjs/mem.h b/gjs/mem.h
index 709971b..f99226a 100644
--- a/gjs/mem.h
+++ b/gjs/mem.h
@@ -54,7 +54,6 @@ GJS_DECLARE_COUNTER(repo)
GJS_DECLARE_COUNTER(resultset)
GJS_DECLARE_COUNTER(weakhash)
GJS_DECLARE_COUNTER(interface)
-GJS_DECLARE_COUNTER(constructor_proxy)
#define GJS_INC_COUNTER(name) \
do { \
diff --git a/modules/lang.js b/modules/lang.js
index 0df22dc..0957158 100644
--- a/modules/lang.js
+++ b/modules/lang.js
@@ -201,28 +201,27 @@ Class.prototype._construct = function(params) {
if (!parent)
parent = _Base;
- let newClassConstructor;
+ let newClass;
if (params.Abstract) {
- newClassConstructor = function() {
+ newClass = function() {
throw new TypeError('Cannot instantiate abstract class ' + name);
};
} else {
- newClassConstructor = function() {
+ newClass = function() {
this.__caller__ = null;
return this._construct.apply(this, arguments);
};
}
- // This is our workaround for creating a constructor with a custom
- // prototype. See jsapi-constructor-proxy.cpp.
- let newClass = __private_GjsConstructorProxy(newClassConstructor,
- this.constructor.prototype);
+ // Since it's not possible to create a constructor with
+ // a custom [[Prototype]], we have to do this to make
+ // "newClass instanceof Class" work, and so we can inherit
+ // methods/properties of Class.prototype, like wrapFunction.
+ Object.setPrototypeOf(newClass, this.constructor.prototype);
newClass.__super__ = parent;
- // Here we have to set this property on newClassConstructor directly because
- // otherwise the 'prototype' property on the proxy isn't configurable
- newClassConstructor.prototype = Object.create(parent.prototype);
+ newClass.prototype = Object.create(parent.prototype);
newClass.prototype.constructor = newClass;
newClass._init.apply(newClass, arguments);
diff --git a/modules/overrides/GObject.js b/modules/overrides/GObject.js
index 4fdf878..ee30779 100644
--- a/modules/overrides/GObject.js
+++ b/modules/overrides/GObject.js
@@ -141,14 +141,13 @@ const GObjectMeta = new Lang.Class({
let propertiesArray = _propertiesAsArray(params);
delete params.Properties;
- let newClassConstructor = Gi.register_type(parent.prototype, gtypename,
+ let newClass = Gi.register_type(parent.prototype, gtypename,
gobjectInterfaces, propertiesArray);
- let newClass = __private_GjsConstructorProxy(newClassConstructor,
- this.constructor.prototype);
-
+ // See Class.prototype._construct in lang.js for the reasoning
+ // behind this direct prototype set.
+ Object.setPrototypeOf(newClass, this.constructor.prototype);
newClass.__super__ = parent;
- newClass.prototype.constructor = newClass;
newClass._init.apply(newClass, arguments);
@@ -206,11 +205,12 @@ GObjectInterface.prototype._construct = function (params) {
let properties = _propertiesAsArray(params);
delete params.Properties;
- let newInterfaceConstructor = Gi.register_interface(gtypename,
- gobjectInterfaces, properties);
+ let newInterface = Gi.register_interface(gtypename, gobjectInterfaces,
+ properties);
- let newInterface = __private_GjsConstructorProxy(newInterfaceConstructor,
- this.constructor.prototype);
+ // See Class.prototype._construct in lang.js for the reasoning
+ // behind this direct prototype set.
+ Object.setPrototypeOf(newInterface, this.constructor.prototype);
newInterface.__super__ = GObjectInterface;
newInterface.prototype.constructor = newInterface;
diff --git a/util/log.cpp b/util/log.cpp
index 1f59e14..afd3aa1 100644
--- a/util/log.cpp
+++ b/util/log.cpp
@@ -238,9 +238,6 @@ _Pragma("GCC diagnostic pop")
case GJS_DEBUG_GERROR:
prefix = "JS G ERR";
break;
- case GJS_DEBUG_PROXY:
- prefix = "JS CPROXY";
- break;
default:
prefix = "???";
break;
diff --git a/util/log.h b/util/log.h
index 4eb56e4..1d5d298 100644
--- a/util/log.h
+++ b/util/log.h
@@ -58,7 +58,6 @@ typedef enum {
GJS_DEBUG_BYTE_ARRAY,
GJS_DEBUG_GERROR,
GJS_DEBUG_GFUNDAMENTAL,
- GJS_DEBUG_PROXY,
} GjsDebugTopic;
/* These defines are because we have some pretty expensive and
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]