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

Side by Side Diff: src/runtime/runtime-interpreter.cc

Issue 1369123002: [Interpreter] Add interpreter support for compare ops and ToBoolean. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Compilation fix. Created 5 years, 2 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 unified diff | Download patch
« no previous file with comments | « src/runtime/runtime.h ('k') | test/cctest/interpreter/test-bytecode-generator.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "src/runtime/runtime-utils.h"
6
7 #include "src/arguments.h"
8 #include "src/isolate-inl.h"
9
10 namespace v8 {
11 namespace internal {
12
13
14 static Object* ComparisonHelper(Isolate* isolate, ComparisonResult expected,
Benedikt Meurer 2015/09/28 09:05:23 Please don't write your own wrapper, but use Objec
oth 2015/09/28 10:23:02 Done.
15 Handle<Object> x, Handle<Object> y,
16 bool negate_result = false) {
17 Maybe<ComparisonResult> result = Object::Compare(x, y, Strength::WEAK);
18 if (!result.IsJust()) return isolate->heap()->exception();
19 ComparisonResult r = result.FromJust();
20 if (r == ComparisonResult::kUndefined) {
21 DCHECK(x->IsNaN() || y->IsNaN());
22 return isolate->heap()->false_value();
23 }
24 return isolate->heap()->ToBoolean((r == expected) ^ negate_result);
25 }
26
27
28 RUNTIME_FUNCTION(Runtime_InterpreterEquals) {
29 HandleScope scope(isolate);
30 DCHECK_EQ(2, args.length());
31 CONVERT_ARG_HANDLE_CHECKED(Object, x, 0);
32 CONVERT_ARG_HANDLE_CHECKED(Object, y, 1);
33 return ComparisonHelper(isolate, ComparisonResult::kEqual, x, y);
Benedikt Meurer 2015/09/28 09:05:23 Equals and NotEquals cannot use Compare; you need
oth 2015/09/28 10:23:02 Done.
34 }
35
36
37 RUNTIME_FUNCTION(Runtime_InterpreterNotEquals) {
38 HandleScope scope(isolate);
39 DCHECK_EQ(2, args.length());
40 CONVERT_ARG_HANDLE_CHECKED(Object, x, 0);
41 CONVERT_ARG_HANDLE_CHECKED(Object, y, 1);
42 return ComparisonHelper(isolate, ComparisonResult::kEqual, x, y, true);
43 }
44
45
46 RUNTIME_FUNCTION(Runtime_InterpreterLessThan) {
47 HandleScope scope(isolate);
48 DCHECK_EQ(2, args.length());
49 CONVERT_ARG_HANDLE_CHECKED(Object, x, 0);
50 CONVERT_ARG_HANDLE_CHECKED(Object, y, 1);
51 return ComparisonHelper(isolate, ComparisonResult::kLessThan, x, y);
52 }
53
54
55 RUNTIME_FUNCTION(Runtime_InterpreterGreaterThan) {
56 HandleScope scope(isolate);
57 DCHECK_EQ(2, args.length());
58 CONVERT_ARG_HANDLE_CHECKED(Object, x, 0);
59 CONVERT_ARG_HANDLE_CHECKED(Object, y, 1);
60 return ComparisonHelper(isolate, ComparisonResult::kGreaterThan, x, y);
61 }
62
63
64 RUNTIME_FUNCTION(Runtime_InterpreterLessThanEqual) {
65 HandleScope scope(isolate);
66 DCHECK_EQ(2, args.length());
67 CONVERT_ARG_HANDLE_CHECKED(Object, x, 0);
68 CONVERT_ARG_HANDLE_CHECKED(Object, y, 1);
69 return ComparisonHelper(isolate, ComparisonResult::kGreaterThan, x, y, true);
70 }
71
72
73 RUNTIME_FUNCTION(Runtime_InterpreterGreaterThanEqual) {
74 HandleScope scope(isolate);
75 DCHECK_EQ(2, args.length());
76 CONVERT_ARG_HANDLE_CHECKED(Object, x, 0);
77 CONVERT_ARG_HANDLE_CHECKED(Object, y, 1);
78 return ComparisonHelper(isolate, ComparisonResult::kLessThan, x, y, true);
79 }
80
81
82 RUNTIME_FUNCTION(Runtime_InterpreterStrictEquals) {
83 SealHandleScope scope(isolate);
84 DCHECK_EQ(2, args.length());
85 CONVERT_ARG_CHECKED(Object, x, 0);
86 CONVERT_ARG_CHECKED(Object, y, 1);
87 return isolate->heap()->ToBoolean(x->StrictEquals(y));
88 }
89
90
91 RUNTIME_FUNCTION(Runtime_InterpreterStrictNotEquals) {
92 SealHandleScope scope(isolate);
93 DCHECK_EQ(2, args.length());
94 CONVERT_ARG_CHECKED(Object, x, 0);
95 CONVERT_ARG_CHECKED(Object, y, 1);
96 return isolate->heap()->ToBoolean(!x->StrictEquals(y));
97 }
98
99
100 RUNTIME_FUNCTION(Runtime_InterpreterCastToBoolean) {
101 SealHandleScope scope(isolate);
102 DCHECK_EQ(1, args.length());
103 CONVERT_ARG_CHECKED(Object, x, 0);
104 return isolate->heap()->ToBoolean(x->BooleanValue());
105 }
106
107
108 } // namespace internal
109 } // namespace v8
OLDNEW
« no previous file with comments | « src/runtime/runtime.h ('k') | test/cctest/interpreter/test-bytecode-generator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698