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