Bug 184008
| Summary: | JSManagedValue doesn't work with primitive values | ||
|---|---|---|---|
| Product: | WebKit | Reporter: | Carlos Garcia Campos <cgarcia> |
| Component: | JavaScriptCore | Assignee: | Nobody <webkit-unassigned> |
| Status: | RESOLVED INVALID | ||
| Severity: | Normal | CC: | fpizlo, mark.lam, mhahnenb, oliver, ysuzuki |
| Priority: | P2 | ||
| Version: | WebKit Nightly Build | ||
| Hardware: | Unspecified | ||
| OS: | Unspecified | ||
| See Also: | https://bugs.webkit.org/show_bug.cgi?id=122351 | ||
Carlos Garcia Campos
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 | ||
|---|---|---|
| Add attachment proposed patch, testcase, etc. |
Filip Pizlo
Non-string primitive values aren’t garbage collected.
Carlos Garcia Campos
(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
(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.