| OLD | NEW |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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/builtins/builtins.h" | 5 #include "src/builtins/builtins.h" |
| 6 #include "src/builtins/builtins-utils.h" | 6 #include "src/builtins/builtins-utils.h" |
| 7 | 7 |
| 8 #include "src/string-builder.h" | 8 #include "src/string-builder.h" |
| 9 #include "src/wasm/wasm-module.h" | 9 #include "src/wasm/wasm-module.h" |
| 10 | 10 |
| 11 namespace v8 { | 11 namespace v8 { |
| 12 namespace internal { | 12 namespace internal { |
| 13 | 13 |
| 14 #define CHECK_CALLSITE(recv, method) \ | 14 #define CHECK_CALLSITE(recv, method) \ |
| 15 CHECK_RECEIVER(JSObject, recv, method); \ | 15 CHECK_RECEIVER(JSObject, recv, method); \ |
| 16 Handle<StackTraceFrame> frame; \ | 16 if (!JSReceiver::HasOwnProperty( \ |
| 17 { \ | 17 recv, isolate->factory()->call_site_position_symbol()) \ |
| 18 Handle<Object> frame_obj; \ | 18 .FromMaybe(false)) { \ |
| 19 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( \ | 19 THROW_NEW_ERROR_RETURN_FAILURE( \ |
| 20 isolate, frame_obj, \ | 20 isolate, \ |
| 21 JSObject::GetProperty(recv, \ | 21 NewTypeError(MessageTemplate::kCallSiteMethod, \ |
| 22 isolate->factory()->call_site_frame_symbol())); \ | 22 isolate->factory()->NewStringFromAsciiChecked(method))); \ |
| 23 if (!frame_obj->IsStackTraceFrame()) { \ | |
| 24 THROW_NEW_ERROR_RETURN_FAILURE( \ | |
| 25 isolate, NewTypeError(MessageTemplate::kCallSiteMethod, \ | |
| 26 isolate->factory()->NewStringFromAsciiChecked( \ | |
| 27 method))); \ | |
| 28 } \ | |
| 29 frame = Handle<StackTraceFrame>::cast(frame_obj); \ | |
| 30 } | 23 } |
| 31 | 24 |
| 32 namespace { | 25 namespace { |
| 33 | 26 |
| 34 Object* PositiveNumberOrNull(int value, Isolate* isolate) { | 27 Object* PositiveNumberOrNull(int value, Isolate* isolate) { |
| 35 if (value >= 0) return *isolate->factory()->NewNumberFromInt(value); | 28 if (value >= 0) return *isolate->factory()->NewNumberFromInt(value); |
| 36 return isolate->heap()->null_value(); | 29 return isolate->heap()->null_value(); |
| 37 } | 30 } |
| 38 | 31 |
| 39 } // namespace | 32 } // namespace |
| 40 | 33 |
| 41 BUILTIN(CallSitePrototypeGetColumnNumber) { | 34 BUILTIN(CallSitePrototypeGetColumnNumber) { |
| 42 HandleScope scope(isolate); | 35 HandleScope scope(isolate); |
| 43 CHECK_CALLSITE(recv, "getColumnNumber"); | 36 CHECK_CALLSITE(recv, "getColumnNumber"); |
| 44 return PositiveNumberOrNull(frame->GetColumnNumber(), isolate); | 37 |
| 38 CallSite call_site(isolate, recv); |
| 39 CHECK(call_site.IsJavaScript() || call_site.IsWasm()); |
| 40 return PositiveNumberOrNull(call_site.GetColumnNumber(), isolate); |
| 45 } | 41 } |
| 46 | 42 |
| 47 BUILTIN(CallSitePrototypeGetEvalOrigin) { | 43 BUILTIN(CallSitePrototypeGetEvalOrigin) { |
| 48 HandleScope scope(isolate); | 44 HandleScope scope(isolate); |
| 49 CHECK_CALLSITE(recv, "getEvalOrigin"); | 45 CHECK_CALLSITE(recv, "getEvalOrigin"); |
| 50 return *frame->GetEvalOrigin(); | 46 |
| 47 CallSite call_site(isolate, recv); |
| 48 CHECK(call_site.IsJavaScript() || call_site.IsWasm()); |
| 49 return *call_site.GetEvalOrigin(); |
| 51 } | 50 } |
| 52 | 51 |
| 53 BUILTIN(CallSitePrototypeGetFileName) { | 52 BUILTIN(CallSitePrototypeGetFileName) { |
| 54 HandleScope scope(isolate); | 53 HandleScope scope(isolate); |
| 55 CHECK_CALLSITE(recv, "getFileName"); | 54 CHECK_CALLSITE(recv, "getFileName"); |
| 56 return *frame->GetFileName(); | 55 |
| 56 CallSite call_site(isolate, recv); |
| 57 CHECK(call_site.IsJavaScript() || call_site.IsWasm()); |
| 58 return *call_site.GetFileName(); |
| 57 } | 59 } |
| 58 | 60 |
| 61 namespace { |
| 62 |
| 63 bool CallSiteIsStrict(Isolate* isolate, Handle<JSObject> receiver) { |
| 64 Handle<Object> strict; |
| 65 Handle<Symbol> symbol = isolate->factory()->call_site_strict_symbol(); |
| 66 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, strict, |
| 67 JSObject::GetProperty(receiver, symbol)); |
| 68 return strict->BooleanValue(); |
| 69 } |
| 70 |
| 71 } // namespace |
| 72 |
| 59 BUILTIN(CallSitePrototypeGetFunction) { | 73 BUILTIN(CallSitePrototypeGetFunction) { |
| 60 HandleScope scope(isolate); | 74 HandleScope scope(isolate); |
| 61 CHECK_CALLSITE(recv, "getFunction"); | 75 CHECK_CALLSITE(recv, "getFunction"); |
| 62 | 76 |
| 63 if (frame->IsStrict() || frame->IsWasmFrame()) { | 77 if (CallSiteIsStrict(isolate, recv)) |
| 64 return *isolate->factory()->undefined_value(); | 78 return *isolate->factory()->undefined_value(); |
| 65 } | |
| 66 | 79 |
| 67 return frame->function(); | 80 Handle<Symbol> symbol = isolate->factory()->call_site_function_symbol(); |
| 81 RETURN_RESULT_OR_FAILURE(isolate, JSObject::GetProperty(recv, symbol)); |
| 68 } | 82 } |
| 69 | 83 |
| 70 BUILTIN(CallSitePrototypeGetFunctionName) { | 84 BUILTIN(CallSitePrototypeGetFunctionName) { |
| 71 HandleScope scope(isolate); | 85 HandleScope scope(isolate); |
| 72 CHECK_CALLSITE(recv, "getFunctionName"); | 86 CHECK_CALLSITE(recv, "getFunctionName"); |
| 73 return *frame->GetFunctionName(); | 87 |
| 88 CallSite call_site(isolate, recv); |
| 89 CHECK(call_site.IsJavaScript() || call_site.IsWasm()); |
| 90 return *call_site.GetFunctionName(); |
| 74 } | 91 } |
| 75 | 92 |
| 76 BUILTIN(CallSitePrototypeGetLineNumber) { | 93 BUILTIN(CallSitePrototypeGetLineNumber) { |
| 77 HandleScope scope(isolate); | 94 HandleScope scope(isolate); |
| 78 CHECK_CALLSITE(recv, "getLineNumber"); | 95 CHECK_CALLSITE(recv, "getLineNumber"); |
| 79 return PositiveNumberOrNull(frame->GetLineNumber(), isolate); | 96 |
| 97 CallSite call_site(isolate, recv); |
| 98 CHECK(call_site.IsJavaScript() || call_site.IsWasm()); |
| 99 |
| 100 int line_number = call_site.IsWasm() ? call_site.wasm_func_index() |
| 101 : call_site.GetLineNumber(); |
| 102 return PositiveNumberOrNull(line_number, isolate); |
| 80 } | 103 } |
| 81 | 104 |
| 82 BUILTIN(CallSitePrototypeGetMethodName) { | 105 BUILTIN(CallSitePrototypeGetMethodName) { |
| 83 HandleScope scope(isolate); | 106 HandleScope scope(isolate); |
| 84 CHECK_CALLSITE(recv, "getMethodName"); | 107 CHECK_CALLSITE(recv, "getMethodName"); |
| 85 return *frame->GetMethodName(); | 108 |
| 109 CallSite call_site(isolate, recv); |
| 110 CHECK(call_site.IsJavaScript() || call_site.IsWasm()); |
| 111 return *call_site.GetMethodName(); |
| 86 } | 112 } |
| 87 | 113 |
| 88 BUILTIN(CallSitePrototypeGetPosition) { | 114 BUILTIN(CallSitePrototypeGetPosition) { |
| 89 HandleScope scope(isolate); | 115 HandleScope scope(isolate); |
| 90 CHECK_CALLSITE(recv, "getPosition"); | 116 CHECK_CALLSITE(recv, "getPosition"); |
| 91 return Smi::FromInt(frame->GetPosition()); | 117 |
| 118 Handle<Symbol> symbol = isolate->factory()->call_site_position_symbol(); |
| 119 RETURN_RESULT_OR_FAILURE(isolate, JSObject::GetProperty(recv, symbol)); |
| 92 } | 120 } |
| 93 | 121 |
| 94 BUILTIN(CallSitePrototypeGetScriptNameOrSourceURL) { | 122 BUILTIN(CallSitePrototypeGetScriptNameOrSourceURL) { |
| 95 HandleScope scope(isolate); | 123 HandleScope scope(isolate); |
| 96 CHECK_CALLSITE(recv, "getScriptNameOrSourceUrl"); | 124 CHECK_CALLSITE(recv, "getScriptNameOrSourceUrl"); |
| 97 return *frame->GetScriptNameOrSourceUrl(); | 125 |
| 126 CallSite call_site(isolate, recv); |
| 127 CHECK(call_site.IsJavaScript() || call_site.IsWasm()); |
| 128 return *call_site.GetScriptNameOrSourceUrl(); |
| 98 } | 129 } |
| 99 | 130 |
| 100 BUILTIN(CallSitePrototypeGetThis) { | 131 BUILTIN(CallSitePrototypeGetThis) { |
| 101 HandleScope scope(isolate); | 132 HandleScope scope(isolate); |
| 102 CHECK_CALLSITE(recv, "getThis"); | 133 CHECK_CALLSITE(recv, "getThis"); |
| 103 | 134 |
| 104 if (frame->IsStrict() || frame->ForceConstructor() || frame->IsWasmFrame()) { | 135 if (CallSiteIsStrict(isolate, recv)) |
| 105 return *isolate->factory()->undefined_value(); | 136 return *isolate->factory()->undefined_value(); |
| 106 } | |
| 107 | 137 |
| 108 return frame->receiver(); | 138 Handle<Object> receiver; |
| 139 Handle<Symbol> symbol = isolate->factory()->call_site_receiver_symbol(); |
| 140 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver, |
| 141 JSObject::GetProperty(recv, symbol)); |
| 142 |
| 143 if (*receiver == isolate->heap()->call_site_constructor_symbol()) |
| 144 return *isolate->factory()->undefined_value(); |
| 145 |
| 146 return *receiver; |
| 109 } | 147 } |
| 110 | 148 |
| 111 BUILTIN(CallSitePrototypeGetTypeName) { | 149 BUILTIN(CallSitePrototypeGetTypeName) { |
| 112 HandleScope scope(isolate); | 150 HandleScope scope(isolate); |
| 113 CHECK_CALLSITE(recv, "getTypeName"); | 151 CHECK_CALLSITE(recv, "getTypeName"); |
| 114 return *frame->GetTypeName(); | 152 |
| 153 CallSite call_site(isolate, recv); |
| 154 CHECK(call_site.IsJavaScript() || call_site.IsWasm()); |
| 155 return *call_site.GetTypeName(); |
| 115 } | 156 } |
| 116 | 157 |
| 117 BUILTIN(CallSitePrototypeIsConstructor) { | 158 BUILTIN(CallSitePrototypeIsConstructor) { |
| 118 HandleScope scope(isolate); | 159 HandleScope scope(isolate); |
| 119 CHECK_CALLSITE(recv, "isConstructor"); | 160 CHECK_CALLSITE(recv, "isConstructor"); |
| 120 return isolate->heap()->ToBoolean(frame->IsConstructor()); | 161 |
| 162 CallSite call_site(isolate, recv); |
| 163 CHECK(call_site.IsJavaScript() || call_site.IsWasm()); |
| 164 return isolate->heap()->ToBoolean(call_site.IsConstructor()); |
| 121 } | 165 } |
| 122 | 166 |
| 123 BUILTIN(CallSitePrototypeIsEval) { | 167 BUILTIN(CallSitePrototypeIsEval) { |
| 124 HandleScope scope(isolate); | 168 HandleScope scope(isolate); |
| 125 CHECK_CALLSITE(recv, "isEval"); | 169 CHECK_CALLSITE(recv, "isEval"); |
| 126 return isolate->heap()->ToBoolean(frame->IsEval()); | 170 |
| 171 CallSite call_site(isolate, recv); |
| 172 CHECK(call_site.IsJavaScript() || call_site.IsWasm()); |
| 173 return isolate->heap()->ToBoolean(call_site.IsEval()); |
| 127 } | 174 } |
| 128 | 175 |
| 129 BUILTIN(CallSitePrototypeIsNative) { | 176 BUILTIN(CallSitePrototypeIsNative) { |
| 130 HandleScope scope(isolate); | 177 HandleScope scope(isolate); |
| 131 CHECK_CALLSITE(recv, "isNative"); | 178 CHECK_CALLSITE(recv, "isNative"); |
| 132 return isolate->heap()->ToBoolean(frame->IsNative()); | 179 |
| 180 CallSite call_site(isolate, recv); |
| 181 CHECK(call_site.IsJavaScript() || call_site.IsWasm()); |
| 182 return isolate->heap()->ToBoolean(call_site.IsNative()); |
| 133 } | 183 } |
| 134 | 184 |
| 135 BUILTIN(CallSitePrototypeIsToplevel) { | 185 BUILTIN(CallSitePrototypeIsToplevel) { |
| 136 HandleScope scope(isolate); | 186 HandleScope scope(isolate); |
| 137 CHECK_CALLSITE(recv, "isToplevel"); | 187 CHECK_CALLSITE(recv, "isToplevel"); |
| 138 return isolate->heap()->ToBoolean(frame->IsToplevel()); | 188 |
| 189 CallSite call_site(isolate, recv); |
| 190 CHECK(call_site.IsJavaScript() || call_site.IsWasm()); |
| 191 return isolate->heap()->ToBoolean(call_site.IsToplevel()); |
| 139 } | 192 } |
| 140 | 193 |
| 141 BUILTIN(CallSitePrototypeToString) { | 194 BUILTIN(CallSitePrototypeToString) { |
| 142 HandleScope scope(isolate); | 195 HandleScope scope(isolate); |
| 143 CHECK_CALLSITE(recv, "toString"); | 196 CHECK_CALLSITE(recv, "toString"); |
| 144 return *frame->ToString(); | 197 RETURN_RESULT_OR_FAILURE(isolate, CallSiteUtils::ToString(isolate, recv)); |
| 145 } | 198 } |
| 146 | 199 |
| 147 #undef CHECK_CALLSITE | 200 #undef CHECK_CALLSITE |
| 148 | 201 |
| 149 } // namespace internal | 202 } // namespace internal |
| 150 } // namespace v8 | 203 } // namespace v8 |
| OLD | NEW |