From c6add47f549e0f3f8b97a9f7aa07a13829559cb9 Mon Sep 17 00:00:00 2001 From: Sami Vaarala Date: Fri, 18 Jul 2014 00:04:50 +0300 Subject: [PATCH] Testcase for user internal props Also tag Date _value access test case as custom. --- .../test-dev-internal-key-access.js | 6 ++ .../test-dev-internal-property-basics.js | 65 +++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 ecmascript-testcases/test-dev-internal-property-basics.js diff --git a/ecmascript-testcases/test-dev-internal-key-access.js b/ecmascript-testcases/test-dev-internal-key-access.js index c64b8dcb..00207d74 100644 --- a/ecmascript-testcases/test-dev-internal-key-access.js +++ b/ecmascript-testcases/test-dev-internal-key-access.js @@ -6,6 +6,12 @@ * buffer values nor the ability to create buffer values. */ +/*--- +{ + "custom": true +} +---*/ + /*=== date: 1970-01-01T00:02:03.456Z using Duktape.Buffer, date \xFFvalue: 123456 diff --git a/ecmascript-testcases/test-dev-internal-property-basics.js b/ecmascript-testcases/test-dev-internal-property-basics.js new file mode 100644 index 00000000..54999bcb --- /dev/null +++ b/ecmascript-testcases/test-dev-internal-property-basics.js @@ -0,0 +1,65 @@ +/* + * Since Duktape 0.12.0, user code can also employ internal properties. + * This testcase exercises a few basics of that. + */ + +/*--- +{ + "custom": true +} +---*/ + +/*=== +for-in: foo +JSON.stringify: {"foo":1} +JX encoded: {foo:1} +Object.keys: foo +Object.getOwnPropertyNames: foo,bar +direct access: 3 +===*/ + +function test() { + var internalKey; + var obj; + + // 'foo' is enumerable, writable, configurable + var obj = { foo: 1 }; + + // 'bar' is not enumerable + Object.defineProperty(obj, 'bar', { + value: 2, writable: true, enumerable: false, configurable: true + }); + + // Internal key \xFF\xFFabc is in principle enumerable, but because + // internal keys have special behavior, it is never enumerated. + internalKey = Duktape.dec('hex', 'ffff616263'); // \xFF\xFFabc + obj[internalKey] = 3; + + // For-in only lists enumerable keys + for (k in obj) { + print('for-in:', k); + } + + // JSON.stringify() also only lists enumerable keys + print('JSON.stringify:', JSON.stringify(obj)); + + // Even the Duktape-specific JX format doesn't list internal keys + print('JX encoded:', Duktape.enc('jx', obj)); + + // Object.keys() only returns enumerable keys (but not internal keys, + // even if they're technically enumerable) + print('Object.keys:', Object.keys(obj)); + + // Object.getOwnPropertyNames() returns also non-enumerable keys, + // but not internal keys + print('Object.getOwnPropertyNames:', Object.getOwnPropertyNames(obj)); + + // Direct property access to the internal property still works. + print('direct access:', obj[internalKey]); +} + +try { + test(); +} catch (e) { + print(e); +}