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

Side by Side Diff: src/accessors.cc

Issue 2142933003: Move Error methods to C++ (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Move to builtins-error.cc Created 4 years, 5 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/accessors.h ('k') | src/bootstrapper.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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<Object> obj = Utils::OpenHandle(*info.Holder());
1160
1161 while (obj->IsJSObject()) {
1162 Handle<JSObject> holder = Handle<JSObject>::cast(obj);
1163 Handle<Object> formatted_stack_trace;
1164
1165 Handle<Object> stack_trace;
1166 Handle<Symbol> stack_trace_symbol =
1167 isolate->factory()->stack_trace_symbol();
1168 MaybeHandle<Object> maybe_stack_trace =
1169 JSObject::GetProperty(holder, stack_trace_symbol);
1170 if (!maybe_stack_trace.ToHandle(&stack_trace) ||
1171 stack_trace->IsUndefined(isolate)) {
1172 // The structured stack trace is not available. Look further up the
Yang 2016/07/19 11:34:59 Can this actually happen? If this is some obscure
jgruber 2016/07/19 13:21:50 Done.
1173 // prototype chain.
1174 obj = JSReceiver::GetPrototype(isolate, holder).ToHandleChecked();
1175 continue;
1176 }
1177
1178 if (!FormatStackTrace(isolate, holder, stack_trace)
1179 .ToHandle(&formatted_stack_trace)) {
1180 isolate->OptionalRescheduleException(false);
1181 return;
1182 }
1183
1184 MaybeHandle<Object> result = ClearInternalStackTrace(isolate, holder);
1185 if (result.is_null()) {
1186 isolate->OptionalRescheduleException(false);
1187 return;
1188 }
1189
1190 Handle<Object> receiver = Utils::OpenHandle(*info.This());
1191 Handle<Name> name = Utils::OpenHandle(*key);
1192 result = ReplaceAccessorWithDataProperty(isolate, receiver, holder, name,
1193 formatted_stack_trace);
1194 if (result.is_null()) {
1195 isolate->OptionalRescheduleException(false);
1196 return;
1197 }
1198
1199 v8::Local<v8::Value> value = Utils::ToLocal(formatted_stack_trace);
1200 info.GetReturnValue().Set(value);
1201 return;
1202 }
1203
1204 Handle<Object> result = isolate->factory()->undefined_value();
1205 info.GetReturnValue().Set(Utils::ToLocal(result));
1206 }
1207
1208 void Accessors::ErrorStackSetter(v8::Local<v8::Name> name,
1209 v8::Local<v8::Value> val,
1210 const v8::PropertyCallbackInfo<void>& info) {
1211 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate());
1212 HandleScope scope(isolate);
1213 Handle<JSObject> obj =
1214 Handle<JSObject>::cast(Utils::OpenHandle(*info.This()));
1215
1216 // Clear internal properties to avoid memory leaks.
1217 Handle<Symbol> stack_trace_symbol = isolate->factory()->stack_trace_symbol();
1218 if (JSReceiver::HasOwnProperty(obj, stack_trace_symbol).FromMaybe(false)) {
1219 ClearInternalStackTrace(isolate, obj);
1220 }
1221
1222 Accessors::ReconfigureToDataProperty(name, val, info);
1223 }
1224
1225 Handle<AccessorInfo> Accessors::ErrorStackInfo(Isolate* isolate,
1226 PropertyAttributes attributes) {
1227 Handle<AccessorInfo> info =
1228 MakeAccessor(isolate, isolate->factory()->stack_string(),
1229 &ErrorStackGetter, &ErrorStackSetter, attributes);
1230 return info;
1231 }
1119 1232
1120 } // namespace internal 1233 } // namespace internal
1121 } // namespace v8 1234 } // namespace v8
OLDNEW
« no previous file with comments | « src/accessors.h ('k') | src/bootstrapper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698