Commit a60e1822 authored by jpp's avatar jpp Committed by Commit bot

[Asm.js] Prevents assignments to immutables.

Adds a check so that module validation fails if there are any
assignments to immutable identifiers (e.g., module name, module
parameters, stdlib imports.)

BUG= https://bugs.chromium.org/p/chromium/issues/detail?id=640194

Review-Url: https://codereview.chromium.org/2268363002
Cr-Commit-Position: refs/heads/master@{#38838}
parent 6fe0b39b
......@@ -1744,7 +1744,11 @@ AsmType* AsmTyper::ValidateAssignmentExpression(Assignment* assignment) {
return value_type;
}
DCHECK(target_info->type() != AsmType::None());
if (!target_info->IsMutable()) {
FAIL(assignment, "Can't assign to immutable symbol.");
}
DCHECK_NE(AsmType::None(), target_info->type());
if (!value_type->IsA(target_info->type())) {
FAIL(assignment, "Type mismatch in assignment.");
}
......
......@@ -1941,4 +1941,63 @@ TEST(B63099) {
}
}
// This issue was triggered because assignments to immutable symbols (e.g., the
// module's name, or any of the asm.js' module parameters) was not being
// handled.
TEST(B640194) {
const char* kTests[] = {
"function asm() {\n"
" 'use asm';\n"
" function f() {\n"
" asm = 0;\n"
" }\n"
" return f;\n"
"}",
"function asm(stdlib) {\n"
" 'use asm';\n"
" function f() {\n"
" stdlib = 0;\n"
" }\n"
" return f;\n"
"}",
"function asm(stdlib, foreign) {\n"
" 'use asm';\n"
" function f() {\n"
" foreign = 0;\n"
" }\n"
" return f;\n"
"}",
"function asm(stdlib, foreign, heap) {\n"
" 'use asm';\n"
" function f() {\n"
" heap = 0;\n"
" }\n"
" return f;\n"
"}",
"function asm(stdlib, foreign, heap) {\n"
" 'use asm';\n"
" var f = stdlib.Math.fround;\n"
" function f() {\n"
" f = 0;\n"
" }\n"
" return f;\n"
"}",
"function asm(stdlib, foreign, heap) {\n"
" 'use asm';\n"
" var E = stdlib.Math.E;\n"
" function f() {\n"
" E = 0;\n"
" }\n"
" return f;\n"
"}",
};
for (size_t ii = 0; ii < arraysize(kTests); ++ii) {
if (!ValidationOf(Module(kTests[ii]))
->FailsWithMessage("Can't assign to immutable symbol")) {
std::cerr << "Test:\n" << kTests[ii];
CHECK(false);
}
}
}
} // namespace
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