[gjs/wip/ptomato/mozjs38: 24/27] js: Various SpiderMonkey 38 improvements
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs/wip/ptomato/mozjs38: 24/27] js: Various SpiderMonkey 38 improvements
- Date: Thu, 9 Feb 2017 06:42:22 +0000 (UTC)
commit fb617ddd69b1de1ad864967bb57cc4b3e8cac496
Author: Philip Chimento <philip endlessm com>
Date: Thu Jan 26 16:19:53 2017 -0800
js: Various SpiderMonkey 38 improvements
Here are three places where SpiderMonkey 38 offers a better API than the
one we were using.
The fourth spot, we could use JS::CallArgs::requireAtLeast(), but there is
an issue with the visibility of that symbol in the shared library. Add a
link to the Mozilla bug for that.
https://bugzilla.gnome.org/show_bug.cgi?id=777962
gi/object.cpp | 8 +-------
gjs/jsapi-constructor-proxy.cpp | 3 +--
gjs/jsapi-util-args.h | 3 ++-
installed-tests/js/testGDBus.js | 11 +++--------
4 files changed, 7 insertions(+), 18 deletions(-)
---
diff --git a/gi/object.cpp b/gi/object.cpp
index 96b5be9..721d197 100644
--- a/gi/object.cpp
+++ b/gi/object.cpp
@@ -1735,13 +1735,7 @@ real_connect_func(JSContext *context,
return false;
}
- /* Best I can tell, there is no way to know if argv[1] is really
- * callable other than to just try it. Checking whether it's a
- * function will not detect native objects that provide
- * JSClass::call, for example.
- */
-
- if (argc != 2 || !argv[0].isString() || !argv[1].isObject()) {
+ if (argc != 2 || !argv[0].isString() || !JS::IsCallable(&argv[1].toObject())) {
gjs_throw(context, "connect() takes two args, the signal name and the callback");
return false;
}
diff --git a/gjs/jsapi-constructor-proxy.cpp b/gjs/jsapi-constructor-proxy.cpp
index 02dc1a1..aede3c3 100644
--- a/gjs/jsapi-constructor-proxy.cpp
+++ b/gjs/jsapi-constructor-proxy.cpp
@@ -144,8 +144,7 @@ create_gjs_constructor_proxy(JSContext *cx,
return false;
}
- if (!args[0].isObject() || !JS_ObjectIsFunction(cx, &args[0].toObject())) {
- /* COMPAT: Use JS::IsConstructor() in mozjs38 */
+ if (!args[0].isObject() || !JS::IsConstructor(&args[0].toObject())) {
gjs_throw(cx, "First argument must be a constructor");
return false;
}
diff --git a/gjs/jsapi-util-args.h b/gjs/jsapi-util-args.h
index 3229350..665aeb6 100644
--- a/gjs/jsapi-util-args.h
+++ b/gjs/jsapi-util-args.h
@@ -394,7 +394,8 @@ gjs_parse_call_args(JSContext *cx,
JSAutoRequest ar(cx);
- /* COMPAT: In future, use args.requireAtLeast() */
+ /* COMPAT: In future, use args.requireAtLeast()
+ * https://bugzilla.mozilla.org/show_bug.cgi?id=1334338 */
if (args.length() < n_required ||
(args.length() > n_total && !ignore_trailing_args)) {
if (n_required == n_total) {
diff --git a/installed-tests/js/testGDBus.js b/installed-tests/js/testGDBus.js
index 28e1f15..ab21585 100644
--- a/installed-tests/js/testGDBus.js
+++ b/installed-tests/js/testGDBus.js
@@ -158,7 +158,7 @@ Test.prototype = {
},
arrayOutBadSig: function() {
- return [ "Hello", "World", "!" ];
+ return Symbol('Hello World!');
},
byteArrayEcho: function(binaryString) {
@@ -375,19 +375,14 @@ describe('Exported DBus object', function () {
loop.run();
});
- /* COMPAT: This test should test what happens when a TypeError is thrown
- * during argument marshalling, but conversions don't throw TypeErrors
- * anymore, so we can't test that ... until we upgrade to mozjs38 which has
- * Symbols. Converting a Symbol to an int32 or string will throw a TypeError.
- */
- xit('handles a bad signature by throwing an exception', function () {
+ it('handles a bad signature by throwing an exception', function () {
proxy.arrayOutBadSigRemote(function(result, excp) {
expect(result).toBeNull();
expect(excp).not.toBeNull();
loop.quit();
});
loop.run();
- }).pend('currently cannot throw TypeError during conversion');
+ });
it('can call a remote method that is implemented asynchronously', function () {
let someString = "Hello world!";
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]