After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 692025 - Replace native modules with JS equivalents
Replace native modules with JS equivalents
Status: RESOLVED FIXED
Product: gjs
Classification: Bindings
Component: general
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gjs-maint
gjs-maint
Depends on:
Blocks:
 
 
Reported: 2013-01-18 18:03 UTC by Giovanni Campagna
Modified: 2013-01-20 15:24 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Convert many native modules to JS modules (40.33 KB, patch)
2013-01-18 18:03 UTC, Giovanni Campagna
committed Details | Review
Rework Lang module to be ES5 compliant (8.40 KB, patch)
2013-01-18 18:03 UTC, Giovanni Campagna
none Details | Review
ByteArray: don't define the ByteArray class in the global object (1.84 KB, patch)
2013-01-18 18:04 UTC, Giovanni Campagna
committed Details | Review
Rework Lang module to be ES5 compliant (7.70 KB, patch)
2013-01-18 18:08 UTC, Giovanni Campagna
reviewed Details | Review
Lang: fix copyProperties regression (1.17 KB, patch)
2013-01-18 20:03 UTC, Giovanni Campagna
accepted-commit_now Details | Review
Rework Lang module to be ES5 compliant (7.07 KB, patch)
2013-01-18 20:04 UTC, Giovanni Campagna
committed Details | Review
Lang: fix copyProperties regression (1.25 KB, patch)
2013-01-18 20:12 UTC, Giovanni Campagna
committed Details | Review

Description Giovanni Campagna 2013-01-18 18:03:00 UTC
Easier to understand, maintain and document.
Comment 1 Giovanni Campagna 2013-01-18 18:03:36 UTC
Created attachment 233776 [details] [review]
Convert many native modules to JS modules

Less C code and more JS + introspection means more maintenability
and fewer bugs.
Comment 2 Giovanni Campagna 2013-01-18 18:03:51 UTC
Created attachment 233777 [details] [review]
Rework Lang module to be ES5 compliant

Use ES5 features to provide the same functionality without a native
module, and stop relying on SpiderMonkey details for accessor
properties.
Comment 3 Giovanni Campagna 2013-01-18 18:04:30 UTC
Created attachment 233778 [details] [review]
ByteArray: don't define the ByteArray class in the global object

Otherwise, a ByteArray property appears, which prevents the byteArray
test from setting it with the module object.
It was not failing before because the byte array module was not initialized.
Comment 4 Giovanni Campagna 2013-01-18 18:08:43 UTC
Created attachment 233779 [details] [review]
Rework Lang module to be ES5 compliant

Use ES5 features to provide the same functionality without a native
module, and stop relying on SpiderMonkey details for accessor
properties.

Argh, I was hoping to avoid the rebase on Jasper's lookupGetter patch.
Btw, there is bug there, wrt prototype handling in copyProperties.
Comment 5 Jasper St. Pierre (not reading bugmail) 2013-01-18 19:06:30 UTC
Review of attachment 233776 [details] [review]:

I'm fine with this.
Comment 6 Jasper St. Pierre (not reading bugmail) 2013-01-18 19:07:19 UTC
Review of attachment 233778 [details] [review]:

OK.
Comment 7 Jasper St. Pierre (not reading bugmail) 2013-01-18 19:08:06 UTC
Review of attachment 233779 [details] [review]:

::: modules/lang.js
@@ +40,3 @@
 function _copyProperty(source, dest, property) {
+    let descriptor = getPropertyDescriptor(source, property);
+    Object.defineProperty(dest, property, descriptor);

Make this fix a separate patch, please.
Comment 8 Giovanni Campagna 2013-01-18 20:03:39 UTC
Created attachment 233793 [details] [review]
Lang: fix copyProperties regression

We need to recurse through the prototype while fetching property
descriptors.
Comment 9 Giovanni Campagna 2013-01-18 20:04:04 UTC
Created attachment 233794 [details] [review]
Rework Lang module to be ES5 compliant

Use ES5 features to provide the same functionality without a native
module, and stop relying on SpiderMonkey details for accessor
properties.
Comment 10 Jasper St. Pierre (not reading bugmail) 2013-01-18 20:07:26 UTC
Review of attachment 233793 [details] [review]:

::: modules/lang.js
@@ +35,3 @@
+    if (obj.hasOwnProperty(property))
+        return Object.getOwnPropertyDescriptor(obj, property);
+    return getPropertyDescriptor(Object.getPrototypeOf(obj), property);

We need to guard against the prototype eventually becoming null.
Comment 11 Jasper St. Pierre (not reading bugmail) 2013-01-18 20:08:25 UTC
Review of attachment 233794 [details] [review]:

One comment nit, otherwise ACN.

::: modules/lang.js
@@ +93,3 @@
     }
 
+    // ECMAScript 5 (but only if not passing any bindArguments,

// Use ES5 Function.prototype.bind (but only...
Comment 12 Giovanni Campagna 2013-01-18 20:12:22 UTC
Created attachment 233795 [details] [review]
Lang: fix copyProperties regression

We need to recurse through the prototype while fetching property
descriptors.
Comment 13 Jasper St. Pierre (not reading bugmail) 2013-01-18 20:15:10 UTC
Review of attachment 233795 [details] [review]:

Almost.

::: modules/lang.js
@@ +42,3 @@
 function _copyProperty(source, dest, property) {
+    let descriptor = getPropertyDescriptor(source, property);
+    if (descriptor != null)

If the user passes in a bad property, we should throw an error, not silently do nothing, I think.
Comment 14 Giovanni Campagna 2013-01-18 20:16:21 UTC
(In reply to comment #13)
> Review of attachment 233795 [details] [review]:
> 
> Almost.
> 
> ::: modules/lang.js
> @@ +42,3 @@
>  function _copyProperty(source, dest, property) {
> +    let descriptor = getPropertyDescriptor(source, property);
> +    if (descriptor != null)
> 
> If the user passes in a bad property, we should throw an error, not silently do
> nothing, I think.

But _copyProperty is not public API, is it is an implementation helper used by copyProperties*()
Comment 15 Jasper St. Pierre (not reading bugmail) 2013-01-18 20:17:28 UTC
Ah, then we should never get a null prototype. Nevermind.
Comment 16 Jasper St. Pierre (not reading bugmail) 2013-01-18 20:18:25 UTC
Review of attachment 233793 [details] [review]:

Let's go with this one without the guard, then.
Comment 17 Giovanni Campagna 2013-01-18 20:21:22 UTC
Attachment 233776 [details] pushed as b5e467d - Convert many native modules to JS modules
Attachment 233794 [details] pushed as c39baaa - Rework Lang module to be ES5 compliant
Attachment 233795 [details] pushed as 391aec6 - Lang: fix copyProperties regression
Comment 18 Giovanni Campagna 2013-01-18 20:22:29 UTC
Attachment 233778 [details] pushed as 03a2147 - ByteArray: don't define the ByteArray class in the global object
Comment 19 Jasper St. Pierre (not reading bugmail) 2013-01-19 22:56:30 UTC
This broke the mainloop test. Please revert.

(and please make test your patches from now on)
Comment 20 Giovanni Campagna 2013-01-20 02:33:01 UTC
(In reply to comment #19)
> This broke the mainloop test. Please revert.
> 
> (and please make test your patches from now on)

It was make tested. I just forgot it depends on glib bug 692034.
Comment 21 Giovanni Campagna 2013-01-20 15:24:38 UTC
Be happy, the glib bug is fixed.