V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
runtime-internal.cc
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 
5 #include <memory>
6 
7 #include "src/api.h"
8 #include "src/arguments-inl.h"
9 #include "src/ast/prettyprinter.h"
10 #include "src/bootstrapper.h"
11 #include "src/builtins/builtins.h"
12 #include "src/conversions.h"
13 #include "src/counters.h"
14 #include "src/debug/debug.h"
15 #include "src/frames-inl.h"
16 #include "src/isolate-inl.h"
17 #include "src/message-template.h"
18 #include "src/objects/js-array-inl.h"
19 #include "src/parsing/parse-info.h"
20 #include "src/parsing/parsing.h"
21 #include "src/runtime/runtime-utils.h"
22 #include "src/snapshot/snapshot.h"
23 #include "src/string-builder-inl.h"
24 
25 namespace v8 {
26 namespace internal {
27 
28 RUNTIME_FUNCTION(Runtime_CheckIsBootstrapping) {
29  SealHandleScope shs(isolate);
30  DCHECK_EQ(0, args.length());
31  CHECK(isolate->bootstrapper()->IsActive());
32  return ReadOnlyRoots(isolate).undefined_value();
33 }
34 
35 RUNTIME_FUNCTION(Runtime_ExportFromRuntime) {
36  HandleScope scope(isolate);
37  DCHECK_EQ(1, args.length());
38  CONVERT_ARG_HANDLE_CHECKED(JSObject, container, 0);
39  CHECK(isolate->bootstrapper()->IsActive());
40  JSObject::NormalizeProperties(container, KEEP_INOBJECT_PROPERTIES, 10,
41  "ExportFromRuntime");
42  Bootstrapper::ExportFromRuntime(isolate, container);
43  JSObject::MigrateSlowToFast(container, 0, "ExportFromRuntime");
44  return *container;
45 }
46 
47 RUNTIME_FUNCTION(Runtime_InstallToContext) {
48  HandleScope scope(isolate);
49  DCHECK_EQ(1, args.length());
50  CONVERT_ARG_HANDLE_CHECKED(JSArray, array, 0);
51  CHECK(array->HasFastElements());
52  CHECK(isolate->bootstrapper()->IsActive());
53  Handle<Context> native_context = isolate->native_context();
54  Handle<FixedArray> fixed_array(FixedArray::cast(array->elements()), isolate);
55  int length = Smi::ToInt(array->length());
56  for (int i = 0; i < length; i += 2) {
57  CHECK(fixed_array->get(i)->IsString());
58  Handle<String> name(String::cast(fixed_array->get(i)), isolate);
59  CHECK(fixed_array->get(i + 1)->IsJSObject());
60  Handle<JSObject> object(JSObject::cast(fixed_array->get(i + 1)), isolate);
61  int index = Context::ImportedFieldIndexForName(name);
62  if (index == Context::kNotFound) {
63  index = Context::IntrinsicIndexForName(name);
64  }
65  CHECK_NE(index, Context::kNotFound);
66  native_context->set(index, *object);
67  }
68  return ReadOnlyRoots(isolate).undefined_value();
69 }
70 
71 RUNTIME_FUNCTION(Runtime_Throw) {
72  HandleScope scope(isolate);
73  DCHECK_EQ(1, args.length());
74  return isolate->Throw(args[0]);
75 }
76 
77 RUNTIME_FUNCTION(Runtime_ReThrow) {
78  HandleScope scope(isolate);
79  DCHECK_EQ(1, args.length());
80  return isolate->ReThrow(args[0]);
81 }
82 
83 RUNTIME_FUNCTION(Runtime_ThrowStackOverflow) {
84  SealHandleScope shs(isolate);
85  DCHECK_LE(0, args.length());
86  return isolate->StackOverflow();
87 }
88 
89 RUNTIME_FUNCTION(Runtime_ThrowSymbolAsyncIteratorInvalid) {
90  HandleScope scope(isolate);
91  DCHECK_EQ(0, args.length());
92  THROW_NEW_ERROR_RETURN_FAILURE(
93  isolate, NewTypeError(MessageTemplate::kSymbolAsyncIteratorInvalid));
94 }
95 
96 #define THROW_ERROR(isolate, args, call) \
97  HandleScope scope(isolate); \
98  DCHECK_LE(1, args.length()); \
99  CONVERT_SMI_ARG_CHECKED(message_id_smi, 0); \
100  \
101  Handle<Object> undefined = isolate->factory()->undefined_value(); \
102  Handle<Object> arg0 = (args.length() > 1) ? args.at(1) : undefined; \
103  Handle<Object> arg1 = (args.length() > 2) ? args.at(2) : undefined; \
104  Handle<Object> arg2 = (args.length() > 3) ? args.at(3) : undefined; \
105  \
106  MessageTemplate message_id = MessageTemplateFromInt(message_id_smi); \
107  \
108  THROW_NEW_ERROR_RETURN_FAILURE(isolate, call(message_id, arg0, arg1, arg2));
109 
110 RUNTIME_FUNCTION(Runtime_ThrowRangeError) {
111  THROW_ERROR(isolate, args, NewRangeError);
112 }
113 
114 RUNTIME_FUNCTION(Runtime_ThrowTypeError) {
115  THROW_ERROR(isolate, args, NewTypeError);
116 }
117 
118 #undef THROW_ERROR
119 
120 namespace {
121 
122 const char* ElementsKindToType(ElementsKind fixed_elements_kind) {
123  switch (fixed_elements_kind) {
124 #define ELEMENTS_KIND_CASE(Type, type, TYPE, ctype) \
125  case TYPE##_ELEMENTS: \
126  return #Type "Array";
127 
128  TYPED_ARRAYS(ELEMENTS_KIND_CASE)
129 #undef ELEMENTS_KIND_CASE
130 
131  default:
132  UNREACHABLE();
133  }
134 }
135 
136 } // namespace
137 
138 RUNTIME_FUNCTION(Runtime_ThrowInvalidTypedArrayAlignment) {
139  HandleScope scope(isolate);
140  DCHECK_EQ(2, args.length());
141  CONVERT_ARG_HANDLE_CHECKED(Map, map, 0);
142  CONVERT_ARG_HANDLE_CHECKED(String, problem_string, 1);
143 
144  ElementsKind kind = map->elements_kind();
145 
146  Handle<String> type =
147  isolate->factory()->NewStringFromAsciiChecked(ElementsKindToType(kind));
148 
149  ExternalArrayType external_type;
150  size_t size;
151  Factory::TypeAndSizeForElementsKind(kind, &external_type, &size);
152  Handle<Object> element_size =
153  handle(Smi::FromInt(static_cast<int>(size)), isolate);
154 
155  THROW_NEW_ERROR_RETURN_FAILURE(
156  isolate, NewRangeError(MessageTemplate::kInvalidTypedArrayAlignment,
157  problem_string, type, element_size));
158 }
159 
160 RUNTIME_FUNCTION(Runtime_UnwindAndFindExceptionHandler) {
161  SealHandleScope shs(isolate);
162  DCHECK_EQ(0, args.length());
163  return isolate->UnwindAndFindHandler();
164 }
165 
166 RUNTIME_FUNCTION(Runtime_PromoteScheduledException) {
167  SealHandleScope shs(isolate);
168  DCHECK_EQ(0, args.length());
169  return isolate->PromoteScheduledException();
170 }
171 
172 RUNTIME_FUNCTION(Runtime_ThrowReferenceError) {
173  HandleScope scope(isolate);
174  DCHECK_EQ(1, args.length());
175  CONVERT_ARG_HANDLE_CHECKED(Object, name, 0);
176  THROW_NEW_ERROR_RETURN_FAILURE(
177  isolate, NewReferenceError(MessageTemplate::kNotDefined, name));
178 }
179 
180 RUNTIME_FUNCTION(Runtime_NewTypeError) {
181  HandleScope scope(isolate);
182  DCHECK_EQ(2, args.length());
183  CONVERT_INT32_ARG_CHECKED(template_index, 0);
184  CONVERT_ARG_HANDLE_CHECKED(Object, arg0, 1);
185  MessageTemplate message_template = MessageTemplateFromInt(template_index);
186  return *isolate->factory()->NewTypeError(message_template, arg0);
187 }
188 
189 RUNTIME_FUNCTION(Runtime_NewReferenceError) {
190  HandleScope scope(isolate);
191  DCHECK_EQ(2, args.length());
192  CONVERT_INT32_ARG_CHECKED(template_index, 0);
193  CONVERT_ARG_HANDLE_CHECKED(Object, arg0, 1);
194  MessageTemplate message_template = MessageTemplateFromInt(template_index);
195  return *isolate->factory()->NewReferenceError(message_template, arg0);
196 }
197 
198 RUNTIME_FUNCTION(Runtime_NewSyntaxError) {
199  HandleScope scope(isolate);
200  DCHECK_EQ(2, args.length());
201  CONVERT_INT32_ARG_CHECKED(template_index, 0);
202  CONVERT_ARG_HANDLE_CHECKED(Object, arg0, 1);
203  MessageTemplate message_template = MessageTemplateFromInt(template_index);
204  return *isolate->factory()->NewSyntaxError(message_template, arg0);
205 }
206 
207 RUNTIME_FUNCTION(Runtime_ThrowInvalidStringLength) {
208  HandleScope scope(isolate);
209  THROW_NEW_ERROR_RETURN_FAILURE(isolate, NewInvalidStringLengthError());
210 }
211 
212 RUNTIME_FUNCTION(Runtime_ThrowIteratorResultNotAnObject) {
213  HandleScope scope(isolate);
214  DCHECK_EQ(1, args.length());
215  CONVERT_ARG_HANDLE_CHECKED(Object, value, 0);
216  THROW_NEW_ERROR_RETURN_FAILURE(
217  isolate,
218  NewTypeError(MessageTemplate::kIteratorResultNotAnObject, value));
219 }
220 
221 RUNTIME_FUNCTION(Runtime_ThrowThrowMethodMissing) {
222  HandleScope scope(isolate);
223  DCHECK_EQ(0, args.length());
224  THROW_NEW_ERROR_RETURN_FAILURE(
225  isolate, NewTypeError(MessageTemplate::kThrowMethodMissing));
226 }
227 
228 RUNTIME_FUNCTION(Runtime_ThrowSymbolIteratorInvalid) {
229  HandleScope scope(isolate);
230  DCHECK_EQ(0, args.length());
231  THROW_NEW_ERROR_RETURN_FAILURE(
232  isolate, NewTypeError(MessageTemplate::kSymbolIteratorInvalid));
233 }
234 
235 RUNTIME_FUNCTION(Runtime_ThrowNotConstructor) {
236  HandleScope scope(isolate);
237  DCHECK_EQ(1, args.length());
238  CONVERT_ARG_HANDLE_CHECKED(Object, object, 0);
239  THROW_NEW_ERROR_RETURN_FAILURE(
240  isolate, NewTypeError(MessageTemplate::kNotConstructor, object));
241 }
242 
243 RUNTIME_FUNCTION(Runtime_ThrowApplyNonFunction) {
244  HandleScope scope(isolate);
245  DCHECK_EQ(1, args.length());
246  CONVERT_ARG_HANDLE_CHECKED(Object, object, 0);
247  Handle<String> type = Object::TypeOf(isolate, object);
248  THROW_NEW_ERROR_RETURN_FAILURE(
249  isolate, NewTypeError(MessageTemplate::kApplyNonFunction, object, type));
250 }
251 
252 RUNTIME_FUNCTION(Runtime_StackGuard) {
253  SealHandleScope shs(isolate);
254  DCHECK_EQ(0, args.length());
255 
256  // First check if this is a real stack overflow.
257  StackLimitCheck check(isolate);
258  if (check.JsHasOverflowed()) {
259  return isolate->StackOverflow();
260  }
261 
262  return isolate->stack_guard()->HandleInterrupts();
263 }
264 
265 RUNTIME_FUNCTION(Runtime_Interrupt) {
266  SealHandleScope shs(isolate);
267  DCHECK_EQ(0, args.length());
268  return isolate->stack_guard()->HandleInterrupts();
269 }
270 
271 RUNTIME_FUNCTION(Runtime_AllocateInNewSpace) {
272  HandleScope scope(isolate);
273  DCHECK_EQ(1, args.length());
274  CONVERT_SMI_ARG_CHECKED(size, 0);
275  CHECK(IsAligned(size, kPointerSize));
276  CHECK_GT(size, 0);
277  CHECK_LE(size, kMaxRegularHeapObjectSize);
278  return *isolate->factory()->NewFillerObject(size, false, NEW_SPACE);
279 }
280 
281 RUNTIME_FUNCTION(Runtime_AllocateInTargetSpace) {
282  HandleScope scope(isolate);
283  DCHECK_EQ(2, args.length());
284  CONVERT_SMI_ARG_CHECKED(size, 0);
285  CONVERT_SMI_ARG_CHECKED(flags, 1);
286  CHECK(IsAligned(size, kPointerSize));
287  CHECK_GT(size, 0);
288  bool double_align = AllocateDoubleAlignFlag::decode(flags);
289  AllocationSpace space = AllocateTargetSpace::decode(flags);
290  CHECK(size <= kMaxRegularHeapObjectSize || space == LO_SPACE);
291  return *isolate->factory()->NewFillerObject(size, double_align, space);
292 }
293 
294 RUNTIME_FUNCTION(Runtime_AllocateSeqOneByteString) {
295  HandleScope scope(isolate);
296  DCHECK_EQ(1, args.length());
297  CONVERT_SMI_ARG_CHECKED(length, 0);
298  if (length == 0) return ReadOnlyRoots(isolate).empty_string();
299  Handle<SeqOneByteString> result;
300  ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
301  isolate, result, isolate->factory()->NewRawOneByteString(length));
302  return *result;
303 }
304 
305 RUNTIME_FUNCTION(Runtime_AllocateSeqTwoByteString) {
306  HandleScope scope(isolate);
307  DCHECK_EQ(1, args.length());
308  CONVERT_SMI_ARG_CHECKED(length, 0);
309  if (length == 0) return ReadOnlyRoots(isolate).empty_string();
310  Handle<SeqTwoByteString> result;
311  ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
312  isolate, result, isolate->factory()->NewRawTwoByteString(length));
313  return *result;
314 }
315 
316 namespace {
317 
318 bool ComputeLocation(Isolate* isolate, MessageLocation* target) {
319  JavaScriptFrameIterator it(isolate);
320  if (!it.done()) {
321  // Compute the location from the function and the relocation info of the
322  // baseline code. For optimized code this will use the deoptimization
323  // information to get canonical location information.
324  std::vector<FrameSummary> frames;
325  it.frame()->Summarize(&frames);
326  auto& summary = frames.back().AsJavaScript();
327  Handle<SharedFunctionInfo> shared(summary.function()->shared(), isolate);
328  Handle<Object> script(shared->script(), isolate);
329  int pos = summary.abstract_code()->SourcePosition(summary.code_offset());
330  if (script->IsScript() &&
331  !(Handle<Script>::cast(script)->source()->IsUndefined(isolate))) {
332  Handle<Script> casted_script = Handle<Script>::cast(script);
333  *target = MessageLocation(casted_script, pos, pos + 1, shared);
334  return true;
335  }
336  }
337  return false;
338 }
339 
340 Handle<String> BuildDefaultCallSite(Isolate* isolate, Handle<Object> object) {
341  IncrementalStringBuilder builder(isolate);
342 
343  builder.AppendString(Object::TypeOf(isolate, object));
344  if (object->IsString()) {
345  builder.AppendCString(" \"");
346  builder.AppendString(Handle<String>::cast(object));
347  builder.AppendCString("\"");
348  } else if (object->IsNull(isolate)) {
349  builder.AppendCString(" ");
350  builder.AppendString(isolate->factory()->null_string());
351  } else if (object->IsTrue(isolate)) {
352  builder.AppendCString(" ");
353  builder.AppendString(isolate->factory()->true_string());
354  } else if (object->IsFalse(isolate)) {
355  builder.AppendCString(" ");
356  builder.AppendString(isolate->factory()->false_string());
357  } else if (object->IsNumber()) {
358  builder.AppendCString(" ");
359  builder.AppendString(isolate->factory()->NumberToString(object));
360  }
361 
362  return builder.Finish().ToHandleChecked();
363 }
364 
365 Handle<String> RenderCallSite(Isolate* isolate, Handle<Object> object,
366  CallPrinter::ErrorHint* hint) {
367  MessageLocation location;
368  if (ComputeLocation(isolate, &location)) {
369  ParseInfo info(isolate, location.shared());
370  if (parsing::ParseAny(&info, location.shared(), isolate)) {
371  info.ast_value_factory()->Internalize(isolate);
372  CallPrinter printer(isolate, location.shared()->IsUserJavaScript());
373  Handle<String> str = printer.Print(info.literal(), location.start_pos());
374  *hint = printer.GetErrorHint();
375  if (str->length() > 0) return str;
376  } else {
377  isolate->clear_pending_exception();
378  }
379  }
380  return BuildDefaultCallSite(isolate, object);
381 }
382 
383 MessageTemplate UpdateErrorTemplate(CallPrinter::ErrorHint hint,
384  MessageTemplate default_id) {
385  switch (hint) {
386  case CallPrinter::ErrorHint::kNormalIterator:
387  return MessageTemplate::kNotIterable;
388 
389  case CallPrinter::ErrorHint::kCallAndNormalIterator:
390  return MessageTemplate::kNotCallableOrIterable;
391 
392  case CallPrinter::ErrorHint::kAsyncIterator:
393  return MessageTemplate::kNotAsyncIterable;
394 
395  case CallPrinter::ErrorHint::kCallAndAsyncIterator:
396  return MessageTemplate::kNotCallableOrAsyncIterable;
397 
398  case CallPrinter::ErrorHint::kNone:
399  return default_id;
400  }
401  return default_id;
402 }
403 
404 } // namespace
405 
406 MaybeHandle<Object> Runtime::ThrowIteratorError(Isolate* isolate,
407  Handle<Object> object) {
408  CallPrinter::ErrorHint hint = CallPrinter::kNone;
409  Handle<String> callsite = RenderCallSite(isolate, object, &hint);
410  MessageTemplate id = MessageTemplate::kNotIterableNoSymbolLoad;
411 
412  if (hint == CallPrinter::kNone) {
413  Handle<Symbol> iterator_symbol = isolate->factory()->iterator_symbol();
414  THROW_NEW_ERROR(isolate, NewTypeError(id, callsite, iterator_symbol),
415  Object);
416  }
417 
418  id = UpdateErrorTemplate(hint, id);
419  THROW_NEW_ERROR(isolate, NewTypeError(id, callsite), Object);
420 }
421 
422 RUNTIME_FUNCTION(Runtime_ThrowIteratorError) {
423  HandleScope scope(isolate);
424  DCHECK_EQ(1, args.length());
425  CONVERT_ARG_HANDLE_CHECKED(Object, object, 0);
426  RETURN_RESULT_OR_FAILURE(isolate,
427  Runtime::ThrowIteratorError(isolate, object));
428 }
429 
430 RUNTIME_FUNCTION(Runtime_ThrowCalledNonCallable) {
431  HandleScope scope(isolate);
432  DCHECK_EQ(1, args.length());
433  CONVERT_ARG_HANDLE_CHECKED(Object, object, 0);
434  CallPrinter::ErrorHint hint = CallPrinter::kNone;
435  Handle<String> callsite = RenderCallSite(isolate, object, &hint);
436  MessageTemplate id = MessageTemplate::kCalledNonCallable;
437  id = UpdateErrorTemplate(hint, id);
438  THROW_NEW_ERROR_RETURN_FAILURE(isolate, NewTypeError(id, callsite));
439 }
440 
441 RUNTIME_FUNCTION(Runtime_ThrowConstructedNonConstructable) {
442  HandleScope scope(isolate);
443  DCHECK_EQ(1, args.length());
444  CONVERT_ARG_HANDLE_CHECKED(Object, object, 0);
445  CallPrinter::ErrorHint hint = CallPrinter::kNone;
446  Handle<String> callsite = RenderCallSite(isolate, object, &hint);
447  MessageTemplate id = MessageTemplate::kNotConstructor;
448  THROW_NEW_ERROR_RETURN_FAILURE(isolate, NewTypeError(id, callsite));
449 }
450 
451 RUNTIME_FUNCTION(Runtime_ThrowConstructorReturnedNonObject) {
452  HandleScope scope(isolate);
453  DCHECK_EQ(0, args.length());
454 
455  THROW_NEW_ERROR_RETURN_FAILURE(
456  isolate,
457  NewTypeError(MessageTemplate::kDerivedConstructorReturnedNonObject));
458 }
459 
460 // ES6 section 7.3.17 CreateListFromArrayLike (obj)
461 RUNTIME_FUNCTION(Runtime_CreateListFromArrayLike) {
462  HandleScope scope(isolate);
463  DCHECK_EQ(1, args.length());
464  CONVERT_ARG_HANDLE_CHECKED(Object, object, 0);
465  RETURN_RESULT_OR_FAILURE(isolate, Object::CreateListFromArrayLike(
466  isolate, object, ElementTypes::kAll));
467 }
468 
469 RUNTIME_FUNCTION(Runtime_IncrementUseCounter) {
470  HandleScope scope(isolate);
471  DCHECK_EQ(1, args.length());
472  CONVERT_SMI_ARG_CHECKED(counter, 0);
473  isolate->CountUsage(static_cast<v8::Isolate::UseCounterFeature>(counter));
474  return ReadOnlyRoots(isolate).undefined_value();
475 }
476 
477 RUNTIME_FUNCTION(Runtime_GetAndResetRuntimeCallStats) {
478  HandleScope scope(isolate);
479 
480  // Append any worker thread runtime call stats to the main table before
481  // printing.
482  isolate->counters()->worker_thread_runtime_call_stats()->AddToMainTable(
483  isolate->counters()->runtime_call_stats());
484 
485  if (args.length() == 0) {
486  // Without arguments, the result is returned as a string.
487  DCHECK_EQ(0, args.length());
488  std::stringstream stats_stream;
489  isolate->counters()->runtime_call_stats()->Print(stats_stream);
490  Handle<String> result = isolate->factory()->NewStringFromAsciiChecked(
491  stats_stream.str().c_str());
492  isolate->counters()->runtime_call_stats()->Reset();
493  return *result;
494  } else {
495  DCHECK_LE(args.length(), 2);
496  std::FILE* f;
497  if (args[0]->IsString()) {
498  // With a string argument, the results are appended to that file.
499  CONVERT_ARG_HANDLE_CHECKED(String, arg0, 0);
500  String::FlatContent flat = arg0->GetFlatContent();
501  const char* filename =
502  reinterpret_cast<const char*>(&(flat.ToOneByteVector()[0]));
503  f = std::fopen(filename, "a");
504  DCHECK_NOT_NULL(f);
505  } else {
506  // With an integer argument, the results are written to stdout/stderr.
507  CONVERT_SMI_ARG_CHECKED(fd, 0);
508  DCHECK(fd == 1 || fd == 2);
509  f = fd == 1 ? stdout : stderr;
510  }
511  // The second argument (if any) is a message header to be printed.
512  if (args.length() >= 2) {
513  CONVERT_ARG_HANDLE_CHECKED(String, arg1, 1);
514  arg1->PrintOn(f);
515  std::fputc('\n', f);
516  std::fflush(f);
517  }
518  OFStream stats_stream(f);
519  isolate->counters()->runtime_call_stats()->Print(stats_stream);
520  isolate->counters()->runtime_call_stats()->Reset();
521  if (args[0]->IsString())
522  std::fclose(f);
523  else
524  std::fflush(f);
525  return ReadOnlyRoots(isolate).undefined_value();
526  }
527 }
528 
529 RUNTIME_FUNCTION(Runtime_OrdinaryHasInstance) {
530  HandleScope scope(isolate);
531  DCHECK_EQ(2, args.length());
532  CONVERT_ARG_HANDLE_CHECKED(Object, callable, 0);
533  CONVERT_ARG_HANDLE_CHECKED(Object, object, 1);
534  RETURN_RESULT_OR_FAILURE(
535  isolate, Object::OrdinaryHasInstance(isolate, callable, object));
536 }
537 
538 RUNTIME_FUNCTION(Runtime_Typeof) {
539  HandleScope scope(isolate);
540  DCHECK_EQ(1, args.length());
541  CONVERT_ARG_HANDLE_CHECKED(Object, object, 0);
542  return *Object::TypeOf(isolate, object);
543 }
544 
545 RUNTIME_FUNCTION(Runtime_AllowDynamicFunction) {
546  HandleScope scope(isolate);
547  DCHECK_EQ(1, args.length());
548  CONVERT_ARG_HANDLE_CHECKED(JSFunction, target, 0);
549  Handle<JSObject> global_proxy(target->global_proxy(), isolate);
550  return *isolate->factory()->ToBoolean(
551  Builtins::AllowDynamicFunction(isolate, target, global_proxy));
552 }
553 
554 RUNTIME_FUNCTION(Runtime_CreateAsyncFromSyncIterator) {
555  HandleScope scope(isolate);
556  DCHECK_EQ(1, args.length());
557 
558  CONVERT_ARG_HANDLE_CHECKED(Object, sync_iterator, 0);
559 
560  if (!sync_iterator->IsJSReceiver()) {
561  THROW_NEW_ERROR_RETURN_FAILURE(
562  isolate, NewTypeError(MessageTemplate::kSymbolIteratorInvalid));
563  }
564 
565  Handle<Object> next;
566  ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
567  isolate, next,
568  Object::GetProperty(isolate, sync_iterator,
569  isolate->factory()->next_string()));
570 
571  return *isolate->factory()->NewJSAsyncFromSyncIterator(
572  Handle<JSReceiver>::cast(sync_iterator), next);
573 }
574 
575 RUNTIME_FUNCTION(Runtime_CreateTemplateObject) {
576  HandleScope scope(isolate);
577  DCHECK_EQ(1, args.length());
578  CONVERT_ARG_HANDLE_CHECKED(TemplateObjectDescription, description, 0);
579 
580  return *TemplateObjectDescription::CreateTemplateObject(isolate, description);
581 }
582 
583 RUNTIME_FUNCTION(Runtime_ReportMessage) {
584  // Helper to report messages and continue JS execution. This is intended to
585  // behave similarly to reporting exceptions which reach the top-level in
586  // Execution.cc, but allow the JS code to continue. This is useful for
587  // implementing algorithms such as RunMicrotasks in JS.
588  HandleScope scope(isolate);
589  DCHECK_EQ(1, args.length());
590 
591  CONVERT_ARG_HANDLE_CHECKED(Object, message_obj, 0);
592 
593  DCHECK(!isolate->has_pending_exception());
594  isolate->set_pending_exception(*message_obj);
595  isolate->ReportPendingMessagesFromJavaScript();
596  isolate->clear_pending_exception();
597  return ReadOnlyRoots(isolate).undefined_value();
598 }
599 
600 RUNTIME_FUNCTION(Runtime_GetInitializerFunction) {
601  HandleScope scope(isolate);
602  DCHECK_EQ(1, args.length());
603 
604  CONVERT_ARG_HANDLE_CHECKED(JSReceiver, constructor, 0);
605  Handle<Symbol> key = isolate->factory()->class_fields_symbol();
606  Handle<Object> initializer = JSReceiver::GetDataProperty(constructor, key);
607  return *initializer;
608 }
609 } // namespace internal
610 } // namespace v8
Definition: libplatform.h:13