| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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/accessors.h" | 5 #include "src/accessors.h" |
| 6 | 6 |
| 7 #include "src/api.h" | 7 #include "src/api.h" |
| 8 #include "src/contexts.h" | 8 #include "src/contexts.h" |
| 9 #include "src/deoptimizer.h" | 9 #include "src/deoptimizer.h" |
| 10 #include "src/execution.h" | 10 #include "src/execution.h" |
| (...skipping 1098 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1109 info.GetReturnValue().Set(Utils::ToLocal(result)); | 1109 info.GetReturnValue().Set(Utils::ToLocal(result)); |
| 1110 } | 1110 } |
| 1111 | 1111 |
| 1112 Handle<AccessorInfo> Accessors::BoundFunctionNameInfo( | 1112 Handle<AccessorInfo> Accessors::BoundFunctionNameInfo( |
| 1113 Isolate* isolate, PropertyAttributes attributes) { | 1113 Isolate* isolate, PropertyAttributes attributes) { |
| 1114 return MakeAccessor(isolate, isolate->factory()->name_string(), | 1114 return MakeAccessor(isolate, isolate->factory()->name_string(), |
| 1115 &BoundFunctionNameGetter, &ReconfigureToDataProperty, | 1115 &BoundFunctionNameGetter, &ReconfigureToDataProperty, |
| 1116 attributes); | 1116 attributes); |
| 1117 } | 1117 } |
| 1118 | 1118 |
| 1119 // | |
| 1120 // Accessors::ErrorStack | |
| 1121 // | |
| 1122 | |
| 1123 namespace { | |
| 1124 | |
| 1125 MaybeHandle<JSReceiver> ClearInternalStackTrace(Isolate* isolate, | |
| 1126 Handle<JSObject> error) { | |
| 1127 RETURN_ON_EXCEPTION( | |
| 1128 isolate, | |
| 1129 JSReceiver::SetProperty(error, isolate->factory()->stack_trace_symbol(), | |
| 1130 isolate->factory()->undefined_value(), STRICT), | |
| 1131 JSReceiver); | |
| 1132 return error; | |
| 1133 } | |
| 1134 | |
| 1135 MaybeHandle<Object> FormatStackTrace(Isolate* isolate, Handle<JSObject> error, | |
| 1136 Handle<Object> stack_trace) { | |
| 1137 // TODO(jgruber): Port FormatStackTrace from JS. | |
| 1138 Handle<JSFunction> fun = isolate->error_format_stack_trace(); | |
| 1139 | |
| 1140 int argc = 2; | |
| 1141 ScopedVector<Handle<Object>> argv(argc); | |
| 1142 argv[0] = error; | |
| 1143 argv[1] = stack_trace; | |
| 1144 | |
| 1145 Handle<Object> formatted_stack_trace; | |
| 1146 ASSIGN_RETURN_ON_EXCEPTION( | |
| 1147 isolate, formatted_stack_trace, | |
| 1148 Execution::Call(isolate, fun, error, argc, argv.start()), Object); | |
| 1149 | |
| 1150 return formatted_stack_trace; | |
| 1151 } | |
| 1152 | |
| 1153 } // namespace | |
| 1154 | |
| 1155 void Accessors::ErrorStackGetter( | |
| 1156 v8::Local<v8::Name> key, const v8::PropertyCallbackInfo<v8::Value>& info) { | |
| 1157 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate()); | |
| 1158 HandleScope scope(isolate); | |
| 1159 Handle<JSObject> holder = | |
| 1160 Handle<JSObject>::cast(Utils::OpenHandle(*info.Holder())); | |
| 1161 | |
| 1162 // Retrieve the structured stack trace. | |
| 1163 | |
| 1164 Handle<Object> stack_trace; | |
| 1165 Handle<Symbol> stack_trace_symbol = isolate->factory()->stack_trace_symbol(); | |
| 1166 MaybeHandle<Object> maybe_stack_trace = | |
| 1167 JSObject::GetProperty(holder, stack_trace_symbol); | |
| 1168 if (!maybe_stack_trace.ToHandle(&stack_trace) || | |
| 1169 stack_trace->IsUndefined(isolate)) { | |
| 1170 Handle<Object> result = isolate->factory()->undefined_value(); | |
| 1171 info.GetReturnValue().Set(Utils::ToLocal(result)); | |
| 1172 return; | |
| 1173 } | |
| 1174 | |
| 1175 // Format it, clear the internal structured trace and reconfigure as a data | |
| 1176 // property. | |
| 1177 | |
| 1178 Handle<Object> formatted_stack_trace; | |
| 1179 if (!FormatStackTrace(isolate, holder, stack_trace) | |
| 1180 .ToHandle(&formatted_stack_trace)) { | |
| 1181 isolate->OptionalRescheduleException(false); | |
| 1182 return; | |
| 1183 } | |
| 1184 | |
| 1185 MaybeHandle<Object> result = ClearInternalStackTrace(isolate, holder); | |
| 1186 if (result.is_null()) { | |
| 1187 isolate->OptionalRescheduleException(false); | |
| 1188 return; | |
| 1189 } | |
| 1190 | |
| 1191 Handle<Object> receiver = Utils::OpenHandle(*info.This()); | |
| 1192 Handle<Name> name = Utils::OpenHandle(*key); | |
| 1193 result = ReplaceAccessorWithDataProperty(isolate, receiver, holder, name, | |
| 1194 formatted_stack_trace); | |
| 1195 if (result.is_null()) { | |
| 1196 isolate->OptionalRescheduleException(false); | |
| 1197 return; | |
| 1198 } | |
| 1199 | |
| 1200 v8::Local<v8::Value> value = Utils::ToLocal(formatted_stack_trace); | |
| 1201 info.GetReturnValue().Set(value); | |
| 1202 } | |
| 1203 | |
| 1204 void Accessors::ErrorStackSetter(v8::Local<v8::Name> name, | |
| 1205 v8::Local<v8::Value> val, | |
| 1206 const v8::PropertyCallbackInfo<void>& info) { | |
| 1207 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate()); | |
| 1208 HandleScope scope(isolate); | |
| 1209 Handle<JSObject> obj = | |
| 1210 Handle<JSObject>::cast(Utils::OpenHandle(*info.This())); | |
| 1211 | |
| 1212 // Clear internal properties to avoid memory leaks. | |
| 1213 Handle<Symbol> stack_trace_symbol = isolate->factory()->stack_trace_symbol(); | |
| 1214 if (JSReceiver::HasOwnProperty(obj, stack_trace_symbol).FromMaybe(false)) { | |
| 1215 ClearInternalStackTrace(isolate, obj); | |
| 1216 } | |
| 1217 | |
| 1218 Accessors::ReconfigureToDataProperty(name, val, info); | |
| 1219 } | |
| 1220 | |
| 1221 Handle<AccessorInfo> Accessors::ErrorStackInfo(Isolate* isolate, | |
| 1222 PropertyAttributes attributes) { | |
| 1223 Handle<AccessorInfo> info = | |
| 1224 MakeAccessor(isolate, isolate->factory()->stack_string(), | |
| 1225 &ErrorStackGetter, &ErrorStackSetter, attributes); | |
| 1226 return info; | |
| 1227 } | |
| 1228 | 1119 |
| 1229 } // namespace internal | 1120 } // namespace internal |
| 1230 } // namespace v8 | 1121 } // namespace v8 |
| OLD | NEW |