[gjs] system: Add clarification to System.addressOf()
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs] system: Add clarification to System.addressOf()
- Date: Tue, 7 Feb 2017 03:27:58 +0000 (UTC)
commit 64d0b9323cd888fa6aa99ca52abfff26d1f736dd
Author: Philip Chimento <philip endlessm com>
Date: Mon Feb 6 17:31:03 2017 -0800
system: Add clarification to System.addressOf()
SpiderMonkey can move objects around in memory during garbage collection,
so System.addressOf() cannot be relied on to identify that an object is
the same as another object.
At the same time, SpiderMonkey 38 also gained the capability to
deduplicate identical objects in memory, so System.addressOf() can also
not be relied on to identify that two identical objects are different
instances.
Adjust our test suite accordingly.
https://bugzilla.gnome.org/show_bug.cgi?id=776966
installed-tests/js/testSystem.js | 9 +++------
modules/system.cpp | 3 +++
2 files changed, 6 insertions(+), 6 deletions(-)
---
diff --git a/installed-tests/js/testSystem.js b/installed-tests/js/testSystem.js
index 927c715..66a868e 100644
--- a/installed-tests/js/testSystem.js
+++ b/installed-tests/js/testSystem.js
@@ -1,13 +1,10 @@
const System = imports.system;
describe('System.addressOf()', function () {
- it('gives the same result for the same object', function () {
- let o = {};
- expect(System.addressOf(o)).toEqual(System.addressOf(o));
- });
-
it('gives different results for different objects', function () {
- expect(System.addressOf({})).not.toEqual(System.addressOf({}));
+ let a = {some: 'object'};
+ let b = {different: 'object'};
+ expect(System.addressOf(a)).not.toEqual(System.addressOf(b));
});
});
diff --git a/modules/system.cpp b/modules/system.cpp
index d8e6287..b39125a 100644
--- a/modules/system.cpp
+++ b/modules/system.cpp
@@ -34,6 +34,9 @@
#include "gjs/jsapi-util-args.h"
#include "system.h"
+/* Note that this cannot be relied on to test whether two objects are the same!
+ * SpiderMonkey can move objects around in memory during garbage collection,
+ * and it can also deduplicate identical instances of objects in memory. */
static bool
gjs_address_of(JSContext *context,
unsigned argc,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]