Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1 | // Copyright 2014 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 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5 | #include "src/runtime/runtime-utils.h" |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 6 | |
| 7 | #include "src/arguments.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8 | #include "src/ast/prettyprinter.h" |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 9 | #include "src/bootstrapper.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10 | #include "src/conversions.h" |
| 11 | #include "src/debug/debug.h" |
| 12 | #include "src/frames-inl.h" |
| 13 | #include "src/isolate-inl.h" |
| 14 | #include "src/messages.h" |
| 15 | #include "src/parsing/parser.h" |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 16 | |
| 17 | namespace v8 { |
| 18 | namespace internal { |
| 19 | |
| 20 | RUNTIME_FUNCTION(Runtime_CheckIsBootstrapping) { |
| 21 | SealHandleScope shs(isolate); |
| 22 | DCHECK(args.length() == 0); |
| 23 | RUNTIME_ASSERT(isolate->bootstrapper()->IsActive()); |
| 24 | return isolate->heap()->undefined_value(); |
| 25 | } |
| 26 | |
| 27 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 28 | RUNTIME_FUNCTION(Runtime_ExportFromRuntime) { |
| 29 | HandleScope scope(isolate); |
| 30 | DCHECK(args.length() == 1); |
| 31 | CONVERT_ARG_HANDLE_CHECKED(JSObject, container, 0); |
| 32 | RUNTIME_ASSERT(isolate->bootstrapper()->IsActive()); |
| 33 | JSObject::NormalizeProperties(container, KEEP_INOBJECT_PROPERTIES, 10, |
| 34 | "ExportFromRuntime"); |
| 35 | Bootstrapper::ExportFromRuntime(isolate, container); |
| 36 | JSObject::MigrateSlowToFast(container, 0, "ExportFromRuntime"); |
| 37 | return *container; |
| 38 | } |
| 39 | |
| 40 | |
| 41 | RUNTIME_FUNCTION(Runtime_ExportExperimentalFromRuntime) { |
| 42 | HandleScope scope(isolate); |
| 43 | DCHECK(args.length() == 1); |
| 44 | CONVERT_ARG_HANDLE_CHECKED(JSObject, container, 0); |
| 45 | RUNTIME_ASSERT(isolate->bootstrapper()->IsActive()); |
| 46 | JSObject::NormalizeProperties(container, KEEP_INOBJECT_PROPERTIES, 10, |
| 47 | "ExportExperimentalFromRuntime"); |
| 48 | Bootstrapper::ExportExperimentalFromRuntime(isolate, container); |
| 49 | JSObject::MigrateSlowToFast(container, 0, "ExportExperimentalFromRuntime"); |
| 50 | return *container; |
| 51 | } |
| 52 | |
| 53 | |
| 54 | RUNTIME_FUNCTION(Runtime_InstallToContext) { |
| 55 | HandleScope scope(isolate); |
| 56 | DCHECK(args.length() == 1); |
| 57 | CONVERT_ARG_HANDLE_CHECKED(JSArray, array, 0); |
| 58 | RUNTIME_ASSERT(array->HasFastElements()); |
| 59 | RUNTIME_ASSERT(isolate->bootstrapper()->IsActive()); |
| 60 | Handle<Context> native_context = isolate->native_context(); |
| 61 | Handle<FixedArray> fixed_array(FixedArray::cast(array->elements())); |
| 62 | int length = Smi::cast(array->length())->value(); |
| 63 | for (int i = 0; i < length; i += 2) { |
| 64 | RUNTIME_ASSERT(fixed_array->get(i)->IsString()); |
| 65 | Handle<String> name(String::cast(fixed_array->get(i))); |
| 66 | RUNTIME_ASSERT(fixed_array->get(i + 1)->IsJSObject()); |
| 67 | Handle<JSObject> object(JSObject::cast(fixed_array->get(i + 1))); |
| 68 | int index = Context::ImportedFieldIndexForName(name); |
| 69 | if (index == Context::kNotFound) { |
| 70 | index = Context::IntrinsicIndexForName(name); |
| 71 | } |
| 72 | RUNTIME_ASSERT(index != Context::kNotFound); |
| 73 | native_context->set(index, *object); |
| 74 | } |
| 75 | return isolate->heap()->undefined_value(); |
| 76 | } |
| 77 | |
| 78 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 79 | RUNTIME_FUNCTION(Runtime_Throw) { |
| 80 | HandleScope scope(isolate); |
| 81 | DCHECK(args.length() == 1); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 82 | return isolate->Throw(args[0]); |
| 83 | } |
| 84 | |
| 85 | |
| 86 | RUNTIME_FUNCTION(Runtime_ReThrow) { |
| 87 | HandleScope scope(isolate); |
| 88 | DCHECK(args.length() == 1); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 89 | return isolate->ReThrow(args[0]); |
| 90 | } |
| 91 | |
| 92 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 93 | RUNTIME_FUNCTION(Runtime_ThrowStackOverflow) { |
| 94 | SealHandleScope shs(isolate); |
| 95 | DCHECK_LE(0, args.length()); |
| 96 | return isolate->StackOverflow(); |
| 97 | } |
| 98 | |
| 99 | |
| 100 | RUNTIME_FUNCTION(Runtime_UnwindAndFindExceptionHandler) { |
| 101 | SealHandleScope shs(isolate); |
| 102 | DCHECK(args.length() == 0); |
| 103 | return isolate->UnwindAndFindHandler(); |
| 104 | } |
| 105 | |
| 106 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 107 | RUNTIME_FUNCTION(Runtime_PromoteScheduledException) { |
| 108 | SealHandleScope shs(isolate); |
| 109 | DCHECK(args.length() == 0); |
| 110 | return isolate->PromoteScheduledException(); |
| 111 | } |
| 112 | |
| 113 | |
| 114 | RUNTIME_FUNCTION(Runtime_ThrowReferenceError) { |
| 115 | HandleScope scope(isolate); |
| 116 | DCHECK(args.length() == 1); |
| 117 | CONVERT_ARG_HANDLE_CHECKED(Object, name, 0); |
| 118 | THROW_NEW_ERROR_RETURN_FAILURE( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 119 | isolate, NewReferenceError(MessageTemplate::kNotDefined, name)); |
| 120 | } |
| 121 | |
| 122 | |
| 123 | RUNTIME_FUNCTION(Runtime_NewTypeError) { |
| 124 | HandleScope scope(isolate); |
| 125 | DCHECK(args.length() == 2); |
| 126 | CONVERT_INT32_ARG_CHECKED(template_index, 0); |
| 127 | CONVERT_ARG_HANDLE_CHECKED(Object, arg0, 1); |
| 128 | auto message_template = |
| 129 | static_cast<MessageTemplate::Template>(template_index); |
| 130 | return *isolate->factory()->NewTypeError(message_template, arg0); |
| 131 | } |
| 132 | |
| 133 | |
| 134 | RUNTIME_FUNCTION(Runtime_NewReferenceError) { |
| 135 | HandleScope scope(isolate); |
| 136 | DCHECK(args.length() == 2); |
| 137 | CONVERT_INT32_ARG_CHECKED(template_index, 0); |
| 138 | CONVERT_ARG_HANDLE_CHECKED(Object, arg0, 1); |
| 139 | auto message_template = |
| 140 | static_cast<MessageTemplate::Template>(template_index); |
| 141 | return *isolate->factory()->NewReferenceError(message_template, arg0); |
| 142 | } |
| 143 | |
| 144 | |
| 145 | RUNTIME_FUNCTION(Runtime_NewSyntaxError) { |
| 146 | HandleScope scope(isolate); |
| 147 | DCHECK(args.length() == 2); |
| 148 | CONVERT_INT32_ARG_CHECKED(template_index, 0); |
| 149 | CONVERT_ARG_HANDLE_CHECKED(Object, arg0, 1); |
| 150 | auto message_template = |
| 151 | static_cast<MessageTemplate::Template>(template_index); |
| 152 | return *isolate->factory()->NewSyntaxError(message_template, arg0); |
| 153 | } |
| 154 | |
| 155 | |
| 156 | RUNTIME_FUNCTION(Runtime_ThrowIllegalInvocation) { |
| 157 | HandleScope scope(isolate); |
| 158 | DCHECK(args.length() == 0); |
| 159 | THROW_NEW_ERROR_RETURN_FAILURE( |
| 160 | isolate, NewTypeError(MessageTemplate::kIllegalInvocation)); |
| 161 | } |
| 162 | |
| 163 | |
| 164 | RUNTIME_FUNCTION(Runtime_ThrowIteratorResultNotAnObject) { |
| 165 | HandleScope scope(isolate); |
| 166 | DCHECK(args.length() == 1); |
| 167 | CONVERT_ARG_HANDLE_CHECKED(Object, value, 0); |
| 168 | THROW_NEW_ERROR_RETURN_FAILURE( |
| 169 | isolate, |
| 170 | NewTypeError(MessageTemplate::kIteratorResultNotAnObject, value)); |
| 171 | } |
| 172 | |
| 173 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 174 | RUNTIME_FUNCTION(Runtime_ThrowApplyNonFunction) { |
| 175 | HandleScope scope(isolate); |
| 176 | DCHECK_EQ(1, args.length()); |
| 177 | CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); |
| 178 | Handle<String> type = Object::TypeOf(isolate, object); |
| 179 | THROW_NEW_ERROR_RETURN_FAILURE( |
| 180 | isolate, NewTypeError(MessageTemplate::kApplyNonFunction, object, type)); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | |
| 184 | RUNTIME_FUNCTION(Runtime_PromiseRejectEvent) { |
| 185 | DCHECK(args.length() == 3); |
| 186 | HandleScope scope(isolate); |
| 187 | CONVERT_ARG_HANDLE_CHECKED(JSObject, promise, 0); |
| 188 | CONVERT_ARG_HANDLE_CHECKED(Object, value, 1); |
| 189 | CONVERT_BOOLEAN_ARG_CHECKED(debug_event, 2); |
| 190 | if (debug_event) isolate->debug()->OnPromiseReject(promise, value); |
| 191 | Handle<Symbol> key = isolate->factory()->promise_has_handler_symbol(); |
| 192 | // Do not report if we actually have a handler. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 193 | if (JSReceiver::GetDataProperty(promise, key)->IsUndefined()) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 194 | isolate->ReportPromiseReject(promise, value, |
| 195 | v8::kPromiseRejectWithNoHandler); |
| 196 | } |
| 197 | return isolate->heap()->undefined_value(); |
| 198 | } |
| 199 | |
| 200 | |
| 201 | RUNTIME_FUNCTION(Runtime_PromiseRevokeReject) { |
| 202 | DCHECK(args.length() == 1); |
| 203 | HandleScope scope(isolate); |
| 204 | CONVERT_ARG_HANDLE_CHECKED(JSObject, promise, 0); |
| 205 | Handle<Symbol> key = isolate->factory()->promise_has_handler_symbol(); |
| 206 | // At this point, no revocation has been issued before |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 207 | RUNTIME_ASSERT(JSReceiver::GetDataProperty(promise, key)->IsUndefined()); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 208 | isolate->ReportPromiseReject(promise, Handle<Object>(), |
| 209 | v8::kPromiseHandlerAddedAfterReject); |
| 210 | return isolate->heap()->undefined_value(); |
| 211 | } |
| 212 | |
| 213 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 214 | RUNTIME_FUNCTION(Runtime_StackGuard) { |
| 215 | SealHandleScope shs(isolate); |
| 216 | DCHECK(args.length() == 0); |
| 217 | |
| 218 | // First check if this is a real stack overflow. |
| 219 | StackLimitCheck check(isolate); |
| 220 | if (check.JsHasOverflowed()) { |
| 221 | return isolate->StackOverflow(); |
| 222 | } |
| 223 | |
| 224 | return isolate->stack_guard()->HandleInterrupts(); |
| 225 | } |
| 226 | |
| 227 | |
| 228 | RUNTIME_FUNCTION(Runtime_Interrupt) { |
| 229 | SealHandleScope shs(isolate); |
| 230 | DCHECK(args.length() == 0); |
| 231 | return isolate->stack_guard()->HandleInterrupts(); |
| 232 | } |
| 233 | |
| 234 | |
| 235 | RUNTIME_FUNCTION(Runtime_AllocateInNewSpace) { |
| 236 | HandleScope scope(isolate); |
| 237 | DCHECK(args.length() == 1); |
| 238 | CONVERT_SMI_ARG_CHECKED(size, 0); |
| 239 | RUNTIME_ASSERT(IsAligned(size, kPointerSize)); |
| 240 | RUNTIME_ASSERT(size > 0); |
| 241 | RUNTIME_ASSERT(size <= Page::kMaxRegularHeapObjectSize); |
| 242 | return *isolate->factory()->NewFillerObject(size, false, NEW_SPACE); |
| 243 | } |
| 244 | |
| 245 | |
| 246 | RUNTIME_FUNCTION(Runtime_AllocateInTargetSpace) { |
| 247 | HandleScope scope(isolate); |
| 248 | DCHECK(args.length() == 2); |
| 249 | CONVERT_SMI_ARG_CHECKED(size, 0); |
| 250 | CONVERT_SMI_ARG_CHECKED(flags, 1); |
| 251 | RUNTIME_ASSERT(IsAligned(size, kPointerSize)); |
| 252 | RUNTIME_ASSERT(size > 0); |
| 253 | RUNTIME_ASSERT(size <= Page::kMaxRegularHeapObjectSize); |
| 254 | bool double_align = AllocateDoubleAlignFlag::decode(flags); |
| 255 | AllocationSpace space = AllocateTargetSpace::decode(flags); |
| 256 | return *isolate->factory()->NewFillerObject(size, double_align, space); |
| 257 | } |
| 258 | |
| 259 | |
| 260 | // Collect the raw data for a stack trace. Returns an array of 4 |
| 261 | // element segments each containing a receiver, function, code and |
| 262 | // native code offset. |
| 263 | RUNTIME_FUNCTION(Runtime_CollectStackTrace) { |
| 264 | HandleScope scope(isolate); |
| 265 | DCHECK(args.length() == 2); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 266 | CONVERT_ARG_HANDLE_CHECKED(JSReceiver, error_object, 0); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 267 | CONVERT_ARG_HANDLE_CHECKED(Object, caller, 1); |
| 268 | |
| 269 | if (!isolate->bootstrapper()->IsActive()) { |
| 270 | // Optionally capture a more detailed stack trace for the message. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 271 | RETURN_FAILURE_ON_EXCEPTION( |
| 272 | isolate, isolate->CaptureAndSetDetailedStackTrace(error_object)); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 273 | // Capture a simple stack trace for the stack property. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 274 | RETURN_FAILURE_ON_EXCEPTION( |
| 275 | isolate, isolate->CaptureAndSetSimpleStackTrace(error_object, caller)); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 276 | } |
| 277 | return isolate->heap()->undefined_value(); |
| 278 | } |
| 279 | |
| 280 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 281 | RUNTIME_FUNCTION(Runtime_MessageGetStartPosition) { |
| 282 | SealHandleScope shs(isolate); |
| 283 | DCHECK(args.length() == 1); |
| 284 | CONVERT_ARG_CHECKED(JSMessageObject, message, 0); |
| 285 | return Smi::FromInt(message->start_position()); |
| 286 | } |
| 287 | |
| 288 | |
| 289 | RUNTIME_FUNCTION(Runtime_MessageGetScript) { |
| 290 | SealHandleScope shs(isolate); |
| 291 | DCHECK(args.length() == 1); |
| 292 | CONVERT_ARG_CHECKED(JSMessageObject, message, 0); |
| 293 | return message->script(); |
| 294 | } |
| 295 | |
| 296 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 297 | RUNTIME_FUNCTION(Runtime_FormatMessageString) { |
| 298 | HandleScope scope(isolate); |
| 299 | DCHECK(args.length() == 4); |
| 300 | CONVERT_INT32_ARG_CHECKED(template_index, 0); |
| 301 | CONVERT_ARG_HANDLE_CHECKED(String, arg0, 1); |
| 302 | CONVERT_ARG_HANDLE_CHECKED(String, arg1, 2); |
| 303 | CONVERT_ARG_HANDLE_CHECKED(String, arg2, 3); |
| 304 | Handle<String> result; |
| 305 | ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 306 | isolate, result, |
| 307 | MessageTemplate::FormatMessage(template_index, arg0, arg1, arg2)); |
| 308 | isolate->native_context()->IncrementErrorsThrown(); |
| 309 | return *result; |
| 310 | } |
| 311 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 312 | #define CALLSITE_GET(NAME, RETURN) \ |
| 313 | RUNTIME_FUNCTION(Runtime_CallSite##NAME##RT) { \ |
| 314 | HandleScope scope(isolate); \ |
| 315 | DCHECK(args.length() == 1); \ |
| 316 | CONVERT_ARG_HANDLE_CHECKED(JSObject, call_site_obj, 0); \ |
| 317 | Handle<String> result; \ |
| 318 | CallSite call_site(isolate, call_site_obj); \ |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 319 | RUNTIME_ASSERT(call_site.IsValid()); \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 320 | return RETURN(call_site.NAME(), isolate); \ |
| 321 | } |
| 322 | |
| 323 | static inline Object* ReturnDereferencedHandle(Handle<Object> obj, |
| 324 | Isolate* isolate) { |
| 325 | return *obj; |
| 326 | } |
| 327 | |
| 328 | |
| 329 | static inline Object* ReturnPositiveNumberOrNull(int value, Isolate* isolate) { |
| 330 | if (value >= 0) return *isolate->factory()->NewNumberFromInt(value); |
| 331 | return isolate->heap()->null_value(); |
| 332 | } |
| 333 | |
| 334 | |
| 335 | static inline Object* ReturnBoolean(bool value, Isolate* isolate) { |
| 336 | return isolate->heap()->ToBoolean(value); |
| 337 | } |
| 338 | |
| 339 | |
| 340 | CALLSITE_GET(GetFileName, ReturnDereferencedHandle) |
| 341 | CALLSITE_GET(GetFunctionName, ReturnDereferencedHandle) |
| 342 | CALLSITE_GET(GetScriptNameOrSourceUrl, ReturnDereferencedHandle) |
| 343 | CALLSITE_GET(GetMethodName, ReturnDereferencedHandle) |
| 344 | CALLSITE_GET(GetLineNumber, ReturnPositiveNumberOrNull) |
| 345 | CALLSITE_GET(GetColumnNumber, ReturnPositiveNumberOrNull) |
| 346 | CALLSITE_GET(IsNative, ReturnBoolean) |
| 347 | CALLSITE_GET(IsToplevel, ReturnBoolean) |
| 348 | CALLSITE_GET(IsEval, ReturnBoolean) |
| 349 | CALLSITE_GET(IsConstructor, ReturnBoolean) |
| 350 | |
| 351 | #undef CALLSITE_GET |
| 352 | |
| 353 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 354 | RUNTIME_FUNCTION(Runtime_IS_VAR) { |
| 355 | UNREACHABLE(); // implemented as macro in the parser |
| 356 | return NULL; |
| 357 | } |
| 358 | |
| 359 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 360 | namespace { |
| 361 | |
| 362 | bool ComputeLocation(Isolate* isolate, MessageLocation* target) { |
| 363 | JavaScriptFrameIterator it(isolate); |
| 364 | if (!it.done()) { |
| 365 | JavaScriptFrame* frame = it.frame(); |
| 366 | JSFunction* fun = frame->function(); |
| 367 | Object* script = fun->shared()->script(); |
| 368 | if (script->IsScript() && |
| 369 | !(Script::cast(script)->source()->IsUndefined())) { |
| 370 | Handle<Script> casted_script(Script::cast(script)); |
| 371 | // Compute the location from the function and the relocation info of the |
| 372 | // baseline code. For optimized code this will use the deoptimization |
| 373 | // information to get canonical location information. |
| 374 | List<FrameSummary> frames(FLAG_max_inlining_levels + 1); |
| 375 | it.frame()->Summarize(&frames); |
| 376 | FrameSummary& summary = frames.last(); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 377 | int pos = summary.abstract_code()->SourcePosition(summary.code_offset()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 378 | *target = MessageLocation(casted_script, pos, pos + 1, handle(fun)); |
| 379 | return true; |
| 380 | } |
| 381 | } |
| 382 | return false; |
| 383 | } |
| 384 | |
| 385 | |
| 386 | Handle<String> RenderCallSite(Isolate* isolate, Handle<Object> object) { |
| 387 | MessageLocation location; |
| 388 | if (ComputeLocation(isolate, &location)) { |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 389 | Zone zone(isolate->allocator()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 390 | base::SmartPointer<ParseInfo> info( |
| 391 | location.function()->shared()->is_function() |
| 392 | ? new ParseInfo(&zone, location.function()) |
| 393 | : new ParseInfo(&zone, location.script())); |
| 394 | if (Parser::ParseStatic(info.get())) { |
| 395 | CallPrinter printer(isolate, location.function()->shared()->IsBuiltin()); |
| 396 | const char* string = printer.Print(info->literal(), location.start_pos()); |
| 397 | if (strlen(string) > 0) { |
| 398 | return isolate->factory()->NewStringFromAsciiChecked(string); |
| 399 | } |
| 400 | } else { |
| 401 | isolate->clear_pending_exception(); |
| 402 | } |
| 403 | } |
| 404 | return Object::TypeOf(isolate, object); |
| 405 | } |
| 406 | |
| 407 | } // namespace |
| 408 | |
| 409 | |
| 410 | RUNTIME_FUNCTION(Runtime_ThrowCalledNonCallable) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 411 | HandleScope scope(isolate); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 412 | DCHECK_EQ(1, args.length()); |
| 413 | CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); |
| 414 | Handle<String> callsite = RenderCallSite(isolate, object); |
| 415 | THROW_NEW_ERROR_RETURN_FAILURE( |
| 416 | isolate, NewTypeError(MessageTemplate::kCalledNonCallable, callsite)); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 417 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 418 | |
| 419 | |
| 420 | RUNTIME_FUNCTION(Runtime_ThrowConstructedNonConstructable) { |
| 421 | HandleScope scope(isolate); |
| 422 | DCHECK_EQ(1, args.length()); |
| 423 | CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); |
| 424 | Handle<String> callsite = RenderCallSite(isolate, object); |
| 425 | THROW_NEW_ERROR_RETURN_FAILURE( |
| 426 | isolate, NewTypeError(MessageTemplate::kNotConstructor, callsite)); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 427 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 428 | |
| 429 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 430 | RUNTIME_FUNCTION(Runtime_ThrowDerivedConstructorReturnedNonObject) { |
| 431 | HandleScope scope(isolate); |
| 432 | DCHECK_EQ(0, args.length()); |
| 433 | THROW_NEW_ERROR_RETURN_FAILURE( |
| 434 | isolate, NewTypeError(MessageTemplate::kDerivedConstructorReturn)); |
| 435 | } |
| 436 | |
| 437 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 438 | // ES6 section 7.3.17 CreateListFromArrayLike (obj) |
| 439 | RUNTIME_FUNCTION(Runtime_CreateListFromArrayLike) { |
| 440 | HandleScope scope(isolate); |
| 441 | DCHECK_EQ(1, args.length()); |
| 442 | CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); |
| 443 | Handle<FixedArray> result; |
| 444 | ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 445 | isolate, result, |
| 446 | Object::CreateListFromArrayLike(isolate, object, ElementTypes::kAll)); |
| 447 | return *result; |
| 448 | } |
| 449 | |
| 450 | |
| 451 | RUNTIME_FUNCTION(Runtime_IncrementUseCounter) { |
| 452 | HandleScope scope(isolate); |
| 453 | DCHECK_EQ(1, args.length()); |
| 454 | CONVERT_SMI_ARG_CHECKED(counter, 0); |
| 455 | isolate->CountUsage(static_cast<v8::Isolate::UseCounterFeature>(counter)); |
| 456 | return isolate->heap()->undefined_value(); |
| 457 | } |
| 458 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 459 | RUNTIME_FUNCTION(Runtime_GetOrdinaryHasInstance) { |
| 460 | HandleScope scope(isolate); |
| 461 | DCHECK_EQ(0, args.length()); |
| 462 | |
| 463 | return isolate->native_context()->ordinary_has_instance(); |
| 464 | } |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 465 | |
| 466 | RUNTIME_FUNCTION(Runtime_GetAndResetRuntimeCallStats) { |
| 467 | HandleScope scope(isolate); |
| 468 | DCHECK_EQ(0, args.length()); |
| 469 | std::stringstream stats_stream; |
| 470 | isolate->counters()->runtime_call_stats()->Print(stats_stream); |
| 471 | Handle<String> result = |
| 472 | isolate->factory()->NewStringFromAsciiChecked(stats_stream.str().c_str()); |
| 473 | isolate->counters()->runtime_call_stats()->Reset(); |
| 474 | return *result; |
| 475 | } |
| 476 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 477 | } // namespace internal |
| 478 | } // namespace v8 |