RESOLVED INVALID 184008
JSManagedValue doesn't work with primitive values
https://bugs.webkit.org/show_bug.cgi?id=184008
Summary JSManagedValue doesn't work with primitive values
Carlos Garcia Campos
Reported 2018-03-26 08:56:03 PDT
The implementation allows to store primitive values since r157119, but JSManagedValue doesn't return nil for its value after garbage collection in case of primitives. The test case added in r157119 works because the context is destroyed. Is this the expected behavior? See this test case: @autoreleasepool { JSContext* context = [[JSContext alloc] init]; JSManagedValue *weakFoo, *weakBar; @autoreleasepool { context[@"foo"] = @42; context[@"bar"] = @"Hello"; JSValue* foo = context[@"foo"]; weakFoo = [JSManagedValue managedValueWithValue:foo]; JSValue* bar = context[@"bar"]; weakBar = [JSManagedValue managedValueWithValue:bar]; } JSSynchronousGarbageCollectForDebugging([context JSGlobalContextRef]); @autoreleasepool { JSValue* value = weakFoo.value; checkResult(@"foo is 42", value.isNumber && [value toInt32] == 42); value = weakBar.value; checkResult(@"bar is Hello", value.isString && [@"Hello" isEqualToString:[value toString]]); } [context evaluateScript:@"foo = undefined; bar = undefined;"]; JSSynchronousGarbageCollectForDebugging([context JSGlobalContextRef]); JSValue* value = weakFoo.value; checkResult(@"foo is nil", !value); value = weakBar.value; checkResult(@"bar is nil", !value); } 2018-03-26 17:52:12.894 testapi[54452:51379955] TEST: "foo is 42": PASSED 2018-03-26 17:52:12.894 testapi[54452:51379955] TEST: "bar is Hello": PASSED 2018-03-26 17:52:12.894 testapi[54452:51379955] TEST: "foo is nil": FAILED 2018-03-26 17:52:12.894 testapi[54452:51379955] TEST: "bar is nil": PASSED Is it even possible to support primitive values? I don't think it's possible to use Weak with them, right? Should it be documented that for primitive values it will only work when the context is destroyed?
Attachments
Filip Pizlo
Comment 1 2018-03-26 09:00:36 PDT
Non-string primitive values aren’t garbage collected.
Carlos Garcia Campos
Comment 2 2018-03-26 09:02:40 PDT
(In reply to Filip Pizlo from comment #1) > Non-string primitive values aren’t garbage collected. Ok, so there's no point in supporting them in JSManagedValue, no? I got confused, at least :-)
Carlos Garcia Campos
Comment 3 2018-03-26 09:04:17 PDT
(In reply to Carlos Garcia Campos from comment #2) > (In reply to Filip Pizlo from comment #1) > > Non-string primitive values aren’t garbage collected. > > Ok, so there's no point in supporting them in JSManagedValue, no? I got > confused, at least :-) Ah, I guess it still makes sense for the case of the context being destroyed. Ok, sorry for the noise.
Note You need to log in before you can comment on or make changes to this bug.