Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(250)

Side by Side Diff: test/cctest/interpreter/test-bytecode-generator.cc

Issue 1524803003: [Interpreter] Add support for Load / Store to Lookup slots. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@init_eval_impl
Patch Set: rebased the patch and fixed tests. Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/compiler.h" 7 #include "src/compiler.h"
8 #include "src/interpreter/bytecode-array-iterator.h" 8 #include "src/interpreter/bytecode-array-iterator.h"
9 #include "src/interpreter/bytecode-generator.h" 9 #include "src/interpreter/bytecode-generator.h"
10 #include "src/interpreter/interpreter.h" 10 #include "src/interpreter/interpreter.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 CompileRun(script); 48 CompileRun(script);
49 v8::Local<v8::Context> context = 49 v8::Local<v8::Context> context =
50 v8::Isolate::GetCurrent()->GetCurrentContext(); 50 v8::Isolate::GetCurrent()->GetCurrentContext();
51 Local<Function> function = Local<Function>::Cast( 51 Local<Function> function = Local<Function>::Cast(
52 CcTest::global()->Get(context, v8_str(function_name)).ToLocalChecked()); 52 CcTest::global()->Get(context, v8_str(function_name)).ToLocalChecked());
53 i::Handle<i::JSFunction> js_function = 53 i::Handle<i::JSFunction> js_function =
54 i::Handle<i::JSFunction>::cast(v8::Utils::OpenHandle(*function)); 54 i::Handle<i::JSFunction>::cast(v8::Utils::OpenHandle(*function));
55 return handle(js_function->shared()->bytecode_array(), CcTest::i_isolate()); 55 return handle(js_function->shared()->bytecode_array(), CcTest::i_isolate());
56 } 56 }
57 57
58 Handle<BytecodeArray> MakeBytecode(const char* script, const char* filter,
59 const char* function_name) {
60 const char* old_ignition_filter = i::FLAG_ignition_filter;
61 i::FLAG_ignition_filter = filter;
62 CompileRun(script);
63 i::FLAG_ignition_filter = old_ignition_filter;
64 v8::Local<v8::Context> context =
65 v8::Isolate::GetCurrent()->GetCurrentContext();
66 Local<Function> function = Local<Function>::Cast(
67 CcTest::global()->Get(context, v8_str(function_name)).ToLocalChecked());
68 i::Handle<i::JSFunction> js_function =
69 i::Handle<i::JSFunction>::cast(v8::Utils::OpenHandle(*function));
70 return handle(js_function->shared()->bytecode_array(), CcTest::i_isolate());
rmcilroy 2015/12/15 16:44:33 nit - pull out common code with MakeTopLevelByteco
mythria 2015/12/16 09:54:21 Done.
71 }
72
58 Handle<BytecodeArray> MakeBytecodeForFunctionBody(const char* body) { 73 Handle<BytecodeArray> MakeBytecodeForFunctionBody(const char* body) {
59 ScopedVector<char> program(3072); 74 ScopedVector<char> program(3072);
60 SNPrintF(program, "function %s() { %s }\n%s();", kFunctionName, body, 75 SNPrintF(program, "function %s() { %s }\n%s();", kFunctionName, body,
61 kFunctionName); 76 kFunctionName);
62 return MakeBytecode(program.start(), kFunctionName); 77 return MakeBytecode(program.start(), kFunctionName);
63 } 78 }
64 79
65 Handle<BytecodeArray> MakeBytecodeForFunction(const char* function) { 80 Handle<BytecodeArray> MakeBytecodeForFunction(const char* function) {
66 ScopedVector<char> program(3072); 81 ScopedVector<char> program(3072);
67 SNPrintF(program, "%s\n%s();", function, kFunctionName); 82 SNPrintF(program, "%s\n%s();", function, kFunctionName);
(...skipping 5443 matching lines...) Expand 10 before | Expand all | Expand 10 after
5511 }, 5526 },
5512 0}}; 5527 0}};
5513 5528
5514 for (size_t i = 0; i < arraysize(snippets); i++) { 5529 for (size_t i = 0; i < arraysize(snippets); i++) {
5515 Handle<BytecodeArray> bytecode_array = 5530 Handle<BytecodeArray> bytecode_array =
5516 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); 5531 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
5517 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 5532 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
5518 } 5533 }
5519 } 5534 }
5520 5535
5536
5537 TEST(LookupSlotInEval) {
5538 InitializedHandleScope handle_scope;
5539 BytecodeGeneratorHelper helper;
5540
5541 const char* function_prologue = "var f;"
5542 "var x = 1;"
5543 "function f1() {"
5544 " eval(\"function t() {";
rmcilroy 2015/12/15 16:44:33 nit - use ' instead of \"
mythria 2015/12/16 09:54:21 I use 'use strict'; in function body in one exampl
5545 const char* function_epilogue = " }; f = t; f();\");"
5546 "}"
5547 "f1();";
5548
5549 ExpectedSnippet<const char*> snippets[] = {
5550 {"return x;",
5551 0 * kPointerSize,
5552 1,
5553 3,
5554 {
5555 B(LdaLookupSlot), U8(0), //
5556 B(Return) //
5557 },
5558 1,
5559 {"x"}},
5560 {"x = 10;",
5561 0 * kPointerSize,
5562 1,
5563 6,
5564 {
5565 B(LdaSmi8), U8(10), //
5566 B(StaLookupSlotSloppy), U8(0), //
5567 B(LdaUndefined), //
5568 B(Return), //
5569 },
5570 1,
5571 {"x"}},
5572 {"'use strict'; x = 10;",
5573 0 * kPointerSize,
5574 1,
5575 6,
5576 {
5577 B(LdaSmi8), U8(10), //
5578 B(StaLookupSlotStrict), U8(0), //
5579 B(LdaUndefined), //
5580 B(Return), //
5581 },
5582 1,
5583 {"x"}},
5584 {"return typeof x;",
5585 0 * kPointerSize,
5586 1,
5587 4,
5588 {
5589 B(LdaLookupSlotInsideTypeof), U8(0), //
5590 B(TypeOf), //
5591 B(Return), //
5592 },
5593 1,
5594 {"x"}},
5595 };
5596
5597 for (size_t i = 0; i < arraysize(snippets); i++) {
5598 std::string script = std::string(function_prologue) +
5599 std::string(snippets[i].code_snippet) +
5600 std::string(function_epilogue);
5601 // TODO(mythria): use * as filter when function declarations are supported
5602 // inside eval.
5603 Handle<BytecodeArray> bytecode_array =
5604 helper.MakeBytecode(script.c_str(), "t", "f");
5605 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
5606 }
5607 }
5608
5521 } // namespace interpreter 5609 } // namespace interpreter
5522 } // namespace internal 5610 } // namespace internal
5523 } // namespace v8 5611 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698