[gjs] Rework Lang module to be ES5 compliant
- From: Giovanni Campagna <gcampagna src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs] Rework Lang module to be ES5 compliant
- Date: Fri, 18 Jan 2013 20:21:14 +0000 (UTC)
commit c39baaac33eddbfc7a1e7ddff0d05eecaf62714e
Author: Giovanni Campagna <gcampagna src gnome org>
Date: Sun Jun 17 20:44:22 2012 +0200
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.
https://bugzilla.gnome.org/show_bug.cgi?id=692025
Makefile-modules.am | 14 +----------
modules/lang.c | 65 ---------------------------------------------------
modules/lang.h | 38 -----------------------------
modules/lang.js | 27 ++++++++++++++++++---
4 files changed, 24 insertions(+), 120 deletions(-)
---
diff --git a/Makefile-modules.am b/Makefile-modules.am
index 7a14264..89f5f14 100644
--- a/Makefile-modules.am
+++ b/Makefile-modules.am
@@ -17,7 +17,7 @@ dist_gjsjs_DATA += \
modules/promise.js \
modules/format.js
-gjsnative_LTLIBRARIES += console.la langNative.la system.la
+gjsnative_LTLIBRARIES += console.la system.la
if ENABLE_CAIRO
dist_gjsjs_DATA += \
@@ -37,18 +37,6 @@ JS_NATIVE_MODULE_LDFLAGS = \
$(EXTRA_LINK_FLAGS) \
-module -avoid-version -no-undefined -rdynamic
-langNative_la_CFLAGS = \
- $(JS_NATIVE_MODULE_CFLAGS)
-langNative_la_LIBADD = \
- libgjs.la \
- $(JS_NATIVE_MODULE_LIBADD)
-langNative_la_LDFLAGS = \
- $(JS_NATIVE_MODULE_LDFLAGS)
-
-langNative_la_SOURCES = \
- modules/lang.h \
- modules/lang.c
-
cairoNative_la_CFLAGS = \
$(JS_NATIVE_MODULE_CFLAGS) \
$(GJS_CAIRO_CFLAGS) \
diff --git a/modules/lang.js b/modules/lang.js
index 9703add..9c8d45e 100644
--- a/modules/lang.js
+++ b/modules/lang.js
@@ -92,7 +92,9 @@ function bind(obj, callback) {
typeof(callback));
}
- if (callback.bind && arguments.length == 2) // ECMAScript 5 (but only if not passing any bindArguments)
+ // Use ES5 Function.prototype.bind, but only if not passing any bindArguments,
+ // because ES5 has them at the beginning, not at the end
+ if (arguments.length == 2)
return callback.bind(obj);
let me = obj;
@@ -112,6 +114,26 @@ function defineAccessorProperty(object, name, getter, setter) {
enumerable: true });
}
+function _deepFreeze(o) {
+ Object.freeze(o);
+
+ for (prop in o) {
+ if (!o.hasOwnProperty(prop) || !(typeof o === "object") || Object.isFrozen(o))
+ continue;
+
+ _deepFreeze(o[prop]);
+ }
+}
+
+// The name of this function is unfortunate, as it wraps
+// Object.freeze, not Object.seal
+function seal(object, deep) {
+ if (deep)
+ _deepFreeze(object);
+ else
+ Object.freeze(object);
+}
+
// Class magic
// Adapted from MooTools, MIT license
// https://github.com/mootools/moootools-core
@@ -274,6 +296,3 @@ Class.prototype._init = function(params) {
enumerable: false,
value: _parent }});
};
-
-// Merge stuff defined in native code
-copyProperties(imports.langNative, this);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]