Commit 8d3e1ca3 authored by mythria's avatar mythria Committed by Commit bot

[Interpreter] Adds support for with statement to interpreter.

Adds implementation and tests for with statement to interprter.

BUG=v8:4280,v8:4684
LOG=N

Review URL: https://codereview.chromium.org/1656863002

Cr-Commit-Position: refs/heads/master@{#33705}
parent e8144576
......@@ -860,7 +860,10 @@ void BytecodeGenerator::VisitReturnStatement(ReturnStatement* stmt) {
void BytecodeGenerator::VisitWithStatement(WithStatement* stmt) {
UNIMPLEMENTED();
VisitForAccumulatorValue(stmt->expression());
builder()->CastAccumulatorToJSObject();
VisitNewLocalWithContext();
VisitInScope(stmt->statement(), stmt->scope());
}
......@@ -2377,6 +2380,19 @@ void BytecodeGenerator::VisitNewLocalBlockContext(Scope* scope) {
execution_result()->SetResultInAccumulator();
}
void BytecodeGenerator::VisitNewLocalWithContext() {
AccumulatorResultScope accumulator_execution_result(this);
register_allocator()->PrepareForConsecutiveAllocations(2);
Register extension_object = register_allocator()->NextConsecutiveRegister();
Register closure = register_allocator()->NextConsecutiveRegister();
builder()->StoreAccumulatorInRegister(extension_object);
VisitFunctionClosureForContext();
builder()->StoreAccumulatorInRegister(closure).CallRuntime(
Runtime::kPushWithContext, extension_object, 2);
execution_result()->SetResultInAccumulator();
}
void BytecodeGenerator::VisitNewLocalCatchContext(Variable* variable) {
AccumulatorResultScope accumulator_execution_result(this);
......@@ -2472,6 +2488,12 @@ void BytecodeGenerator::VisitFunctionClosureForContext() {
Context::NATIVE_CONTEXT_INDEX)
.StoreAccumulatorInRegister(native_context)
.LoadContextSlot(native_context, Context::CLOSURE_INDEX);
} else if (closure_scope->is_eval_scope()) {
// Contexts created by a call to eval have the same closure as the
// context calling eval, not the anonymous closure containing the eval
// code. Fetch it from the context.
builder()->LoadContextSlot(execution_context()->reg(),
Context::CLOSURE_INDEX);
} else {
DCHECK(closure_scope->is_function_scope());
builder()->LoadAccumulatorWithRegister(Register::function_closure());
......
......@@ -84,6 +84,7 @@ class BytecodeGenerator final : public AstVisitor {
void VisitBlockDeclarationsAndStatements(Block* stmt);
void VisitNewLocalBlockContext(Scope* scope);
void VisitNewLocalCatchContext(Variable* variable);
void VisitNewLocalWithContext();
void VisitFunctionClosureForContext();
void VisitSetHomeObject(Register value, Register home_object,
ObjectLiteralProperty* property, int slot_number = 0);
......
......@@ -563,22 +563,6 @@
'test-api/ClassPrototypeCreationContext': [FAIL],
'test-run-jsops/ClassLiteral': [FAIL],
# TODO(rmcilroy,4684): Requires support for with statements.
'test-unscopables-hidden-prototype/Unscopables': [FAIL],
'test-decls/CrossScriptDynamicLookup': [FAIL],
'test-api/EvalAliasedDynamic': [FAIL],
'test-api/CrossEval': [FAIL],
'test-api/ReadOnlyPropertyInGlobalProto': [FAIL],
'test-api/StreamingWithDebuggingEnabledLate': [FAIL],
'test-heap/CellsInOptimizedCodeAreWeak': [FAIL],
'test-heap/NoWeakHashTableLeakWithIncrementalMarking': [FAIL],
'test-api/CatchExceptionFromWith': [FAIL],
'test-api/CallbackExceptionRegression': [FAIL],
'test-api/UseWithFromExtension': [FAIL],
'test-run-jscalls/LookupCall': [FAIL],
'test-run-jsops/LookupLoad': [FAIL],
'test-run-jsops/LookupStore': [FAIL],
# TODO(rmcilroy,4681): Requires support for generators.
'test-inobject-slack-tracking/JSGeneratorObjectBasic': [FAIL],
'test-inobject-slack-tracking/JSGeneratorObjectBasicNoInlineNew': [FAIL],
......@@ -664,6 +648,7 @@
'test-heap/IncrementalMarkingPreservesMonomorphicConstructor': [FAIL],
'test-heap/IncrementalMarkingPreservesMonomorphicCallIC': [FAIL],
'test-heap/CompilationCacheCachingBehavior': [FAIL],
'test-heap/CellsInOptimizedCodeAreWeak': [FAIL],
'test-run-inlining/InlineTwice': [FAIL],
'test-run-jsobjects/ArgumentsRest': [FAIL],
'test-decls/Regress425510': [FAIL],
......@@ -750,7 +735,7 @@
['ignition == True and arch == arm64', {
# TODO(rmcilroy,4680): Arm64 specific test failures.
'test-js-arm64-variables/lookup_slots': [FAIL],
'test-heap/NoWeakHashTableLeakWithIncrementalMarking': [FAIL],
# TODO(rmcilroy,4680): Arm64 flakes.
'test-serialize/SerializeInternalReference': [PASS, FAIL],
......
......@@ -2632,6 +2632,43 @@ TEST(BytecodeGraphBuilderDoExpressions) {
FLAG_harmony_do_expressions = old_flag;
}
TEST(BytecodeGraphBuilderWithStatement) {
HandleAndZoneScope scope;
Isolate* isolate = scope.main_isolate();
Zone* zone = scope.main_zone();
ExpectedSnippet<0> snippets[] = {
{"with({x:42}) return x;", {handle(Smi::FromInt(42), isolate)}},
{"with({}) { var y = 10; return y;}",
{handle(Smi::FromInt(10), isolate)}},
{"var y = {x:42};"
" function inner() {"
" var x = 20;"
" with(y) return x;"
"}"
"return inner();",
{handle(Smi::FromInt(42), isolate)}},
{"var y = {x:42};"
" function inner(o) {"
" var x = 20;"
" with(o) return x;"
"}"
"return inner(y);",
{handle(Smi::FromInt(42), isolate)}},
};
for (size_t i = 0; i < arraysize(snippets); i++) {
ScopedVector<char> script(1024);
SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName,
snippets[i].code_snippet, kFunctionName);
BytecodeGraphTester tester(isolate, zone, script.start());
auto callable = tester.GetCallable<>();
Handle<Object> return_value = callable().ToHandleChecked();
CHECK(return_value->SameValue(*snippets[i].return_value()));
}
}
} // namespace compiler
} // namespace internal
} // namespace v8
......@@ -7602,6 +7602,55 @@ TEST(DoExpression) {
FLAG_harmony_do_expressions = old_flag;
}
TEST(WithStatement) {
InitializedHandleScope handle_scope;
BytecodeGeneratorHelper helper;
int deep_elements_flags =
ObjectLiteral::kFastElements | ObjectLiteral::kDisableMementos;
int context = Register::current_context().index();
int closure = Register::function_closure().index();
int new_target = Register::new_target().index();
ExpectedSnippet<InstanceType> snippets[] = {
{"with ({x:42}) { return x; }",
5 * kPointerSize,
1,
46,
{
B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), //
U8(1), //
B(PushContext), R(0), //
B(Ldar), THIS(1), //
B(StaContextSlot), R(context), U8(4), //
B(CreateMappedArguments), //
B(StaContextSlot), R(context), U8(5), //
B(Ldar), R(new_target), //
B(StaContextSlot), R(context), U8(6), //
B(CreateObjectLiteral), U8(0), U8(0), U8(deep_elements_flags), //
B(Star), R(2), //
B(ToObject), //
B(Star), R(3), //
B(Ldar), R(closure), //
B(Star), R(4), //
B(CallRuntime), U16(Runtime::kPushWithContext), R(3), U8(2), //
B(PushContext), R(1), //
B(LdaLookupSlot), U8(1), //
B(PopContext), R(0), //
B(Return), //
},
2,
{InstanceType::FIXED_ARRAY_TYPE,
InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
};
for (size_t i = 0; i < arraysize(snippets); i++) {
Handle<BytecodeArray> bytecode_array =
helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
CheckBytecodeArrayEqual(snippets[i], bytecode_array);
}
}
} // namespace interpreter
} // namespace internal
} // namespace v8
......@@ -3750,6 +3750,39 @@ TEST(InterpreterDoExpression) {
FLAG_harmony_do_expressions = old_flag;
}
TEST(InterpreterWithStatement) {
HandleAndZoneScope handles;
i::Isolate* isolate = handles.main_isolate();
std::pair<const char*, Handle<Object>> with_stmt[] = {
{"with({x:42}) return x;", handle(Smi::FromInt(42), isolate)},
{"with({}) { var y = 10; return y;}", handle(Smi::FromInt(10), isolate)},
{"var y = {x:42};"
" function inner() {"
" var x = 20;"
" with(y) return x;"
"}"
"return inner();",
handle(Smi::FromInt(42), isolate)},
{"var y = {x:42};"
" function inner(o) {"
" var x = 20;"
" with(o) return x;"
"}"
"return inner(y);",
handle(Smi::FromInt(42), isolate)},
};
for (size_t i = 0; i < arraysize(with_stmt); i++) {
std::string source(InterpreterTester::SourceForBody(with_stmt[i].first));
InterpreterTester tester(handles.main_isolate(), source.c_str());
auto callable = tester.GetCallable<>();
Handle<i::Object> return_value = callable().ToHandleChecked();
CHECK(return_value->SameValue(*with_stmt[i].second));
}
}
} // namespace interpreter
} // namespace internal
} // namespace v8
......@@ -756,20 +756,10 @@
'regress/debug*': [SKIP],
'regress/regress-debug*': [SKIP],
# TODO(4684): Support for "with" statements is missing.
'regress/regress-1528': [FAIL],
'regress/regress-2594': [FAIL],
'regress/regress-410030': [FAIL],
'regress/regress-583260': [FAIL],
'regress/regress-96523': [FAIL],
'regress/regress-crbug-505907': [FAIL],
'regress/regress-crbug-506956': [FAIL],
'strict-mode-implicit-receiver': [FAIL],
'throw-and-catch-function': [FAIL],
# TODO(4674): This might be failing because of missing context switch.
'with-leave': [FAIL],
'arguments-load-across-eval': [SKIP],
'arguments-read-and-assignment': [SKIP],
'array-constructor': [PASS, SLOW],
'array-functions-prototype-misc': [SKIP],
'array-join': [SKIP],
......@@ -780,58 +770,38 @@
'compiler/deopt-inlined-smi': [SKIP],
'compiler/deopt-tonumber-compare': [SKIP],
'compiler/expression-trees': [SKIP],
'compiler/optimized-for-in': [SKIP],
'compiler/opt-next-call-turbo': [SKIP],
'compiler/regress-446647': [SKIP],
'compiler/regress-447567': [SKIP],
'compiler/regress-96989': [SKIP],
'compiler/regress-const': [SKIP],
'compiler/regress-funarguments': [SKIP],
'compiler/regress-stacktrace-methods': [SKIP],
'compiler/rotate': [SKIP],
'compiler/strict-recompile': [SKIP],
'compiler/uint32': [SKIP],
'compiler/variables': [SKIP],
'contextual-calls': [SKIP],
'cyclic-array-to-string': [SKIP],
'd8-worker-sharedarraybuffer': [SKIP],
'declare-locally': [SKIP],
'delete-in-with': [SKIP],
'deserialize-optimize-inner': [SKIP],
'eval-enclosing-function-name': [SKIP],
'eval': [SKIP],
'eval-stack-trace': [SKIP],
'eval-typeof-non-existing': [SKIP],
'field-type-tracking': [SKIP],
'getter-in-prototype': [SKIP],
'global-const-var-conflicts': [SKIP],
'global-hash': [SKIP],
'global-load-from-eval-in-with': [SKIP],
'global-load-from-nested-eval': [SKIP],
'global-vars-with': [SKIP],
'messages': [SKIP],
'override-read-only-property': [SKIP],
'property-load-across-eval': [SKIP],
'proto-accessor': [SKIP],
'readonly': [SKIP],
'receiver-in-with-calls': [SKIP],
'regress-3225': [SKIP],
'regress/poly_count_operation': [SKIP],
'regress/regress-102153': [SKIP],
'regress/regress-1030466': [SKIP],
'regress/regress-1079': [SKIP],
'regress/regress-109195': [SKIP],
'regress/regress-1114040': [SKIP],
'regress/regress-1125': [SKIP],
'regress/regress-1170187': [SKIP],
'regress/regress-1170': [SKIP],
'regress/regress-1178598': [SKIP],
'regress/regress-119609': [SKIP],
'regress/regress-1199637': [SKIP],
'regress/regress-1200351': [SKIP],
'regress/regress-123919': [SKIP],
'regress/regress-124594': [SKIP],
'regress/regress-124': [SKIP],
'regress/regress-131994': [SKIP],
'regress/regress-1412': [SKIP],
'regress/regress-1436': [SKIP],
......@@ -844,17 +814,12 @@
'regress/regress-1853': [SKIP],
'regress/regress-186': [SKIP],
'regress/regress-1980': [SKIP],
'regress/regress-2071': [SKIP],
'regress/regress-220': [SKIP],
'regress/regress-2318': [SKIP],
'regress/regress-2618': [SKIP],
'regress/regress-263': [SKIP],
'regress/regress-265': [SKIP],
'regress/regress-269': [SKIP],
'regress/regress-2790': [SKIP],
'regress/regress-2825': [SKIP],
'regress/regress-3138': [SKIP],
'regress/regress-318420': [SKIP],
'regress/regress-353551': [SKIP],
'regress/regress-354357': [SKIP],
'regress/regress-3926': [SKIP],
......@@ -862,9 +827,7 @@
'regress/regress-3969': [SKIP],
'regress/regress-3985': [SKIP],
'regress/regress-4121': [SKIP],
'regress/regress-4169': [SKIP],
'regress/regress-419663': [SKIP],
'regress/regress-4214': [SKIP],
'regress/regress-4255-4': [SKIP],
'regress/regress-4266': [SKIP],
'regress/regress-430201b': [SKIP],
......@@ -888,14 +851,11 @@
'regress/regress-503565': [SKIP],
'regress/regress-514362': [SKIP],
'regress/regress-520029': [SKIP],
'regress/regress-542100': [SKIP],
'regress/regress-544991': [SKIP],
'regress/regress-572589': [SKIP],
'regress/regress-70066': [SKIP],
'regress/regress-799761': [SKIP],
'regress/regress-88591': [SKIP],
'regress/regress-94873': [SKIP],
'regress/regress-95485': [SKIP],
'regress/regress-97116b': [SKIP],
'regress/regress-97116': [SKIP],
'regress/regress-998565': [SKIP],
......@@ -904,7 +864,6 @@
'regress/regress-conditional-position': [SKIP],
'regress/regress-crbug-109362': [SKIP],
'regress/regress-crbug-119800': [SKIP],
'regress/regress-crbug-135008': [SKIP],
'regress/regress-crbug-259300': [SKIP],
'regress/regress-crbug-352058': [SKIP],
'regress/regress-crbug-387599': [SKIP],
......@@ -915,9 +874,7 @@
'regress/regress-crbug-429159': [SKIP],
'regress/regress-crbug-431602': [SKIP],
'regress/regress-crbug-432493': [SKIP],
'regress/regress-crbug-450642': [SKIP],
'regress/regress-crbug-451770': [SKIP],
'regress/regress-crbug-455644': [SKIP],
'regress/regress-crbug-465298': [SKIP],
'regress/regress-crbug-467180': [SKIP],
'regress/regress-crbug-467531': [SKIP],
......@@ -951,19 +908,10 @@
'regress/regress-osr-in-literal': [SKIP],
'regress/regress-prepare-break-while-recompile': [SKIP],
'regress/regress-typedarray-length': [SKIP],
'scope-calls-eval': [SKIP],
'shift-for-integer-div': [SKIP],
'stack-traces': [SKIP],
'strict-mode': [SKIP],
'tools/profviz': [SKIP],
'undetectable-compare': [SKIP],
'unused-context-in-with': [SKIP],
'value-wrapper': [SKIP],
'with-function-expression': [SKIP],
'with-parameter-access': [SKIP],
'with-prototype': [SKIP],
'with-readonly': [SKIP],
'with-value': [SKIP],
}], # ignition == True
['ignition == True and (arch == arm or arch == arm64)', {
......
......@@ -548,7 +548,6 @@
'built-ins/Promise/prototype/then/capability-executor-called-twice': [SKIP],
'built-ins/Promise/prototype/then/capability-executor-not-callable': [SKIP],
'built-ins/Promise/prototype/then/deferred-is-resolved-value': [SKIP],
'built-ins/Proxy/has/*': [SKIP],
'built-ins/Reflect/enumerate/*': [SKIP],
'language/computed-property-names/class/*': [SKIP],
'language/computed-property-names/to-name-side-effects/*': [SKIP],
......@@ -562,12 +561,10 @@
'language/expressions/instanceof/prototype-getter-with-object': [SKIP],
'language/expressions/object/method-definition/yield*': [SKIP],
'language/expressions/object/method-definition/generator*': [SKIP],
'language/expressions/object/prop-def-id-eval-error-2': [SKIP],
'language/expressions/yield/*': [SKIP],
'language/statements/class/*': [SKIP],
'language/statements/const/*': [SKIP],
'language/statements/generators/*': [SKIP],
'language/statements/with/*': [SKIP],
'built-ins/Array/prototype/concat/Array.prototype.concat_non-array': [SKIP],
'built-ins/Date/prototype/toISOString/15.9.5.43-0-13': [SKIP],
......@@ -595,7 +592,6 @@
'built-ins/String/prototype/repeat/this-is-undefined-throws': [SKIP],
'built-ins/String/prototype/startsWith/this-is-undefined-throws': [SKIP],
'built-ins/String/prototype/trim/15.5.4.20-1-1': [SKIP],
'built-ins/String/S15.5.5.1_A4_T1': [SKIP],
'language/block-scope/leave/nested-block-let-declaration-only-shadows-outer-parameter-value-1': [SKIP],
'language/block-scope/leave/nested-block-let-declaration-only-shadows-outer-parameter-value-2': [SKIP],
'language/block-scope/leave/verify-context-in-labelled-block': [SKIP],
......@@ -606,13 +602,9 @@
'language/default-parameters/class-definitions': [SKIP],
'language/default-parameters/generators': [SKIP],
'language/default-parameters/param-ref-uninitialized': [SKIP],
'language/eval-code/10.4.2-1-4': [SKIP],
'language/expressions/delete/11.4.1-4.a-5': [SKIP],
'language/expressions/delete/11.4.1-4.a-6': [SKIP],
'language/expressions/object/method-definition/name-prop-name-yield-expr': [SKIP],
'language/expressions/object/method-definition/name-super-prop-param': [SKIP],
'language/expressions/object/method-definition/name-super-prop-body': [SKIP],
'language/expressions/object/prop-def-id-eval-error': [SKIP],
'language/expressions/tagged-template/call-expression-context-no-strict': [SKIP],
'language/expressions/tagged-template/call-expression-context-strict': [SKIP],
'language/expressions/template-literal/evaluation-order': [SKIP],
......@@ -655,11 +647,6 @@
'language/statements/for-of/yield-star-from-catch': [SKIP],
'language/statements/for-of/yield-star-from-finally': [SKIP],
'language/statements/for-of/yield-star-from-try': [SKIP],
'language/identifier-resolution/S10.2.2_A1_T5': [SKIP],
'language/identifier-resolution/S10.2.2_A1_T6': [SKIP],
'language/identifier-resolution/S10.2.2_A1_T7': [SKIP],
'language/identifier-resolution/S10.2.2_A1_T8': [SKIP],
'language/identifier-resolution/S10.2.2_A1_T9': [SKIP],
'language/object-literal/concise-generator': [SKIP],
'language/object-literal/getter': [SKIP],
'language/object-literal/method': [SKIP],
......@@ -673,18 +660,6 @@
'language/rest-parameters/rest-parameters-produce-an-array': [SKIP],
'language/rest-parameters/with-new-target': [SKIP],
'language/statements/do-while/S12.6.1_A4_T5': [SKIP],
'language/statements/function/S13.2.2_A18_T2': [SKIP],
'language/statements/function/S13.2.2_A19_T1': [SKIP],
'language/statements/function/S13.2.2_A19_T2': [SKIP],
'language/statements/function/S13.2.2_A19_T3': [SKIP],
'language/statements/function/S13.2.2_A19_T4': [SKIP],
'language/statements/function/S13.2.2_A19_T5': [SKIP],
'language/statements/function/S13.2.2_A19_T6': [SKIP],
'language/statements/function/S13.2.2_A19_T7': [SKIP],
'language/statements/function/S13.2.2_A19_T8': [SKIP],
'language/statements/function/S13.2.2_A18_T1': [SKIP],
'language/statements/function/S13.2.2_A17_T2': [SKIP],
'language/statements/function/S13.2.2_A17_T3': [SKIP],
'language/statements/let/block-local-closure-get-before-initialization': [SKIP],
'language/statements/let/block-local-closure-set-before-initialization': [SKIP],
'language/statements/let/block-local-use-before-initialization-in-declaration-statement': [SKIP],
......@@ -697,7 +672,6 @@
'language/statements/let/global-closure-set-before-initialization': [SKIP],
'language/statements/let/global-use-before-initialization-in-declaration-statement': [SKIP],
'language/statements/let/global-use-before-initialization-in-prior-statement': [SKIP],
'language/statements/try/S12.14_A14': [SKIP],
'language/statements/while/S12.6.2_A4_T5': [SKIP],
}], # ignition == True
......
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