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

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

Issue 1645763003: [Interpreter] TurboFan implementation of intrinsics. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Merged with oth@'s changes. Created 4 years, 9 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
Index: test/cctest/interpreter/test-interpreter-intrinsics.cc
diff --git a/test/cctest/interpreter/test-interpreter-intrinsics.cc b/test/cctest/interpreter/test-interpreter-intrinsics.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e4cf809ad74efbcf852d2d840f7bd09151cacfa9
--- /dev/null
+++ b/test/cctest/interpreter/test-interpreter-intrinsics.cc
@@ -0,0 +1,96 @@
+// Copyright 2015 the V8 project authors. All rights reserved.
+// 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/interpreter/interpreter-intrinsics.h"
+#include "test/cctest/interpreter/interpreter-tester.h"
+
+namespace v8 {
+namespace internal {
+namespace interpreter {
+
+namespace {
+
+class InvokeIntrinsicHelper {
+ public:
+ InvokeIntrinsicHelper(Isolate* isolate, Zone* zone,
+ Runtime::FunctionId function_id)
+ : isolate_(isolate),
+ zone_(zone),
+ factory_(isolate->factory()),
+ function_id_(function_id) {}
+
+ template <class... A>
+ Handle<Object> Invoke(A... args) {
+ CHECK(IntrinsicsHelper::IsSupported(function_id_));
+ BytecodeArrayBuilder builder(isolate_, zone_, sizeof...(args), 0, 0);
+ builder.CallRuntime(function_id_, builder.Parameter(0), sizeof...(args))
+ .Return();
+ InterpreterTester tester(isolate_, builder.ToBytecodeArray());
+ auto callable = tester.GetCallable<Handle<Object>>();
+ return callable(args...).ToHandleChecked();
+ }
+
+ Handle<Object> NewObject(const char* script) {
+ return v8::Utils::OpenHandle(*CompileRun(script));
+ }
+
+ Handle<Object> Undefined() { return factory_->undefined_value(); }
+ Handle<Object> Null() { return factory_->null_value(); }
+
+ private:
+ Isolate* isolate_;
+ Zone* zone_;
+ Factory* factory_;
+ Runtime::FunctionId function_id_;
+};
+
+} // namespace
+
+TEST(IsJSReceiver) {
+ HandleAndZoneScope handles;
+
+ InvokeIntrinsicHelper helper(handles.main_isolate(), handles.main_zone(),
+ Runtime::kInlineIsJSReceiver);
+ Factory* factory = handles.main_isolate()->factory();
+
+ CHECK_EQ(*factory->true_value(),
+ *helper.Invoke(helper.NewObject("new Date()")));
+ CHECK_EQ(*factory->true_value(),
+ *helper.Invoke(helper.NewObject("(function() {})")));
+ CHECK_EQ(*factory->true_value(), *helper.Invoke(helper.NewObject("([1])")));
+ CHECK_EQ(*factory->true_value(), *helper.Invoke(helper.NewObject("({})")));
+ CHECK_EQ(*factory->true_value(), *helper.Invoke(helper.NewObject("(/x/)")));
+ CHECK_EQ(*factory->false_value(), *helper.Invoke(helper.Undefined()));
+ CHECK_EQ(*factory->false_value(), *helper.Invoke(helper.Null()));
+ CHECK_EQ(*factory->false_value(),
+ *helper.Invoke(helper.NewObject("'string'")));
+ CHECK_EQ(*factory->false_value(), *helper.Invoke(helper.NewObject("42")));
+}
+
+TEST(IsArray) {
+ HandleAndZoneScope handles;
+
+ InvokeIntrinsicHelper helper(handles.main_isolate(), handles.main_zone(),
+ Runtime::kInlineIsArray);
+ Factory* factory = handles.main_isolate()->factory();
+
+ CHECK_EQ(*factory->false_value(),
+ *helper.Invoke(helper.NewObject("new Date()")));
+ CHECK_EQ(*factory->false_value(),
+ *helper.Invoke(helper.NewObject("(function() {})")));
+ CHECK_EQ(*factory->true_value(), *helper.Invoke(helper.NewObject("([1])")));
+ CHECK_EQ(*factory->false_value(), *helper.Invoke(helper.NewObject("({})")));
+ CHECK_EQ(*factory->false_value(), *helper.Invoke(helper.NewObject("(/x/)")));
+ CHECK_EQ(*factory->false_value(), *helper.Invoke(helper.Undefined()));
+ CHECK_EQ(*factory->false_value(), *helper.Invoke(helper.Null()));
+ CHECK_EQ(*factory->false_value(),
+ *helper.Invoke(helper.NewObject("'string'")));
+ CHECK_EQ(*factory->false_value(), *helper.Invoke(helper.NewObject("42")));
+}
+
+} // namespace interpreter
+} // namespace internal
+} // namespace v8
« no previous file with comments | « test/cctest/interpreter/test-interpreter.cc ('k') | test/unittests/interpreter/bytecode-array-builder-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698