Previously, a direct pointer to the first element of an array of
rejected promise values was used to convert that element to a string.
This is not correct because that pointer may become invalid if rejected
promise values array is resized between invocation of "toString" and
"valueOf" methods which are called while converting the element to a
string.
The fix is to ensure that the rejected promise value is never changed.
This closes #580 issue on Github.
}
if (njs_vm_unhandled_rejection(vm)) {
- ret = njs_value_to_string(vm, &string,
- &vm->promise_reason->start[0]);
+ njs_value_assign(&string, &vm->promise_reason->start[0]);
+ ret = njs_value_to_string(vm, &string, &string);
if (njs_slow_path(ret != NJS_OK)) {
return ret;
}
--- /dev/null
+/*---
+includes: []
+flags: []
+negative:
+ phase: runtime
+---*/
+
+String.toString = async () => {
+ String.prototype.concat([String, {toString(){ throw String; }}]);
+ throw 1;
+};
+String.valueOf = String;
+
+(async function() { throw String; })()