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 /**
6 * Implementation for v8-experimental.h.
7 */
8
9 #include "src/api-experimental.h"
10
11 #include "include/v8-experimental.h"
12 #include "include/v8.h"
13 #include "src/api.h"
14 #include "src/fast-accessor-assembler.h"
15 #include "src/objects-inl.h"
16
17 namespace {
18
FromApi(v8::experimental::FastAccessorBuilder * builder)19 v8::internal::FastAccessorAssembler* FromApi(
20 v8::experimental::FastAccessorBuilder* builder) {
21 return reinterpret_cast<v8::internal::FastAccessorAssembler*>(builder);
22 }
23
FromInternal(v8::internal::FastAccessorAssembler * fast_accessor_assembler)24 v8::experimental::FastAccessorBuilder* FromInternal(
25 v8::internal::FastAccessorAssembler* fast_accessor_assembler) {
26 return reinterpret_cast<v8::experimental::FastAccessorBuilder*>(
27 fast_accessor_assembler);
28 }
29
30 } // namespace
31
32 namespace v8 {
33 namespace internal {
34 namespace experimental {
35
36
BuildCodeFromFastAccessorBuilder(v8::experimental::FastAccessorBuilder * fast_handler)37 MaybeHandle<Code> BuildCodeFromFastAccessorBuilder(
38 v8::experimental::FastAccessorBuilder* fast_handler) {
39 i::MaybeHandle<i::Code> code;
40 if (fast_handler != nullptr) {
41 auto faa = FromApi(fast_handler);
42 code = faa->Build();
43 CHECK(!code.is_null());
44 delete faa;
45 }
46 return code;
47 }
48
49 } // namespace experimental
50 } // namespace internal
51
52
53 namespace experimental {
54
55
New(Isolate * isolate)56 FastAccessorBuilder* FastAccessorBuilder::New(Isolate* isolate) {
57 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
58 internal::FastAccessorAssembler* faa =
59 new internal::FastAccessorAssembler(i_isolate);
60 return FromInternal(faa);
61 }
62
63
IntegerConstant(int const_value)64 FastAccessorBuilder::ValueId FastAccessorBuilder::IntegerConstant(
65 int const_value) {
66 return FromApi(this)->IntegerConstant(const_value);
67 }
68
69
GetReceiver()70 FastAccessorBuilder::ValueId FastAccessorBuilder::GetReceiver() {
71 return FromApi(this)->GetReceiver();
72 }
73
74
LoadInternalField(ValueId value,int field_no)75 FastAccessorBuilder::ValueId FastAccessorBuilder::LoadInternalField(
76 ValueId value, int field_no) {
77 return FromApi(this)->LoadInternalField(value, field_no);
78 }
79
LoadInternalFieldUnchecked(ValueId value,int field_no)80 FastAccessorBuilder::ValueId FastAccessorBuilder::LoadInternalFieldUnchecked(
81 ValueId value, int field_no) {
82 return FromApi(this)->LoadInternalFieldUnchecked(value, field_no);
83 }
84
LoadValue(ValueId value_id,int offset)85 FastAccessorBuilder::ValueId FastAccessorBuilder::LoadValue(ValueId value_id,
86 int offset) {
87 return FromApi(this)->LoadValue(value_id, offset);
88 }
89
90
LoadObject(ValueId value_id,int offset)91 FastAccessorBuilder::ValueId FastAccessorBuilder::LoadObject(ValueId value_id,
92 int offset) {
93 return FromApi(this)->LoadObject(value_id, offset);
94 }
95
ToSmi(ValueId value_id)96 FastAccessorBuilder::ValueId FastAccessorBuilder::ToSmi(ValueId value_id) {
97 return FromApi(this)->ToSmi(value_id);
98 }
99
ReturnValue(ValueId value)100 void FastAccessorBuilder::ReturnValue(ValueId value) {
101 FromApi(this)->ReturnValue(value);
102 }
103
104
CheckFlagSetOrReturnNull(ValueId value_id,int mask)105 void FastAccessorBuilder::CheckFlagSetOrReturnNull(ValueId value_id, int mask) {
106 FromApi(this)->CheckFlagSetOrReturnNull(value_id, mask);
107 }
108
109
CheckNotZeroOrReturnNull(ValueId value_id)110 void FastAccessorBuilder::CheckNotZeroOrReturnNull(ValueId value_id) {
111 FromApi(this)->CheckNotZeroOrReturnNull(value_id);
112 }
113
114
MakeLabel()115 FastAccessorBuilder::LabelId FastAccessorBuilder::MakeLabel() {
116 return FromApi(this)->MakeLabel();
117 }
118
119
SetLabel(LabelId label_id)120 void FastAccessorBuilder::SetLabel(LabelId label_id) {
121 FromApi(this)->SetLabel(label_id);
122 }
123
Goto(LabelId label_id)124 void FastAccessorBuilder::Goto(LabelId label_id) {
125 FromApi(this)->Goto(label_id);
126 }
127
CheckNotZeroOrJump(ValueId value_id,LabelId label_id)128 void FastAccessorBuilder::CheckNotZeroOrJump(ValueId value_id,
129 LabelId label_id) {
130 FromApi(this)->CheckNotZeroOrJump(value_id, label_id);
131 }
132
Call(v8::FunctionCallback callback,ValueId value_id)133 FastAccessorBuilder::ValueId FastAccessorBuilder::Call(
134 v8::FunctionCallback callback, ValueId value_id) {
135 return FromApi(this)->Call(callback, value_id);
136 }
137
138 } // namespace experimental
139 } // namespace v8
140