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,61 +191,24 @@ void Parser::PatternRewriter::VisitVariableProxy(VariableProxy* pattern) { ...@@ -191,61 +191,24 @@ void Parser::PatternRewriter::VisitVariableProxy(VariableProxy* pattern) {
// 'with' statement or 'catch' block). Global var declarations // 'with' statement or 'catch' block). Global var declarations
// also need special treatment. // also need special treatment.
if (descriptor_->mode == VAR && var_init_scope->is_script_scope()) { // For 'let' and 'const' declared variables the initialization always
// Global variable declarations must be compiled in a specific // assigns to the declared variable.
// way. When the script containing the global variable declaration // But for var declarations we need to do a new lookup.
// is entered, the global variable must be declared, so that if it if (descriptor_->mode == VAR) {
// doesn't exist (on the global object itself, see ES5 errata) it proxy = var_init_scope->NewUnresolved(factory(), name);
// 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 { } else {
// For 'let' and 'const' declared variables the initialization always DCHECK_NOT_NULL(proxy);
// assigns to the declared variable. DCHECK_NOT_NULL(proxy->var());
// But for var declarations we need to do a new lookup. }
if (descriptor_->mode == VAR) { // Add break location for destructured sub-pattern.
proxy = var_init_scope->NewUnresolved(factory(), name); int pos = value_beg_position_;
} else { if (pos == kNoSourcePosition) {
DCHECK_NOT_NULL(proxy); pos = IsSubPattern() ? pattern->position() : value->position();
DCHECK_NOT_NULL(proxy->var());
}
// Add break location for destructured sub-pattern.
int pos = value_beg_position_;
if (pos == kNoSourcePosition) {
pos = IsSubPattern() ? pattern->position() : value->position();
}
Assignment* assignment =
factory()->NewAssignment(Token::INIT, proxy, value, pos);
block_->statements()->Add(
factory()->NewExpressionStatement(assignment, pos), zone());
} }
Assignment* assignment =
factory()->NewAssignment(Token::INIT, proxy, value, pos);
block_->statements()->Add(factory()->NewExpressionStatement(assignment, pos),
zone());
} }
......
...@@ -211,18 +211,6 @@ RUNTIME_FUNCTION(Runtime_DeclareGlobalsForInterpreter) { ...@@ -211,18 +211,6 @@ RUNTIME_FUNCTION(Runtime_DeclareGlobalsForInterpreter) {
return DeclareGlobals(isolate, declarations, flags, feedback_vector); 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 { namespace {
Object* DeclareEvalHelper(Isolate* isolate, Handle<String> name, Object* DeclareEvalHelper(Isolate* isolate, Handle<String> name,
......
...@@ -505,7 +505,6 @@ namespace internal { ...@@ -505,7 +505,6 @@ namespace internal {
F(ThrowConstAssignError, 0, 1) \ F(ThrowConstAssignError, 0, 1) \
F(DeclareGlobals, 3, 1) \ F(DeclareGlobals, 3, 1) \
F(DeclareGlobalsForInterpreter, 3, 1) \ F(DeclareGlobalsForInterpreter, 3, 1) \
F(InitializeVarGlobal, 3, 1) \
F(DeclareEvalFunction, 2, 1) \ F(DeclareEvalFunction, 2, 1) \
F(DeclareEvalVar, 1, 1) \ F(DeclareEvalVar, 1, 1) \
F(NewSloppyArguments_Generic, 1, 1) \ F(NewSloppyArguments_Generic, 1, 1) \
......
...@@ -12,7 +12,7 @@ snippet: " ...@@ -12,7 +12,7 @@ snippet: "
" "
frame size: 4 frame size: 4
parameter count: 1 parameter count: 1
bytecode array length: 34 bytecode array length: 23
bytecodes: [ bytecodes: [
B(LdaConstant), U8(0), B(LdaConstant), U8(0),
B(Star), R(1), B(Star), R(1),
...@@ -21,13 +21,8 @@ bytecodes: [ ...@@ -21,13 +21,8 @@ bytecodes: [
B(Mov), R(closure), R(3), B(Mov), R(closure), R(3),
B(CallRuntime), U16(Runtime::kDeclareGlobalsForInterpreter), R(1), U8(3), B(CallRuntime), U16(Runtime::kDeclareGlobalsForInterpreter), R(1), U8(3),
/* 0 E> */ B(StackCheck), /* 0 E> */ B(StackCheck),
/* 8 S> */ B(LdaConstant), U8(1), /* 8 S> */ B(LdaSmi), I8(1),
B(Star), R(1), /* 8 E> */ B(StaGlobalSloppy), U8(1), U8(5),
B(LdaZero),
B(Star), R(2),
B(LdaSmi), I8(1),
B(Star), R(3),
B(CallRuntime), U16(Runtime::kInitializeVarGlobal), R(1), U8(3),
B(LdaUndefined), B(LdaUndefined),
/* 10 S> */ B(Return), /* 10 S> */ B(Return),
] ]
...@@ -69,7 +64,7 @@ snippet: " ...@@ -69,7 +64,7 @@ snippet: "
" "
frame size: 4 frame size: 4
parameter count: 1 parameter count: 1
bytecode array length: 40 bytecode array length: 29
bytecodes: [ bytecodes: [
B(LdaConstant), U8(0), B(LdaConstant), U8(0),
B(Star), R(1), B(Star), R(1),
...@@ -78,15 +73,10 @@ bytecodes: [ ...@@ -78,15 +73,10 @@ bytecodes: [
B(Mov), R(closure), R(3), B(Mov), R(closure), R(3),
B(CallRuntime), U16(Runtime::kDeclareGlobalsForInterpreter), R(1), U8(3), B(CallRuntime), U16(Runtime::kDeclareGlobalsForInterpreter), R(1), U8(3),
/* 0 E> */ B(StackCheck), /* 0 E> */ B(StackCheck),
/* 8 S> */ B(LdaConstant), U8(1), /* 8 S> */ B(LdaSmi), I8(1),
B(Star), R(1), /* 8 E> */ B(StaGlobalSloppy), U8(1), U8(5),
B(LdaZero),
B(Star), R(2),
B(LdaSmi), I8(1),
B(Star), R(3),
B(CallRuntime), U16(Runtime::kInitializeVarGlobal), R(1), U8(3),
/* 11 S> */ B(LdaSmi), I8(2), /* 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), B(Star), R(0),
/* 15 S> */ B(Return), /* 15 S> */ B(Return),
] ]
......
...@@ -12,7 +12,7 @@ snippet: " ...@@ -12,7 +12,7 @@ snippet: "
" "
frame size: 4 frame size: 4
parameter count: 1 parameter count: 1
bytecode array length: 43 bytecode array length: 36
bytecodes: [ bytecodes: [
B(LdaConstant), U8(0), B(LdaConstant), U8(0),
B(Star), R(1), B(Star), R(1),
...@@ -21,23 +21,20 @@ bytecodes: [ ...@@ -21,23 +21,20 @@ bytecodes: [
B(Mov), R(closure), R(3), B(Mov), R(closure), R(3),
B(CallRuntime), U16(Runtime::kDeclareGlobalsForInterpreter), R(1), U8(3), B(CallRuntime), U16(Runtime::kDeclareGlobalsForInterpreter), R(1), U8(3),
/* 0 E> */ B(StackCheck), /* 0 E> */ B(StackCheck),
/* 8 S> */ B(LdaConstant), U8(1), /* 8 S> */ B(CreateObjectLiteral), U8(1), U8(6), U8(21), R(1),
B(Star), R(1), B(CreateClosure), U8(2), U8(5), U8(0),
B(LdaZero), B(StaNamedOwnProperty), R(1), U8(3), U8(7),
B(CreateObjectLiteral), U8(2), U8(6), U8(21), R(3), B(Ldar), R(1),
B(Star), R(2), /* 8 E> */ B(StaGlobalSloppy), U8(4), U8(9),
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),
B(LdaUndefined), B(LdaUndefined),
/* 33 S> */ B(Return), /* 33 S> */ B(Return),
] ]
constant pool: [ constant pool: [
FIXED_ARRAY_TYPE, FIXED_ARRAY_TYPE,
ONE_BYTE_INTERNALIZED_STRING_TYPE ["a"],
FIXED_ARRAY_TYPE, FIXED_ARRAY_TYPE,
SHARED_FUNCTION_INFO_TYPE, SHARED_FUNCTION_INFO_TYPE,
ONE_BYTE_INTERNALIZED_STRING_TYPE ["func"], ONE_BYTE_INTERNALIZED_STRING_TYPE ["func"],
ONE_BYTE_INTERNALIZED_STRING_TYPE ["a"],
] ]
handlers: [ handlers: [
] ]
......
...@@ -53,8 +53,8 @@ assertEquals(42, get); ...@@ -53,8 +53,8 @@ assertEquals(42, get);
assertEquals([ assertEquals([
"a0", "a0",
"b17", "h4b17", "i2b17", // [[Has]] "b10", "h4b17", "i2b17", // [[Has]]
"c15", "j4c15", "k2c15", // [[Get]] "c10", "j4c15", "k2c15", // [[Get]]
"d0", "l4d11", "m2d11", // [[Set]] "d0", "l4d11", "m2d11", // [[Set]]
"g0" "g0"
], log); ], log);
...@@ -47,8 +47,7 @@ assertNull(exception); ...@@ -47,8 +47,7 @@ assertNull(exception);
assertEquals([ assertEquals([
"a0", "a0",
"b44", "b8",
"b13",
"d2b13", "d2b13",
"e0b13", "e0b13",
"b25", "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