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

Unified Diff: test/cctest/interpreter/test-interpreter.cc

Issue 1269683002: [interpreter] Adds interpreter cctests. (Closed) Base URL: ssh://rmcilroy.lon.corp.google.com///usr/local/google/code/v8_full/v8@interpreter_builtins
Patch Set: Created 5 years, 5 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/cctest/cctest.gyp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/interpreter/test-interpreter.cc
diff --git a/test/cctest/interpreter/test-interpreter.cc b/test/cctest/interpreter/test-interpreter.cc
new file mode 100644
index 0000000000000000000000000000000000000000..0c869389788ed2570a098c93890c9fdd667c1ae2
--- /dev/null
+++ b/test/cctest/interpreter/test-interpreter.cc
@@ -0,0 +1,76 @@
+// Copyright 2014 the V8 project authors. All rights reserved.
oth 2015/07/30 09:49:01 s/2014/2015/
rmcilroy 2015/07/30 11:02:17 Done, thanks.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "src/v8.h"
+
+#include "src/execution.h"
+#include "src/handles.h"
+#include "src/interpreter/interpreter.h"
+#include "test/cctest/cctest.h"
+
+namespace v8 {
+namespace internal {
+
+class InterpreterTester {
+ public:
+ InterpreterTester(Isolate* isolate, Handle<BytecodeArray> bytecode)
+ : isolate_(isolate), function_(GetBytecodeFunction(isolate, bytecode)) {
+ i::FLAG_ignition = true;
+ // TODO(rmcilroy): don't regenerate if it's already generated.
+ isolate_->interpreter()->Initialize(isolate_);
+ }
+ virtual ~InterpreterTester() {}
+
+ MaybeHandle<Object> Call() {
+ Handle<Object> args[] = {};
+ return Execution::Call(isolate_, function_,
+ isolate_->factory()->undefined_value(), 0, args,
+ false);
+ }
+
+ private:
+ Isolate* isolate_;
+ Handle<JSFunction> function_;
+
+ static Handle<JSFunction> GetBytecodeFunction(
+ Isolate* isolate, Handle<BytecodeArray> bytecode_array) {
+ Handle<JSFunction> function = v8::Utils::OpenHandle(
+ *v8::Handle<v8::Function>::Cast(CompileRun("(function(){})")));
+ function->ReplaceCode(*isolate->builtins()->InterpreterEntryTrampoline());
+ function->shared()->set_function_data(*bytecode_array);
+ return function;
+ }
+};
+
+} // namespace internal
+} // namespace v8
+
+using namespace v8::internal;
+
+TEST(TestInterpreterReturn) {
+ InitializedHandleScope handles;
+ Handle<Object> undefined_value =
+ handles.main_isolate()->factory()->undefined_value();
+ // TODO(rmcilroy): Use a proper bytecode builder for this.
+ uint8_t raw_bytecodes[1] = {1};
+ Handle<BytecodeArray> bytecode_array =
+ handles.main_isolate()->factory()->NewBytecodeArray(1, raw_bytecodes,
+ kPointerSize);
+ InterpreterTester tester(handles.main_isolate(), bytecode_array);
+ Handle<Object> return_val = tester.Call().ToHandleChecked();
+ CHECK(return_val.is_identical_to(undefined_value));
+}
+
+
+TEST(TestInterpreterLiteral0) {
+ InitializedHandleScope handles;
+ // TODO(rmcilroy): Use a proper bytecode builder for this.
+ uint8_t raw_bytecodes[3] = {0, 0, 1};
+ Handle<BytecodeArray> bytecode_array =
+ handles.main_isolate()->factory()->NewBytecodeArray(3, raw_bytecodes,
+ kPointerSize);
+ InterpreterTester tester(handles.main_isolate(), bytecode_array);
+ Handle<Object> return_val = tester.Call().ToHandleChecked();
+ CHECK_EQ(*return_val, i::Smi::FromInt(0));
+}
« no previous file with comments | « test/cctest/cctest.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698