Commit 2b1eb978 authored by Leszek Swirski's avatar Leszek Swirski Committed by Commit Bot

[parsing/runtime] Remove InitializeVarGlobal

Change-Id: I2ee0ff9db1bbc8c17a1ad3dea1de1ad996895852
Reviewed-on: https://chromium-review.googlesource.com/474807Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Reviewed-by: 's avatarAleksey Kozyatinskiy <kozyatinskiy@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#46338}
parent 1c555714
......@@ -191,42 +191,6 @@ void Parser::PatternRewriter::VisitVariableProxy(VariableProxy* pattern) {
// 'with' statement or 'catch' block). Global var declarations
// also need special treatment.
if (descriptor_->mode == VAR && var_init_scope->is_script_scope()) {
// Global variable declarations must be compiled in a specific
// way. When the script containing the global variable declaration
// is entered, the global variable must be declared, so that if it
// doesn't exist (on the global object itself, see ES5 errata) it
// gets created with an initial undefined value. This is handled
// by the declarations part of the function representing the
// top-level global code; see Runtime::DeclareGlobalVariable. If
// it already exists (in the object or in a prototype), it is
// *not* touched until the variable declaration statement is
// executed.
//
// Executing the variable declaration statement will always
// guarantee to give the global object an own property.
// This way, global variable declarations can shadow
// properties in the prototype chain, but only after the variable
// declaration statement has been executed. This is important in
// browsers where the global object (window) has lots of
// properties defined in prototype objects.
ZoneList<Expression*>* arguments =
new (zone()) ZoneList<Expression*>(3, zone());
arguments->Add(
factory()->NewStringLiteral(name, descriptor_->declaration_pos),
zone());
arguments->Add(factory()->NewNumberLiteral(var_init_scope->language_mode(),
kNoSourcePosition),
zone());
arguments->Add(value, zone());
CallRuntime* initialize = factory()->NewCallRuntime(
Runtime::kInitializeVarGlobal, arguments, value->position());
block_->statements()->Add(
factory()->NewExpressionStatement(initialize, initialize->position()),
zone());
} else {
// For 'let' and 'const' declared variables the initialization always
// assigns to the declared variable.
// But for var declarations we need to do a new lookup.
......@@ -243,9 +207,8 @@ void Parser::PatternRewriter::VisitVariableProxy(VariableProxy* pattern) {
}
Assignment* assignment =
factory()->NewAssignment(Token::INIT, proxy, value, pos);
block_->statements()->Add(
factory()->NewExpressionStatement(assignment, pos), zone());
}
block_->statements()->Add(factory()->NewExpressionStatement(assignment, pos),
zone());
}
......
......@@ -211,18 +211,6 @@ RUNTIME_FUNCTION(Runtime_DeclareGlobalsForInterpreter) {
return DeclareGlobals(isolate, declarations, flags, feedback_vector);
}
RUNTIME_FUNCTION(Runtime_InitializeVarGlobal) {
HandleScope scope(isolate);
DCHECK_EQ(3, args.length());
CONVERT_ARG_HANDLE_CHECKED(String, name, 0);
CONVERT_LANGUAGE_MODE_ARG_CHECKED(language_mode, 1);
CONVERT_ARG_HANDLE_CHECKED(Object, value, 2);
Handle<JSGlobalObject> global(isolate->global_object());
RETURN_RESULT_OR_FAILURE(
isolate, Object::SetProperty(global, name, value, language_mode));
}
namespace {
Object* DeclareEvalHelper(Isolate* isolate, Handle<String> name,
......
......@@ -505,7 +505,6 @@ namespace internal {
F(ThrowConstAssignError, 0, 1) \
F(DeclareGlobals, 3, 1) \
F(DeclareGlobalsForInterpreter, 3, 1) \
F(InitializeVarGlobal, 3, 1) \
F(DeclareEvalFunction, 2, 1) \
F(DeclareEvalVar, 1, 1) \
F(NewSloppyArguments_Generic, 1, 1) \
......
......@@ -12,7 +12,7 @@ snippet: "
"
frame size: 4
parameter count: 1
bytecode array length: 34
bytecode array length: 23
bytecodes: [
B(LdaConstant), U8(0),
B(Star), R(1),
......@@ -21,13 +21,8 @@ bytecodes: [
B(Mov), R(closure), R(3),
B(CallRuntime), U16(Runtime::kDeclareGlobalsForInterpreter), R(1), U8(3),
/* 0 E> */ B(StackCheck),
/* 8 S> */ B(LdaConstant), U8(1),
B(Star), R(1),
B(LdaZero),
B(Star), R(2),
B(LdaSmi), I8(1),
B(Star), R(3),
B(CallRuntime), U16(Runtime::kInitializeVarGlobal), R(1), U8(3),
/* 8 S> */ B(LdaSmi), I8(1),
/* 8 E> */ B(StaGlobalSloppy), U8(1), U8(5),
B(LdaUndefined),
/* 10 S> */ B(Return),
]
......@@ -69,7 +64,7 @@ snippet: "
"
frame size: 4
parameter count: 1
bytecode array length: 40
bytecode array length: 29
bytecodes: [
B(LdaConstant), U8(0),
B(Star), R(1),
......@@ -78,15 +73,10 @@ bytecodes: [
B(Mov), R(closure), R(3),
B(CallRuntime), U16(Runtime::kDeclareGlobalsForInterpreter), R(1), U8(3),
/* 0 E> */ B(StackCheck),
/* 8 S> */ B(LdaConstant), U8(1),
B(Star), R(1),
B(LdaZero),
B(Star), R(2),
B(LdaSmi), I8(1),
B(Star), R(3),
B(CallRuntime), U16(Runtime::kInitializeVarGlobal), R(1), U8(3),
/* 8 S> */ B(LdaSmi), I8(1),
/* 8 E> */ B(StaGlobalSloppy), U8(1), U8(5),
/* 11 S> */ B(LdaSmi), I8(2),
/* 12 E> */ B(StaGlobalSloppy), U8(1), U8(5),
/* 12 E> */ B(StaGlobalSloppy), U8(1), U8(7),
B(Star), R(0),
/* 15 S> */ B(Return),
]
......
......@@ -12,7 +12,7 @@ snippet: "
"
frame size: 4
parameter count: 1
bytecode array length: 43
bytecode array length: 36
bytecodes: [
B(LdaConstant), U8(0),
B(Star), R(1),
......@@ -21,23 +21,20 @@ bytecodes: [
B(Mov), R(closure), R(3),
B(CallRuntime), U16(Runtime::kDeclareGlobalsForInterpreter), R(1), U8(3),
/* 0 E> */ B(StackCheck),
/* 8 S> */ B(LdaConstant), U8(1),
B(Star), R(1),
B(LdaZero),
B(CreateObjectLiteral), U8(2), U8(6), U8(21), R(3),
B(Star), R(2),
B(CreateClosure), U8(3), U8(5), U8(0),
B(StaNamedOwnProperty), R(3), U8(4), U8(7),
B(CallRuntime), U16(Runtime::kInitializeVarGlobal), R(1), U8(3),
/* 8 S> */ B(CreateObjectLiteral), U8(1), U8(6), U8(21), R(1),
B(CreateClosure), U8(2), U8(5), U8(0),
B(StaNamedOwnProperty), R(1), U8(3), U8(7),
B(Ldar), R(1),
/* 8 E> */ B(StaGlobalSloppy), U8(4), U8(9),
B(LdaUndefined),
/* 33 S> */ B(Return),
]
constant pool: [
FIXED_ARRAY_TYPE,
ONE_BYTE_INTERNALIZED_STRING_TYPE ["a"],
FIXED_ARRAY_TYPE,
SHARED_FUNCTION_INFO_TYPE,
ONE_BYTE_INTERNALIZED_STRING_TYPE ["func"],
ONE_BYTE_INTERNALIZED_STRING_TYPE ["a"],
]
handlers: [
]
......
......@@ -53,8 +53,8 @@ assertEquals(42, get);
assertEquals([
"a0",
"b17", "h4b17", "i2b17", // [[Has]]
"c15", "j4c15", "k2c15", // [[Get]]
"b10", "h4b17", "i2b17", // [[Has]]
"c10", "j4c15", "k2c15", // [[Get]]
"d0", "l4d11", "m2d11", // [[Set]]
"g0"
], log);
......@@ -47,8 +47,7 @@ assertNull(exception);
assertEquals([
"a0",
"b44",
"b13",
"b8",
"d2b13",
"e0b13",
"b25",
......
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