Implement WeakRef Object (#4546)
Related test262 test-cases has been removed from skip list. Execpt two test-case since they need other feature to work (Finalization registry and async GC) JerryScript-DCO-1.0-Signed-off-by: Bence Gabor Kis kisbg@inf.u-szeged.hu
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
// Copyright JS Foundation and other contributors, http://js.foundation
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
var target_obj = {};
|
||||
var not_target_obj = {};
|
||||
var weak_ref = new WeakRef(target_obj);
|
||||
var weak_ref2 = new WeakRef(target_obj);
|
||||
|
||||
assert (weak_ref.deref() === target_obj);
|
||||
assert (weak_ref.deref() === weak_ref2.deref());
|
||||
assert (weak_ref.deref() !== not_target_obj);
|
||||
|
||||
assert (weak_ref2.deref() === target_obj);
|
||||
assert (weak_ref2.deref() !== not_target_obj);
|
||||
assert (weak_ref2.deref() === weak_ref2.deref());
|
||||
|
||||
target_obj = undefined;
|
||||
gc();
|
||||
|
||||
assert (weak_ref.deref() === undefined);
|
||||
assert (weak_ref2.deref() === undefined);
|
||||
|
||||
var key_obj_1 = {};
|
||||
var key_obj_2 = {};
|
||||
var key_obj_3 = {};
|
||||
var target_obj_2 = {};
|
||||
var target_obj_3 = {};
|
||||
var weak_ref_3 = new WeakRef(key_obj_1);
|
||||
var weak_ref_4 = new WeakRef(target_obj_2);
|
||||
var weak_ref_5 = new WeakRef(target_obj_3);
|
||||
|
||||
var weak_map = new WeakMap();
|
||||
weak_map.set(key_obj_1, weak_ref_3);
|
||||
weak_map.set(key_obj_2, weak_ref_4);
|
||||
weak_map.set(key_obj_3, weak_ref_5);
|
||||
|
||||
assert(weak_map.has(key_obj_1));
|
||||
assert(weak_map.has(key_obj_2));
|
||||
assert(weak_map.has(key_obj_3));
|
||||
|
||||
assert(weak_map.get(key_obj_1).deref() === key_obj_1);
|
||||
assert(weak_map.get(key_obj_2).deref() === target_obj_2);
|
||||
assert(weak_map.get(key_obj_3).deref() === target_obj_3);
|
||||
|
||||
key_obj_1 = undefined;
|
||||
gc();
|
||||
assert(weak_map.get(key_obj_1) === undefined);
|
||||
assert(weak_ref_3.deref() === undefined);
|
||||
|
||||
key_obj_2 = undefined;
|
||||
gc();
|
||||
assert(weak_map.get(key_obj_2) === undefined);
|
||||
assert(weak_ref_4.deref() === target_obj_2);
|
||||
|
||||
target_obj_3 = undefined;
|
||||
gc();
|
||||
assert(weak_map.get(key_obj_3) !== undefined);
|
||||
assert(weak_ref_5.deref() === undefined);
|
||||
@@ -5295,32 +5295,8 @@
|
||||
<test id="built-ins/FinalizationRegistry/target-not-callable-throws.js"><reason></reason></test>
|
||||
<test id="built-ins/FinalizationRegistry/undefined-newtarget-throws.js"><reason></reason></test>
|
||||
<test id="built-ins/FinalizationRegistry/unnaffected-by-poisoned-cleanupCallback.js"><reason></reason></test>
|
||||
<test id="built-ins/WeakRef/constructor.js"><reason></reason></test>
|
||||
<test id="built-ins/WeakRef/instance-extensible.js"><reason></reason></test>
|
||||
<test id="built-ins/WeakRef/length.js"><reason></reason></test>
|
||||
<test id="built-ins/WeakRef/name.js"><reason></reason></test>
|
||||
<test id="built-ins/WeakRef/newtarget-prototype-is-not-object.js"><reason></reason></test>
|
||||
<test id="built-ins/WeakRef/prop-desc.js"><reason></reason></test>
|
||||
<test id="built-ins/WeakRef/proto-from-ctor-realm.js"><reason></reason></test>
|
||||
<test id="built-ins/WeakRef/proto.js"><reason></reason></test>
|
||||
<test id="built-ins/WeakRef/prototype-from-newtarget-abrupt.js"><reason></reason></test>
|
||||
<test id="built-ins/WeakRef/prototype-from-newtarget-custom.js"><reason></reason></test>
|
||||
<test id="built-ins/WeakRef/prototype-from-newtarget.js"><reason></reason></test>
|
||||
<test id="built-ins/WeakRef/prototype/Symbol.toStringTag.js"><reason></reason></test>
|
||||
<test id="built-ins/WeakRef/prototype/constructor.js"><reason></reason></test>
|
||||
<test id="built-ins/WeakRef/prototype/deref/custom-this.js"><reason></reason></test>
|
||||
<test id="built-ins/WeakRef/prototype/deref/gc-cleanup-not-prevented-with-wr-deref.js"><reason></reason></test>
|
||||
<test id="built-ins/WeakRef/prototype/deref/length.js"><reason></reason></test>
|
||||
<test id="built-ins/WeakRef/prototype/deref/name.js"><reason></reason></test>
|
||||
<test id="built-ins/WeakRef/prototype/deref/prop-desc.js"><reason></reason></test>
|
||||
<test id="built-ins/WeakRef/prototype/deref/return-target.js"><reason></reason></test>
|
||||
<test id="built-ins/WeakRef/prototype/deref/this-does-not-have-internal-target-throws.js"><reason></reason></test>
|
||||
<test id="built-ins/WeakRef/prototype/deref/this-not-object-throws.js"><reason></reason></test>
|
||||
<test id="built-ins/WeakRef/prototype/prop-desc.js"><reason></reason></test>
|
||||
<test id="built-ins/WeakRef/prototype/proto.js"><reason></reason></test>
|
||||
<test id="built-ins/WeakRef/returns-new-object-from-constructor.js"><reason></reason></test>
|
||||
<test id="built-ins/WeakRef/target-not-object-throws.js"><reason></reason></test>
|
||||
<test id="built-ins/WeakRef/undefined-newtarget-throws.js"><reason></reason></test>
|
||||
<!-- END - ESNext stage 4 proposal: WeakRefs -->
|
||||
|
||||
<!-- ESNext stage 4 proposal: Logical Assignment Operators
|
||||
@@ -8605,7 +8581,6 @@
|
||||
<test id="built-ins/TypedArrayConstructors/internals/HasProperty/detached-buffer-realm.js"><reason></reason></test>
|
||||
<test id="built-ins/TypedArrayConstructors/internals/Set/BigInt/detached-buffer-realm.js"><reason></reason></test>
|
||||
<test id="built-ins/TypedArrayConstructors/internals/Set/detached-buffer-realm.js"><reason></reason></test>
|
||||
<test id="built-ins/WeakRef/proto-from-ctor-realm.js"><reason></reason></test>
|
||||
<test id="intl402/Collator/proto-from-ctor-realm.js"><reason></reason></test>
|
||||
<test id="intl402/DateTimeFormat/proto-from-ctor-realm.js"><reason></reason></test>
|
||||
<test id="intl402/DisplayNames/proto-from-ctor-realm.js"><reason></reason></test>
|
||||
|
||||
@@ -73,6 +73,7 @@ main (void)
|
||||
const jerry_char_t number_object[] = "new Number(5)";
|
||||
const jerry_char_t regexp_object[] = "new RegExp()";
|
||||
const jerry_char_t string_object[] = "new String('foo')";
|
||||
const jerry_char_t weak_ref_object[] = "new WeakRef({})";
|
||||
|
||||
test_entry_t entries[] =
|
||||
{
|
||||
@@ -115,6 +116,7 @@ main (void)
|
||||
ENTRY_IF (JERRY_OBJECT_TYPE_SYMBOL, EVALUATE (symbol_object), JERRY_FEATURE_SYMBOL),
|
||||
ENTRY_IF (JERRY_OBJECT_TYPE_GENERATOR, EVALUATE (generator_object), JERRY_FEATURE_SYMBOL),
|
||||
ENTRY_IF (JERRY_OBJECT_TYPE_BIGINT, EVALUATE (bigint_object), JERRY_FEATURE_BIGINT),
|
||||
ENTRY_IF (JERRY_OBJECT_TYPE_WEAKREF, EVALUATE (weak_ref_object), JERRY_FEATURE_WEAKREF),
|
||||
};
|
||||
|
||||
for (size_t idx = 0; idx < sizeof (entries) / sizeof (entries[0]); idx++)
|
||||
|
||||
Reference in New Issue
Block a user