Commit cadfe092 authored by neis's avatar neis Committed by Commit bot

[modules] Fix bugs in assignments to exported variables.

- Add hole check if needed.
- Preserve the accumulator so that the result is the rhs.

R=adamk@chromium.org
BUG=v8:1569,v8:5547

Review-Url: https://chromiumcodereview.appspot.com/2438653003
Cr-Commit-Position: refs/heads/master@{#40510}
parent 44375382
...@@ -2042,8 +2042,14 @@ void BytecodeGenerator::BuildVariableAssignment(Variable* variable, ...@@ -2042,8 +2042,14 @@ void BytecodeGenerator::BuildVariableAssignment(Variable* variable,
builder() builder()
->StoreAccumulatorInRegister(args[1]) ->StoreAccumulatorInRegister(args[1])
.LoadLiteral(it->second->export_name->string()) .LoadLiteral(it->second->export_name->string())
.StoreAccumulatorInRegister(args[0]) .StoreAccumulatorInRegister(args[0]);
.CallRuntime(Runtime::kStoreModuleExport, args); if (needs_hole_check) {
builder()->CallRuntime(Runtime::kLoadModuleExport, args[0]);
BuildHoleCheckForVariableAssignment(variable, op);
}
builder()
->CallRuntime(Runtime::kStoreModuleExport, args)
.LoadAccumulatorWithRegister(args[1]);
break; break;
} }
} }
......
...@@ -11,6 +11,11 @@ assertThrows(() => x, ReferenceError); ...@@ -11,6 +11,11 @@ assertThrows(() => x, ReferenceError);
assertThrows(() => y, ReferenceError); assertThrows(() => y, ReferenceError);
assertThrows(() => z, ReferenceError); assertThrows(() => z, ReferenceError);
assertEquals(23, w = 23);
assertThrows(() => x = 666, ReferenceError);
assertThrows(() => y = 666, ReferenceError);
assertThrows(() => z = 666, TypeError);
export function* v() { return 40 } export function* v() { return 40 }
export var w = 41; export var w = 41;
export let x = 42; export let x = 42;
......
...@@ -10,6 +10,12 @@ assertThrows(() => x, ReferenceError); ...@@ -10,6 +10,12 @@ assertThrows(() => x, ReferenceError);
assertThrows(() => y, ReferenceError); assertThrows(() => y, ReferenceError);
assertThrows(() => z, ReferenceError); assertThrows(() => z, ReferenceError);
assertThrows(() => v = 666, TypeError);
assertThrows(() => w = 666, TypeError);
assertThrows(() => x = 666, TypeError);
assertThrows(() => y = 666, TypeError);
assertThrows(() => z = 666, TypeError);
export function check() { export function check() {
assertEquals({value: 40, done: true}, v().next()); assertEquals({value: 40, done: true}, v().next());
assertEquals(41, w); assertEquals(41, w);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment