V8 Project
api.cc
Go to the documentation of this file.
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
3 // found in the LICENSE file.
4 
5 #include "src/api.h"
6 
7 #include <string.h> // For memcpy, strlen.
8 #ifdef V8_USE_ADDRESS_SANITIZER
9 #include <sanitizer/asan_interface.h>
10 #endif // V8_USE_ADDRESS_SANITIZER
11 #include <cmath> // For isnan.
12 #include "include/v8-debug.h"
13 #include "include/v8-profiler.h"
14 #include "include/v8-testing.h"
15 #include "src/assert-scope.h"
18 #include "src/base/platform/time.h"
20 #include "src/bootstrapper.h"
21 #include "src/code-stubs.h"
22 #include "src/compiler.h"
23 #include "src/conversions-inl.h"
24 #include "src/counters.h"
25 #include "src/cpu-profiler.h"
26 #include "src/debug.h"
27 #include "src/deoptimizer.h"
28 #include "src/execution.h"
29 #include "src/global-handles.h"
30 #include "src/heap-profiler.h"
32 #include "src/icu_util.h"
33 #include "src/json-parser.h"
34 #include "src/messages.h"
35 #include "src/natives.h"
36 #include "src/parser.h"
38 #include "src/property.h"
39 #include "src/property-details.h"
40 #include "src/prototype.h"
41 #include "src/runtime/runtime.h"
42 #include "src/runtime-profiler.h"
44 #include "src/simulator.h"
45 #include "src/snapshot.h"
46 #include "src/unicode-inl.h"
47 #include "src/v8threads.h"
48 #include "src/version.h"
49 #include "src/vm-state-inl.h"
50 
51 
52 #define LOG_API(isolate, expr) LOG(isolate, ApiEntryCall(expr))
53 
54 #define ENTER_V8(isolate) \
55  DCHECK((isolate)->IsInitialized()); \
56  i::VMState<i::OTHER> __state__((isolate))
57 
58 namespace v8 {
59 
60 #define ON_BAILOUT(isolate, location, code) \
61  if (IsExecutionTerminatingCheck(isolate)) { \
62  code; \
63  UNREACHABLE(); \
64  }
65 
66 
67 #define EXCEPTION_PREAMBLE(isolate) \
68  (isolate)->handle_scope_implementer()->IncrementCallDepth(); \
69  DCHECK(!(isolate)->external_caught_exception()); \
70  bool has_pending_exception = false
71 
72 
73 #define EXCEPTION_BAILOUT_CHECK_GENERIC(isolate, value, do_callback) \
74  do { \
75  i::HandleScopeImplementer* handle_scope_implementer = \
76  (isolate)->handle_scope_implementer(); \
77  handle_scope_implementer->DecrementCallDepth(); \
78  if (has_pending_exception) { \
79  bool call_depth_is_zero = handle_scope_implementer->CallDepthIsZero(); \
80  (isolate)->OptionalRescheduleException(call_depth_is_zero); \
81  do_callback \
82  return value; \
83  } \
84  do_callback \
85  } while (false)
86 
87 
88 #define EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, value) \
89  EXCEPTION_BAILOUT_CHECK_GENERIC( \
90  isolate, value, isolate->FireCallCompletedCallback();)
91 
92 
93 #define EXCEPTION_BAILOUT_CHECK(isolate, value) \
94  EXCEPTION_BAILOUT_CHECK_GENERIC(isolate, value, ;)
95 
96 
97 // --- E x c e p t i o n B e h a v i o r ---
98 
99 
100 void i::FatalProcessOutOfMemory(const char* location) {
101  i::V8::FatalProcessOutOfMemory(location, false);
102 }
103 
104 
105 // When V8 cannot allocated memory FatalProcessOutOfMemory is called.
106 // The default fatal error handler is called and execution is stopped.
107 void i::V8::FatalProcessOutOfMemory(const char* location, bool take_snapshot) {
109  int start_marker;
110  heap_stats.start_marker = &start_marker;
111  int new_space_size;
112  heap_stats.new_space_size = &new_space_size;
113  int new_space_capacity;
114  heap_stats.new_space_capacity = &new_space_capacity;
115  intptr_t old_pointer_space_size;
116  heap_stats.old_pointer_space_size = &old_pointer_space_size;
117  intptr_t old_pointer_space_capacity;
118  heap_stats.old_pointer_space_capacity = &old_pointer_space_capacity;
119  intptr_t old_data_space_size;
120  heap_stats.old_data_space_size = &old_data_space_size;
121  intptr_t old_data_space_capacity;
122  heap_stats.old_data_space_capacity = &old_data_space_capacity;
123  intptr_t code_space_size;
124  heap_stats.code_space_size = &code_space_size;
125  intptr_t code_space_capacity;
126  heap_stats.code_space_capacity = &code_space_capacity;
127  intptr_t map_space_size;
128  heap_stats.map_space_size = &map_space_size;
129  intptr_t map_space_capacity;
130  heap_stats.map_space_capacity = &map_space_capacity;
131  intptr_t cell_space_size;
132  heap_stats.cell_space_size = &cell_space_size;
133  intptr_t cell_space_capacity;
134  heap_stats.cell_space_capacity = &cell_space_capacity;
135  intptr_t property_cell_space_size;
136  heap_stats.property_cell_space_size = &property_cell_space_size;
137  intptr_t property_cell_space_capacity;
138  heap_stats.property_cell_space_capacity = &property_cell_space_capacity;
139  intptr_t lo_space_size;
140  heap_stats.lo_space_size = &lo_space_size;
141  int global_handle_count;
142  heap_stats.global_handle_count = &global_handle_count;
143  int weak_global_handle_count;
144  heap_stats.weak_global_handle_count = &weak_global_handle_count;
145  int pending_global_handle_count;
146  heap_stats.pending_global_handle_count = &pending_global_handle_count;
147  int near_death_global_handle_count;
148  heap_stats.near_death_global_handle_count = &near_death_global_handle_count;
149  int free_global_handle_count;
150  heap_stats.free_global_handle_count = &free_global_handle_count;
151  intptr_t memory_allocator_size;
152  heap_stats.memory_allocator_size = &memory_allocator_size;
153  intptr_t memory_allocator_capacity;
154  heap_stats.memory_allocator_capacity = &memory_allocator_capacity;
155  int objects_per_type[LAST_TYPE + 1] = {0};
156  heap_stats.objects_per_type = objects_per_type;
157  int size_per_type[LAST_TYPE + 1] = {0};
158  heap_stats.size_per_type = size_per_type;
159  int os_error;
160  heap_stats.os_error = &os_error;
161  int end_marker;
162  heap_stats.end_marker = &end_marker;
163  i::Isolate* isolate = i::Isolate::Current();
164  if (isolate->heap()->HasBeenSetUp()) {
165  // BUG(1718): Don't use the take_snapshot since we don't support
166  // HeapIterator here without doing a special GC.
167  isolate->heap()->RecordStats(&heap_stats, false);
168  }
169  Utils::ApiCheck(false, location, "Allocation failed - process out of memory");
170  // If the fatal error handler returns, we stop execution.
171  FATAL("API fatal error handler returned after process out of memory");
172 }
173 
174 
175 void Utils::ReportApiFailure(const char* location, const char* message) {
176  i::Isolate* isolate = i::Isolate::Current();
177  FatalErrorCallback callback = isolate->exception_behavior();
178  if (callback == NULL) {
179  base::OS::PrintError("\n#\n# Fatal error in %s\n# %s\n#\n\n", location,
180  message);
181  base::OS::Abort();
182  } else {
183  callback(location, message);
184  }
185  isolate->SignalFatalError();
186 }
187 
188 
189 bool V8::IsDead() {
190  i::Isolate* isolate = i::Isolate::Current();
191  return isolate->IsDead();
192 }
193 
194 
195 static inline bool IsExecutionTerminatingCheck(i::Isolate* isolate) {
196  if (!isolate->IsInitialized()) return false;
197  if (isolate->has_scheduled_exception()) {
198  return isolate->scheduled_exception() ==
199  isolate->heap()->termination_exception();
200  }
201  return false;
202 }
203 
204 
206  : raw_data(i::NewArray<char*>(V8::GetCompressedStartupDataCount())) {
207  for (int i = 0; i < V8::GetCompressedStartupDataCount(); ++i) {
208  raw_data[i] = NULL;
209  }
210 }
211 
212 
214  for (int i = 0; i < V8::GetCompressedStartupDataCount(); ++i) {
216  }
218 }
219 
220 
222  int compressed_data_count = V8::GetCompressedStartupDataCount();
223  StartupData* compressed_data =
224  i::NewArray<StartupData>(compressed_data_count);
225  V8::GetCompressedStartupData(compressed_data);
226  for (int i = 0; i < compressed_data_count; ++i) {
227  char* decompressed = raw_data[i] =
228  i::NewArray<char>(compressed_data[i].raw_size);
229  if (compressed_data[i].compressed_size != 0) {
230  int result = DecompressData(decompressed,
231  &compressed_data[i].raw_size,
232  compressed_data[i].data,
233  compressed_data[i].compressed_size);
234  if (result != 0) return result;
235  } else {
236  DCHECK_EQ(0, compressed_data[i].raw_size);
237  }
238  compressed_data[i].data = decompressed;
239  }
240  V8::SetDecompressedStartupData(compressed_data);
241  i::DeleteArray(compressed_data);
242  return 0;
243 }
244 
245 
247 #ifdef COMPRESS_STARTUP_DATA_BZ2
248  return StartupData::kBZip2;
249 #else
251 #endif
252 }
253 
254 
261 };
262 
263 
265 #ifdef COMPRESS_STARTUP_DATA_BZ2
267 #else
268  return 0;
269 #endif
270 }
271 
272 
274 #ifdef COMPRESS_STARTUP_DATA_BZ2
275  compressed_data[kSnapshot].data =
276  reinterpret_cast<const char*>(i::Snapshot::data());
277  compressed_data[kSnapshot].compressed_size = i::Snapshot::size();
278  compressed_data[kSnapshot].raw_size = i::Snapshot::raw_size();
279 
280  compressed_data[kSnapshotContext].data =
281  reinterpret_cast<const char*>(i::Snapshot::context_data());
282  compressed_data[kSnapshotContext].compressed_size =
285 
287  compressed_data[kLibraries].data =
288  reinterpret_cast<const char*>(libraries_source.start());
289  compressed_data[kLibraries].compressed_size = libraries_source.length();
291 
292  i::Vector<const i::byte> exp_libraries_source =
294  compressed_data[kExperimentalLibraries].data =
295  reinterpret_cast<const char*>(exp_libraries_source.start());
296  compressed_data[kExperimentalLibraries].compressed_size =
297  exp_libraries_source.length();
298  compressed_data[kExperimentalLibraries].raw_size =
300 #endif
301 }
302 
303 
304 void V8::SetDecompressedStartupData(StartupData* decompressed_data) {
305 #ifdef COMPRESS_STARTUP_DATA_BZ2
306  DCHECK_EQ(i::Snapshot::raw_size(), decompressed_data[kSnapshot].raw_size);
308  reinterpret_cast<const i::byte*>(decompressed_data[kSnapshot].data));
309 
311  decompressed_data[kSnapshotContext].raw_size);
313  reinterpret_cast<const i::byte*>(
314  decompressed_data[kSnapshotContext].data));
315 
317  decompressed_data[kLibraries].raw_size);
318  i::Vector<const char> libraries_source(
319  decompressed_data[kLibraries].data,
320  decompressed_data[kLibraries].raw_size);
321  i::Natives::SetRawScriptsSource(libraries_source);
322 
324  decompressed_data[kExperimentalLibraries].raw_size);
325  i::Vector<const char> exp_libraries_source(
326  decompressed_data[kExperimentalLibraries].data,
327  decompressed_data[kExperimentalLibraries].raw_size);
328  i::ExperimentalNatives::SetRawScriptsSource(exp_libraries_source);
329 #endif
330 }
331 
332 
333 void V8::SetNativesDataBlob(StartupData* natives_blob) {
334 #ifdef V8_USE_EXTERNAL_STARTUP_DATA
335  i::SetNativesFromFile(natives_blob);
336 #else
337  CHECK(false);
338 #endif
339 }
340 
341 
342 void V8::SetSnapshotDataBlob(StartupData* snapshot_blob) {
343 #ifdef V8_USE_EXTERNAL_STARTUP_DATA
344  i::SetSnapshotFromFile(snapshot_blob);
345 #else
346  CHECK(false);
347 #endif
348 }
349 
350 
352  i::Isolate* isolate = i::Isolate::Current();
353  isolate->set_exception_behavior(that);
354 }
355 
356 
359  i::Isolate* isolate = i::Isolate::Current();
360  isolate->set_allow_code_gen_callback(callback);
361 }
362 
363 
364 void V8::SetFlagsFromString(const char* str, int length) {
365  i::FlagList::SetFlagsFromString(str, length);
366 }
367 
368 
369 void V8::SetFlagsFromCommandLine(int* argc, char** argv, bool remove_flags) {
370  i::FlagList::SetFlagsFromCommandLine(argc, argv, remove_flags);
371 }
372 
373 
375 
376 
378  : extension_(extension) { }
379 
380 
382  that->next_ = first_extension_;
383  first_extension_ = that;
384 }
385 
386 
389  while (re != NULL) {
390  RegisteredExtension* next = re->next();
391  delete re;
392  re = next;
393  }
395 }
396 
397 
399  RegisteredExtension* extension = new RegisteredExtension(that);
401 }
402 
403 
405  const char* source,
406  int dep_count,
407  const char** deps,
408  int source_length)
409  : name_(name),
410  source_length_(source_length >= 0 ?
411  source_length :
412  (source ? static_cast<int>(strlen(source)) : 0)),
413  source_(source, source_length_),
414  dep_count_(dep_count),
415  deps_(deps),
416  auto_enable_(false) {
417  CHECK(source != NULL || source_length_ == 0);
418 }
419 
420 
422  : max_semi_space_size_(0),
423  max_old_space_size_(0),
424  max_executable_size_(0),
425  stack_limit_(NULL),
426  max_available_threads_(0),
427  code_range_size_(0) { }
428 
429 void ResourceConstraints::ConfigureDefaults(uint64_t physical_memory,
430  uint64_t virtual_memory_limit,
431  uint32_t number_of_processors) {
432 #if V8_OS_ANDROID
433  // Android has higher physical memory requirements before raising the maximum
434  // heap size limits since it has no swap space.
435  const uint64_t low_limit = 512ul * i::MB;
436  const uint64_t medium_limit = 1ul * i::GB;
437  const uint64_t high_limit = 2ul * i::GB;
438 #else
439  const uint64_t low_limit = 512ul * i::MB;
440  const uint64_t medium_limit = 768ul * i::MB;
441  const uint64_t high_limit = 1ul * i::GB;
442 #endif
443 
444  if (physical_memory <= low_limit) {
448  } else if (physical_memory <= medium_limit) {
452  } else if (physical_memory <= high_limit) {
456  } else {
460  }
461 
462  set_max_available_threads(i::Max(i::Min(number_of_processors, 4u), 1u));
463 
464  if (virtual_memory_limit > 0 && i::kRequiresCodeRange) {
465  // Reserve no more than 1/8 of the memory for the code range, but at most
466  // kMaximalCodeRangeSize.
469  static_cast<size_t>((virtual_memory_limit >> 3) / i::MB)));
470  }
471 }
472 
473 
475  const ResourceConstraints& constraints) {
476  int semi_space_size = constraints.max_semi_space_size();
477  int old_space_size = constraints.max_old_space_size();
478  int max_executable_size = constraints.max_executable_size();
479  size_t code_range_size = constraints.code_range_size();
480  if (semi_space_size != 0 || old_space_size != 0 ||
481  max_executable_size != 0 || code_range_size != 0) {
482  isolate->heap()->ConfigureHeap(semi_space_size, old_space_size,
483  max_executable_size, code_range_size);
484  }
485  if (constraints.stack_limit() != NULL) {
486  uintptr_t limit = reinterpret_cast<uintptr_t>(constraints.stack_limit());
487  isolate->stack_guard()->SetStackLimit(limit);
488  }
489 
490  isolate->set_max_available_threads(constraints.max_available_threads());
491 }
492 
493 
495  LOG_API(isolate, "Persistent::New");
496  i::Handle<i::Object> result = isolate->global_handles()->Create(*obj);
497 #ifdef DEBUG
498  (*obj)->ObjectVerify();
499 #endif // DEBUG
500  return result.location();
501 }
502 
503 
506 #ifdef DEBUG
507  (*obj)->ObjectVerify();
508 #endif // DEBUG
509  return result.location();
510 }
511 
512 
513 void V8::MakeWeak(i::Object** object,
514  void* parameters,
515  WeakCallback weak_callback) {
516  i::GlobalHandles::MakeWeak(object, parameters, weak_callback);
517 }
518 
519 
520 void* V8::ClearWeak(i::Object** obj) {
522 }
523 
524 
527 }
528 
529 
530 void V8::Eternalize(Isolate* v8_isolate, Value* value, int* index) {
531  i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
532  i::Object* object = *Utils::OpenHandle(value);
533  isolate->eternal_handles()->Create(isolate, object, index);
534 }
535 
536 
537 Local<Value> V8::GetEternal(Isolate* v8_isolate, int index) {
538  i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
539  return Utils::ToLocal(isolate->eternal_handles()->Get(index));
540 }
541 
542 
543 // --- H a n d l e s ---
544 
545 
547  Initialize(isolate);
548 }
549 
550 
552  i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
553  // We do not want to check the correct usage of the Locker class all over the
554  // place, so we do it only here: Without a HandleScope, an embedder can do
555  // almost nothing, so it is enough to check in this central place.
557  internal_isolate->thread_manager()->IsLockedByCurrentThread(),
558  "HandleScope::HandleScope",
559  "Entering the V8 API without proper locking in place");
560  i::HandleScopeData* current = internal_isolate->handle_scope_data();
561  isolate_ = internal_isolate;
562  prev_next_ = current->next;
563  prev_limit_ = current->limit;
564  current->level++;
565 }
566 
567 
570 }
571 
572 
575  reinterpret_cast<i::Isolate*>(isolate));
576 }
577 
578 
580  return i::HandleScope::CreateHandle(isolate, value);
581 }
582 
583 
585  i::Object* value) {
586  DCHECK(heap_object->IsHeapObject());
587  return i::HandleScope::CreateHandle(heap_object->GetIsolate(), value);
588 }
589 
590 
592  i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
593  escape_slot_ = CreateHandle(isolate, isolate->heap()->the_hole_value());
594  Initialize(v8_isolate);
595 }
596 
597 
599  i::Heap* heap = reinterpret_cast<i::Isolate*>(GetIsolate())->heap();
600  Utils::ApiCheck(*escape_slot_ == heap->the_hole_value(),
601  "EscapeableHandleScope::Escape",
602  "Escape value set twice");
603  if (escape_value == NULL) {
604  *escape_slot_ = heap->undefined_value();
605  return NULL;
606  }
607  *escape_slot_ = *escape_value;
608  return escape_slot_;
609 }
610 
611 
614  i::Isolate* isolate = env->GetIsolate();
615  ENTER_V8(isolate);
617  impl->EnterContext(env);
618  impl->SaveContext(isolate->context());
619  isolate->set_context(*env);
620 }
621 
622 
625  i::Isolate* isolate = env->GetIsolate();
626  ENTER_V8(isolate);
628  if (!Utils::ApiCheck(impl->LastEnteredContextWas(env),
629  "v8::Context::Exit()",
630  "Cannot exit non-entered context")) {
631  return;
632  }
633  impl->LeaveContext();
634  isolate->set_context(impl->RestoreContext());
635 }
636 
637 
638 static void* DecodeSmiToAligned(i::Object* value, const char* location) {
639  Utils::ApiCheck(value->IsSmi(), location, "Not a Smi");
640  return reinterpret_cast<void*>(value);
641 }
642 
643 
644 static i::Smi* EncodeAlignedAsSmi(void* value, const char* location) {
645  i::Smi* smi = reinterpret_cast<i::Smi*>(value);
646  Utils::ApiCheck(smi->IsSmi(), location, "Pointer is not aligned");
647  return smi;
648 }
649 
650 
652  int index,
653  bool can_grow,
654  const char* location) {
656  bool ok =
657  Utils::ApiCheck(env->IsNativeContext(),
658  location,
659  "Not a native context") &&
660  Utils::ApiCheck(index >= 0, location, "Negative index");
661  if (!ok) return i::Handle<i::FixedArray>();
662  i::Handle<i::FixedArray> data(env->embedder_data());
663  if (index < data->length()) return data;
664  if (!Utils::ApiCheck(can_grow, location, "Index too large")) {
665  return i::Handle<i::FixedArray>();
666  }
667  int new_size = i::Max(index, data->length() << 1) + 1;
668  data = i::FixedArray::CopySize(data, new_size);
669  env->set_embedder_data(*data);
670  return data;
671 }
672 
673 
675  const char* location = "v8::Context::GetEmbedderData()";
676  i::Handle<i::FixedArray> data = EmbedderDataFor(this, index, false, location);
677  if (data.is_null()) return Local<Value>();
678  i::Handle<i::Object> result(data->get(index), data->GetIsolate());
679  return Utils::ToLocal(result);
680 }
681 
682 
684  const char* location = "v8::Context::SetEmbedderData()";
685  i::Handle<i::FixedArray> data = EmbedderDataFor(this, index, true, location);
686  if (data.is_null()) return;
688  data->set(index, *val);
689  DCHECK_EQ(*Utils::OpenHandle(*value),
691 }
692 
693 
695  const char* location = "v8::Context::GetAlignedPointerFromEmbedderData()";
696  i::Handle<i::FixedArray> data = EmbedderDataFor(this, index, false, location);
697  if (data.is_null()) return NULL;
698  return DecodeSmiToAligned(data->get(index), location);
699 }
700 
701 
702 void Context::SetAlignedPointerInEmbedderData(int index, void* value) {
703  const char* location = "v8::Context::SetAlignedPointerInEmbedderData()";
704  i::Handle<i::FixedArray> data = EmbedderDataFor(this, index, true, location);
705  data->set(index, EncodeAlignedAsSmi(value, location));
707 }
708 
709 
710 // --- N e a n d e r ---
711 
712 
713 // A constructor cannot easily return an error value, therefore it is necessary
714 // to check for a dead VM with ON_BAILOUT before constructing any Neander
715 // objects. To remind you about this there is no HandleScope in the
716 // NeanderObject constructor. When you add one to the site calling the
717 // constructor you should check that you ensured the VM was not dead first.
719  ENTER_V8(isolate);
720  value_ = isolate->factory()->NewNeanderObject();
721  i::Handle<i::FixedArray> elements = isolate->factory()->NewFixedArray(size);
722  value_->set_elements(*elements);
723 }
724 
725 
727  return i::FixedArray::cast(value_->elements())->length();
728 }
729 
730 
731 NeanderArray::NeanderArray(v8::internal::Isolate* isolate) : obj_(isolate, 2) {
732  obj_.set(0, i::Smi::FromInt(0));
733 }
734 
735 
737  return i::Smi::cast(obj_.get(0))->value();
738 }
739 
740 
742  DCHECK(0 <= offset);
743  DCHECK(offset < length());
744  return obj_.get(offset + 1);
745 }
746 
747 
748 // This method cannot easily return an error value, therefore it is necessary
749 // to check for a dead VM with ON_BAILOUT before calling it. To remind you
750 // about this there is no HandleScope in this method. When you add one to the
751 // site calling this method you should check that you ensured the VM was not
752 // dead first.
754  int length = this->length();
755  int size = obj_.size();
756  if (length == size - 1) {
757  i::Factory* factory = i::Isolate::Current()->factory();
758  i::Handle<i::FixedArray> new_elms = factory->NewFixedArray(2 * size);
759  for (int i = 0; i < length; i++)
760  new_elms->set(i + 1, get(i));
761  obj_.value()->set_elements(*new_elms);
762  }
763  obj_.set(length + 1, *value);
764  obj_.set(0, i::Smi::FromInt(length + 1));
765 }
766 
767 
768 void NeanderArray::set(int index, i::Object* value) {
769  if (index < 0 || index >= this->length()) return;
770  obj_.set(index + 1, value);
771 }
772 
773 
774 // --- T e m p l a t e ---
775 
776 
777 static void InitializeTemplate(i::Handle<i::TemplateInfo> that, int type) {
778  that->set_tag(i::Smi::FromInt(type));
779 }
780 
781 
782 static void TemplateSet(i::Isolate* isolate,
783  v8::Template* templ,
784  int length,
785  v8::Handle<v8::Data>* data) {
786  i::Handle<i::Object> list(Utils::OpenHandle(templ)->property_list(), isolate);
787  if (list->IsUndefined()) {
788  list = NeanderArray(isolate).value();
789  Utils::OpenHandle(templ)->set_property_list(*list);
790  }
791  NeanderArray array(list);
792  array.add(isolate->factory()->NewNumberFromInt(length));
793  for (int i = 0; i < length; i++) {
794  i::Handle<i::Object> value = data[i].IsEmpty() ?
795  i::Handle<i::Object>(isolate->factory()->undefined_value()) :
796  Utils::OpenHandle(*data[i]);
797  array.add(value);
798  }
799 }
800 
801 
803  v8::Handle<Data> value,
804  v8::PropertyAttribute attribute) {
805  i::Isolate* isolate = i::Isolate::Current();
806  ENTER_V8(isolate);
807  i::HandleScope scope(isolate);
808  const int kSize = 3;
809  v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate);
810  v8::Handle<v8::Data> data[kSize] = {
811  name,
812  value,
813  v8::Integer::New(v8_isolate, attribute)};
814  TemplateSet(isolate, this, kSize, data);
815 }
816 
817 
822  v8::PropertyAttribute attribute,
823  v8::AccessControl access_control) {
824  // TODO(verwaest): Remove |access_control|.
825  DCHECK_EQ(v8::DEFAULT, access_control);
826  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
827  ENTER_V8(isolate);
828  DCHECK(!name.IsEmpty());
829  DCHECK(!getter.IsEmpty() || !setter.IsEmpty());
830  i::HandleScope scope(isolate);
831  const int kSize = 5;
832  v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate);
833  v8::Handle<v8::Data> data[kSize] = {
834  name,
835  getter,
836  setter,
837  v8::Integer::New(v8_isolate, attribute)};
838  TemplateSet(isolate, this, kSize, data);
839 }
840 
841 
842 // --- F u n c t i o n T e m p l a t e ---
846  info->set_flag(0);
847 }
848 
849 
851  i::Isolate* i_isolate = Utils::OpenHandle(this)->GetIsolate();
852  ENTER_V8(i_isolate);
854  i_isolate);
855  if (result->IsUndefined()) {
856  v8::Isolate* isolate = reinterpret_cast<v8::Isolate*>(i_isolate);
857  result = Utils::OpenHandle(*ObjectTemplate::New(isolate));
858  Utils::OpenHandle(this)->set_prototype_template(*result);
859  }
860  return ToApiHandle<ObjectTemplate>(result);
861 }
862 
863 
865  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
866  ENTER_V8(isolate);
867  Utils::OpenHandle(this)->set_parent_template(*Utils::OpenHandle(*value));
868 }
869 
870 
872  i::Isolate* isolate,
873  FunctionCallback callback,
874  v8::Handle<Value> data,
875  v8::Handle<Signature> signature,
876  int length,
877  bool do_not_cache) {
878  i::Handle<i::Struct> struct_obj =
879  isolate->factory()->NewStruct(i::FUNCTION_TEMPLATE_INFO_TYPE);
883  obj->set_do_not_cache(do_not_cache);
884  int next_serial_number = 0;
885  if (!do_not_cache) {
886  next_serial_number = isolate->next_serial_number() + 1;
887  isolate->set_next_serial_number(next_serial_number);
888  }
889  obj->set_serial_number(i::Smi::FromInt(next_serial_number));
890  if (callback != 0) {
891  if (data.IsEmpty()) {
892  data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate));
893  }
894  Utils::ToLocal(obj)->SetCallHandler(callback, data);
895  }
896  obj->set_length(length);
897  obj->set_undetectable(false);
898  obj->set_needs_access_check(false);
899  if (!signature.IsEmpty())
900  obj->set_signature(*Utils::OpenHandle(*signature));
901  return Utils::ToLocal(obj);
902 }
903 
905  Isolate* isolate,
906  FunctionCallback callback,
907  v8::Handle<Value> data,
908  v8::Handle<Signature> signature,
909  int length) {
910  i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
911  LOG_API(i_isolate, "FunctionTemplate::New");
912  ENTER_V8(i_isolate);
913  return FunctionTemplateNew(
914  i_isolate, callback, data, signature, length, false);
915 }
916 
917 
919  Handle<FunctionTemplate> receiver, int argc,
920  Handle<FunctionTemplate> argv[]) {
921  i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
922  LOG_API(i_isolate, "Signature::New");
923  ENTER_V8(i_isolate);
924  i::Handle<i::Struct> struct_obj =
925  i_isolate->factory()->NewStruct(i::SIGNATURE_INFO_TYPE);
928  if (!receiver.IsEmpty()) obj->set_receiver(*Utils::OpenHandle(*receiver));
929  if (argc > 0) {
930  i::Handle<i::FixedArray> args = i_isolate->factory()->NewFixedArray(argc);
931  for (int i = 0; i < argc; i++) {
932  if (!argv[i].IsEmpty())
933  args->set(i, *Utils::OpenHandle(*argv[i]));
934  }
935  obj->set_args(*args);
936  }
937  return Utils::ToLocal(obj);
938 }
939 
940 
942  Isolate* isolate,
943  Handle<FunctionTemplate> receiver) {
945 }
946 
947 
948 template<typename Operation>
950  Isolate* isolate,
952  Data* previous_descriptor) {
953  i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
956  if (previous_descriptor != NULL) {
957  previous = Utils::OpenHandle(
958  static_cast<DeclaredAccessorDescriptor*>(previous_descriptor));
959  }
961  i::DeclaredAccessorDescriptor::Create(internal_isolate, data, previous);
962  return Utils::Convert<i::DeclaredAccessorDescriptor, Operation>(descriptor);
963 }
964 
965 
966 Local<RawOperationDescriptor>
968  Isolate* isolate,
969  int internal_field) {
972  data.object_dereference_descriptor.internal_field = internal_field;
973  return NewDescriptor<RawOperationDescriptor>(isolate, data, NULL);
974 }
975 
976 
978  Isolate* isolate,
979  int16_t byte_offset) {
982  data.pointer_shift_descriptor.byte_offset = byte_offset;
983  return NewDescriptor<RawOperationDescriptor>(isolate, data, this);
984 }
985 
986 
988  Isolate* isolate) {
991  return NewDescriptor<DeclaredAccessorDescriptor>(isolate, data, this);
992 }
993 
994 
996  Isolate* isolate) {
999  return NewDescriptor<RawOperationDescriptor>(isolate, data, this);
1000 }
1001 
1002 
1004  Isolate* isolate,
1005  void* compare_value) {
1008  data.pointer_compare_descriptor.compare_value = compare_value;
1009  return NewDescriptor<DeclaredAccessorDescriptor>(isolate, data, this);
1010 }
1011 
1012 
1014  Isolate* isolate,
1016  uint8_t bool_offset) {
1019  data.primitive_value_descriptor.data_type = data_type;
1020  data.primitive_value_descriptor.bool_offset = bool_offset;
1021  return NewDescriptor<DeclaredAccessorDescriptor>(isolate, data, this);
1022 }
1023 
1024 
1025 template<typename T>
1027  Isolate* isolate,
1028  T bitmask,
1029  T compare_value,
1030  RawOperationDescriptor* operation) {
1033  data.bitmask_compare_descriptor.bitmask = bitmask;
1034  data.bitmask_compare_descriptor.compare_value = compare_value;
1035  data.bitmask_compare_descriptor.size = sizeof(T);
1036  return NewDescriptor<DeclaredAccessorDescriptor>(isolate, data, operation);
1037 }
1038 
1039 
1041  Isolate* isolate,
1042  uint8_t bitmask,
1043  uint8_t compare_value) {
1044  return NewBitmaskCompare(isolate, bitmask, compare_value, this);
1045 }
1046 
1047 
1049  Isolate* isolate,
1050  uint16_t bitmask,
1051  uint16_t compare_value) {
1052  return NewBitmaskCompare(isolate, bitmask, compare_value, this);
1053 }
1054 
1055 
1057  Isolate* isolate,
1058  uint32_t bitmask,
1059  uint32_t compare_value) {
1060  return NewBitmaskCompare(isolate, bitmask, compare_value, this);
1061 }
1062 
1063 
1065  Handle<FunctionTemplate> types[1] = { type };
1066  return TypeSwitch::New(1, types);
1067 }
1068 
1069 
1071  i::Isolate* isolate = i::Isolate::Current();
1072  LOG_API(isolate, "TypeSwitch::New");
1073  ENTER_V8(isolate);
1074  i::Handle<i::FixedArray> vector = isolate->factory()->NewFixedArray(argc);
1075  for (int i = 0; i < argc; i++)
1076  vector->set(i, *Utils::OpenHandle(*types[i]));
1077  i::Handle<i::Struct> struct_obj =
1078  isolate->factory()->NewStruct(i::TYPE_SWITCH_INFO_TYPE);
1081  obj->set_types(*vector);
1082  return Utils::ToLocal(obj);
1083 }
1084 
1085 
1087  i::Isolate* isolate = i::Isolate::Current();
1088  LOG_API(isolate, "TypeSwitch::match");
1089  USE(isolate);
1092  i::FixedArray* types = i::FixedArray::cast(info->types());
1093  for (int i = 0; i < types->length(); i++) {
1094  if (i::FunctionTemplateInfo::cast(types->get(i))->IsTemplateFor(*obj))
1095  return i + 1;
1096  }
1097  return 0;
1098 }
1099 
1100 
1101 #define SET_FIELD_WRAPPED(obj, setter, cdata) do { \
1102  i::Handle<i::Object> foreign = FromCData(obj->GetIsolate(), cdata); \
1103  (obj)->setter(*foreign); \
1104  } while (false)
1105 
1106 
1108  v8::Handle<Value> data) {
1109  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
1110  ENTER_V8(isolate);
1111  i::HandleScope scope(isolate);
1112  i::Handle<i::Struct> struct_obj =
1113  isolate->factory()->NewStruct(i::CALL_HANDLER_INFO_TYPE);
1116  SET_FIELD_WRAPPED(obj, set_callback, callback);
1117  if (data.IsEmpty()) {
1118  data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate));
1119  }
1120  obj->set_data(*Utils::OpenHandle(*data));
1121  Utils::OpenHandle(this)->set_call_code(*obj);
1122 }
1123 
1124 
1128  v8::AccessControl settings,
1129  v8::PropertyAttribute attributes,
1130  v8::Handle<AccessorSignature> signature) {
1131  obj->set_name(*Utils::OpenHandle(*name));
1132  if (settings & ALL_CAN_READ) obj->set_all_can_read(true);
1133  if (settings & ALL_CAN_WRITE) obj->set_all_can_write(true);
1134  obj->set_property_attributes(static_cast<PropertyAttributes>(attributes));
1135  if (!signature.IsEmpty()) {
1136  obj->set_expected_receiver_type(*Utils::OpenHandle(*signature));
1137  }
1138  return obj;
1139 }
1140 
1141 
1142 template<typename Getter, typename Setter>
1145  Getter getter,
1146  Setter setter,
1147  v8::Handle<Value> data,
1148  v8::AccessControl settings,
1149  v8::PropertyAttribute attributes,
1150  v8::Handle<AccessorSignature> signature) {
1151  i::Isolate* isolate = Utils::OpenHandle(*name)->GetIsolate();
1153  isolate->factory()->NewExecutableAccessorInfo();
1154  SET_FIELD_WRAPPED(obj, set_getter, getter);
1155  SET_FIELD_WRAPPED(obj, set_setter, setter);
1156  if (data.IsEmpty()) {
1157  data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate));
1158  }
1159  obj->set_data(*Utils::OpenHandle(*data));
1160  return SetAccessorInfoProperties(obj, name, settings, attributes, signature);
1161 }
1162 
1163 
1167  void* setter_ignored,
1168  void* data_ignored,
1169  v8::AccessControl settings,
1170  v8::PropertyAttribute attributes,
1171  v8::Handle<AccessorSignature> signature) {
1172  i::Isolate* isolate = Utils::OpenHandle(*name)->GetIsolate();
1173  if (descriptor.IsEmpty()) return i::Handle<i::DeclaredAccessorInfo>();
1175  isolate->factory()->NewDeclaredAccessorInfo();
1176  obj->set_descriptor(*Utils::OpenHandle(*descriptor));
1177  return SetAccessorInfoProperties(obj, name, settings, attributes, signature);
1178 }
1179 
1180 
1183  if (!Utils::ApiCheck(!handle.is_null(),
1184  "v8::FunctionTemplate::InstanceTemplate()",
1185  "Reading from empty handle")) {
1186  return Local<ObjectTemplate>();
1187  }
1188  i::Isolate* isolate = handle->GetIsolate();
1189  ENTER_V8(isolate);
1190  if (handle->instance_template()->IsUndefined()) {
1191  Local<ObjectTemplate> templ =
1192  ObjectTemplate::New(isolate, ToApiHandle<FunctionTemplate>(handle));
1193  handle->set_instance_template(*Utils::OpenHandle(*templ));
1194  }
1196  i::ObjectTemplateInfo::cast(handle->instance_template()));
1197  return Utils::ToLocal(result);
1198 }
1199 
1200 
1202  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
1203  ENTER_V8(isolate);
1204  Utils::OpenHandle(this)->set_length(length);
1205 }
1206 
1207 
1209  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
1210  ENTER_V8(isolate);
1211  Utils::OpenHandle(this)->set_class_name(*Utils::OpenHandle(*name));
1212 }
1213 
1214 
1216  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
1217  ENTER_V8(isolate);
1218  Utils::OpenHandle(this)->set_hidden_prototype(value);
1219 }
1220 
1221 
1223  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
1224  ENTER_V8(isolate);
1225  Utils::OpenHandle(this)->set_read_only_prototype(true);
1226 }
1227 
1228 
1230  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
1231  ENTER_V8(isolate);
1232  Utils::OpenHandle(this)->set_remove_prototype(true);
1233 }
1234 
1235 
1236 // --- O b j e c t T e m p l a t e ---
1237 
1238 
1240  return New(reinterpret_cast<i::Isolate*>(isolate), Local<FunctionTemplate>());
1241 }
1242 
1243 
1245  return New(i::Isolate::Current(), Local<FunctionTemplate>());
1246 }
1247 
1248 
1250  i::Isolate* isolate,
1251  v8::Handle<FunctionTemplate> constructor) {
1252  LOG_API(isolate, "ObjectTemplate::New");
1253  ENTER_V8(isolate);
1254  i::Handle<i::Struct> struct_obj =
1255  isolate->factory()->NewStruct(i::OBJECT_TEMPLATE_INFO_TYPE);
1259  if (!constructor.IsEmpty())
1260  obj->set_constructor(*Utils::OpenHandle(*constructor));
1261  obj->set_internal_field_count(i::Smi::FromInt(0));
1262  return Utils::ToLocal(obj);
1263 }
1264 
1265 
1266 // Ensure that the object template has a constructor. If no
1267 // constructor is available we create one.
1269  i::Isolate* isolate,
1270  ObjectTemplate* object_template) {
1271  i::Object* obj = Utils::OpenHandle(object_template)->constructor();
1272  if (!obj ->IsUndefined()) {
1273  i::FunctionTemplateInfo* info = i::FunctionTemplateInfo::cast(obj);
1274  return i::Handle<i::FunctionTemplateInfo>(info, isolate);
1275  }
1276  Local<FunctionTemplate> templ =
1277  FunctionTemplate::New(reinterpret_cast<Isolate*>(isolate));
1279  constructor->set_instance_template(*Utils::OpenHandle(object_template));
1280  Utils::OpenHandle(object_template)->set_constructor(*constructor);
1281  return constructor;
1282 }
1283 
1284 
1285 static inline void AddPropertyToTemplate(
1288  i::Isolate* isolate = info->GetIsolate();
1289  i::Handle<i::Object> list(info->property_accessors(), isolate);
1290  if (list->IsUndefined()) {
1291  list = NeanderArray(isolate).value();
1292  info->set_property_accessors(*list);
1293  }
1294  NeanderArray array(list);
1295  array.add(obj);
1296 }
1297 
1298 
1300  i::Isolate* isolate,
1301  Template* template_obj) {
1302  return Utils::OpenHandle(template_obj);
1303 }
1304 
1305 
1306 // TODO(dcarney): remove this with ObjectTemplate::SetAccessor
1308  i::Isolate* isolate,
1309  ObjectTemplate* object_template) {
1310  EnsureConstructor(isolate, object_template);
1311  return Utils::OpenHandle(object_template);
1312 }
1313 
1314 
1315 template<typename Getter, typename Setter, typename Data, typename Template>
1317  Template* template_obj,
1319  Getter getter,
1320  Setter setter,
1321  Data data,
1322  AccessControl settings,
1323  PropertyAttribute attribute,
1324  v8::Local<AccessorSignature> signature) {
1325  i::Isolate* isolate = Utils::OpenHandle(template_obj)->GetIsolate();
1326  ENTER_V8(isolate);
1327  i::HandleScope scope(isolate);
1329  name, getter, setter, data, settings, attribute, signature);
1330  if (obj.is_null()) return false;
1331  i::Handle<i::TemplateInfo> info = GetTemplateInfo(isolate, template_obj);
1332  AddPropertyToTemplate(info, obj);
1333  return true;
1334 }
1335 
1336 
1338  Local<Name> name,
1340  PropertyAttribute attribute,
1341  Local<AccessorSignature> signature,
1342  AccessControl settings) {
1343  void* null = NULL;
1344  return TemplateSetAccessor(
1345  this, name, descriptor, null, null, settings, attribute, signature);
1346 }
1347 
1348 
1350  AccessorGetterCallback getter,
1351  AccessorSetterCallback setter,
1352  v8::Handle<Value> data,
1353  PropertyAttribute attribute,
1354  v8::Local<AccessorSignature> signature,
1355  AccessControl settings) {
1357  this, name, getter, setter, data, settings, attribute, signature);
1358 }
1359 
1360 
1364  v8::Handle<Value> data,
1365  PropertyAttribute attribute,
1366  v8::Local<AccessorSignature> signature,
1367  AccessControl settings) {
1369  this, name, getter, setter, data, settings, attribute, signature);
1370 }
1371 
1372 
1374  AccessorGetterCallback getter,
1375  AccessorSetterCallback setter,
1376  v8::Handle<Value> data,
1377  AccessControl settings,
1378  PropertyAttribute attribute,
1379  v8::Handle<AccessorSignature> signature) {
1381  this, name, getter, setter, data, settings, attribute, signature);
1382 }
1383 
1384 
1388  v8::Handle<Value> data,
1389  AccessControl settings,
1390  PropertyAttribute attribute,
1391  v8::Handle<AccessorSignature> signature) {
1393  this, name, getter, setter, data, settings, attribute, signature);
1394 }
1395 
1396 
1403  Handle<Value> data) {
1404  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
1405  ENTER_V8(isolate);
1406  i::HandleScope scope(isolate);
1407  EnsureConstructor(isolate, this);
1408  i::FunctionTemplateInfo* constructor = i::FunctionTemplateInfo::cast(
1409  Utils::OpenHandle(this)->constructor());
1410  i::Handle<i::FunctionTemplateInfo> cons(constructor);
1411  i::Handle<i::Struct> struct_obj =
1412  isolate->factory()->NewStruct(i::INTERCEPTOR_INFO_TYPE);
1415 
1416  if (getter != 0) SET_FIELD_WRAPPED(obj, set_getter, getter);
1417  if (setter != 0) SET_FIELD_WRAPPED(obj, set_setter, setter);
1418  if (query != 0) SET_FIELD_WRAPPED(obj, set_query, query);
1419  if (remover != 0) SET_FIELD_WRAPPED(obj, set_deleter, remover);
1420  if (enumerator != 0) SET_FIELD_WRAPPED(obj, set_enumerator, enumerator);
1421 
1422  if (data.IsEmpty()) {
1423  data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate));
1424  }
1425  obj->set_data(*Utils::OpenHandle(*data));
1426  cons->set_named_property_handler(*obj);
1427 }
1428 
1429 
1431  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
1432  ENTER_V8(isolate);
1433  i::HandleScope scope(isolate);
1434  EnsureConstructor(isolate, this);
1435  i::FunctionTemplateInfo* constructor =
1436  i::FunctionTemplateInfo::cast(Utils::OpenHandle(this)->constructor());
1437  i::Handle<i::FunctionTemplateInfo> cons(constructor);
1438  cons->set_undetectable(true);
1439 }
1440 
1441 
1443  NamedSecurityCallback named_callback,
1444  IndexedSecurityCallback indexed_callback,
1445  Handle<Value> data,
1446  bool turned_on_by_default) {
1447  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
1448  ENTER_V8(isolate);
1449  i::HandleScope scope(isolate);
1450  EnsureConstructor(isolate, this);
1451 
1452  i::Handle<i::Struct> struct_info =
1453  isolate->factory()->NewStruct(i::ACCESS_CHECK_INFO_TYPE);
1456 
1457  SET_FIELD_WRAPPED(info, set_named_callback, named_callback);
1458  SET_FIELD_WRAPPED(info, set_indexed_callback, indexed_callback);
1459 
1460  if (data.IsEmpty()) {
1461  data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate));
1462  }
1463  info->set_data(*Utils::OpenHandle(*data));
1464 
1465  i::FunctionTemplateInfo* constructor =
1466  i::FunctionTemplateInfo::cast(Utils::OpenHandle(this)->constructor());
1467  i::Handle<i::FunctionTemplateInfo> cons(constructor);
1468  cons->set_access_check_info(*info);
1469  cons->set_needs_access_check(turned_on_by_default);
1470 }
1471 
1472 
1479  Handle<Value> data) {
1480  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
1481  ENTER_V8(isolate);
1482  i::HandleScope scope(isolate);
1483  EnsureConstructor(isolate, this);
1484  i::FunctionTemplateInfo* constructor = i::FunctionTemplateInfo::cast(
1485  Utils::OpenHandle(this)->constructor());
1486  i::Handle<i::FunctionTemplateInfo> cons(constructor);
1487  i::Handle<i::Struct> struct_obj =
1488  isolate->factory()->NewStruct(i::INTERCEPTOR_INFO_TYPE);
1491 
1492  if (getter != 0) SET_FIELD_WRAPPED(obj, set_getter, getter);
1493  if (setter != 0) SET_FIELD_WRAPPED(obj, set_setter, setter);
1494  if (query != 0) SET_FIELD_WRAPPED(obj, set_query, query);
1495  if (remover != 0) SET_FIELD_WRAPPED(obj, set_deleter, remover);
1496  if (enumerator != 0) SET_FIELD_WRAPPED(obj, set_enumerator, enumerator);
1497 
1498  if (data.IsEmpty()) {
1499  data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate));
1500  }
1501  obj->set_data(*Utils::OpenHandle(*data));
1502  cons->set_indexed_property_handler(*obj);
1503 }
1504 
1505 
1507  Handle<Value> data) {
1508  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
1509  ENTER_V8(isolate);
1510  i::HandleScope scope(isolate);
1511  EnsureConstructor(isolate, this);
1512  i::FunctionTemplateInfo* constructor = i::FunctionTemplateInfo::cast(
1513  Utils::OpenHandle(this)->constructor());
1514  i::Handle<i::FunctionTemplateInfo> cons(constructor);
1515  i::Handle<i::Struct> struct_obj =
1516  isolate->factory()->NewStruct(i::CALL_HANDLER_INFO_TYPE);
1519  SET_FIELD_WRAPPED(obj, set_callback, callback);
1520  if (data.IsEmpty()) {
1521  data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate));
1522  }
1523  obj->set_data(*Utils::OpenHandle(*data));
1524  cons->set_instance_call_handler(*obj);
1525 }
1526 
1527 
1529  return i::Smi::cast(Utils::OpenHandle(this)->internal_field_count())->value();
1530 }
1531 
1532 
1534  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
1535  if (!Utils::ApiCheck(i::Smi::IsValid(value),
1536  "v8::ObjectTemplate::SetInternalFieldCount()",
1537  "Invalid internal field count")) {
1538  return;
1539  }
1540  ENTER_V8(isolate);
1541  if (value > 0) {
1542  // The internal field count is set by the constructor function's
1543  // construct code, so we ensure that there is a constructor
1544  // function to do the setting.
1545  EnsureConstructor(isolate, this);
1546  }
1547  Utils::OpenHandle(this)->set_internal_field_count(i::Smi::FromInt(value));
1548 }
1549 
1550 
1551 // --- S c r i p t s ---
1552 
1553 
1554 // Internally, UnboundScript is a SharedFunctionInfo, and Script is a
1555 // JSFunction.
1556 
1557 ScriptCompiler::CachedData::CachedData(const uint8_t* data_, int length_,
1558  BufferPolicy buffer_policy_)
1559  : data(data_), length(length_), buffer_policy(buffer_policy_) {}
1560 
1561 
1563  if (buffer_policy == BufferOwned) {
1564  delete[] data;
1565  }
1566 }
1567 
1568 
1570  Encoding encoding)
1571  : impl_(new i::StreamedSource(stream, encoding)) {}
1572 
1573 
1575 
1576 
1579  return impl_->cached_data.get();
1580 }
1581 
1582 
1587  function_info(i::SharedFunctionInfo::cast(*obj), obj->GetIsolate());
1588  i::Handle<i::JSFunction> function =
1589  obj->GetIsolate()->factory()->NewFunctionFromSharedFunctionInfo(
1590  function_info, obj->GetIsolate()->global_context());
1591  return ToApiHandle<Script>(function);
1592 }
1593 
1594 
1598  i::Isolate* isolate = obj->GetIsolate();
1599  ON_BAILOUT(isolate, "v8::UnboundScript::GetId()", return -1);
1600  LOG_API(isolate, "v8::UnboundScript::GetId");
1601  {
1602  i::HandleScope scope(isolate);
1603  i::Handle<i::SharedFunctionInfo> function_info(
1604  i::SharedFunctionInfo::cast(*obj));
1605  i::Handle<i::Script> script(i::Script::cast(function_info->script()));
1606  return script->id()->value();
1607  }
1608 }
1609 
1610 
1611 int UnboundScript::GetLineNumber(int code_pos) {
1614  i::Isolate* isolate = obj->GetIsolate();
1615  ON_BAILOUT(isolate, "v8::UnboundScript::GetLineNumber()", return -1);
1616  LOG_API(isolate, "UnboundScript::GetLineNumber");
1617  if (obj->script()->IsScript()) {
1618  i::Handle<i::Script> script(i::Script::cast(obj->script()));
1619  return i::Script::GetLineNumber(script, code_pos);
1620  } else {
1621  return -1;
1622  }
1623 }
1624 
1625 
1629  i::Isolate* isolate = obj->GetIsolate();
1630  ON_BAILOUT(isolate, "v8::UnboundScript::GetName()",
1631  return Handle<String>());
1632  LOG_API(isolate, "UnboundScript::GetName");
1633  if (obj->script()->IsScript()) {
1634  i::Object* name = i::Script::cast(obj->script())->name();
1635  return Utils::ToLocal(i::Handle<i::Object>(name, isolate));
1636  } else {
1637  return Handle<String>();
1638  }
1639 }
1640 
1641 
1645  i::Isolate* isolate = obj->GetIsolate();
1646  ON_BAILOUT(isolate, "v8::UnboundScript::GetSourceURL()",
1647  return Handle<String>());
1648  LOG_API(isolate, "UnboundScript::GetSourceURL");
1649  if (obj->script()->IsScript()) {
1650  i::Object* url = i::Script::cast(obj->script())->source_url();
1651  return Utils::ToLocal(i::Handle<i::Object>(url, isolate));
1652  } else {
1653  return Handle<String>();
1654  }
1655 }
1656 
1657 
1661  i::Isolate* isolate = obj->GetIsolate();
1662  ON_BAILOUT(isolate, "v8::UnboundScript::GetSourceMappingURL()",
1663  return Handle<String>());
1664  LOG_API(isolate, "UnboundScript::GetSourceMappingURL");
1665  if (obj->script()->IsScript()) {
1666  i::Object* url = i::Script::cast(obj->script())->source_mapping_url();
1667  return Utils::ToLocal(i::Handle<i::Object>(url, isolate));
1668  } else {
1669  return Handle<String>();
1670  }
1671 }
1672 
1673 
1675  i::Handle<i::Object> obj = Utils::OpenHandle(this, true);
1676  // If execution is terminating, Compile(..)->Run() requires this
1677  // check.
1678  if (obj.is_null()) return Local<Value>();
1679  i::Isolate* isolate = i::Handle<i::HeapObject>::cast(obj)->GetIsolate();
1680  ON_BAILOUT(isolate, "v8::Script::Run()", return Local<Value>());
1681  LOG_API(isolate, "Script::Run");
1682  ENTER_V8(isolate);
1683  i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate);
1684  i::HandleScope scope(isolate);
1686  EXCEPTION_PREAMBLE(isolate);
1687  i::Handle<i::Object> receiver(isolate->global_proxy(), isolate);
1688  i::Handle<i::Object> result;
1689  has_pending_exception = !i::Execution::Call(
1690  isolate, fun, receiver, 0, NULL).ToHandle(&result);
1692  return Utils::ToLocal(scope.CloseAndEscape(result));
1693 }
1694 
1695 
1698  return ToApiHandle<UnboundScript>(
1699  i::Handle<i::SharedFunctionInfo>(i::JSFunction::cast(*obj)->shared()));
1700 }
1701 
1702 
1704  Isolate* v8_isolate,
1705  Source* source,
1706  CompileOptions options) {
1707  i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
1708  ON_BAILOUT(isolate, "v8::ScriptCompiler::CompileUnbound()",
1709  return Local<UnboundScript>());
1710 
1711  // Support the old API for a transition period:
1712  // - kProduceToCache -> kProduceParserCache
1713  // - kNoCompileOptions + cached_data != NULL -> kConsumeParserCache
1714  if (options == kProduceDataToCache) {
1715  options = kProduceParserCache;
1716  } else if (options == kNoCompileOptions && source->cached_data) {
1717  options = kConsumeParserCache;
1718  }
1719 
1720  i::ScriptData* script_data = NULL;
1721  if (options == kConsumeParserCache || options == kConsumeCodeCache) {
1722  DCHECK(source->cached_data);
1723  // ScriptData takes care of pointer-aligning the data.
1724  script_data = new i::ScriptData(source->cached_data->data,
1725  source->cached_data->length);
1726  }
1727 
1729  LOG_API(isolate, "ScriptCompiler::CompileUnbound");
1730  ENTER_V8(isolate);
1731  i::SharedFunctionInfo* raw_result = NULL;
1732  { i::HandleScope scope(isolate);
1733  i::Handle<i::Object> name_obj;
1734  int line_offset = 0;
1735  int column_offset = 0;
1736  bool is_shared_cross_origin = false;
1737  if (!source->resource_name.IsEmpty()) {
1738  name_obj = Utils::OpenHandle(*(source->resource_name));
1739  }
1740  if (!source->resource_line_offset.IsEmpty()) {
1741  line_offset = static_cast<int>(source->resource_line_offset->Value());
1742  }
1743  if (!source->resource_column_offset.IsEmpty()) {
1744  column_offset =
1745  static_cast<int>(source->resource_column_offset->Value());
1746  }
1747  if (!source->resource_is_shared_cross_origin.IsEmpty()) {
1748  v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate);
1749  is_shared_cross_origin =
1750  source->resource_is_shared_cross_origin == v8::True(v8_isolate);
1751  }
1752  EXCEPTION_PREAMBLE(isolate);
1754  str, name_obj, line_offset, column_offset, is_shared_cross_origin,
1755  isolate->global_context(), NULL, &script_data, options,
1757  has_pending_exception = result.is_null();
1758  if (has_pending_exception && script_data != NULL) {
1759  // This case won't happen during normal operation; we have compiled
1760  // successfully and produced cached data, and but the second compilation
1761  // of the same source code fails.
1762  delete script_data;
1763  script_data = NULL;
1764  }
1766  raw_result = *result;
1767 
1768  if ((options == kProduceParserCache || options == kProduceCodeCache) &&
1769  script_data != NULL) {
1770  // script_data now contains the data that was generated. source will
1771  // take the ownership.
1772  source->cached_data = new CachedData(
1773  script_data->data(), script_data->length(), CachedData::BufferOwned);
1774  script_data->ReleaseDataOwnership();
1775  }
1776  delete script_data;
1777  }
1778  i::Handle<i::SharedFunctionInfo> result(raw_result, isolate);
1779  return ToApiHandle<UnboundScript>(result);
1780 }
1781 
1782 
1784  Isolate* v8_isolate,
1785  Source* source,
1786  CompileOptions options) {
1787  i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
1788  ON_BAILOUT(isolate, "v8::ScriptCompiler::Compile()", return Local<Script>());
1789  LOG_API(isolate, "ScriptCompiler::CompiletBound()");
1790  ENTER_V8(isolate);
1791  Local<UnboundScript> generic = CompileUnbound(v8_isolate, source, options);
1792  if (generic.IsEmpty()) return Local<Script>();
1793  return generic->BindToCurrentContext();
1794 }
1795 
1796 
1798  Isolate* v8_isolate, StreamedSource* source, CompileOptions options) {
1799  i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
1800  if (!isolate->global_context().is_null() &&
1801  !isolate->global_context()->IsNativeContext()) {
1802  // The context chain is non-trivial, and constructing the corresponding
1803  // non-trivial Scope chain outside the V8 heap is not implemented. Don't
1804  // stream the script. This will only occur if Harmony scoping is enabled and
1805  // a previous script has introduced "let" or "const" variables. TODO(marja):
1806  // Implement externalizing ScopeInfos and constructing non-trivial Scope
1807  // chains independent of the V8 heap so that we can stream also in this
1808  // case.
1809  return NULL;
1810  }
1811  return new i::BackgroundParsingTask(source->impl(), options,
1812  i::FLAG_stack_size, isolate);
1813 }
1814 
1815 
1817  StreamedSource* v8_source,
1818  Handle<String> full_source_string,
1819  const ScriptOrigin& origin) {
1820  i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
1821  i::StreamedSource* source = v8_source->impl();
1822  ON_BAILOUT(isolate, "v8::ScriptCompiler::Compile()", return Local<Script>());
1823  LOG_API(isolate, "ScriptCompiler::Compile()");
1824  ENTER_V8(isolate);
1825  i::SharedFunctionInfo* raw_result = NULL;
1826 
1827  {
1828  i::HandleScope scope(isolate);
1829  i::Handle<i::String> str = Utils::OpenHandle(*(full_source_string));
1830  i::Handle<i::Script> script = isolate->factory()->NewScript(str);
1831  if (!origin.ResourceName().IsEmpty()) {
1832  script->set_name(*Utils::OpenHandle(*(origin.ResourceName())));
1833  }
1834  if (!origin.ResourceLineOffset().IsEmpty()) {
1835  script->set_line_offset(i::Smi::FromInt(
1836  static_cast<int>(origin.ResourceLineOffset()->Value())));
1837  }
1838  if (!origin.ResourceColumnOffset().IsEmpty()) {
1839  script->set_column_offset(i::Smi::FromInt(
1840  static_cast<int>(origin.ResourceColumnOffset()->Value())));
1841  }
1842  if (!origin.ResourceIsSharedCrossOrigin().IsEmpty()) {
1843  script->set_is_shared_cross_origin(origin.ResourceIsSharedCrossOrigin() ==
1844  v8::True(v8_isolate));
1845  }
1846  source->info->set_script(script);
1847  source->info->SetContext(isolate->global_context());
1848 
1849  EXCEPTION_PREAMBLE(isolate);
1850 
1851  // Do the parsing tasks which need to be done on the main thread. This will
1852  // also handle parse errors.
1853  source->parser->Internalize();
1854 
1857  if (source->info->function() != NULL) {
1858  // Parsing has succeeded.
1859  result =
1860  i::Compiler::CompileStreamedScript(source->info.get(), str->length());
1861  }
1862  has_pending_exception = result.is_null();
1863  if (has_pending_exception) isolate->ReportPendingMessages();
1865 
1866  raw_result = *result;
1867  // The Handle<Script> will go out of scope soon; make sure CompilationInfo
1868  // doesn't point to it.
1869  source->info->set_script(i::Handle<i::Script>());
1870  } // HandleScope goes out of scope.
1871  i::Handle<i::SharedFunctionInfo> result(raw_result, isolate);
1872  Local<UnboundScript> generic = ToApiHandle<UnboundScript>(result);
1873  if (generic.IsEmpty()) {
1874  return Local<Script>();
1875  }
1876  return generic->BindToCurrentContext();
1877 }
1878 
1879 
1881  v8::ScriptOrigin* origin) {
1882  i::Handle<i::String> str = Utils::OpenHandle(*source);
1883  if (origin) {
1884  ScriptCompiler::Source script_source(source, *origin);
1885  return ScriptCompiler::Compile(
1886  reinterpret_cast<v8::Isolate*>(str->GetIsolate()),
1887  &script_source);
1888  }
1889  ScriptCompiler::Source script_source(source);
1890  return ScriptCompiler::Compile(
1891  reinterpret_cast<v8::Isolate*>(str->GetIsolate()),
1892  &script_source);
1893 }
1894 
1895 
1897  v8::Handle<String> file_name) {
1898  ScriptOrigin origin(file_name);
1899  return Compile(source, &origin);
1900 }
1901 
1902 
1903 // --- E x c e p t i o n s ---
1904 
1905 
1907  : isolate_(i::Isolate::Current()),
1908  next_(isolate_->try_catch_handler()),
1909  is_verbose_(false),
1910  can_continue_(true),
1911  capture_message_(true),
1912  rethrow_(false),
1913  has_terminated_(false) {
1914  ResetInternal();
1915  // Special handling for simulators which have a separate JS stack.
1917  reinterpret_cast<void*>(v8::internal::SimulatorStack::RegisterCTryCatch(
1920 }
1921 
1922 
1924  DCHECK(isolate_ == i::Isolate::Current());
1925  if (rethrow_) {
1926  v8::Isolate* isolate = reinterpret_cast<Isolate*>(isolate_);
1927  v8::HandleScope scope(isolate);
1929  if (HasCaught() && capture_message_) {
1930  // If an exception was caught and rethrow_ is indicated, the saved
1931  // message, script, and location need to be restored to Isolate TLS
1932  // for reuse. capture_message_ needs to be disabled so that DoThrow()
1933  // does not create a new message.
1934  isolate_->thread_local_top()->rethrowing_message_ = true;
1935  isolate_->RestorePendingMessageFromTryCatch(this);
1936  }
1937  isolate_->UnregisterTryCatchHandler(this);
1939  reinterpret_cast<Isolate*>(isolate_)->ThrowException(exc);
1940  DCHECK(!isolate_->thread_local_top()->rethrowing_message_);
1941  } else {
1942  if (HasCaught() && isolate_->has_scheduled_exception()) {
1943  // If an exception was caught but is still scheduled because no API call
1944  // promoted it, then it is canceled to prevent it from being propagated.
1945  // Note that this will not cancel termination exceptions.
1946  isolate_->CancelScheduledExceptionFromTryCatch(this);
1947  }
1948  isolate_->UnregisterTryCatchHandler(this);
1950  }
1951 }
1952 
1953 
1955  return !reinterpret_cast<i::Object*>(exception_)->IsTheHole();
1956 }
1957 
1958 
1960  return can_continue_;
1961 }
1962 
1963 
1965  return has_terminated_;
1966 }
1967 
1968 
1970  if (!HasCaught()) return v8::Local<v8::Value>();
1971  rethrow_ = true;
1972  return v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate_));
1973 }
1974 
1975 
1977  DCHECK(isolate_ == i::Isolate::Current());
1978  if (HasCaught()) {
1979  // Check for out of memory exception.
1980  i::Object* exception = reinterpret_cast<i::Object*>(exception_);
1981  return v8::Utils::ToLocal(i::Handle<i::Object>(exception, isolate_));
1982  } else {
1983  return v8::Local<Value>();
1984  }
1985 }
1986 
1987 
1989  DCHECK(isolate_ == i::Isolate::Current());
1990  if (HasCaught()) {
1991  i::Object* raw_obj = reinterpret_cast<i::Object*>(exception_);
1992  if (!raw_obj->IsJSObject()) return v8::Local<Value>();
1993  i::HandleScope scope(isolate_);
1994  i::Handle<i::JSObject> obj(i::JSObject::cast(raw_obj), isolate_);
1995  i::Handle<i::String> name = isolate_->factory()->stack_string();
1996  EXCEPTION_PREAMBLE(isolate_);
1998  has_pending_exception = !maybe.has_value;
2000  if (!maybe.value) return v8::Local<Value>();
2001  i::Handle<i::Object> value;
2002  if (!i::Object::GetProperty(obj, name).ToHandle(&value)) {
2003  return v8::Local<Value>();
2004  }
2005  return v8::Utils::ToLocal(scope.CloseAndEscape(value));
2006  } else {
2007  return v8::Local<Value>();
2008  }
2009 }
2010 
2011 
2013  DCHECK(isolate_ == i::Isolate::Current());
2014  i::Object* message = reinterpret_cast<i::Object*>(message_obj_);
2015  DCHECK(message->IsJSMessageObject() || message->IsTheHole());
2016  if (HasCaught() && !message->IsTheHole()) {
2017  return v8::Utils::MessageToLocal(i::Handle<i::Object>(message, isolate_));
2018  } else {
2019  return v8::Local<v8::Message>();
2020  }
2021 }
2022 
2023 
2025  DCHECK(isolate_ == i::Isolate::Current());
2026  if (!rethrow_ && HasCaught() && isolate_->has_scheduled_exception()) {
2027  // If an exception was caught but is still scheduled because no API call
2028  // promoted it, then it is canceled to prevent it from being propagated.
2029  // Note that this will not cancel termination exceptions.
2030  isolate_->CancelScheduledExceptionFromTryCatch(this);
2031  }
2032  ResetInternal();
2033 }
2034 
2035 
2037  i::Object* the_hole = isolate_->heap()->the_hole_value();
2038  exception_ = the_hole;
2039  message_obj_ = the_hole;
2040  message_script_ = the_hole;
2041  message_start_pos_ = 0;
2042  message_end_pos_ = 0;
2043 }
2044 
2045 
2046 void v8::TryCatch::SetVerbose(bool value) {
2047  is_verbose_ = value;
2048 }
2049 
2050 
2052  capture_message_ = value;
2053 }
2054 
2055 
2056 // --- M e s s a g e ---
2057 
2058 
2060  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
2061  ON_BAILOUT(isolate, "v8::Message::Get()", return Local<String>());
2062  ENTER_V8(isolate);
2063  EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate));
2065  i::Handle<i::String> raw_result = i::MessageHandler::GetMessage(isolate, obj);
2066  Local<String> result = Utils::ToLocal(raw_result);
2067  return scope.Escape(result);
2068 }
2069 
2070 
2072  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
2075  i::Handle<i::Object> script_wraper =
2076  i::Handle<i::Object>(message->script(), isolate);
2077  i::Handle<i::JSValue> script_value =
2078  i::Handle<i::JSValue>::cast(script_wraper);
2079  i::Handle<i::Script> script(i::Script::cast(script_value->value()));
2081  v8::Isolate* v8_isolate =
2082  reinterpret_cast<v8::Isolate*>(script->GetIsolate());
2083  v8::ScriptOrigin origin(
2084  Utils::ToLocal(scriptName),
2085  v8::Integer::New(v8_isolate, script->line_offset()->value()),
2086  v8::Integer::New(v8_isolate, script->column_offset()->value()),
2087  Handle<Boolean>(),
2088  v8::Integer::New(v8_isolate, script->id()->value()));
2089  return origin;
2090 }
2091 
2092 
2094  return GetScriptOrigin().ResourceName();
2095 }
2096 
2097 
2099  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
2100  ENTER_V8(isolate);
2101  EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate));
2104  i::Handle<i::Object> stackFramesObj(message->stack_frames(), isolate);
2105  if (!stackFramesObj->IsJSArray()) return v8::Handle<v8::StackTrace>();
2106  i::Handle<i::JSArray> stackTrace =
2107  i::Handle<i::JSArray>::cast(stackFramesObj);
2108  return scope.Escape(Utils::StackTraceToLocal(stackTrace));
2109 }
2110 
2111 
2113  const char* name,
2114  i::Handle<i::Object> recv,
2115  int argc,
2116  i::Handle<i::Object> argv[]) {
2117  i::Isolate* isolate = i::Isolate::Current();
2118  i::Handle<i::Object> object_fun =
2120  isolate, isolate->js_builtins_object(), name).ToHandleChecked();
2122  return i::Execution::Call(isolate, fun, recv, argc, argv);
2123 }
2124 
2125 
2127  const char* name,
2128  i::Handle<i::Object> data) {
2129  i::Handle<i::Object> argv[] = { data };
2130  return CallV8HeapFunction(name,
2131  i::Isolate::Current()->js_builtins_object(),
2132  arraysize(argv),
2133  argv);
2134 }
2135 
2136 
2138  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
2139  ON_BAILOUT(isolate, "v8::Message::GetLineNumber()", return kNoLineNumberInfo);
2140  ENTER_V8(isolate);
2141  i::HandleScope scope(isolate);
2142 
2143  EXCEPTION_PREAMBLE(isolate);
2144  i::Handle<i::Object> result;
2145  has_pending_exception = !CallV8HeapFunction(
2146  "GetLineNumber", Utils::OpenHandle(this)).ToHandle(&result);
2147  EXCEPTION_BAILOUT_CHECK(isolate, 0);
2148  return static_cast<int>(result->Number());
2149 }
2150 
2151 
2153  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
2154  ENTER_V8(isolate);
2155  i::HandleScope scope(isolate);
2158  return message->start_position();
2159 }
2160 
2161 
2163  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
2164  ENTER_V8(isolate);
2165  i::HandleScope scope(isolate);
2168  return message->end_position();
2169 }
2170 
2171 
2173  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
2174  ON_BAILOUT(isolate, "v8::Message::GetStartColumn()", return kNoColumnInfo);
2175  ENTER_V8(isolate);
2176  i::HandleScope scope(isolate);
2177  i::Handle<i::JSObject> data_obj = Utils::OpenHandle(this);
2178  EXCEPTION_PREAMBLE(isolate);
2179  i::Handle<i::Object> start_col_obj;
2180  has_pending_exception = !CallV8HeapFunction(
2181  "GetPositionInLine", data_obj).ToHandle(&start_col_obj);
2182  EXCEPTION_BAILOUT_CHECK(isolate, 0);
2183  return static_cast<int>(start_col_obj->Number());
2184 }
2185 
2186 
2188  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
2189  ON_BAILOUT(isolate, "v8::Message::GetEndColumn()", return kNoColumnInfo);
2190  ENTER_V8(isolate);
2191  i::HandleScope scope(isolate);
2192  i::Handle<i::JSObject> data_obj = Utils::OpenHandle(this);
2193  EXCEPTION_PREAMBLE(isolate);
2194  i::Handle<i::Object> start_col_obj;
2195  has_pending_exception = !CallV8HeapFunction(
2196  "GetPositionInLine", data_obj).ToHandle(&start_col_obj);
2197  EXCEPTION_BAILOUT_CHECK(isolate, 0);
2200  int start = message->start_position();
2201  int end = message->end_position();
2202  return static_cast<int>(start_col_obj->Number()) + (end - start);
2203 }
2204 
2205 
2207  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
2208  ENTER_V8(isolate);
2209  i::HandleScope scope(isolate);
2212  i::Handle<i::JSValue> script =
2214  isolate));
2215  return i::Script::cast(script->value())->is_shared_cross_origin();
2216 }
2217 
2218 
2220  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
2221  ON_BAILOUT(isolate, "v8::Message::GetSourceLine()", return Local<String>());
2222  ENTER_V8(isolate);
2223  EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate));
2224  EXCEPTION_PREAMBLE(isolate);
2225  i::Handle<i::Object> result;
2226  has_pending_exception = !CallV8HeapFunction(
2227  "GetSourceLine", Utils::OpenHandle(this)).ToHandle(&result);
2229  if (result->IsString()) {
2230  return scope.Escape(Utils::ToLocal(i::Handle<i::String>::cast(result)));
2231  } else {
2232  return Local<String>();
2233  }
2234 }
2235 
2236 
2237 void Message::PrintCurrentStackTrace(Isolate* isolate, FILE* out) {
2238  i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
2239  ENTER_V8(i_isolate);
2240  i_isolate->PrintCurrentStackTrace(out);
2241 }
2242 
2243 
2244 // --- S t a c k T r a c e ---
2245 
2247  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
2248  ENTER_V8(isolate);
2249  EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate));
2251  i::Handle<i::Object> obj =
2252  i::Object::GetElement(isolate, self, index).ToHandleChecked();
2254  return scope.Escape(Utils::StackFrameToLocal(jsobj));
2255 }
2256 
2257 
2259  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
2260  ENTER_V8(isolate);
2261  return i::Smi::cast(Utils::OpenHandle(this)->length())->value();
2262 }
2263 
2264 
2266  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
2267  ENTER_V8(isolate);
2268  return Utils::ToLocal(Utils::OpenHandle(this));
2269 }
2270 
2271 
2273  Isolate* isolate,
2274  int frame_limit,
2275  StackTraceOptions options) {
2276  i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
2277  ENTER_V8(i_isolate);
2278  // TODO(dcarney): remove when ScriptDebugServer is fixed.
2279  options = static_cast<StackTraceOptions>(
2280  static_cast<int>(options) | kExposeFramesAcrossSecurityOrigins);
2281  i::Handle<i::JSArray> stackTrace =
2282  i_isolate->CaptureCurrentStackTrace(frame_limit, options);
2283  return Utils::StackTraceToLocal(stackTrace);
2284 }
2285 
2286 
2287 // --- S t a c k F r a m e ---
2288 
2289 static int getIntProperty(const StackFrame* f, const char* propertyName,
2290  int defaultValue) {
2291  i::Isolate* isolate = Utils::OpenHandle(f)->GetIsolate();
2292  ENTER_V8(isolate);
2293  i::HandleScope scope(isolate);
2295  i::Handle<i::Object> obj =
2296  i::Object::GetProperty(isolate, self, propertyName).ToHandleChecked();
2297  return obj->IsSmi() ? i::Smi::cast(*obj)->value() : defaultValue;
2298 }
2299 
2300 
2302  return getIntProperty(this, "lineNumber", Message::kNoLineNumberInfo);
2303 }
2304 
2305 
2307  return getIntProperty(this, "column", Message::kNoColumnInfo);
2308 }
2309 
2310 
2312  return getIntProperty(this, "scriptId", Message::kNoScriptIdInfo);
2313 }
2314 
2315 
2317  const char* propertyName) {
2318  i::Isolate* isolate = Utils::OpenHandle(f)->GetIsolate();
2319  ENTER_V8(isolate);
2320  EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate));
2322  i::Handle<i::Object> obj =
2323  i::Object::GetProperty(isolate, self, propertyName).ToHandleChecked();
2324  return obj->IsString()
2326  : Local<String>();
2327 }
2328 
2329 
2331  return getStringProperty(this, "scriptName");
2332 }
2333 
2334 
2336  return getStringProperty(this, "scriptNameOrSourceURL");
2337 }
2338 
2339 
2341  return getStringProperty(this, "functionName");
2342 }
2343 
2344 
2345 static bool getBoolProperty(const StackFrame* f, const char* propertyName) {
2346  i::Isolate* isolate = Utils::OpenHandle(f)->GetIsolate();
2347  ENTER_V8(isolate);
2348  i::HandleScope scope(isolate);
2350  i::Handle<i::Object> obj =
2351  i::Object::GetProperty(isolate, self, propertyName).ToHandleChecked();
2352  return obj->IsTrue();
2353 }
2354 
2355 bool StackFrame::IsEval() const { return getBoolProperty(this, "isEval"); }
2356 
2357 
2359  return getBoolProperty(this, "isConstructor");
2360 }
2361 
2362 
2363 // --- J S O N ---
2364 
2366  i::Handle<i::String> string = Utils::OpenHandle(*json_string);
2367  i::Isolate* isolate = string->GetIsolate();
2368  ENTER_V8(isolate);
2369  i::HandleScope scope(isolate);
2370  i::Handle<i::String> source = i::String::Flatten(string);
2371  EXCEPTION_PREAMBLE(isolate);
2372  i::MaybeHandle<i::Object> maybe_result =
2373  source->IsSeqOneByteString() ? i::JsonParser<true>::Parse(source)
2374  : i::JsonParser<false>::Parse(source);
2375  i::Handle<i::Object> result;
2376  has_pending_exception = !maybe_result.ToHandle(&result);
2378  return Utils::ToLocal(
2380 }
2381 
2382 
2383 // --- D a t a ---
2384 
2386  bool result = Utils::OpenHandle(this)->IsUndefined();
2387  DCHECK_EQ(result, QuickIsUndefined());
2388  return result;
2389 }
2390 
2391 
2392 bool Value::FullIsNull() const {
2393  bool result = Utils::OpenHandle(this)->IsNull();
2394  DCHECK_EQ(result, QuickIsNull());
2395  return result;
2396 }
2397 
2398 
2399 bool Value::IsTrue() const {
2400  return Utils::OpenHandle(this)->IsTrue();
2401 }
2402 
2403 
2404 bool Value::IsFalse() const {
2405  return Utils::OpenHandle(this)->IsFalse();
2406 }
2407 
2408 
2409 bool Value::IsFunction() const {
2410  return Utils::OpenHandle(this)->IsJSFunction();
2411 }
2412 
2413 
2414 bool Value::IsName() const {
2415  return Utils::OpenHandle(this)->IsName();
2416 }
2417 
2418 
2419 bool Value::FullIsString() const {
2420  bool result = Utils::OpenHandle(this)->IsString();
2421  DCHECK_EQ(result, QuickIsString());
2422  return result;
2423 }
2424 
2425 
2426 bool Value::IsSymbol() const {
2427  return Utils::OpenHandle(this)->IsSymbol();
2428 }
2429 
2430 
2431 bool Value::IsArray() const {
2432  return Utils::OpenHandle(this)->IsJSArray();
2433 }
2434 
2435 
2436 bool Value::IsArrayBuffer() const {
2437  return Utils::OpenHandle(this)->IsJSArrayBuffer();
2438 }
2439 
2440 
2442  return Utils::OpenHandle(this)->IsJSArrayBufferView();
2443 }
2444 
2445 
2446 bool Value::IsTypedArray() const {
2447  return Utils::OpenHandle(this)->IsJSTypedArray();
2448 }
2449 
2450 
2451 #define VALUE_IS_TYPED_ARRAY(Type, typeName, TYPE, ctype, size) \
2452  bool Value::Is##Type##Array() const { \
2453  i::Handle<i::Object> obj = Utils::OpenHandle(this); \
2454  return obj->IsJSTypedArray() && \
2455  i::JSTypedArray::cast(*obj)->type() == kExternal##Type##Array; \
2456  }
2457 
2459 
2460 #undef VALUE_IS_TYPED_ARRAY
2461 
2462 
2463 bool Value::IsDataView() const {
2464  return Utils::OpenHandle(this)->IsJSDataView();
2465 }
2466 
2467 
2468 bool Value::IsObject() const {
2469  return Utils::OpenHandle(this)->IsJSObject();
2470 }
2471 
2472 
2473 bool Value::IsNumber() const {
2474  return Utils::OpenHandle(this)->IsNumber();
2475 }
2476 
2477 
2478 #define VALUE_IS_SPECIFIC_TYPE(Type, Class) \
2479  bool Value::Is##Type() const { \
2480  i::Handle<i::Object> obj = Utils::OpenHandle(this); \
2481  if (!obj->IsHeapObject()) return false; \
2482  i::Isolate* isolate = i::HeapObject::cast(*obj)->GetIsolate(); \
2483  return obj->HasSpecificClassOf(isolate->heap()->Class##_string()); \
2484  }
2485 
2486 VALUE_IS_SPECIFIC_TYPE(ArgumentsObject, Arguments)
2487 VALUE_IS_SPECIFIC_TYPE(BooleanObject, Boolean)
2488 VALUE_IS_SPECIFIC_TYPE(NumberObject, Number)
2489 VALUE_IS_SPECIFIC_TYPE(StringObject, String)
2490 VALUE_IS_SPECIFIC_TYPE(SymbolObject, Symbol)
2491 VALUE_IS_SPECIFIC_TYPE(Date, Date)
2492 VALUE_IS_SPECIFIC_TYPE(Map, Map)
2493 VALUE_IS_SPECIFIC_TYPE(Set, Set)
2494 VALUE_IS_SPECIFIC_TYPE(WeakMap, WeakMap)
2495 VALUE_IS_SPECIFIC_TYPE(WeakSet, WeakSet)
2496 
2497 #undef VALUE_IS_SPECIFIC_TYPE
2498 
2499 
2500 bool Value::IsBoolean() const {
2501  return Utils::OpenHandle(this)->IsBoolean();
2502 }
2503 
2504 
2505 bool Value::IsExternal() const {
2506  return Utils::OpenHandle(this)->IsExternal();
2507 }
2508 
2509 
2510 bool Value::IsInt32() const {
2512  if (obj->IsSmi()) return true;
2513  if (obj->IsNumber()) {
2514  return i::IsInt32Double(obj->Number());
2515  }
2516  return false;
2517 }
2518 
2519 
2520 bool Value::IsUint32() const {
2522  if (obj->IsSmi()) return i::Smi::cast(*obj)->value() >= 0;
2523  if (obj->IsNumber()) {
2524  double value = obj->Number();
2525  return !i::IsMinusZero(value) &&
2526  value >= 0 &&
2527  value <= i::kMaxUInt32 &&
2528  value == i::FastUI2D(i::FastD2UI(value));
2529  }
2530  return false;
2531 }
2532 
2533 
2534 static bool CheckConstructor(i::Isolate* isolate,
2536  const char* class_name) {
2537  i::Handle<i::Object> constr(obj->map()->constructor(), isolate);
2538  if (!constr->IsJSFunction()) return false;
2540  return func->shared()->native() && constr.is_identical_to(
2541  i::Object::GetProperty(isolate,
2542  isolate->js_builtins_object(),
2543  class_name).ToHandleChecked());
2544 }
2545 
2546 
2547 bool Value::IsNativeError() const {
2549  if (obj->IsJSObject()) {
2550  i::Handle<i::JSObject> js_obj(i::JSObject::cast(*obj));
2551  i::Isolate* isolate = js_obj->GetIsolate();
2552  return CheckConstructor(isolate, js_obj, "$Error") ||
2553  CheckConstructor(isolate, js_obj, "$EvalError") ||
2554  CheckConstructor(isolate, js_obj, "$RangeError") ||
2555  CheckConstructor(isolate, js_obj, "$ReferenceError") ||
2556  CheckConstructor(isolate, js_obj, "$SyntaxError") ||
2557  CheckConstructor(isolate, js_obj, "$TypeError") ||
2558  CheckConstructor(isolate, js_obj, "$URIError");
2559  } else {
2560  return false;
2561  }
2562 }
2563 
2564 
2565 bool Value::IsRegExp() const {
2567  return obj->IsJSRegExp();
2568 }
2569 
2570 
2573  if (!obj->IsJSFunction()) return false;
2575  return func->shared()->is_generator();
2576 }
2577 
2578 
2580  return Utils::OpenHandle(this)->IsJSGeneratorObject();
2581 }
2582 
2583 
2587  if (obj->IsString()) {
2588  str = obj;
2589  } else {
2590  i::Isolate* isolate = i::Isolate::Current();
2591  LOG_API(isolate, "ToString");
2592  ENTER_V8(isolate);
2593  EXCEPTION_PREAMBLE(isolate);
2594  has_pending_exception = !i::Execution::ToString(
2595  isolate, obj).ToHandle(&str);
2597  }
2598  return ToApiHandle<String>(str);
2599 }
2600 
2601 
2605  if (obj->IsString()) {
2606  str = obj;
2607  } else {
2608  i::Isolate* isolate = i::Isolate::Current();
2609  LOG_API(isolate, "ToDetailString");
2610  ENTER_V8(isolate);
2611  EXCEPTION_PREAMBLE(isolate);
2612  has_pending_exception = !i::Execution::ToDetailString(
2613  isolate, obj).ToHandle(&str);
2615  }
2616  return ToApiHandle<String>(str);
2617 }
2618 
2619 
2623  if (obj->IsJSObject()) {
2624  val = obj;
2625  } else {
2626  i::Isolate* isolate = i::Isolate::Current();
2627  LOG_API(isolate, "ToObject");
2628  ENTER_V8(isolate);
2629  EXCEPTION_PREAMBLE(isolate);
2630  has_pending_exception = !i::Execution::ToObject(
2631  isolate, obj).ToHandle(&val);
2633  }
2634  return ToApiHandle<Object>(val);
2635 }
2636 
2637 
2640  if (obj->IsBoolean()) {
2641  return ToApiHandle<Boolean>(obj);
2642  } else {
2643  i::Isolate* isolate = i::Isolate::Current();
2644  LOG_API(isolate, "ToBoolean");
2645  ENTER_V8(isolate);
2646  i::Handle<i::Object> val =
2647  isolate->factory()->ToBoolean(obj->BooleanValue());
2648  return ToApiHandle<Boolean>(val);
2649  }
2650 }
2651 
2652 
2656  if (obj->IsNumber()) {
2657  num = obj;
2658  } else {
2659  i::Isolate* isolate = i::HeapObject::cast(*obj)->GetIsolate();
2660  LOG_API(isolate, "ToNumber");
2661  ENTER_V8(isolate);
2662  EXCEPTION_PREAMBLE(isolate);
2663  has_pending_exception = !i::Execution::ToNumber(
2664  isolate, obj).ToHandle(&num);
2666  }
2667  return ToApiHandle<Number>(num);
2668 }
2669 
2670 
2674  if (obj->IsSmi()) {
2675  num = obj;
2676  } else {
2677  i::Isolate* isolate = i::HeapObject::cast(*obj)->GetIsolate();
2678  LOG_API(isolate, "ToInteger");
2679  ENTER_V8(isolate);
2680  EXCEPTION_PREAMBLE(isolate);
2681  has_pending_exception = !i::Execution::ToInteger(
2682  isolate, obj).ToHandle(&num);
2684  }
2685  return ToApiHandle<Integer>(num);
2686 }
2687 
2688 
2689 void i::Internals::CheckInitializedImpl(v8::Isolate* external_isolate) {
2690  i::Isolate* isolate = reinterpret_cast<i::Isolate*>(external_isolate);
2691  Utils::ApiCheck(isolate != NULL &&
2692  isolate->IsInitialized() &&
2693  !isolate->IsDead(),
2694  "v8::internal::Internals::CheckInitialized()",
2695  "Isolate is not initialized or V8 has died");
2696 }
2697 
2698 
2701  "v8::External::Cast()",
2702  "Could not convert to external");
2703 }
2704 
2705 
2708  Utils::ApiCheck(obj->IsJSObject(),
2709  "v8::Object::Cast()",
2710  "Could not convert to object");
2711 }
2712 
2713 
2716  Utils::ApiCheck(obj->IsJSFunction(),
2717  "v8::Function::Cast()",
2718  "Could not convert to function");
2719 }
2720 
2721 
2724  Utils::ApiCheck(obj->IsName(),
2725  "v8::Name::Cast()",
2726  "Could not convert to name");
2727 }
2728 
2729 
2732  Utils::ApiCheck(obj->IsString(),
2733  "v8::String::Cast()",
2734  "Could not convert to string");
2735 }
2736 
2737 
2740  Utils::ApiCheck(obj->IsSymbol(),
2741  "v8::Symbol::Cast()",
2742  "Could not convert to symbol");
2743 }
2744 
2745 
2748  Utils::ApiCheck(obj->IsNumber(),
2749  "v8::Number::Cast()",
2750  "Could not convert to number");
2751 }
2752 
2753 
2756  Utils::ApiCheck(obj->IsNumber(),
2757  "v8::Integer::Cast()",
2758  "Could not convert to number");
2759 }
2760 
2761 
2764  Utils::ApiCheck(obj->IsJSArray(),
2765  "v8::Array::Cast()",
2766  "Could not convert to array");
2767 }
2768 
2769 
2771  Utils::ApiCheck(that->IsPromise(),
2772  "v8::Promise::Cast()",
2773  "Could not convert to promise");
2774 }
2775 
2776 
2778  Utils::ApiCheck(that->IsPromise(),
2779  "v8::Promise::Resolver::Cast()",
2780  "Could not convert to promise resolver");
2781 }
2782 
2783 
2786  Utils::ApiCheck(obj->IsJSArrayBuffer(),
2787  "v8::ArrayBuffer::Cast()",
2788  "Could not convert to ArrayBuffer");
2789 }
2790 
2791 
2794  Utils::ApiCheck(obj->IsJSArrayBufferView(),
2795  "v8::ArrayBufferView::Cast()",
2796  "Could not convert to ArrayBufferView");
2797 }
2798 
2799 
2802  Utils::ApiCheck(obj->IsJSTypedArray(),
2803  "v8::TypedArray::Cast()",
2804  "Could not convert to TypedArray");
2805 }
2806 
2807 
2808 #define CHECK_TYPED_ARRAY_CAST(Type, typeName, TYPE, ctype, size) \
2809  void v8::Type##Array::CheckCast(Value* that) { \
2810  i::Handle<i::Object> obj = Utils::OpenHandle(that); \
2811  Utils::ApiCheck(obj->IsJSTypedArray() && \
2812  i::JSTypedArray::cast(*obj)->type() == \
2813  kExternal##Type##Array, \
2814  "v8::" #Type "Array::Cast()", \
2815  "Could not convert to " #Type "Array"); \
2816  }
2817 
2818 
2820 
2821 #undef CHECK_TYPED_ARRAY_CAST
2822 
2823 
2826  Utils::ApiCheck(obj->IsJSDataView(),
2827  "v8::DataView::Cast()",
2828  "Could not convert to DataView");
2829 }
2830 
2831 
2834  i::Isolate* isolate = NULL;
2835  if (obj->IsHeapObject()) isolate = i::HeapObject::cast(*obj)->GetIsolate();
2836  Utils::ApiCheck(isolate != NULL &&
2837  obj->HasSpecificClassOf(isolate->heap()->Date_string()),
2838  "v8::Date::Cast()",
2839  "Could not convert to date");
2840 }
2841 
2842 
2845  i::Isolate* isolate = NULL;
2846  if (obj->IsHeapObject()) isolate = i::HeapObject::cast(*obj)->GetIsolate();
2847  Utils::ApiCheck(isolate != NULL &&
2848  obj->HasSpecificClassOf(isolate->heap()->String_string()),
2849  "v8::StringObject::Cast()",
2850  "Could not convert to StringObject");
2851 }
2852 
2853 
2856  i::Isolate* isolate = NULL;
2857  if (obj->IsHeapObject()) isolate = i::HeapObject::cast(*obj)->GetIsolate();
2858  Utils::ApiCheck(isolate != NULL &&
2859  obj->HasSpecificClassOf(isolate->heap()->Symbol_string()),
2860  "v8::SymbolObject::Cast()",
2861  "Could not convert to SymbolObject");
2862 }
2863 
2864 
2867  i::Isolate* isolate = NULL;
2868  if (obj->IsHeapObject()) isolate = i::HeapObject::cast(*obj)->GetIsolate();
2869  Utils::ApiCheck(isolate != NULL &&
2870  obj->HasSpecificClassOf(isolate->heap()->Number_string()),
2871  "v8::NumberObject::Cast()",
2872  "Could not convert to NumberObject");
2873 }
2874 
2875 
2878  i::Isolate* isolate = NULL;
2879  if (obj->IsHeapObject()) isolate = i::HeapObject::cast(*obj)->GetIsolate();
2880  Utils::ApiCheck(isolate != NULL &&
2881  obj->HasSpecificClassOf(isolate->heap()->Boolean_string()),
2882  "v8::BooleanObject::Cast()",
2883  "Could not convert to BooleanObject");
2884 }
2885 
2886 
2889  Utils::ApiCheck(obj->IsJSRegExp(),
2890  "v8::RegExp::Cast()",
2891  "Could not convert to regular expression");
2892 }
2893 
2894 
2895 bool Value::BooleanValue() const {
2896  return Utils::OpenHandle(this)->BooleanValue();
2897 }
2898 
2899 
2900 double Value::NumberValue() const {
2903  if (obj->IsNumber()) {
2904  num = obj;
2905  } else {
2906  i::Isolate* isolate = i::HeapObject::cast(*obj)->GetIsolate();
2907  LOG_API(isolate, "NumberValue");
2908  ENTER_V8(isolate);
2909  EXCEPTION_PREAMBLE(isolate);
2910  has_pending_exception = !i::Execution::ToNumber(
2911  isolate, obj).ToHandle(&num);
2913  }
2914  return num->Number();
2915 }
2916 
2917 
2918 int64_t Value::IntegerValue() const {
2921  if (obj->IsNumber()) {
2922  num = obj;
2923  } else {
2924  i::Isolate* isolate = i::HeapObject::cast(*obj)->GetIsolate();
2925  LOG_API(isolate, "IntegerValue");
2926  ENTER_V8(isolate);
2927  EXCEPTION_PREAMBLE(isolate);
2928  has_pending_exception = !i::Execution::ToInteger(
2929  isolate, obj).ToHandle(&num);
2930  EXCEPTION_BAILOUT_CHECK(isolate, 0);
2931  }
2932  if (num->IsSmi()) {
2933  return i::Smi::cast(*num)->value();
2934  } else {
2935  return static_cast<int64_t>(num->Number());
2936  }
2937 }
2938 
2939 
2943  if (obj->IsSmi()) {
2944  num = obj;
2945  } else {
2946  i::Isolate* isolate = i::HeapObject::cast(*obj)->GetIsolate();
2947  LOG_API(isolate, "ToInt32");
2948  ENTER_V8(isolate);
2949  EXCEPTION_PREAMBLE(isolate);
2950  has_pending_exception = !i::Execution::ToInt32(isolate, obj).ToHandle(&num);
2952  }
2953  return ToApiHandle<Int32>(num);
2954 }
2955 
2956 
2960  if (obj->IsSmi()) {
2961  num = obj;
2962  } else {
2963  i::Isolate* isolate = i::HeapObject::cast(*obj)->GetIsolate();
2964  LOG_API(isolate, "ToUInt32");
2965  ENTER_V8(isolate);
2966  EXCEPTION_PREAMBLE(isolate);
2967  has_pending_exception = !i::Execution::ToUint32(
2968  isolate, obj).ToHandle(&num);
2970  }
2971  return ToApiHandle<Uint32>(num);
2972 }
2973 
2974 
2977  if (obj->IsSmi()) {
2978  if (i::Smi::cast(*obj)->value() >= 0) return Utils::Uint32ToLocal(obj);
2979  return Local<Uint32>();
2980  }
2981  i::Isolate* isolate = i::HeapObject::cast(*obj)->GetIsolate();
2982  LOG_API(isolate, "ToArrayIndex");
2983  ENTER_V8(isolate);
2984  EXCEPTION_PREAMBLE(isolate);
2985  i::Handle<i::Object> string_obj;
2986  has_pending_exception = !i::Execution::ToString(
2987  isolate, obj).ToHandle(&string_obj);
2990  uint32_t index;
2991  if (str->AsArrayIndex(&index)) {
2992  i::Handle<i::Object> value;
2993  if (index <= static_cast<uint32_t>(i::Smi::kMaxValue)) {
2994  value = i::Handle<i::Object>(i::Smi::FromInt(index), isolate);
2995  } else {
2996  value = isolate->factory()->NewNumber(index);
2997  }
2998  return Utils::Uint32ToLocal(value);
2999  }
3000  return Local<Uint32>();
3001 }
3002 
3003 
3006  if (obj->IsSmi()) {
3007  return i::Smi::cast(*obj)->value();
3008  } else {
3009  i::Isolate* isolate = i::HeapObject::cast(*obj)->GetIsolate();
3010  LOG_API(isolate, "Int32Value (slow)");
3011  ENTER_V8(isolate);
3012  EXCEPTION_PREAMBLE(isolate);
3014  has_pending_exception = !i::Execution::ToInt32(isolate, obj).ToHandle(&num);
3015  EXCEPTION_BAILOUT_CHECK(isolate, 0);
3016  if (num->IsSmi()) {
3017  return i::Smi::cast(*num)->value();
3018  } else {
3019  return static_cast<int32_t>(num->Number());
3020  }
3021  }
3022 }
3023 
3024 
3025 bool Value::Equals(Handle<Value> that) const {
3026  i::Isolate* isolate = i::Isolate::Current();
3027  i::Handle<i::Object> obj = Utils::OpenHandle(this, true);
3028  if (!Utils::ApiCheck(!obj.is_null() && !that.IsEmpty(),
3029  "v8::Value::Equals()",
3030  "Reading from empty handle")) {
3031  return false;
3032  }
3033  LOG_API(isolate, "Equals");
3034  ENTER_V8(isolate);
3035  i::Handle<i::Object> other = Utils::OpenHandle(*that);
3036  // If both obj and other are JSObjects, we'd better compare by identity
3037  // immediately when going into JS builtin. The reason is Invoke
3038  // would overwrite global object receiver with global proxy.
3039  if (obj->IsJSObject() && other->IsJSObject()) {
3040  return *obj == *other;
3041  }
3042  i::Handle<i::Object> args[] = { other };
3043  EXCEPTION_PREAMBLE(isolate);
3044  i::Handle<i::Object> result;
3045  has_pending_exception = !CallV8HeapFunction(
3046  "EQUALS", obj, arraysize(args), args).ToHandle(&result);
3047  EXCEPTION_BAILOUT_CHECK(isolate, false);
3048  return *result == i::Smi::FromInt(i::EQUAL);
3049 }
3050 
3051 
3053  i::Isolate* isolate = i::Isolate::Current();
3054  i::Handle<i::Object> obj = Utils::OpenHandle(this, true);
3055  if (!Utils::ApiCheck(!obj.is_null() && !that.IsEmpty(),
3056  "v8::Value::StrictEquals()",
3057  "Reading from empty handle")) {
3058  return false;
3059  }
3060  LOG_API(isolate, "StrictEquals");
3061  i::Handle<i::Object> other = Utils::OpenHandle(*that);
3062  // Must check HeapNumber first, since NaN !== NaN.
3063  if (obj->IsHeapNumber()) {
3064  if (!other->IsNumber()) return false;
3065  double x = obj->Number();
3066  double y = other->Number();
3067  // Must check explicitly for NaN:s on Windows, but -0 works fine.
3068  return x == y && !std::isnan(x) && !std::isnan(y);
3069  } else if (*obj == *other) { // Also covers Booleans.
3070  return true;
3071  } else if (obj->IsSmi()) {
3072  return other->IsNumber() && obj->Number() == other->Number();
3073  } else if (obj->IsString()) {
3074  return other->IsString() &&
3077  } else if (obj->IsUndefined() || obj->IsUndetectableObject()) {
3078  return other->IsUndefined() || other->IsUndetectableObject();
3079  } else {
3080  return false;
3081  }
3082 }
3083 
3084 
3086  i::Handle<i::Object> obj = Utils::OpenHandle(this, true);
3087  if (!Utils::ApiCheck(!obj.is_null() && !that.IsEmpty(),
3088  "v8::Value::SameValue()",
3089  "Reading from empty handle")) {
3090  return false;
3091  }
3092  i::Handle<i::Object> other = Utils::OpenHandle(*that);
3093  return obj->SameValue(*other);
3094 }
3095 
3096 
3099  if (obj->IsSmi()) {
3100  return i::Smi::cast(*obj)->value();
3101  } else {
3102  i::Isolate* isolate = i::HeapObject::cast(*obj)->GetIsolate();
3103  LOG_API(isolate, "Uint32Value");
3104  ENTER_V8(isolate);
3105  EXCEPTION_PREAMBLE(isolate);
3107  has_pending_exception = !i::Execution::ToUint32(
3108  isolate, obj).ToHandle(&num);
3109  EXCEPTION_BAILOUT_CHECK(isolate, 0);
3110  if (num->IsSmi()) {
3111  return i::Smi::cast(*num)->value();
3112  } else {
3113  return static_cast<uint32_t>(num->Number());
3114  }
3115  }
3116 }
3117 
3118 
3120  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3121  ON_BAILOUT(isolate, "v8::Object::Set()", return false);
3122  ENTER_V8(isolate);
3123  i::HandleScope scope(isolate);
3125  i::Handle<i::Object> key_obj = Utils::OpenHandle(*key);
3126  i::Handle<i::Object> value_obj = Utils::OpenHandle(*value);
3127  EXCEPTION_PREAMBLE(isolate);
3128  has_pending_exception =
3129  i::Runtime::SetObjectProperty(isolate, self, key_obj, value_obj,
3130  i::SLOPPY).is_null();
3131  EXCEPTION_BAILOUT_CHECK(isolate, false);
3132  return true;
3133 }
3134 
3135 
3137  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3138  ON_BAILOUT(isolate, "v8::Object::Set()", return false);
3139  ENTER_V8(isolate);
3140  i::HandleScope scope(isolate);
3142  i::Handle<i::Object> value_obj = Utils::OpenHandle(*value);
3143  EXCEPTION_PREAMBLE(isolate);
3144  has_pending_exception = i::JSObject::SetElement(
3145  self, index, value_obj, NONE, i::SLOPPY).is_null();
3146  EXCEPTION_BAILOUT_CHECK(isolate, false);
3147  return true;
3148 }
3149 
3150 
3152  v8::Handle<Value> value,
3153  v8::PropertyAttribute attribs) {
3154  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3155  ON_BAILOUT(isolate, "v8::Object::ForceSet()", return false);
3156  ENTER_V8(isolate);
3157  i::HandleScope scope(isolate);
3159  i::Handle<i::Object> key_obj = Utils::OpenHandle(*key);
3160  i::Handle<i::Object> value_obj = Utils::OpenHandle(*value);
3161  EXCEPTION_PREAMBLE(isolate);
3162  has_pending_exception = i::Runtime::DefineObjectProperty(
3163  self,
3164  key_obj,
3165  value_obj,
3166  static_cast<PropertyAttributes>(attribs)).is_null();
3167  EXCEPTION_BAILOUT_CHECK(isolate, false);
3168  return true;
3169 }
3170 
3171 
3173  return ForceSet(v8::Handle<Value>(reinterpret_cast<Value*>(*key)),
3174  value, DontEnum);
3175 }
3176 
3177 
3179  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3180  ON_BAILOUT(isolate, "v8::Object::ForceDelete()", return false);
3181  ENTER_V8(isolate);
3182  i::HandleScope scope(isolate);
3184  i::Handle<i::Object> key_obj = Utils::OpenHandle(*key);
3185 
3186  // When deleting a property on the global object using ForceDelete
3187  // deoptimize all functions as optimized code does not check for the hole
3188  // value with DontDelete properties. We have to deoptimize all contexts
3189  // because of possible cross-context inlined functions.
3190  if (self->IsJSGlobalProxy() || self->IsGlobalObject()) {
3192  }
3193 
3194  EXCEPTION_PREAMBLE(isolate);
3196  has_pending_exception = !i::Runtime::DeleteObjectProperty(
3197  isolate, self, key_obj, i::JSReceiver::FORCE_DELETION).ToHandle(&obj);
3198  EXCEPTION_BAILOUT_CHECK(isolate, false);
3199  return obj->IsTrue();
3200 }
3201 
3202 
3204  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3205  ON_BAILOUT(isolate, "v8::Object::Get()", return Local<v8::Value>());
3206  ENTER_V8(isolate);
3208  i::Handle<i::Object> key_obj = Utils::OpenHandle(*key);
3209  EXCEPTION_PREAMBLE(isolate);
3210  i::Handle<i::Object> result;
3211  has_pending_exception =
3212  !i::Runtime::GetObjectProperty(isolate, self, key_obj).ToHandle(&result);
3214  return Utils::ToLocal(result);
3215 }
3216 
3217 
3219  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3220  ON_BAILOUT(isolate, "v8::Object::Get()", return Local<v8::Value>());
3221  ENTER_V8(isolate);
3223  EXCEPTION_PREAMBLE(isolate);
3224  i::Handle<i::Object> result;
3225  has_pending_exception =
3226  !i::Object::GetElement(isolate, self, index).ToHandle(&result);
3228  return Utils::ToLocal(result);
3229 }
3230 
3231 
3233  return Get(v8::Handle<Value>(reinterpret_cast<Value*>(*key)));
3234 }
3235 
3236 
3238  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3239  ON_BAILOUT(isolate, "v8::Object::GetPropertyAttributes()",
3240  return static_cast<PropertyAttribute>(NONE));
3241  ENTER_V8(isolate);
3242  i::HandleScope scope(isolate);
3244  i::Handle<i::Object> key_obj = Utils::OpenHandle(*key);
3245  if (!key_obj->IsName()) {
3246  EXCEPTION_PREAMBLE(isolate);
3247  has_pending_exception = !i::Execution::ToString(
3248  isolate, key_obj).ToHandle(&key_obj);
3249  EXCEPTION_BAILOUT_CHECK(isolate, static_cast<PropertyAttribute>(NONE));
3250  }
3251  i::Handle<i::Name> key_name = i::Handle<i::Name>::cast(key_obj);
3252  EXCEPTION_PREAMBLE(isolate);
3253  Maybe<PropertyAttributes> result =
3254  i::JSReceiver::GetPropertyAttributes(self, key_name);
3255  has_pending_exception = !result.has_value;
3256  EXCEPTION_BAILOUT_CHECK(isolate, static_cast<PropertyAttribute>(NONE));
3257  if (result.value == ABSENT) return static_cast<PropertyAttribute>(NONE);
3258  return static_cast<PropertyAttribute>(result.value);
3259 }
3260 
3261 
3263  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3264  ON_BAILOUT(isolate, "v8::Object::GetOwnPropertyDescriptor()",
3265  return Local<Value>());
3266  ENTER_V8(isolate);
3268  i::Handle<i::Name> key_name = Utils::OpenHandle(*key);
3269  i::Handle<i::Object> args[] = { obj, key_name };
3270  EXCEPTION_PREAMBLE(isolate);
3271  i::Handle<i::Object> result;
3272  has_pending_exception = !CallV8HeapFunction(
3273  "ObjectGetOwnPropertyDescriptor",
3274  isolate->factory()->undefined_value(),
3275  arraysize(args),
3276  args).ToHandle(&result);
3278  return Utils::ToLocal(result);
3279 }
3280 
3281 
3283  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3284  ON_BAILOUT(isolate, "v8::Object::GetPrototype()", return Local<v8::Value>());
3285  ENTER_V8(isolate);
3287  i::PrototypeIterator iter(isolate, self);
3289 }
3290 
3291 
3293  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3294  ON_BAILOUT(isolate, "v8::Object::SetPrototype()", return false);
3295  ENTER_V8(isolate);
3297  i::Handle<i::Object> value_obj = Utils::OpenHandle(*value);
3298  // We do not allow exceptions thrown while setting the prototype
3299  // to propagate outside.
3300  TryCatch try_catch;
3301  EXCEPTION_PREAMBLE(isolate);
3302  i::MaybeHandle<i::Object> result =
3303  i::JSObject::SetPrototype(self, value_obj, false);
3304  has_pending_exception = result.is_null();
3305  EXCEPTION_BAILOUT_CHECK(isolate, false);
3306  return true;
3307 }
3308 
3309 
3312  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3313  ON_BAILOUT(isolate,
3314  "v8::Object::FindInstanceInPrototypeChain()",
3315  return Local<v8::Object>());
3316  ENTER_V8(isolate);
3317  i::PrototypeIterator iter(isolate, *Utils::OpenHandle(this),
3319  i::FunctionTemplateInfo* tmpl_info = *Utils::OpenHandle(*tmpl);
3320  while (!tmpl_info->IsTemplateFor(iter.GetCurrent())) {
3321  iter.Advance();
3322  if (iter.IsAtEnd()) {
3323  return Local<Object>();
3324  }
3325  }
3326  return Utils::ToLocal(
3327  i::handle(i::JSObject::cast(iter.GetCurrent()), isolate));
3328 }
3329 
3330 
3332  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3333  ON_BAILOUT(isolate, "v8::Object::GetPropertyNames()",
3334  return Local<v8::Array>());
3335  ENTER_V8(isolate);
3336  i::HandleScope scope(isolate);
3338  EXCEPTION_PREAMBLE(isolate);
3340  has_pending_exception = !i::JSReceiver::GetKeys(
3341  self, i::JSReceiver::INCLUDE_PROTOS).ToHandle(&value);
3343  // Because we use caching to speed up enumeration it is important
3344  // to never change the result of the basic enumeration function so
3345  // we clone the result.
3346  i::Handle<i::FixedArray> elms = isolate->factory()->CopyFixedArray(value);
3347  i::Handle<i::JSArray> result =
3348  isolate->factory()->NewJSArrayWithElements(elms);
3349  return Utils::ToLocal(scope.CloseAndEscape(result));
3350 }
3351 
3352 
3354  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3355  ON_BAILOUT(isolate, "v8::Object::GetOwnPropertyNames()",
3356  return Local<v8::Array>());
3357  ENTER_V8(isolate);
3358  i::HandleScope scope(isolate);
3360  EXCEPTION_PREAMBLE(isolate);
3362  has_pending_exception = !i::JSReceiver::GetKeys(
3363  self, i::JSReceiver::OWN_ONLY).ToHandle(&value);
3365  // Because we use caching to speed up enumeration it is important
3366  // to never change the result of the basic enumeration function so
3367  // we clone the result.
3368  i::Handle<i::FixedArray> elms = isolate->factory()->CopyFixedArray(value);
3369  i::Handle<i::JSArray> result =
3370  isolate->factory()->NewJSArrayWithElements(elms);
3371  return Utils::ToLocal(scope.CloseAndEscape(result));
3372 }
3373 
3374 
3376  i::Isolate* i_isolate = Utils::OpenHandle(this)->GetIsolate();
3377  Isolate* isolate = reinterpret_cast<Isolate*>(i_isolate);
3378  ON_BAILOUT(i_isolate, "v8::Object::ObjectProtoToString()",
3379  return Local<v8::String>());
3380  ENTER_V8(i_isolate);
3382 
3383  i::Handle<i::Object> name(self->class_name(), i_isolate);
3384 
3385  // Native implementation of Object.prototype.toString (v8natives.js):
3386  // var c = %_ClassOf(this);
3387  // if (c === 'Arguments') c = 'Object';
3388  // return "[object " + c + "]";
3389 
3390  if (!name->IsString()) {
3391  return v8::String::NewFromUtf8(isolate, "[object ]");
3392  } else {
3394  if (i::String::Equals(class_name,
3395  i_isolate->factory()->Arguments_string())) {
3396  return v8::String::NewFromUtf8(isolate, "[object Object]");
3397  } else {
3398  const char* prefix = "[object ";
3399  Local<String> str = Utils::ToLocal(class_name);
3400  const char* postfix = "]";
3401 
3402  int prefix_len = i::StrLength(prefix);
3403  int str_len = str->Utf8Length();
3404  int postfix_len = i::StrLength(postfix);
3405 
3406  int buf_len = prefix_len + str_len + postfix_len;
3407  i::ScopedVector<char> buf(buf_len);
3408 
3409  // Write prefix.
3410  char* ptr = buf.start();
3411  i::MemCopy(ptr, prefix, prefix_len * v8::internal::kCharSize);
3412  ptr += prefix_len;
3413 
3414  // Write real content.
3415  str->WriteUtf8(ptr, str_len);
3416  ptr += str_len;
3417 
3418  // Write postfix.
3419  i::MemCopy(ptr, postfix, postfix_len * v8::internal::kCharSize);
3420 
3421  // Copy the buffer into a heap-allocated string and return it.
3423  isolate, buf.start(), String::kNormalString, buf_len);
3424  return result;
3425  }
3426  }
3427 }
3428 
3429 
3431  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3432  ON_BAILOUT(isolate, "v8::Object::GetConstructorName()",
3433  return Local<v8::String>());
3434  ENTER_V8(isolate);
3436  i::Handle<i::String> name(self->constructor_name());
3437  return Utils::ToLocal(name);
3438 }
3439 
3440 
3442  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3443  ON_BAILOUT(isolate, "v8::Object::Delete()", return false);
3444  ENTER_V8(isolate);
3445  i::HandleScope scope(isolate);
3447  i::Handle<i::Object> key_obj = Utils::OpenHandle(*key);
3448  EXCEPTION_PREAMBLE(isolate);
3450  has_pending_exception = !i::Runtime::DeleteObjectProperty(
3451  isolate, self, key_obj, i::JSReceiver::NORMAL_DELETION).ToHandle(&obj);
3452  EXCEPTION_BAILOUT_CHECK(isolate, false);
3453  return obj->IsTrue();
3454 }
3455 
3456 
3458  return Delete(v8::Handle<Value>(reinterpret_cast<Value*>(*key)));
3459 }
3460 
3461 
3463  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3464  ON_BAILOUT(isolate, "v8::Object::Has()", return false);
3465  ENTER_V8(isolate);
3467  i::Handle<i::Object> key_obj = Utils::OpenHandle(*key);
3468  EXCEPTION_PREAMBLE(isolate);
3470  has_pending_exception = !i::Runtime::HasObjectProperty(
3471  isolate, self, key_obj).ToHandle(&obj);
3472  EXCEPTION_BAILOUT_CHECK(isolate, false);
3473  return obj->IsTrue();
3474 }
3475 
3476 
3478  // TODO(rossberg): this should use HasOwnProperty, but we'd need to
3479  // generalise that to a (noy yet existant) Name argument first.
3480  return Has(v8::Handle<Value>(reinterpret_cast<Value*>(*key)));
3481 }
3482 
3483 
3485  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3486  ON_BAILOUT(isolate, "v8::Object::DeleteProperty()",
3487  return false);
3488  ENTER_V8(isolate);
3489  HandleScope scope(reinterpret_cast<Isolate*>(isolate));
3491 
3492  EXCEPTION_PREAMBLE(isolate);
3494  has_pending_exception =
3495  !i::JSReceiver::DeleteElement(self, index).ToHandle(&obj);
3496  EXCEPTION_BAILOUT_CHECK(isolate, false);
3497  return obj->IsTrue();
3498 }
3499 
3500 
3502  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3503  ON_BAILOUT(isolate, "v8::Object::HasProperty()", return false);
3505  EXCEPTION_PREAMBLE(isolate);
3507  has_pending_exception = !maybe.has_value;
3508  EXCEPTION_BAILOUT_CHECK(isolate, false);
3509  return maybe.value;
3510 }
3511 
3512 
3513 template<typename Getter, typename Setter, typename Data>
3514 static inline bool ObjectSetAccessor(Object* obj,
3516  Getter getter,
3517  Setter setter,
3518  Data data,
3519  AccessControl settings,
3520  PropertyAttribute attributes) {
3521  i::Isolate* isolate = Utils::OpenHandle(obj)->GetIsolate();
3522  ON_BAILOUT(isolate, "v8::Object::SetAccessor()", return false);
3523  ENTER_V8(isolate);
3524  i::HandleScope scope(isolate);
3527  name, getter, setter, data, settings, attributes, signature);
3528  if (info.is_null()) return false;
3529  bool fast = Utils::OpenHandle(obj)->HasFastProperties();
3530  i::Handle<i::Object> result;
3532  isolate, result,
3534  false);
3535  if (result->IsUndefined()) return false;
3537  return true;
3538 }
3539 
3540 
3542  AccessorGetterCallback getter,
3543  AccessorSetterCallback setter,
3544  v8::Handle<Value> data,
3545  AccessControl settings,
3546  PropertyAttribute attributes) {
3547  return ObjectSetAccessor(
3548  this, name, getter, setter, data, settings, attributes);
3549 }
3550 
3551 
3555  v8::Handle<Value> data,
3556  AccessControl settings,
3557  PropertyAttribute attributes) {
3558  return ObjectSetAccessor(
3559  this, name, getter, setter, data, settings, attributes);
3560 }
3561 
3562 
3565  PropertyAttribute attributes,
3566  AccessControl settings) {
3567  void* null = NULL;
3568  return ObjectSetAccessor(
3569  this, name, descriptor, null, null, settings, attributes);
3570 }
3571 
3572 
3574  Local<Function> getter,
3575  Handle<Function> setter,
3576  PropertyAttribute attribute,
3577  AccessControl settings) {
3578  // TODO(verwaest): Remove |settings|.
3579  DCHECK_EQ(v8::DEFAULT, settings);
3580  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3581  ON_BAILOUT(isolate, "v8::Object::SetAccessorProperty()", return);
3582  ENTER_V8(isolate);
3583  i::HandleScope scope(isolate);
3584  i::Handle<i::Object> getter_i = v8::Utils::OpenHandle(*getter);
3585  i::Handle<i::Object> setter_i = v8::Utils::OpenHandle(*setter, true);
3586  if (setter_i.is_null()) setter_i = isolate->factory()->null_value();
3589  getter_i,
3590  setter_i,
3591  static_cast<PropertyAttributes>(attribute));
3592 }
3593 
3594 
3596  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3597  ON_BAILOUT(isolate, "v8::Object::HasOwnProperty()",
3598  return false);
3599  EXCEPTION_PREAMBLE(isolate);
3601  Utils::OpenHandle(*key));
3602  has_pending_exception = !maybe.has_value;
3603  EXCEPTION_BAILOUT_CHECK(isolate, false);
3604  return maybe.value;
3605 }
3606 
3607 
3609  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3610  ON_BAILOUT(isolate, "v8::Object::HasRealNamedProperty()",
3611  return false);
3612  EXCEPTION_PREAMBLE(isolate);
3614  Utils::OpenHandle(this), Utils::OpenHandle(*key));
3615  has_pending_exception = !maybe.has_value;
3616  EXCEPTION_BAILOUT_CHECK(isolate, false);
3617  return maybe.value;
3618 }
3619 
3620 
3622  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3623  ON_BAILOUT(isolate, "v8::Object::HasRealIndexedProperty()",
3624  return false);
3625  EXCEPTION_PREAMBLE(isolate);
3626  Maybe<bool> maybe =
3628  has_pending_exception = !maybe.has_value;
3629  EXCEPTION_BAILOUT_CHECK(isolate, false);
3630  return maybe.value;
3631 }
3632 
3633 
3635  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3636  ON_BAILOUT(isolate,
3637  "v8::Object::HasRealNamedCallbackProperty()",
3638  return false);
3639  ENTER_V8(isolate);
3640  EXCEPTION_PREAMBLE(isolate);
3642  Utils::OpenHandle(this), Utils::OpenHandle(*key));
3643  has_pending_exception = !maybe.has_value;
3644  EXCEPTION_BAILOUT_CHECK(isolate, false);
3645  return maybe.value;
3646 }
3647 
3648 
3650  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3651  ON_BAILOUT(isolate, "v8::Object::HasNamedLookupInterceptor()",
3652  return false);
3653  return Utils::OpenHandle(this)->HasNamedInterceptor();
3654 }
3655 
3656 
3658  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3659  ON_BAILOUT(isolate, "v8::Object::HasIndexedLookupInterceptor()",
3660  return false);
3661  return Utils::OpenHandle(this)->HasIndexedInterceptor();
3662 }
3663 
3664 
3665 static Local<Value> GetPropertyByLookup(i::LookupIterator* it) {
3666  // If the property being looked up is a callback, it can throw an exception.
3667  EXCEPTION_PREAMBLE(it->isolate());
3668  i::Handle<i::Object> result;
3669  has_pending_exception = !i::Object::GetProperty(it).ToHandle(&result);
3670  EXCEPTION_BAILOUT_CHECK(it->isolate(), Local<Value>());
3671 
3672  if (it->IsFound()) return Utils::ToLocal(result);
3673  return Local<Value>();
3674 }
3675 
3676 
3678  Handle<String> key) {
3679  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3680  ON_BAILOUT(isolate,
3681  "v8::Object::GetRealNamedPropertyInPrototypeChain()",
3682  return Local<Value>());
3683  ENTER_V8(isolate);
3684  i::Handle<i::JSObject> self_obj = Utils::OpenHandle(this);
3685  i::Handle<i::String> key_obj = Utils::OpenHandle(*key);
3686  i::PrototypeIterator iter(isolate, self_obj);
3687  if (iter.IsAtEnd()) return Local<Value>();
3689  i::LookupIterator it(self_obj, key_obj, i::Handle<i::JSReceiver>::cast(proto),
3690  i::LookupIterator::PROTOTYPE_CHAIN_SKIP_INTERCEPTOR);
3691  return GetPropertyByLookup(&it);
3692 }
3693 
3694 
3696  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3697  ON_BAILOUT(isolate, "v8::Object::GetRealNamedProperty()",
3698  return Local<Value>());
3699  ENTER_V8(isolate);
3700  i::Handle<i::JSObject> self_obj = Utils::OpenHandle(this);
3701  i::Handle<i::String> key_obj = Utils::OpenHandle(*key);
3702  i::LookupIterator it(self_obj, key_obj,
3703  i::LookupIterator::PROTOTYPE_CHAIN_SKIP_INTERCEPTOR);
3704  return GetPropertyByLookup(&it);
3705 }
3706 
3707 
3708 // Turns on access checks by copying the map and setting the check flag.
3709 // Because the object gets a new map, existing inline cache caching
3710 // the old map of this object will fail.
3712  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3713  ON_BAILOUT(isolate, "v8::Object::TurnOnAccessCheck()", return);
3714  ENTER_V8(isolate);
3715  i::HandleScope scope(isolate);
3717 
3718  // When turning on access checks for a global object deoptimize all functions
3719  // as optimized code does not always handle access checks.
3721 
3722  i::Handle<i::Map> new_map = i::Map::Copy(i::Handle<i::Map>(obj->map()));
3723  new_map->set_is_access_check_needed(true);
3724  i::JSObject::MigrateToMap(obj, new_map);
3725 }
3726 
3727 
3729  return Utils::OpenHandle(this)->IsDirty();
3730 }
3731 
3732 
3734  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3735  ON_BAILOUT(isolate, "v8::Object::Clone()", return Local<Object>());
3736  ENTER_V8(isolate);
3738  EXCEPTION_PREAMBLE(isolate);
3739  i::Handle<i::JSObject> result = isolate->factory()->CopyJSObject(self);
3740  has_pending_exception = result.is_null();
3742  return Utils::ToLocal(result);
3743 }
3744 
3745 
3747  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3748  ON_BAILOUT(isolate,
3749  "v8::Object::CreationContext()", return Local<v8::Context>());
3750  ENTER_V8(isolate);
3752  i::Context* context = self->GetCreationContext();
3753  return Utils::ToLocal(i::Handle<i::Context>(context));
3754 }
3755 
3756 
3758  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3759  ON_BAILOUT(isolate, "v8::Object::GetIdentityHash()", return 0);
3760  ENTER_V8(isolate);
3761  i::HandleScope scope(isolate);
3763  return i::JSReceiver::GetOrCreateIdentityHash(self)->value();
3764 }
3765 
3766 
3768  v8::Handle<v8::Value> value) {
3769  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3770  ON_BAILOUT(isolate, "v8::Object::SetHiddenValue()", return false);
3771  if (value.IsEmpty()) return DeleteHiddenValue(key);
3772  ENTER_V8(isolate);
3773  i::HandleScope scope(isolate);
3775  i::Handle<i::String> key_obj = Utils::OpenHandle(*key);
3776  i::Handle<i::String> key_string =
3777  isolate->factory()->InternalizeString(key_obj);
3778  i::Handle<i::Object> value_obj = Utils::OpenHandle(*value);
3779  i::Handle<i::Object> result =
3780  i::JSObject::SetHiddenProperty(self, key_string, value_obj);
3781  return *result == *self;
3782 }
3783 
3784 
3786  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3787  ON_BAILOUT(isolate, "v8::Object::GetHiddenValue()",
3788  return Local<v8::Value>());
3789  ENTER_V8(isolate);
3791  i::Handle<i::String> key_obj = Utils::OpenHandle(*key);
3792  i::Handle<i::String> key_string =
3793  isolate->factory()->InternalizeString(key_obj);
3794  i::Handle<i::Object> result(self->GetHiddenProperty(key_string), isolate);
3795  if (result->IsTheHole()) return v8::Local<v8::Value>();
3796  return Utils::ToLocal(result);
3797 }
3798 
3799 
3801  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3802  ON_BAILOUT(isolate, "v8::DeleteHiddenValue()", return false);
3803  ENTER_V8(isolate);
3804  i::HandleScope scope(isolate);
3806  i::Handle<i::String> key_obj = Utils::OpenHandle(*key);
3807  i::Handle<i::String> key_string =
3808  isolate->factory()->InternalizeString(key_obj);
3809  i::JSObject::DeleteHiddenProperty(self, key_string);
3810  return true;
3811 }
3812 
3813 
3814 namespace {
3815 
3817  ExternalArrayType array_type) {
3818  switch (array_type) {
3819 #define ARRAY_TYPE_TO_ELEMENTS_KIND(Type, type, TYPE, ctype, size) \
3820  case kExternal##Type##Array: \
3821  return i::EXTERNAL_##TYPE##_ELEMENTS;
3822 
3824 #undef ARRAY_TYPE_TO_ELEMENTS_KIND
3825  }
3826  UNREACHABLE();
3827  return i::DICTIONARY_ELEMENTS;
3828 }
3829 
3830 
3832  void* data,
3833  ExternalArrayType array_type,
3834  int length) {
3835  i::Isolate* isolate = object->GetIsolate();
3837  isolate->factory()->NewExternalArray(length, array_type, data);
3838 
3839  i::Handle<i::Map> external_array_map =
3841  object,
3843 
3844  i::JSObject::SetMapAndElements(object, external_array_map, array);
3845 }
3846 
3847 } // namespace
3848 
3849 
3850 void v8::Object::SetIndexedPropertiesToPixelData(uint8_t* data, int length) {
3851  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3852  ON_BAILOUT(isolate, "v8::SetElementsToPixelData()", return);
3853  ENTER_V8(isolate);
3854  i::HandleScope scope(isolate);
3855  if (!Utils::ApiCheck(length >= 0 &&
3856  length <= i::ExternalUint8ClampedArray::kMaxLength,
3857  "v8::Object::SetIndexedPropertiesToPixelData()",
3858  "length exceeds max acceptable value")) {
3859  return;
3860  }
3862  if (!Utils::ApiCheck(!self->IsJSArray(),
3863  "v8::Object::SetIndexedPropertiesToPixelData()",
3864  "JSArray is not supported")) {
3865  return;
3866  }
3868 }
3869 
3870 
3873  ON_BAILOUT(self->GetIsolate(), "v8::HasIndexedPropertiesInPixelData()",
3874  return false);
3875  return self->HasExternalUint8ClampedElements();
3876 }
3877 
3878 
3881  ON_BAILOUT(self->GetIsolate(), "v8::GetIndexedPropertiesPixelData()",
3882  return NULL);
3883  if (self->HasExternalUint8ClampedElements()) {
3884  return i::ExternalUint8ClampedArray::cast(self->elements())->
3885  external_uint8_clamped_pointer();
3886  } else {
3887  return NULL;
3888  }
3889 }
3890 
3891 
3894  ON_BAILOUT(self->GetIsolate(), "v8::GetIndexedPropertiesPixelDataLength()",
3895  return -1);
3896  if (self->HasExternalUint8ClampedElements()) {
3897  return i::ExternalUint8ClampedArray::cast(self->elements())->length();
3898  } else {
3899  return -1;
3900  }
3901 }
3902 
3903 
3905  void* data,
3906  ExternalArrayType array_type,
3907  int length) {
3908  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3909  ON_BAILOUT(isolate, "v8::SetIndexedPropertiesToExternalArrayData()", return);
3910  ENTER_V8(isolate);
3911  i::HandleScope scope(isolate);
3912  if (!Utils::ApiCheck(length >= 0 && length <= i::ExternalArray::kMaxLength,
3913  "v8::Object::SetIndexedPropertiesToExternalArrayData()",
3914  "length exceeds max acceptable value")) {
3915  return;
3916  }
3918  if (!Utils::ApiCheck(!self->IsJSArray(),
3919  "v8::Object::SetIndexedPropertiesToExternalArrayData()",
3920  "JSArray is not supported")) {
3921  return;
3922  }
3923  PrepareExternalArrayElements(self, data, array_type, length);
3924 }
3925 
3926 
3929  ON_BAILOUT(self->GetIsolate(),
3930  "v8::HasIndexedPropertiesInExternalArrayData()",
3931  return false);
3932  return self->HasExternalArrayElements();
3933 }
3934 
3935 
3938  ON_BAILOUT(self->GetIsolate(),
3939  "v8::GetIndexedPropertiesExternalArrayData()",
3940  return NULL);
3941  if (self->HasExternalArrayElements()) {
3942  return i::ExternalArray::cast(self->elements())->external_pointer();
3943  } else {
3944  return NULL;
3945  }
3946 }
3947 
3948 
3951  ON_BAILOUT(self->GetIsolate(),
3952  "v8::GetIndexedPropertiesExternalArrayDataType()",
3953  return static_cast<ExternalArrayType>(-1));
3954  switch (self->elements()->map()->instance_type()) {
3955 #define INSTANCE_TYPE_TO_ARRAY_TYPE(Type, type, TYPE, ctype, size) \
3956  case i::EXTERNAL_##TYPE##_ARRAY_TYPE: \
3957  return kExternal##Type##Array;
3959 #undef INSTANCE_TYPE_TO_ARRAY_TYPE
3960  default:
3961  return static_cast<ExternalArrayType>(-1);
3962  }
3963 }
3964 
3965 
3968  ON_BAILOUT(self->GetIsolate(),
3969  "v8::GetIndexedPropertiesExternalArrayDataLength()",
3970  return 0);
3971  if (self->HasExternalArrayElements()) {
3972  return i::ExternalArray::cast(self->elements())->length();
3973  } else {
3974  return -1;
3975  }
3976 }
3977 
3978 
3980  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3981  ON_BAILOUT(isolate, "v8::Object::IsCallable()", return false);
3982  ENTER_V8(isolate);
3983  i::HandleScope scope(isolate);
3985  return obj->IsCallable();
3986 }
3987 
3988 
3990  int argc,
3991  v8::Handle<v8::Value> argv[]) {
3992  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3993  ON_BAILOUT(isolate, "v8::Object::CallAsFunction()",
3994  return Local<v8::Value>());
3995  LOG_API(isolate, "Object::CallAsFunction");
3996  ENTER_V8(isolate);
3997  i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate);
3998  i::HandleScope scope(isolate);
4000  i::Handle<i::Object> recv_obj = Utils::OpenHandle(*recv);
4001  STATIC_ASSERT(sizeof(v8::Handle<v8::Value>) == sizeof(i::Object**));
4002  i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv);
4004  if (obj->IsJSFunction()) {
4005  fun = i::Handle<i::JSFunction>::cast(obj);
4006  } else {
4007  EXCEPTION_PREAMBLE(isolate);
4008  i::Handle<i::Object> delegate;
4009  has_pending_exception = !i::Execution::TryGetFunctionDelegate(
4010  isolate, obj).ToHandle(&delegate);
4012  fun = i::Handle<i::JSFunction>::cast(delegate);
4013  recv_obj = obj;
4014  }
4015  EXCEPTION_PREAMBLE(isolate);
4016  i::Handle<i::Object> returned;
4017  has_pending_exception = !i::Execution::Call(
4018  isolate, fun, recv_obj, argc, args, true).ToHandle(&returned);
4020  return Utils::ToLocal(scope.CloseAndEscape(returned));
4021 }
4022 
4023 
4025  v8::Handle<v8::Value> argv[]) {
4026  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
4027  ON_BAILOUT(isolate, "v8::Object::CallAsConstructor()",
4028  return Local<v8::Object>());
4029  LOG_API(isolate, "Object::CallAsConstructor");
4030  ENTER_V8(isolate);
4031  i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate);
4032  i::HandleScope scope(isolate);
4034  STATIC_ASSERT(sizeof(v8::Handle<v8::Value>) == sizeof(i::Object**));
4035  i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv);
4036  if (obj->IsJSFunction()) {
4038  EXCEPTION_PREAMBLE(isolate);
4039  i::Handle<i::Object> returned;
4040  has_pending_exception = !i::Execution::New(
4041  fun, argc, args).ToHandle(&returned);
4043  return Utils::ToLocal(scope.CloseAndEscape(
4044  i::Handle<i::JSObject>::cast(returned)));
4045  }
4046  EXCEPTION_PREAMBLE(isolate);
4047  i::Handle<i::Object> delegate;
4048  has_pending_exception = !i::Execution::TryGetConstructorDelegate(
4049  isolate, obj).ToHandle(&delegate);
4051  if (!delegate->IsUndefined()) {
4053  EXCEPTION_PREAMBLE(isolate);
4054  i::Handle<i::Object> returned;
4055  has_pending_exception = !i::Execution::Call(
4056  isolate, fun, obj, argc, args).ToHandle(&returned);
4058  DCHECK(!delegate->IsUndefined());
4059  return Utils::ToLocal(scope.CloseAndEscape(returned));
4060  }
4061  return Local<v8::Object>();
4062 }
4063 
4064 
4066  FunctionCallback callback,
4067  Local<Value> data,
4068  int length) {
4069  i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
4070  LOG_API(isolate, "Function::New");
4071  ENTER_V8(isolate);
4072  return FunctionTemplateNew(
4073  isolate, callback, data, Local<Signature>(), length, true)->
4074  GetFunction();
4075 }
4076 
4077 
4079  return NewInstance(0, NULL);
4080 }
4081 
4082 
4084  v8::Handle<v8::Value> argv[]) const {
4085  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
4086  ON_BAILOUT(isolate, "v8::Function::NewInstance()",
4087  return Local<v8::Object>());
4088  LOG_API(isolate, "Function::NewInstance");
4089  ENTER_V8(isolate);
4090  i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate);
4091  EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate));
4093  STATIC_ASSERT(sizeof(v8::Handle<v8::Value>) == sizeof(i::Object**));
4094  i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv);
4095  EXCEPTION_PREAMBLE(isolate);
4096  i::Handle<i::Object> returned;
4097  has_pending_exception = !i::Execution::New(
4098  function, argc, args).ToHandle(&returned);
4100  return scope.Escape(Utils::ToLocal(i::Handle<i::JSObject>::cast(returned)));
4101 }
4102 
4103 
4105  v8::Handle<v8::Value> argv[]) {
4106  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
4107  ON_BAILOUT(isolate, "v8::Function::Call()", return Local<v8::Value>());
4108  LOG_API(isolate, "Function::Call");
4109  ENTER_V8(isolate);
4110  i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate);
4111  i::HandleScope scope(isolate);
4113  i::Handle<i::Object> recv_obj = Utils::OpenHandle(*recv);
4114  STATIC_ASSERT(sizeof(v8::Handle<v8::Value>) == sizeof(i::Object**));
4115  i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv);
4116  EXCEPTION_PREAMBLE(isolate);
4117  i::Handle<i::Object> returned;
4118  has_pending_exception = !i::Execution::Call(
4119  isolate, fun, recv_obj, argc, args, true).ToHandle(&returned);
4121  return Utils::ToLocal(scope.CloseAndEscape(returned));
4122 }
4123 
4124 
4126  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
4127  ENTER_V8(isolate);
4128  USE(isolate);
4130  func->shared()->set_name(*Utils::OpenHandle(*name));
4131 }
4132 
4133 
4136  return Utils::ToLocal(i::Handle<i::Object>(func->shared()->name(),
4137  func->GetIsolate()));
4138 }
4139 
4140 
4143  return Utils::ToLocal(i::Handle<i::Object>(func->shared()->inferred_name(),
4144  func->GetIsolate()));
4145 }
4146 
4147 
4149  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
4150  ON_BAILOUT(isolate, "v8::Function::GetDisplayName()",
4151  return ToApiHandle<Primitive>(
4152  isolate->factory()->undefined_value()));
4153  ENTER_V8(isolate);
4155  i::Handle<i::String> property_name =
4156  isolate->factory()->InternalizeOneByteString(
4157  STATIC_CHAR_VECTOR("displayName"));
4158 
4159  i::Handle<i::Object> value =
4160  i::JSObject::GetDataProperty(func, property_name);
4161  if (value->IsString()) {
4163  if (name->length() > 0) return Utils::ToLocal(name);
4164  }
4165 
4166  return ToApiHandle<Primitive>(isolate->factory()->undefined_value());
4167 }
4168 
4169 
4172  if (func->shared()->script()->IsScript()) {
4173  i::Handle<i::Script> script(i::Script::cast(func->shared()->script()));
4175  v8::Isolate* isolate = reinterpret_cast<v8::Isolate*>(func->GetIsolate());
4176  v8::ScriptOrigin origin(
4177  Utils::ToLocal(scriptName),
4178  v8::Integer::New(isolate, script->line_offset()->value()),
4179  v8::Integer::New(isolate, script->column_offset()->value()));
4180  return origin;
4181  }
4182  return v8::ScriptOrigin(Handle<Value>());
4183 }
4184 
4185 
4186 const int Function::kLineOffsetNotFound = -1;
4187 
4188 
4191  if (func->shared()->script()->IsScript()) {
4192  i::Handle<i::Script> script(i::Script::cast(func->shared()->script()));
4193  return i::Script::GetLineNumber(script, func->shared()->start_position());
4194  }
4195  return kLineOffsetNotFound;
4196 }
4197 
4198 
4201  if (func->shared()->script()->IsScript()) {
4202  i::Handle<i::Script> script(i::Script::cast(func->shared()->script()));
4203  return i::Script::GetColumnNumber(script, func->shared()->start_position());
4204  }
4205  return kLineOffsetNotFound;
4206 }
4207 
4208 
4209 bool Function::IsBuiltin() const {
4211  return func->IsBuiltin();
4212 }
4213 
4214 
4215 int Function::ScriptId() const {
4217  if (!func->shared()->script()->IsScript()) {
4219  }
4220  i::Handle<i::Script> script(i::Script::cast(func->shared()->script()));
4221  return script->id()->value();
4222 }
4223 
4224 
4227  if (!func->shared()->bound()) {
4228  return v8::Undefined(reinterpret_cast<v8::Isolate*>(func->GetIsolate()));
4229  }
4231  i::FixedArray::cast(func->function_bindings()));
4232  i::Handle<i::Object> original(
4233  bound_args->get(i::JSFunction::kBoundFunctionIndex),
4234  func->GetIsolate());
4236 }
4237 
4238 
4239 int String::Length() const {
4241  return str->length();
4242 }
4243 
4244 
4245 bool String::IsOneByte() const {
4247  return str->HasOnlyOneByteChars();
4248 }
4249 
4250 
4251 // Helpers for ContainsOnlyOneByteHelper
4252 template<size_t size> struct OneByteMask;
4253 template<> struct OneByteMask<4> {
4254  static const uint32_t value = 0xFF00FF00;
4255 };
4256 template<> struct OneByteMask<8> {
4257  static const uint64_t value = V8_2PART_UINT64_C(0xFF00FF00, FF00FF00);
4258 };
4259 static const uintptr_t kOneByteMask = OneByteMask<sizeof(uintptr_t)>::value;
4260 static const uintptr_t kAlignmentMask = sizeof(uintptr_t) - 1;
4261 static inline bool Unaligned(const uint16_t* chars) {
4262  return reinterpret_cast<const uintptr_t>(chars) & kAlignmentMask;
4263 }
4264 
4265 
4266 static inline const uint16_t* Align(const uint16_t* chars) {
4267  return reinterpret_cast<uint16_t*>(
4268  reinterpret_cast<uintptr_t>(chars) & ~kAlignmentMask);
4269 }
4270 
4272  public:
4274  bool Check(i::String* string) {
4275  i::ConsString* cons_string = i::String::VisitFlat(this, string, 0);
4276  if (cons_string == NULL) return is_one_byte_;
4277  return CheckCons(cons_string);
4278  }
4279  void VisitOneByteString(const uint8_t* chars, int length) {
4280  // Nothing to do.
4281  }
4282  void VisitTwoByteString(const uint16_t* chars, int length) {
4283  // Accumulated bits.
4284  uintptr_t acc = 0;
4285  // Align to uintptr_t.
4286  const uint16_t* end = chars + length;
4287  while (Unaligned(chars) && chars != end) {
4288  acc |= *chars++;
4289  }
4290  // Read word aligned in blocks,
4291  // checking the return value at the end of each block.
4292  const uint16_t* aligned_end = Align(end);
4293  const int increment = sizeof(uintptr_t)/sizeof(uint16_t);
4294  const int inner_loops = 16;
4295  while (chars + inner_loops*increment < aligned_end) {
4296  for (int i = 0; i < inner_loops; i++) {
4297  acc |= *reinterpret_cast<const uintptr_t*>(chars);
4298  chars += increment;
4299  }
4300  // Check for early return.
4301  if ((acc & kOneByteMask) != 0) {
4302  is_one_byte_ = false;
4303  return;
4304  }
4305  }
4306  // Read the rest.
4307  while (chars != end) {
4308  acc |= *chars++;
4309  }
4310  // Check result.
4311  if ((acc & kOneByteMask) != 0) is_one_byte_ = false;
4312  }
4313 
4314  private:
4315  bool CheckCons(i::ConsString* cons_string) {
4316  while (true) {
4317  // Check left side if flat.
4318  i::String* left = cons_string->first();
4319  i::ConsString* left_as_cons =
4320  i::String::VisitFlat(this, left, 0);
4321  if (!is_one_byte_) return false;
4322  // Check right side if flat.
4323  i::String* right = cons_string->second();
4324  i::ConsString* right_as_cons =
4325  i::String::VisitFlat(this, right, 0);
4326  if (!is_one_byte_) return false;
4327  // Standard recurse/iterate trick.
4328  if (left_as_cons != NULL && right_as_cons != NULL) {
4329  if (left->length() < right->length()) {
4330  CheckCons(left_as_cons);
4331  cons_string = right_as_cons;
4332  } else {
4333  CheckCons(right_as_cons);
4334  cons_string = left_as_cons;
4335  }
4336  // Check fast return.
4337  if (!is_one_byte_) return false;
4338  continue;
4339  }
4340  // Descend left in place.
4341  if (left_as_cons != NULL) {
4342  cons_string = left_as_cons;
4343  continue;
4344  }
4345  // Descend right in place.
4346  if (right_as_cons != NULL) {
4347  cons_string = right_as_cons;
4348  continue;
4349  }
4350  // Terminate.
4351  break;
4352  }
4353  return is_one_byte_;
4354  }
4357 };
4358 
4359 
4362  if (str->HasOnlyOneByteChars()) return true;
4364  return helper.Check(*str);
4365 }
4366 
4367 
4369  public:
4370  enum State {
4376  kRightmostEdgeIsSurrogate = 1 << 5
4377  };
4378 
4379  static const uint8_t kInitialState = 0;
4380 
4381  static inline bool EndsWithSurrogate(uint8_t state) {
4382  return state & kEndsWithLeadingSurrogate;
4383  }
4384 
4385  static inline bool StartsWithSurrogate(uint8_t state) {
4386  return state & kStartsWithTrailingSurrogate;
4387  }
4388 
4389  class Visitor {
4390  public:
4392 
4393  void VisitOneByteString(const uint8_t* chars, int length) {
4394  int utf8_length = 0;
4395  // Add in length 1 for each non-Latin1 character.
4396  for (int i = 0; i < length; i++) {
4397  utf8_length += *chars++ >> 7;
4398  }
4399  // Add in length 1 for each character.
4400  utf8_length_ = utf8_length + length;
4402  }
4403 
4404  void VisitTwoByteString(const uint16_t* chars, int length) {
4405  int utf8_length = 0;
4406  int last_character = unibrow::Utf16::kNoPreviousCharacter;
4407  for (int i = 0; i < length; i++) {
4408  uint16_t c = chars[i];
4409  utf8_length += unibrow::Utf8::Length(c, last_character);
4410  last_character = c;
4411  }
4412  utf8_length_ = utf8_length;
4413  uint8_t state = 0;
4414  if (unibrow::Utf16::IsTrailSurrogate(chars[0])) {
4416  }
4417  if (unibrow::Utf16::IsLeadSurrogate(chars[length-1])) {
4418  state |= kEndsWithLeadingSurrogate;
4419  }
4420  state_ = state;
4421  }
4422 
4424  int* length,
4425  uint8_t* state) {
4426  Visitor visitor;
4427  i::ConsString* cons_string = i::String::VisitFlat(&visitor, string);
4428  *length = visitor.utf8_length_;
4429  *state = visitor.state_;
4430  return cons_string;
4431  }
4432 
4433  private:
4435  uint8_t state_;
4437  };
4438 
4439  static inline void MergeLeafLeft(int* length,
4440  uint8_t* state,
4441  uint8_t leaf_state) {
4442  bool edge_surrogate = StartsWithSurrogate(leaf_state);
4443  if (!(*state & kLeftmostEdgeIsCalculated)) {
4444  DCHECK(!(*state & kLeftmostEdgeIsSurrogate));
4445  *state |= kLeftmostEdgeIsCalculated
4446  | (edge_surrogate ? kLeftmostEdgeIsSurrogate : 0);
4447  } else if (EndsWithSurrogate(*state) && edge_surrogate) {
4449  }
4450  if (EndsWithSurrogate(leaf_state)) {
4451  *state |= kEndsWithLeadingSurrogate;
4452  } else {
4453  *state &= ~kEndsWithLeadingSurrogate;
4454  }
4455  }
4456 
4457  static inline void MergeLeafRight(int* length,
4458  uint8_t* state,
4459  uint8_t leaf_state) {
4460  bool edge_surrogate = EndsWithSurrogate(leaf_state);
4461  if (!(*state & kRightmostEdgeIsCalculated)) {
4462  DCHECK(!(*state & kRightmostEdgeIsSurrogate));
4463  *state |= (kRightmostEdgeIsCalculated
4464  | (edge_surrogate ? kRightmostEdgeIsSurrogate : 0));
4465  } else if (edge_surrogate && StartsWithSurrogate(*state)) {
4467  }
4468  if (StartsWithSurrogate(leaf_state)) {
4469  *state |= kStartsWithTrailingSurrogate;
4470  } else {
4471  *state &= ~kStartsWithTrailingSurrogate;
4472  }
4473  }
4474 
4475  static inline void MergeTerminal(int* length,
4476  uint8_t state,
4477  uint8_t* state_out) {
4478  DCHECK((state & kLeftmostEdgeIsCalculated) &&
4479  (state & kRightmostEdgeIsCalculated));
4480  if (EndsWithSurrogate(state) && StartsWithSurrogate(state)) {
4482  }
4483  *state_out = kInitialState |
4486  }
4487 
4488  static int Calculate(i::ConsString* current, uint8_t* state_out) {
4489  using namespace internal;
4490  int total_length = 0;
4491  uint8_t state = kInitialState;
4492  while (true) {
4493  i::String* left = current->first();
4494  i::String* right = current->second();
4495  uint8_t right_leaf_state;
4496  uint8_t left_leaf_state;
4497  int leaf_length;
4498  ConsString* left_as_cons =
4499  Visitor::VisitFlat(left, &leaf_length, &left_leaf_state);
4500  if (left_as_cons == NULL) {
4501  total_length += leaf_length;
4502  MergeLeafLeft(&total_length, &state, left_leaf_state);
4503  }
4504  ConsString* right_as_cons =
4505  Visitor::VisitFlat(right, &leaf_length, &right_leaf_state);
4506  if (right_as_cons == NULL) {
4507  total_length += leaf_length;
4508  MergeLeafRight(&total_length, &state, right_leaf_state);
4509  if (left_as_cons != NULL) {
4510  // 1 Leaf node. Descend in place.
4511  current = left_as_cons;
4512  continue;
4513  } else {
4514  // Terminal node.
4515  MergeTerminal(&total_length, state, state_out);
4516  return total_length;
4517  }
4518  } else if (left_as_cons == NULL) {
4519  // 1 Leaf node. Descend in place.
4520  current = right_as_cons;
4521  continue;
4522  }
4523  // Both strings are ConsStrings.
4524  // Recurse on smallest.
4525  if (left->length() < right->length()) {
4526  total_length += Calculate(left_as_cons, &left_leaf_state);
4527  MergeLeafLeft(&total_length, &state, left_leaf_state);
4528  current = right_as_cons;
4529  } else {
4530  total_length += Calculate(right_as_cons, &right_leaf_state);
4531  MergeLeafRight(&total_length, &state, right_leaf_state);
4532  current = left_as_cons;
4533  }
4534  }
4535  UNREACHABLE();
4536  return 0;
4537  }
4538 
4539  static inline int Calculate(i::ConsString* current) {
4540  uint8_t state = kInitialState;
4541  return Calculate(current, &state);
4542  }
4543 
4544  private:
4546 };
4547 
4548 
4549 static int Utf8Length(i::String* str, i::Isolate* isolate) {
4550  int length = str->length();
4551  if (length == 0) return 0;
4552  uint8_t state;
4553  i::ConsString* cons_string =
4554  Utf8LengthHelper::Visitor::VisitFlat(str, &length, &state);
4555  if (cons_string == NULL) return length;
4556  return Utf8LengthHelper::Calculate(cons_string);
4557 }
4558 
4559 
4560 int String::Utf8Length() const {
4562  i::Isolate* isolate = str->GetIsolate();
4563  return v8::Utf8Length(*str, isolate);
4564 }
4565 
4566 
4568  public:
4570  char* buffer,
4571  int capacity,
4572  bool skip_capacity_check,
4573  bool replace_invalid_utf8)
4574  : early_termination_(false),
4575  last_character_(unibrow::Utf16::kNoPreviousCharacter),
4576  buffer_(buffer),
4577  start_(buffer),
4578  capacity_(capacity),
4579  skip_capacity_check_(capacity == -1 || skip_capacity_check),
4580  replace_invalid_utf8_(replace_invalid_utf8),
4581  utf16_chars_read_(0) {
4582  }
4583 
4584  static int WriteEndCharacter(uint16_t character,
4585  int last_character,
4586  int remaining,
4587  char* const buffer,
4588  bool replace_invalid_utf8) {
4589  using namespace unibrow;
4590  DCHECK(remaining > 0);
4591  // We can't use a local buffer here because Encode needs to modify
4592  // previous characters in the stream. We know, however, that
4593  // exactly one character will be advanced.
4594  if (Utf16::IsSurrogatePair(last_character, character)) {
4595  int written = Utf8::Encode(buffer,
4596  character,
4597  last_character,
4598  replace_invalid_utf8);
4599  DCHECK(written == 1);
4600  return written;
4601  }
4602  // Use a scratch buffer to check the required characters.
4603  char temp_buffer[Utf8::kMaxEncodedSize];
4604  // Can't encode using last_character as gcc has array bounds issues.
4605  int written = Utf8::Encode(temp_buffer,
4606  character,
4607  Utf16::kNoPreviousCharacter,
4608  replace_invalid_utf8);
4609  // Won't fit.
4610  if (written > remaining) return 0;
4611  // Copy over the character from temp_buffer.
4612  for (int j = 0; j < written; j++) {
4613  buffer[j] = temp_buffer[j];
4614  }
4615  return written;
4616  }
4617 
4618  // Visit writes out a group of code units (chars) of a v8::String to the
4619  // internal buffer_. This is done in two phases. The first phase calculates a
4620  // pesimistic estimate (writable_length) on how many code units can be safely
4621  // written without exceeding the buffer capacity and without writing the last
4622  // code unit (it could be a lead surrogate). The estimated number of code
4623  // units is then written out in one go, and the reported byte usage is used
4624  // to correct the estimate. This is repeated until the estimate becomes <= 0
4625  // or all code units have been written out. The second phase writes out code
4626  // units until the buffer capacity is reached, would be exceeded by the next
4627  // unit, or all units have been written out.
4628  template<typename Char>
4629  void Visit(const Char* chars, const int length) {
4630  using namespace unibrow;
4631  DCHECK(!early_termination_);
4632  if (length == 0) return;
4633  // Copy state to stack.
4634  char* buffer = buffer_;
4635  int last_character =
4636  sizeof(Char) == 1 ? Utf16::kNoPreviousCharacter : last_character_;
4637  int i = 0;
4638  // Do a fast loop where there is no exit capacity check.
4639  while (true) {
4640  int fast_length;
4641  if (skip_capacity_check_) {
4642  fast_length = length;
4643  } else {
4644  int remaining_capacity = capacity_ - static_cast<int>(buffer - start_);
4645  // Need enough space to write everything but one character.
4646  STATIC_ASSERT(Utf16::kMaxExtraUtf8BytesForOneUtf16CodeUnit == 3);
4647  int max_size_per_char = sizeof(Char) == 1 ? 2 : 3;
4648  int writable_length =
4649  (remaining_capacity - max_size_per_char)/max_size_per_char;
4650  // Need to drop into slow loop.
4651  if (writable_length <= 0) break;
4652  fast_length = i + writable_length;
4653  if (fast_length > length) fast_length = length;
4654  }
4655  // Write the characters to the stream.
4656  if (sizeof(Char) == 1) {
4657  for (; i < fast_length; i++) {
4658  buffer +=
4659  Utf8::EncodeOneByte(buffer, static_cast<uint8_t>(*chars++));
4660  DCHECK(capacity_ == -1 || (buffer - start_) <= capacity_);
4661  }
4662  } else {
4663  for (; i < fast_length; i++) {
4664  uint16_t character = *chars++;
4665  buffer += Utf8::Encode(buffer,
4666  character,
4667  last_character,
4668  replace_invalid_utf8_);
4669  last_character = character;
4670  DCHECK(capacity_ == -1 || (buffer - start_) <= capacity_);
4671  }
4672  }
4673  // Array is fully written. Exit.
4674  if (fast_length == length) {
4675  // Write state back out to object.
4676  last_character_ = last_character;
4677  buffer_ = buffer;
4678  utf16_chars_read_ += length;
4679  return;
4680  }
4681  }
4682  DCHECK(!skip_capacity_check_);
4683  // Slow loop. Must check capacity on each iteration.
4684  int remaining_capacity = capacity_ - static_cast<int>(buffer - start_);
4685  DCHECK(remaining_capacity >= 0);
4686  for (; i < length && remaining_capacity > 0; i++) {
4687  uint16_t character = *chars++;
4688  // remaining_capacity is <= 3 bytes at this point, so we do not write out
4689  // an umatched lead surrogate.
4690  if (replace_invalid_utf8_ && Utf16::IsLeadSurrogate(character)) {
4691  early_termination_ = true;
4692  break;
4693  }
4694  int written = WriteEndCharacter(character,
4695  last_character,
4696  remaining_capacity,
4697  buffer,
4698  replace_invalid_utf8_);
4699  if (written == 0) {
4700  early_termination_ = true;
4701  break;
4702  }
4703  buffer += written;
4704  remaining_capacity -= written;
4705  last_character = character;
4706  }
4707  // Write state back out to object.
4708  last_character_ = last_character;
4709  buffer_ = buffer;
4710  utf16_chars_read_ += i;
4711  }
4712 
4713  inline bool IsDone() {
4714  return early_termination_;
4715  }
4716 
4717  inline void VisitOneByteString(const uint8_t* chars, int length) {
4718  Visit(chars, length);
4719  }
4720 
4721  inline void VisitTwoByteString(const uint16_t* chars, int length) {
4722  Visit(chars, length);
4723  }
4724 
4725  int CompleteWrite(bool write_null, int* utf16_chars_read_out) {
4726  // Write out number of utf16 characters written to the stream.
4727  if (utf16_chars_read_out != NULL) {
4728  *utf16_chars_read_out = utf16_chars_read_;
4729  }
4730  // Only null terminate if all of the string was written and there's space.
4731  if (write_null &&
4732  !early_termination_ &&
4733  (capacity_ == -1 || (buffer_ - start_) < capacity_)) {
4734  *buffer_++ = '\0';
4735  }
4736  return static_cast<int>(buffer_ - start_);
4737  }
4738 
4739  private:
4742  char* buffer_;
4743  char* const start_;
4749 };
4750 
4751 
4753  Utf8WriterVisitor* writer,
4754  int recursion_budget) {
4755  while (!writer->IsDone()) {
4756  i::ConsString* cons_string = i::String::VisitFlat(writer, current);
4757  if (cons_string == NULL) return true; // Leaf node.
4758  if (recursion_budget <= 0) return false;
4759  // Must write the left branch first.
4760  i::String* first = cons_string->first();
4761  bool success = RecursivelySerializeToUtf8(first,
4762  writer,
4763  recursion_budget - 1);
4764  if (!success) return false;
4765  // Inline tail recurse for right branch.
4766  current = cons_string->second();
4767  }
4768  return true;
4769 }
4770 
4771 
4772 int String::WriteUtf8(char* buffer,
4773  int capacity,
4774  int* nchars_ref,
4775  int options) const {
4776  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
4777  LOG_API(isolate, "String::WriteUtf8");
4778  ENTER_V8(isolate);
4780  if (options & HINT_MANY_WRITES_EXPECTED) {
4781  str = i::String::Flatten(str); // Flatten the string for efficiency.
4782  }
4783  const int string_length = str->length();
4784  bool write_null = !(options & NO_NULL_TERMINATION);
4785  bool replace_invalid_utf8 = (options & REPLACE_INVALID_UTF8);
4786  int max16BitCodeUnitSize = unibrow::Utf8::kMax16BitCodeUnitSize;
4787  // First check if we can just write the string without checking capacity.
4788  if (capacity == -1 || capacity / max16BitCodeUnitSize >= string_length) {
4789  Utf8WriterVisitor writer(buffer, capacity, true, replace_invalid_utf8);
4790  const int kMaxRecursion = 100;
4791  bool success = RecursivelySerializeToUtf8(*str, &writer, kMaxRecursion);
4792  if (success) return writer.CompleteWrite(write_null, nchars_ref);
4793  } else if (capacity >= string_length) {
4794  // First check that the buffer is large enough.
4795  int utf8_bytes = v8::Utf8Length(*str, str->GetIsolate());
4796  if (utf8_bytes <= capacity) {
4797  // one-byte fast path.
4798  if (utf8_bytes == string_length) {
4799  WriteOneByte(reinterpret_cast<uint8_t*>(buffer), 0, capacity, options);
4800  if (nchars_ref != NULL) *nchars_ref = string_length;
4801  if (write_null && (utf8_bytes+1 <= capacity)) {
4802  return string_length + 1;
4803  }
4804  return string_length;
4805  }
4806  if (write_null && (utf8_bytes+1 > capacity)) {
4807  options |= NO_NULL_TERMINATION;
4808  }
4809  // Recurse once without a capacity limit.
4810  // This will get into the first branch above.
4811  // TODO(dcarney) Check max left rec. in Utf8Length and fall through.
4812  return WriteUtf8(buffer, -1, nchars_ref, options);
4813  }
4814  }
4815  // Recursive slow path can potentially be unreasonable slow. Flatten.
4816  str = i::String::Flatten(str);
4817  Utf8WriterVisitor writer(buffer, capacity, false, replace_invalid_utf8);
4818  i::String::VisitFlat(&writer, *str);
4819  return writer.CompleteWrite(write_null, nchars_ref);
4820 }
4821 
4822 
4823 template<typename CharType>
4824 static inline int WriteHelper(const String* string,
4825  CharType* buffer,
4826  int start,
4827  int length,
4828  int options) {
4829  i::Isolate* isolate = Utils::OpenHandle(string)->GetIsolate();
4830  LOG_API(isolate, "String::Write");
4831  ENTER_V8(isolate);
4832  DCHECK(start >= 0 && length >= -1);
4834  isolate->string_tracker()->RecordWrite(str);
4835  if (options & String::HINT_MANY_WRITES_EXPECTED) {
4836  // Flatten the string for efficiency. This applies whether we are
4837  // using StringCharacterStream or Get(i) to access the characters.
4838  str = i::String::Flatten(str);
4839  }
4840  int end = start + length;
4841  if ((length == -1) || (length > str->length() - start) )
4842  end = str->length();
4843  if (end < 0) return 0;
4844  i::String::WriteToFlat(*str, buffer, start, end);
4845  if (!(options & String::NO_NULL_TERMINATION) &&
4846  (length == -1 || end - start < length)) {
4847  buffer[end - start] = '\0';
4848  }
4849  return end - start;
4850 }
4851 
4852 
4853 int String::WriteOneByte(uint8_t* buffer,
4854  int start,
4855  int length,
4856  int options) const {
4857  return WriteHelper(this, buffer, start, length, options);
4858 }
4859 
4860 
4862  int start,
4863  int length,
4864  int options) const {
4865  return WriteHelper(this, buffer, start, length, options);
4866 }
4867 
4868 
4871  return i::StringShape(*str).IsExternalTwoByte();
4872 }
4873 
4874 
4877  return i::StringShape(*str).IsExternalOneByte();
4878 }
4879 
4880 
4882  v8::String::ExternalStringResource* value) const {
4884  const v8::String::ExternalStringResource* expected;
4885  if (i::StringShape(*str).IsExternalTwoByte()) {
4886  const void* resource =
4888  expected = reinterpret_cast<const ExternalStringResource*>(resource);
4889  } else {
4890  expected = NULL;
4891  }
4892  CHECK_EQ(expected, value);
4893 }
4894 
4896  v8::String::ExternalStringResourceBase* value, Encoding encoding) const {
4899  Encoding expectedEncoding;
4900  if (i::StringShape(*str).IsExternalOneByte()) {
4901  const void* resource =
4903  expected = reinterpret_cast<const ExternalStringResourceBase*>(resource);
4904  expectedEncoding = ONE_BYTE_ENCODING;
4905  } else if (i::StringShape(*str).IsExternalTwoByte()) {
4906  const void* resource =
4908  expected = reinterpret_cast<const ExternalStringResourceBase*>(resource);
4909  expectedEncoding = TWO_BYTE_ENCODING;
4910  } else {
4911  expected = NULL;
4912  expectedEncoding =
4913  str->IsOneByteRepresentation() ? ONE_BYTE_ENCODING : TWO_BYTE_ENCODING;
4914  }
4915  CHECK_EQ(expected, value);
4916  CHECK_EQ(expectedEncoding, encoding);
4917 }
4918 
4922  if (i::StringShape(*str).IsExternalOneByte()) {
4923  const void* resource =
4925  return reinterpret_cast<const ExternalOneByteStringResource*>(resource);
4926  } else {
4927  return NULL;
4928  }
4929 }
4930 
4931 
4934  i::Handle<i::Object> name(sym->name(), sym->GetIsolate());
4935  return Utils::ToLocal(name);
4936 }
4937 
4938 
4940  return reinterpret_cast<const Symbol*>(this)->Name();
4941 }
4942 
4943 
4944 double Number::Value() const {
4946  return obj->Number();
4947 }
4948 
4949 
4950 bool Boolean::Value() const {
4952  return obj->IsTrue();
4953 }
4954 
4955 
4956 int64_t Integer::Value() const {
4958  if (obj->IsSmi()) {
4959  return i::Smi::cast(*obj)->value();
4960  } else {
4961  return static_cast<int64_t>(obj->Number());
4962  }
4963 }
4964 
4965 
4968  if (obj->IsSmi()) {
4969  return i::Smi::cast(*obj)->value();
4970  } else {
4971  return static_cast<int32_t>(obj->Number());
4972  }
4973 }
4974 
4975 
4978  if (obj->IsSmi()) {
4979  return i::Smi::cast(*obj)->value();
4980  } else {
4981  return static_cast<uint32_t>(obj->Number());
4982  }
4983 }
4984 
4985 
4988  return obj->GetInternalFieldCount();
4989 }
4990 
4991 
4993  int index,
4994  const char* location) {
4995  return Utils::ApiCheck(index < obj->GetInternalFieldCount(),
4996  location,
4997  "Internal field out of bounds");
4998 }
4999 
5000 
5003  const char* location = "v8::Object::GetInternalField()";
5004  if (!InternalFieldOK(obj, index, location)) return Local<Value>();
5005  i::Handle<i::Object> value(obj->GetInternalField(index), obj->GetIsolate());
5006  return Utils::ToLocal(value);
5007 }
5008 
5009 
5012  const char* location = "v8::Object::SetInternalField()";
5013  if (!InternalFieldOK(obj, index, location)) return;
5015  obj->SetInternalField(index, *val);
5016  DCHECK_EQ(value, GetInternalField(index));
5017 }
5018 
5019 
5022  const char* location = "v8::Object::GetAlignedPointerFromInternalField()";
5023  if (!InternalFieldOK(obj, index, location)) return NULL;
5024  return DecodeSmiToAligned(obj->GetInternalField(index), location);
5025 }
5026 
5027 
5028 void v8::Object::SetAlignedPointerInInternalField(int index, void* value) {
5030  const char* location = "v8::Object::SetAlignedPointerInInternalField()";
5031  if (!InternalFieldOK(obj, index, location)) return;
5032  obj->SetInternalField(index, EncodeAlignedAsSmi(value, location));
5033  DCHECK_EQ(value, GetAlignedPointerFromInternalField(index));
5034 }
5035 
5036 
5037 static void* ExternalValue(i::Object* obj) {
5038  // Obscure semantics for undefined, but somehow checked in our unit tests...
5039  if (obj->IsUndefined()) return NULL;
5040  i::Object* foreign = i::JSObject::cast(obj)->GetInternalField(0);
5041  return i::Foreign::cast(foreign)->foreign_address();
5042 }
5043 
5044 
5045 // --- E n v i r o n m e n t ---
5046 
5047 
5049  i::V8::InitializePlatform(platform);
5050 }
5051 
5052 
5055 }
5056 
5057 
5060  return true;
5061 }
5062 
5063 
5065  base::RandomNumberGenerator::SetEntropySource(entropy_source);
5066 }
5067 
5068 
5070  ReturnAddressLocationResolver return_address_resolver) {
5071  i::V8::SetReturnAddressLocationResolver(return_address_resolver);
5072 }
5073 
5075  ArrayBuffer::Allocator* allocator) {
5077  "v8::V8::SetArrayBufferAllocator",
5078  "ArrayBufferAllocator might only be set once"))
5079  return;
5080  i::V8::SetArrayBufferAllocator(allocator);
5081 }
5082 
5083 
5085  i::V8::TearDown();
5086  return true;
5087 }
5088 
5089 
5090 HeapStatistics::HeapStatistics(): total_heap_size_(0),
5091  total_heap_size_executable_(0),
5092  total_physical_size_(0),
5093  used_heap_size_(0),
5094  heap_size_limit_(0) { }
5095 
5096 
5098  i::Isolate* isolate = i::Isolate::Current();
5099  isolate->heap()->VisitExternalResources(visitor);
5100 }
5101 
5102 
5104  public:
5106  : visitor_(visitor) {}
5107  virtual void VisitPointers(i::Object** start, i::Object** end) {
5108  UNREACHABLE();
5109  }
5110  virtual void VisitEmbedderReference(i::Object** p, uint16_t class_id) {
5111  Value* value = ToApi<Value>(i::Handle<i::Object>(p));
5113  reinterpret_cast<Persistent<Value>*>(&value), class_id);
5114  }
5115  private:
5117 };
5118 
5119 
5121  i::Isolate* isolate = i::Isolate::Current();
5122  i::DisallowHeapAllocation no_allocation;
5123 
5124  VisitorAdapter visitor_adapter(visitor);
5125  isolate->global_handles()->IterateAllRootsWithClassIds(&visitor_adapter);
5126 }
5127 
5128 
5130  Isolate* exported_isolate, PersistentHandleVisitor* visitor) {
5131  i::Isolate* isolate = reinterpret_cast<i::Isolate*>(exported_isolate);
5132  DCHECK(isolate == i::Isolate::Current());
5133  i::DisallowHeapAllocation no_allocation;
5134 
5135  VisitorAdapter visitor_adapter(visitor);
5137  &visitor_adapter);
5138 }
5139 
5140 
5141 bool v8::V8::InitializeICU(const char* icu_data_file) {
5142  return i::InitializeICU(icu_data_file);
5143 }
5144 
5145 
5146 const char* v8::V8::GetVersion() {
5147  return i::Version::GetVersion();
5148 }
5149 
5150 
5152  i::Isolate* isolate,
5153  v8::ExtensionConfiguration* extensions,
5154  v8::Handle<ObjectTemplate> global_template,
5155  v8::Handle<Value> maybe_global_proxy) {
5157 
5158  // Enter V8 via an ENTER_V8 scope.
5159  {
5160  ENTER_V8(isolate);
5161  v8::Handle<ObjectTemplate> proxy_template = global_template;
5162  i::Handle<i::FunctionTemplateInfo> proxy_constructor;
5163  i::Handle<i::FunctionTemplateInfo> global_constructor;
5164 
5165  if (!global_template.IsEmpty()) {
5166  // Make sure that the global_template has a constructor.
5167  global_constructor = EnsureConstructor(isolate, *global_template);
5168 
5169  // Create a fresh template for the global proxy object.
5170  proxy_template = ObjectTemplate::New(
5171  reinterpret_cast<v8::Isolate*>(isolate));
5172  proxy_constructor = EnsureConstructor(isolate, *proxy_template);
5173 
5174  // Set the global template to be the prototype template of
5175  // global proxy template.
5176  proxy_constructor->set_prototype_template(
5177  *Utils::OpenHandle(*global_template));
5178 
5179  // Migrate security handlers from global_template to
5180  // proxy_template. Temporarily removing access check
5181  // information from the global template.
5182  if (!global_constructor->access_check_info()->IsUndefined()) {
5183  proxy_constructor->set_access_check_info(
5184  global_constructor->access_check_info());
5185  proxy_constructor->set_needs_access_check(
5186  global_constructor->needs_access_check());
5187  global_constructor->set_needs_access_check(false);
5188  global_constructor->set_access_check_info(
5189  isolate->heap()->undefined_value());
5190  }
5191  }
5192 
5193  i::Handle<i::Object> proxy = Utils::OpenHandle(*maybe_global_proxy, true);
5195  if (!proxy.is_null()) {
5196  maybe_proxy = i::Handle<i::JSGlobalProxy>::cast(proxy);
5197  }
5198  // Create the environment.
5199  env = isolate->bootstrapper()->CreateEnvironment(
5200  maybe_proxy, proxy_template, extensions);
5201 
5202  // Restore the access check info on the global template.
5203  if (!global_template.IsEmpty()) {
5204  DCHECK(!global_constructor.is_null());
5205  DCHECK(!proxy_constructor.is_null());
5206  global_constructor->set_access_check_info(
5207  proxy_constructor->access_check_info());
5208  global_constructor->set_needs_access_check(
5209  proxy_constructor->needs_access_check());
5210  }
5211  }
5212  // Leave V8.
5213 
5214  return env;
5215 }
5216 
5218  v8::Isolate* external_isolate,
5219  v8::ExtensionConfiguration* extensions,
5220  v8::Handle<ObjectTemplate> global_template,
5221  v8::Handle<Value> global_object) {
5222  i::Isolate* isolate = reinterpret_cast<i::Isolate*>(external_isolate);
5223  LOG_API(isolate, "Context::New");
5224  ON_BAILOUT(isolate, "v8::Context::New()", return Local<Context>());
5225  i::HandleScope scope(isolate);
5226  ExtensionConfiguration no_extensions;
5227  if (extensions == NULL) extensions = &no_extensions;
5228  i::Handle<i::Context> env =
5229  CreateEnvironment(isolate, extensions, global_template, global_object);
5230  if (env.is_null()) return Local<Context>();
5231  return Utils::ToLocal(scope.CloseAndEscape(env));
5232 }
5233 
5234 
5236  i::Isolate* isolate = i::Isolate::Current();
5237  ENTER_V8(isolate);
5239  i::Handle<i::Object> token_handle = Utils::OpenHandle(*token);
5240  env->set_security_token(*token_handle);
5241 }
5242 
5243 
5245  i::Isolate* isolate = i::Isolate::Current();
5246  ENTER_V8(isolate);
5248  env->set_security_token(env->global_object());
5249 }
5250 
5251 
5253  i::Isolate* isolate = i::Isolate::Current();
5255  i::Object* security_token = env->security_token();
5256  i::Handle<i::Object> token_handle(security_token, isolate);
5257  return Utils::ToLocal(token_handle);
5258 }
5259 
5260 
5263  return reinterpret_cast<Isolate*>(env->GetIsolate());
5264 }
5265 
5266 
5268  i::Handle<i::Context> context = Utils::OpenHandle(this);
5269  i::Isolate* isolate = context->GetIsolate();
5270  i::Handle<i::Object> global(context->global_proxy(), isolate);
5271  // TODO(dcarney): This should always return the global proxy
5272  // but can't presently as calls to GetProtoype will return the wrong result.
5274  global)->IsDetachedFrom(context->global_object())) {
5275  global = i::Handle<i::Object>(context->global_object(), isolate);
5276  }
5278 }
5279 
5280 
5282  i::Handle<i::Context> context = Utils::OpenHandle(this);
5283  i::Isolate* isolate = context->GetIsolate();
5284  ENTER_V8(isolate);
5285  isolate->bootstrapper()->DetachGlobal(context);
5286 }
5287 
5288 
5290  i::Handle<i::Context> context = Utils::OpenHandle(this);
5291  i::Isolate* isolate = context->GetIsolate();
5292  ENTER_V8(isolate);
5293  context->set_allow_code_gen_from_strings(
5294  allow ? isolate->heap()->true_value() : isolate->heap()->false_value());
5295 }
5296 
5297 
5299  i::Handle<i::Context> context = Utils::OpenHandle(this);
5300  return !context->allow_code_gen_from_strings()->IsFalse();
5301 }
5302 
5303 
5305  Handle<String> error) {
5306  i::Handle<i::Context> context = Utils::OpenHandle(this);
5307  i::Handle<i::String> error_handle = Utils::OpenHandle(*error);
5308  context->set_error_message_for_code_gen_from_strings(*error_handle);
5309 }
5310 
5311 
5313  i::Isolate* isolate = i::Isolate::Current();
5314  ON_BAILOUT(isolate, "v8::ObjectTemplate::NewInstance()",
5315  return Local<v8::Object>());
5316  LOG_API(isolate, "ObjectTemplate::NewInstance");
5317  ENTER_V8(isolate);
5318  EXCEPTION_PREAMBLE(isolate);
5320  has_pending_exception = !i::Execution::InstantiateObject(
5321  Utils::OpenHandle(this)).ToHandle(&obj);
5324 }
5325 
5326 
5328  i::Isolate* isolate = i::Isolate::Current();
5329  ON_BAILOUT(isolate, "v8::FunctionTemplate::GetFunction()",
5330  return Local<v8::Function>());
5331  LOG_API(isolate, "FunctionTemplate::GetFunction");
5332  ENTER_V8(isolate);
5333  EXCEPTION_PREAMBLE(isolate);
5335  has_pending_exception = !i::Execution::InstantiateFunction(
5336  Utils::OpenHandle(this)).ToHandle(&obj);
5339 }
5340 
5341 
5343  ON_BAILOUT(i::Isolate::Current(), "v8::FunctionTemplate::HasInstanceOf()",
5344  return false);
5345  i::Object* obj = *Utils::OpenHandle(*value);
5346  return Utils::OpenHandle(this)->IsTemplateFor(obj);
5347 }
5348 
5349 
5351  STATIC_ASSERT(sizeof(value) == sizeof(i::Address));
5352  i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
5353  LOG_API(i_isolate, "External::New");
5354  ENTER_V8(i_isolate);
5355  i::Handle<i::JSObject> external = i_isolate->factory()->NewExternal(value);
5356  return Utils::ExternalToLocal(external);
5357 }
5358 
5359 
5360 void* External::Value() const {
5361  return ExternalValue(*Utils::OpenHandle(this));
5362 }
5363 
5364 
5365 // anonymous namespace for string creation helper functions
5366 namespace {
5367 
5368 inline int StringLength(const char* string) {
5369  return i::StrLength(string);
5370 }
5371 
5372 
5373 inline int StringLength(const uint8_t* string) {
5374  return i::StrLength(reinterpret_cast<const char*>(string));
5375 }
5376 
5377 
5378 inline int StringLength(const uint16_t* string) {
5379  int length = 0;
5380  while (string[length] != '\0')
5381  length++;
5382  return length;
5383 }
5384 
5385 
5387 inline i::MaybeHandle<i::String> NewString(i::Factory* factory,
5388  String::NewStringType type,
5389  i::Vector<const char> string) {
5390  if (type == String::kInternalizedString) {
5391  return factory->InternalizeUtf8String(string);
5392  }
5393  return factory->NewStringFromUtf8(string);
5394 }
5395 
5396 
5398 inline i::MaybeHandle<i::String> NewString(i::Factory* factory,
5399  String::NewStringType type,
5400  i::Vector<const uint8_t> string) {
5401  if (type == String::kInternalizedString) {
5402  return factory->InternalizeOneByteString(string);
5403  }
5404  return factory->NewStringFromOneByte(string);
5405 }
5406 
5407 
5409 inline i::MaybeHandle<i::String> NewString(i::Factory* factory,
5410  String::NewStringType type,
5411  i::Vector<const uint16_t> string) {
5412  if (type == String::kInternalizedString) {
5413  return factory->InternalizeTwoByteString(string);
5414  }
5415  return factory->NewStringFromTwoByte(string);
5416 }
5417 
5418 
5419 template<typename Char>
5420 inline Local<String> NewString(Isolate* v8_isolate,
5421  const char* location,
5422  const char* env,
5423  const Char* data,
5424  String::NewStringType type,
5425  int length) {
5426  i::Isolate* isolate = reinterpret_cast<internal::Isolate*>(v8_isolate);
5427  LOG_API(isolate, env);
5428  if (length == 0 && type != String::kUndetectableString) {
5429  return String::Empty(v8_isolate);
5430  }
5431  ENTER_V8(isolate);
5432  if (length == -1) length = StringLength(data);
5433  // We do not expect this to fail. Change this if it does.
5435  isolate->factory(),
5436  type,
5437  i::Vector<const Char>(data, length)).ToHandleChecked();
5438  if (type == String::kUndetectableString) {
5439  result->MarkAsUndetectable();
5440  }
5441  return Utils::ToLocal(result);
5442 }
5443 
5444 } // anonymous namespace
5445 
5446 
5448  const char* data,
5449  NewStringType type,
5450  int length) {
5451  return NewString(isolate,
5452  "v8::String::NewFromUtf8()",
5453  "String::NewFromUtf8",
5454  data,
5455  type,
5456  length);
5457 }
5458 
5459 
5461  const uint8_t* data,
5462  NewStringType type,
5463  int length) {
5464  return NewString(isolate,
5465  "v8::String::NewFromOneByte()",
5466  "String::NewFromOneByte",
5467  data,
5468  type,
5469  length);
5470 }
5471 
5472 
5474  const uint16_t* data,
5475  NewStringType type,
5476  int length) {
5477  return NewString(isolate,
5478  "v8::String::NewFromTwoByte()",
5479  "String::NewFromTwoByte",
5480  data,
5481  type,
5482  length);
5483 }
5484 
5485 
5487  i::Handle<i::String> left_string = Utils::OpenHandle(*left);
5488  i::Isolate* isolate = left_string->GetIsolate();
5489  LOG_API(isolate, "String::New(char)");
5490  ENTER_V8(isolate);
5491  i::Handle<i::String> right_string = Utils::OpenHandle(*right);
5492  // We do not expect this to fail. Change this if it does.
5493  i::Handle<i::String> result = isolate->factory()->NewConsString(
5494  left_string, right_string).ToHandleChecked();
5495  return Utils::ToLocal(result);
5496 }
5497 
5498 
5500  i::Isolate* isolate, v8::String::ExternalStringResource* resource) {
5501  return isolate->factory()->NewExternalStringFromTwoByte(resource);
5502 }
5503 
5504 
5507  return isolate->factory()->NewExternalStringFromOneByte(resource);
5508 }
5509 
5510 
5512  Isolate* isolate,
5514  i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
5515  LOG_API(i_isolate, "String::NewExternal");
5516  ENTER_V8(i_isolate);
5517  CHECK(resource && resource->data());
5518  EXCEPTION_PREAMBLE(i_isolate);
5519  i::Handle<i::String> string;
5520  has_pending_exception =
5521  !NewExternalStringHandle(i_isolate, resource).ToHandle(&string);
5522  EXCEPTION_BAILOUT_CHECK(i_isolate, Local<String>());
5523  i_isolate->heap()->external_string_table()->AddString(*string);
5524  return Utils::ToLocal(string);
5525 }
5526 
5527 
5530  i::Isolate* isolate = obj->GetIsolate();
5531  if (i::StringShape(*obj).IsExternal()) {
5532  return false; // Already an external string.
5533  }
5534  ENTER_V8(isolate);
5535  if (isolate->string_tracker()->IsFreshUnusedString(obj)) {
5536  return false;
5537  }
5538  if (isolate->heap()->IsInGCPostProcessing()) {
5539  return false;
5540  }
5541  CHECK(resource && resource->data());
5542 
5543  bool result = obj->MakeExternal(resource);
5544  // Assert that if CanMakeExternal(), then externalizing actually succeeds.
5545  DCHECK(!CanMakeExternal() || result);
5546  if (result) {
5547  DCHECK(obj->IsExternalString());
5548  isolate->heap()->external_string_table()->AddString(*obj);
5549  }
5550  return result;
5551 }
5552 
5553 
5555  Isolate* isolate, v8::String::ExternalOneByteStringResource* resource) {
5556  i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
5557  LOG_API(i_isolate, "String::NewExternal");
5558  ENTER_V8(i_isolate);
5559  CHECK(resource && resource->data());
5560  EXCEPTION_PREAMBLE(i_isolate);
5561  i::Handle<i::String> string;
5562  has_pending_exception =
5563  !NewExternalOneByteStringHandle(i_isolate, resource).ToHandle(&string);
5564  EXCEPTION_BAILOUT_CHECK(i_isolate, Local<String>());
5565  i_isolate->heap()->external_string_table()->AddString(*string);
5566  return Utils::ToLocal(string);
5567 }
5568 
5569 
5573  i::Isolate* isolate = obj->GetIsolate();
5574  if (i::StringShape(*obj).IsExternal()) {
5575  return false; // Already an external string.
5576  }
5577  ENTER_V8(isolate);
5578  if (isolate->string_tracker()->IsFreshUnusedString(obj)) {
5579  return false;
5580  }
5581  if (isolate->heap()->IsInGCPostProcessing()) {
5582  return false;
5583  }
5584  CHECK(resource && resource->data());
5585 
5586  bool result = obj->MakeExternal(resource);
5587  // Assert that if CanMakeExternal(), then externalizing actually succeeds.
5588  DCHECK(!CanMakeExternal() || result);
5589  if (result) {
5590  DCHECK(obj->IsExternalString());
5591  isolate->heap()->external_string_table()->AddString(*obj);
5592  }
5593  return result;
5594 }
5595 
5596 
5598  if (!internal::FLAG_clever_optimizations) return false;
5600  i::Isolate* isolate = obj->GetIsolate();
5601 
5602  if (isolate->string_tracker()->IsFreshUnusedString(obj)) return false;
5603  int size = obj->Size(); // Byte size of the original string.
5604  if (size < i::ExternalString::kShortSize) return false;
5605  i::StringShape shape(*obj);
5606  return !shape.IsExternal();
5607 }
5608 
5609 
5611  i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
5612  LOG_API(i_isolate, "Object::New");
5613  ENTER_V8(i_isolate);
5615  i_isolate->factory()->NewJSObject(i_isolate->object_function());
5616  return Utils::ToLocal(obj);
5617 }
5618 
5619 
5621  i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
5622  LOG_API(i_isolate, "NumberObject::New");
5623  ENTER_V8(i_isolate);
5624  i::Handle<i::Object> number = i_isolate->factory()->NewNumber(value);
5625  i::Handle<i::Object> obj =
5626  i::Object::ToObject(i_isolate, number).ToHandleChecked();
5627  return Utils::ToLocal(obj);
5628 }
5629 
5630 
5634  i::Isolate* isolate = jsvalue->GetIsolate();
5635  LOG_API(isolate, "NumberObject::NumberValue");
5636  return jsvalue->value()->Number();
5637 }
5638 
5639 
5641  i::Isolate* isolate = i::Isolate::Current();
5642  LOG_API(isolate, "BooleanObject::New");
5643  ENTER_V8(isolate);
5644  i::Handle<i::Object> boolean(value
5645  ? isolate->heap()->true_value()
5646  : isolate->heap()->false_value(),
5647  isolate);
5648  i::Handle<i::Object> obj =
5649  i::Object::ToObject(isolate, boolean).ToHandleChecked();
5650  return Utils::ToLocal(obj);
5651 }
5652 
5653 
5657  i::Isolate* isolate = jsvalue->GetIsolate();
5658  LOG_API(isolate, "BooleanObject::BooleanValue");
5659  return jsvalue->value()->IsTrue();
5660 }
5661 
5662 
5664  i::Handle<i::String> string = Utils::OpenHandle(*value);
5665  i::Isolate* isolate = string->GetIsolate();
5666  LOG_API(isolate, "StringObject::New");
5667  ENTER_V8(isolate);
5668  i::Handle<i::Object> obj =
5669  i::Object::ToObject(isolate, string).ToHandleChecked();
5670  return Utils::ToLocal(obj);
5671 }
5672 
5673 
5677  i::Isolate* isolate = jsvalue->GetIsolate();
5678  LOG_API(isolate, "StringObject::StringValue");
5679  return Utils::ToLocal(
5680  i::Handle<i::String>(i::String::cast(jsvalue->value())));
5681 }
5682 
5683 
5685  i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
5686  LOG_API(i_isolate, "SymbolObject::New");
5687  ENTER_V8(i_isolate);
5689  i_isolate, Utils::OpenHandle(*value)).ToHandleChecked();
5690  return Utils::ToLocal(obj);
5691 }
5692 
5693 
5697  i::Isolate* isolate = jsvalue->GetIsolate();
5698  LOG_API(isolate, "SymbolObject::SymbolValue");
5699  return Utils::ToLocal(
5700  i::Handle<i::Symbol>(i::Symbol::cast(jsvalue->value())));
5701 }
5702 
5703 
5704 Local<v8::Value> v8::Date::New(Isolate* isolate, double time) {
5705  i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
5706  LOG_API(i_isolate, "Date::New");
5707  if (std::isnan(time)) {
5708  // Introduce only canonical NaN value into the VM, to avoid signaling NaNs.
5709  time = base::OS::nan_value();
5710  }
5711  ENTER_V8(i_isolate);
5712  EXCEPTION_PREAMBLE(i_isolate);
5714  has_pending_exception = !i::Execution::NewDate(
5715  i_isolate, time).ToHandle(&obj);
5717  return Utils::ToLocal(obj);
5718 }
5719 
5720 
5721 double v8::Date::ValueOf() const {
5724  i::Isolate* isolate = jsdate->GetIsolate();
5725  LOG_API(isolate, "Date::NumberValue");
5726  return jsdate->value()->Number();
5727 }
5728 
5729 
5731  i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
5732  if (!i_isolate->IsInitialized()) return;
5733  ON_BAILOUT(i_isolate, "v8::Date::DateTimeConfigurationChangeNotification()",
5734  return);
5735  LOG_API(i_isolate, "Date::DateTimeConfigurationChangeNotification");
5736  ENTER_V8(i_isolate);
5737 
5738  i_isolate->date_cache()->ResetDateCache();
5739 
5740  if (!i_isolate->eternal_handles()->Exists(
5742  return;
5743  }
5744  i::Handle<i::FixedArray> date_cache_version =
5747  DCHECK_EQ(1, date_cache_version->length());
5748  CHECK(date_cache_version->get(0)->IsSmi());
5749  date_cache_version->set(
5750  0,
5751  i::Smi::FromInt(i::Smi::cast(date_cache_version->get(0))->value() + 1));
5752 }
5753 
5754 
5756  i::Isolate* isolate = i::Isolate::Current();
5757  uint8_t flags_buf[3];
5758  int num_flags = 0;
5759  if ((flags & RegExp::kGlobal) != 0) flags_buf[num_flags++] = 'g';
5760  if ((flags & RegExp::kMultiline) != 0) flags_buf[num_flags++] = 'm';
5761  if ((flags & RegExp::kIgnoreCase) != 0) flags_buf[num_flags++] = 'i';
5762  DCHECK(num_flags <= static_cast<int>(arraysize(flags_buf)));
5763  return isolate->factory()->InternalizeOneByteString(
5764  i::Vector<const uint8_t>(flags_buf, num_flags));
5765 }
5766 
5767 
5769  Flags flags) {
5770  i::Isolate* isolate = Utils::OpenHandle(*pattern)->GetIsolate();
5771  LOG_API(isolate, "RegExp::New");
5772  ENTER_V8(isolate);
5773  EXCEPTION_PREAMBLE(isolate);
5775  has_pending_exception = !i::Execution::NewJSRegExp(
5776  Utils::OpenHandle(*pattern),
5777  RegExpFlagsToString(flags)).ToHandle(&obj);
5780 }
5781 
5782 
5785  return Utils::ToLocal(i::Handle<i::String>(obj->Pattern()));
5786 }
5787 
5788 
5789 // Assert that the static flags cast in GetFlags is valid.
5790 #define REGEXP_FLAG_ASSERT_EQ(api_flag, internal_flag) \
5791  STATIC_ASSERT(static_cast<int>(v8::RegExp::api_flag) == \
5792  static_cast<int>(i::JSRegExp::internal_flag))
5795 REGEXP_FLAG_ASSERT_EQ(kIgnoreCase, IGNORE_CASE);
5796 REGEXP_FLAG_ASSERT_EQ(kMultiline, MULTILINE);
5797 #undef REGEXP_FLAG_ASSERT_EQ
5798 
5801  return static_cast<RegExp::Flags>(obj->GetFlags().value());
5802 }
5803 
5804 
5805 Local<v8::Array> v8::Array::New(Isolate* isolate, int length) {
5806  i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
5807  LOG_API(i_isolate, "Array::New");
5808  ENTER_V8(i_isolate);
5809  int real_length = length > 0 ? length : 0;
5810  i::Handle<i::JSArray> obj = i_isolate->factory()->NewJSArray(real_length);
5811  i::Handle<i::Object> length_obj =
5812  i_isolate->factory()->NewNumberFromInt(real_length);
5813  obj->set_length(*length_obj);
5814  return Utils::ToLocal(obj);
5815 }
5816 
5817 
5820  i::Object* length = obj->length();
5821  if (length->IsSmi()) {
5822  return i::Smi::cast(length)->value();
5823  } else {
5824  return static_cast<uint32_t>(length->Number());
5825  }
5826 }
5827 
5828 
5830  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
5831  ON_BAILOUT(isolate, "v8::Array::CloneElementAt()", return Local<Object>());
5833  if (!self->HasFastObjectElements()) {
5834  return Local<Object>();
5835  }
5836  i::FixedArray* elms = i::FixedArray::cast(self->elements());
5837  i::Object* paragon = elms->get(index);
5838  if (!paragon->IsJSObject()) {
5839  return Local<Object>();
5840  }
5841  i::Handle<i::JSObject> paragon_handle(i::JSObject::cast(paragon));
5842  EXCEPTION_PREAMBLE(isolate);
5843  ENTER_V8(isolate);
5844  i::Handle<i::JSObject> result =
5845  isolate->factory()->CopyJSObject(paragon_handle);
5846  has_pending_exception = result.is_null();
5848  return Utils::ToLocal(result);
5849 }
5850 
5851 
5852 bool Value::IsPromise() const {
5854  if (!val->IsJSObject()) return false;
5856  i::Isolate* isolate = obj->GetIsolate();
5857  LOG_API(isolate, "IsPromise");
5858  ENTER_V8(isolate);
5859  EXCEPTION_PREAMBLE(isolate);
5860  i::Handle<i::Object> argv[] = { obj };
5862  has_pending_exception = !i::Execution::Call(
5863  isolate,
5864  isolate->is_promise(),
5865  isolate->factory()->undefined_value(),
5866  arraysize(argv), argv,
5867  false).ToHandle(&b);
5868  EXCEPTION_BAILOUT_CHECK(isolate, false);
5869  return b->BooleanValue();
5870 }
5871 
5872 
5874  i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
5875  LOG_API(isolate, "Promise::Resolver::New");
5876  ENTER_V8(isolate);
5877  EXCEPTION_PREAMBLE(isolate);
5878  i::Handle<i::Object> result;
5879  has_pending_exception = !i::Execution::Call(
5880  isolate,
5881  isolate->promise_create(),
5882  isolate->factory()->undefined_value(),
5883  0, NULL,
5884  false).ToHandle(&result);
5887 }
5888 
5889 
5891  i::Handle<i::JSObject> promise = Utils::OpenHandle(this);
5892  return Local<Promise>::Cast(Utils::ToLocal(promise));
5893 }
5894 
5895 
5897  i::Handle<i::JSObject> promise = Utils::OpenHandle(this);
5898  i::Isolate* isolate = promise->GetIsolate();
5899  LOG_API(isolate, "Promise::Resolver::Resolve");
5900  ENTER_V8(isolate);
5901  EXCEPTION_PREAMBLE(isolate);
5902  i::Handle<i::Object> argv[] = { promise, Utils::OpenHandle(*value) };
5903  has_pending_exception = i::Execution::Call(
5904  isolate,
5905  isolate->promise_resolve(),
5906  isolate->factory()->undefined_value(),
5907  arraysize(argv), argv,
5908  false).is_null();
5909  EXCEPTION_BAILOUT_CHECK(isolate, /* void */ ;);
5910 }
5911 
5912 
5914  i::Handle<i::JSObject> promise = Utils::OpenHandle(this);
5915  i::Isolate* isolate = promise->GetIsolate();
5916  LOG_API(isolate, "Promise::Resolver::Reject");
5917  ENTER_V8(isolate);
5918  EXCEPTION_PREAMBLE(isolate);
5919  i::Handle<i::Object> argv[] = { promise, Utils::OpenHandle(*value) };
5920  has_pending_exception = i::Execution::Call(
5921  isolate,
5922  isolate->promise_reject(),
5923  isolate->factory()->undefined_value(),
5924  arraysize(argv), argv,
5925  false).is_null();
5926  EXCEPTION_BAILOUT_CHECK(isolate, /* void */ ;);
5927 }
5928 
5929 
5931  i::Handle<i::JSObject> promise = Utils::OpenHandle(this);
5932  i::Isolate* isolate = promise->GetIsolate();
5933  LOG_API(isolate, "Promise::Chain");
5934  ENTER_V8(isolate);
5935  EXCEPTION_PREAMBLE(isolate);
5936  i::Handle<i::Object> argv[] = { Utils::OpenHandle(*handler) };
5937  i::Handle<i::Object> result;
5938  has_pending_exception = !i::Execution::Call(
5939  isolate,
5940  isolate->promise_chain(),
5941  promise,
5942  arraysize(argv), argv,
5943  false).ToHandle(&result);
5945  return Local<Promise>::Cast(Utils::ToLocal(result));
5946 }
5947 
5948 
5950  i::Handle<i::JSObject> promise = Utils::OpenHandle(this);
5951  i::Isolate* isolate = promise->GetIsolate();
5952  LOG_API(isolate, "Promise::Catch");
5953  ENTER_V8(isolate);
5954  EXCEPTION_PREAMBLE(isolate);
5955  i::Handle<i::Object> argv[] = { Utils::OpenHandle(*handler) };
5956  i::Handle<i::Object> result;
5957  has_pending_exception = !i::Execution::Call(
5958  isolate,
5959  isolate->promise_catch(),
5960  promise,
5961  arraysize(argv), argv,
5962  false).ToHandle(&result);
5964  return Local<Promise>::Cast(Utils::ToLocal(result));
5965 }
5966 
5967 
5969  i::Handle<i::JSObject> promise = Utils::OpenHandle(this);
5970  i::Isolate* isolate = promise->GetIsolate();
5971  LOG_API(isolate, "Promise::Then");
5972  ENTER_V8(isolate);
5973  EXCEPTION_PREAMBLE(isolate);
5974  i::Handle<i::Object> argv[] = { Utils::OpenHandle(*handler) };
5975  i::Handle<i::Object> result;
5976  has_pending_exception = !i::Execution::Call(
5977  isolate,
5978  isolate->promise_then(),
5979  promise,
5980  arraysize(argv), argv,
5981  false).ToHandle(&result);
5983  return Local<Promise>::Cast(Utils::ToLocal(result));
5984 }
5985 
5986 
5988  return Utils::OpenHandle(this)->is_external();
5989 }
5990 
5991 
5994  Utils::ApiCheck(!obj->is_external(),
5995  "v8::ArrayBuffer::Externalize",
5996  "ArrayBuffer already externalized");
5997  obj->set_is_external(true);
5998  size_t byte_length = static_cast<size_t>(obj->byte_length()->Number());
5999  Contents contents;
6000  contents.data_ = obj->backing_store();
6001  contents.byte_length_ = byte_length;
6002  return contents;
6003 }
6004 
6005 
6008  i::Isolate* isolate = obj->GetIsolate();
6009  Utils::ApiCheck(obj->is_external(),
6010  "v8::ArrayBuffer::Neuter",
6011  "Only externalized ArrayBuffers can be neutered");
6012  LOG_API(obj->GetIsolate(), "v8::ArrayBuffer::Neuter()");
6013  ENTER_V8(isolate);
6015 }
6016 
6017 
6020  return static_cast<size_t>(obj->byte_length()->Number());
6021 }
6022 
6023 
6024 Local<ArrayBuffer> v8::ArrayBuffer::New(Isolate* isolate, size_t byte_length) {
6025  i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
6026  LOG_API(i_isolate, "v8::ArrayBuffer::New(size_t)");
6027  ENTER_V8(i_isolate);
6029  i_isolate->factory()->NewJSArrayBuffer();
6030  i::Runtime::SetupArrayBufferAllocatingData(i_isolate, obj, byte_length);
6031  return Utils::ToLocal(obj);
6032 }
6033 
6034 
6036  size_t byte_length) {
6037  i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
6038  LOG_API(i_isolate, "v8::ArrayBuffer::New(void*, size_t)");
6039  ENTER_V8(i_isolate);
6041  i_isolate->factory()->NewJSArrayBuffer();
6042  i::Runtime::SetupArrayBuffer(i_isolate, obj, true, data, byte_length);
6043  return Utils::ToLocal(obj);
6044 }
6045 
6046 
6050  if (obj->IsJSDataView()) {
6051  i::Handle<i::JSDataView> data_view(i::JSDataView::cast(*obj));
6052  DCHECK(data_view->buffer()->IsJSArrayBuffer());
6053  buffer = i::handle(i::JSArrayBuffer::cast(data_view->buffer()));
6054  } else {
6055  DCHECK(obj->IsJSTypedArray());
6056  buffer = i::JSTypedArray::cast(*obj)->GetBuffer();
6057  }
6058  return Utils::ToLocal(buffer);
6059 }
6060 
6061 
6064  return static_cast<size_t>(obj->byte_offset()->Number());
6065 }
6066 
6067 
6070  return static_cast<size_t>(obj->byte_length()->Number());
6071 }
6072 
6073 
6076  return static_cast<size_t>(obj->length()->Number());
6077 }
6078 
6079 
6080 static inline void SetupArrayBufferView(
6081  i::Isolate* isolate,
6084  size_t byte_offset,
6085  size_t byte_length) {
6086  DCHECK(byte_offset + byte_length <=
6087  static_cast<size_t>(buffer->byte_length()->Number()));
6088 
6089  obj->set_buffer(*buffer);
6090 
6091  obj->set_weak_next(buffer->weak_first_view());
6092  buffer->set_weak_first_view(*obj);
6093 
6094  i::Handle<i::Object> byte_offset_object =
6095  isolate->factory()->NewNumberFromSize(byte_offset);
6096  obj->set_byte_offset(*byte_offset_object);
6097 
6098  i::Handle<i::Object> byte_length_object =
6099  isolate->factory()->NewNumberFromSize(byte_length);
6100  obj->set_byte_length(*byte_length_object);
6101 }
6102 
6103 template<typename ElementType,
6104  ExternalArrayType array_type,
6105  i::ElementsKind elements_kind>
6107  i::Isolate* isolate,
6108  Handle<ArrayBuffer> array_buffer, size_t byte_offset, size_t length) {
6110  isolate->factory()->NewJSTypedArray(array_type);
6111  i::Handle<i::JSArrayBuffer> buffer = Utils::OpenHandle(*array_buffer);
6112 
6113  DCHECK(byte_offset % sizeof(ElementType) == 0);
6114 
6115  CHECK(length <= (std::numeric_limits<size_t>::max() / sizeof(ElementType)));
6116  CHECK(length <= static_cast<size_t>(i::Smi::kMaxValue));
6117  size_t byte_length = length * sizeof(ElementType);
6119  isolate, obj, buffer, byte_offset, byte_length);
6120 
6121  i::Handle<i::Object> length_object =
6122  isolate->factory()->NewNumberFromSize(length);
6123  obj->set_length(*length_object);
6124 
6125  i::Handle<i::ExternalArray> elements =
6126  isolate->factory()->NewExternalArray(
6127  static_cast<int>(length), array_type,
6128  static_cast<uint8_t*>(buffer->backing_store()) + byte_offset);
6130  i::JSObject::GetElementsTransitionMap(obj, elements_kind);
6131  i::JSObject::SetMapAndElements(obj, map, elements);
6132  return obj;
6133 }
6134 
6135 
6136 #define TYPED_ARRAY_NEW(Type, type, TYPE, ctype, size) \
6137  Local<Type##Array> Type##Array::New(Handle<ArrayBuffer> array_buffer, \
6138  size_t byte_offset, size_t length) { \
6139  i::Isolate* isolate = Utils::OpenHandle(*array_buffer)->GetIsolate(); \
6140  LOG_API(isolate, \
6141  "v8::" #Type "Array::New(Handle<ArrayBuffer>, size_t, size_t)"); \
6142  ENTER_V8(isolate); \
6143  if (!Utils::ApiCheck(length <= static_cast<size_t>(i::Smi::kMaxValue), \
6144  "v8::" #Type "Array::New(Handle<ArrayBuffer>, size_t, size_t)", \
6145  "length exceeds max allowed value")) { \
6146  return Local<Type##Array>(); \
6147  } \
6148  i::Handle<i::JSTypedArray> obj = \
6149  NewTypedArray<ctype, v8::kExternal##Type##Array, \
6150  i::EXTERNAL_##TYPE##_ELEMENTS>( \
6151  isolate, array_buffer, byte_offset, length); \
6152  return Utils::ToLocal##Type##Array(obj); \
6153  }
6154 
6155 
6157 #undef TYPED_ARRAY_NEW
6158 
6160  size_t byte_offset, size_t byte_length) {
6161  i::Handle<i::JSArrayBuffer> buffer = Utils::OpenHandle(*array_buffer);
6162  i::Isolate* isolate = buffer->GetIsolate();
6163  LOG_API(isolate, "v8::DataView::New(void*, size_t, size_t)");
6164  ENTER_V8(isolate);
6165  i::Handle<i::JSDataView> obj = isolate->factory()->NewJSDataView();
6167  isolate, obj, buffer, byte_offset, byte_length);
6168  return Utils::ToLocal(obj);
6169 }
6170 
6171 
6173  i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
6174  LOG_API(i_isolate, "Symbol::New()");
6175  ENTER_V8(i_isolate);
6176  i::Handle<i::Symbol> result = i_isolate->factory()->NewSymbol();
6177  if (!name.IsEmpty()) result->set_name(*Utils::OpenHandle(*name));
6178  return Utils::ToLocal(result);
6179 }
6180 
6181 
6184  i::Handle<i::String> part) {
6185  i::Handle<i::JSObject> registry = isolate->GetSymbolRegistry();
6186  i::Handle<i::JSObject> symbols =
6188  i::Object::GetPropertyOrElement(registry, part).ToHandleChecked());
6189  i::Handle<i::Object> symbol =
6190  i::Object::GetPropertyOrElement(symbols, name).ToHandleChecked();
6191  if (!symbol->IsSymbol()) {
6192  DCHECK(symbol->IsUndefined());
6193  symbol = isolate->factory()->NewSymbol();
6194  i::Handle<i::Symbol>::cast(symbol)->set_name(*name);
6195  i::JSObject::SetProperty(symbols, name, symbol, i::STRICT).Assert();
6196  }
6197  return i::Handle<i::Symbol>::cast(symbol);
6198 }
6199 
6200 
6202  i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
6204  i::Handle<i::String> part = i_isolate->factory()->for_string();
6205  return Utils::ToLocal(SymbolFor(i_isolate, i_name, part));
6206 }
6207 
6208 
6210  i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
6212  i::Handle<i::String> part = i_isolate->factory()->for_api_string();
6213  return Utils::ToLocal(SymbolFor(i_isolate, i_name, part));
6214 }
6215 
6216 
6217 static Local<Symbol> GetWellKnownSymbol(Isolate* isolate, const char* name) {
6218  i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
6219  i::Handle<i::String> i_name =
6221  i::Handle<i::String> part = i_isolate->factory()->for_intern_string();
6222  return Utils::ToLocal(SymbolFor(i_isolate, i_name, part));
6223 }
6224 
6225 
6227  return GetWellKnownSymbol(isolate, "Symbol.iterator");
6228 }
6229 
6230 
6232  return GetWellKnownSymbol(isolate, "Symbol.unscopables");
6233 }
6234 
6235 
6237  i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
6238  LOG_API(i_isolate, "Private::New()");
6239  ENTER_V8(i_isolate);
6240  i::Handle<i::Symbol> symbol = i_isolate->factory()->NewPrivateSymbol();
6241  if (!name.IsEmpty()) symbol->set_name(*Utils::OpenHandle(*name));
6242  Local<Symbol> result = Utils::ToLocal(symbol);
6243  return v8::Handle<Private>(reinterpret_cast<Private*>(*result));
6244 }
6245 
6246 
6248  i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
6250  i::Handle<i::JSObject> registry = i_isolate->GetSymbolRegistry();
6251  i::Handle<i::String> part = i_isolate->factory()->private_api_string();
6252  i::Handle<i::JSObject> privates =
6254  i::Object::GetPropertyOrElement(registry, part).ToHandleChecked());
6255  i::Handle<i::Object> symbol =
6256  i::Object::GetPropertyOrElement(privates, i_name).ToHandleChecked();
6257  if (!symbol->IsSymbol()) {
6258  DCHECK(symbol->IsUndefined());
6259  symbol = i_isolate->factory()->NewPrivateSymbol();
6260  i::Handle<i::Symbol>::cast(symbol)->set_name(*i_name);
6261  i::JSObject::SetProperty(privates, i_name, symbol, i::STRICT).Assert();
6262  }
6264  return v8::Handle<Private>(reinterpret_cast<Private*>(*result));
6265 }
6266 
6267 
6268 Local<Number> v8::Number::New(Isolate* isolate, double value) {
6269  i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
6270  DCHECK(internal_isolate->IsInitialized());
6271  if (std::isnan(value)) {
6272  // Introduce only canonical NaN value into the VM, to avoid signaling NaNs.
6273  value = base::OS::nan_value();
6274  }
6275  ENTER_V8(internal_isolate);
6276  i::Handle<i::Object> result = internal_isolate->factory()->NewNumber(value);
6277  return Utils::NumberToLocal(result);
6278 }
6279 
6280 
6282  i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
6283  DCHECK(internal_isolate->IsInitialized());
6284  if (i::Smi::IsValid(value)) {
6286  internal_isolate));
6287  }
6288  ENTER_V8(internal_isolate);
6289  i::Handle<i::Object> result = internal_isolate->factory()->NewNumber(value);
6290  return Utils::IntegerToLocal(result);
6291 }
6292 
6293 
6295  i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
6296  DCHECK(internal_isolate->IsInitialized());
6297  bool fits_into_int32_t = (value & (1 << 31)) == 0;
6298  if (fits_into_int32_t) {
6299  return Integer::New(isolate, static_cast<int32_t>(value));
6300  }
6301  ENTER_V8(internal_isolate);
6302  i::Handle<i::Object> result = internal_isolate->factory()->NewNumber(value);
6303  return Utils::IntegerToLocal(result);
6304 }
6305 
6306 
6308  i::Isolate* isolate = i::Isolate::Current();
6309  ON_BAILOUT(isolate, "v8::V8::AddMessageListener()", return false);
6310  ENTER_V8(isolate);
6311  i::HandleScope scope(isolate);
6312  NeanderArray listeners(isolate->factory()->message_listeners());
6313  NeanderObject obj(isolate, 2);
6314  obj.set(0, *isolate->factory()->NewForeign(FUNCTION_ADDR(that)));
6315  obj.set(1, data.IsEmpty() ? isolate->heap()->undefined_value()
6316  : *Utils::OpenHandle(*data));
6317  listeners.add(obj.value());
6318  return true;
6319 }
6320 
6321 
6323  i::Isolate* isolate = i::Isolate::Current();
6324  ON_BAILOUT(isolate, "v8::V8::RemoveMessageListeners()", return);
6325  ENTER_V8(isolate);
6326  i::HandleScope scope(isolate);
6327  NeanderArray listeners(isolate->factory()->message_listeners());
6328  for (int i = 0; i < listeners.length(); i++) {
6329  if (listeners.get(i)->IsUndefined()) continue; // skip deleted ones
6330 
6331  NeanderObject listener(i::JSObject::cast(listeners.get(i)));
6332  i::Handle<i::Foreign> callback_obj(i::Foreign::cast(listener.get(0)));
6333  if (callback_obj->foreign_address() == FUNCTION_ADDR(that)) {
6334  listeners.set(i, isolate->heap()->undefined_value());
6335  }
6336  }
6337 }
6338 
6339 
6341  bool capture,
6342  int frame_limit,
6344  i::Isolate::Current()->SetCaptureStackTraceForUncaughtExceptions(
6345  capture,
6346  frame_limit,
6347  options);
6348 }
6349 
6350 
6352  FailedAccessCheckCallback callback) {
6353  i::Isolate* isolate = i::Isolate::Current();
6354  isolate->SetFailedAccessCheckCallback(callback);
6355 }
6356 
6357 
6358 void Isolate::CollectAllGarbage(const char* gc_reason) {
6359  reinterpret_cast<i::Isolate*>(this)->heap()->CollectAllGarbage(
6360  i::Heap::kNoGCFlags, gc_reason);
6361 }
6362 
6363 
6365  i::HeapProfiler* heap_profiler =
6366  reinterpret_cast<i::Isolate*>(this)->heap_profiler();
6367  return reinterpret_cast<HeapProfiler*>(heap_profiler);
6368 }
6369 
6370 
6372  i::CpuProfiler* cpu_profiler =
6373  reinterpret_cast<i::Isolate*>(this)->cpu_profiler();
6374  return reinterpret_cast<CpuProfiler*>(cpu_profiler);
6375 }
6376 
6377 
6379  i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
6380  return isolate->context() != NULL;
6381 }
6382 
6383 
6385  i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
6386  i::Context* context = isolate->context();
6387  if (context == NULL) return Local<Context>();
6388  i::Context* native_context = context->native_context();
6389  if (native_context == NULL) return Local<Context>();
6390  return Utils::ToLocal(i::Handle<i::Context>(native_context));
6391 }
6392 
6393 
6395  i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
6396  i::Handle<i::Object> calling = isolate->GetCallingNativeContext();
6397  if (calling.is_null()) return Local<Context>();
6399 }
6400 
6401 
6403  i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
6404  i::Handle<i::Object> last =
6406  if (last.is_null()) return Local<Context>();
6408 }
6409 
6410 
6412  i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
6413  ENTER_V8(isolate);
6414  // If we're passed an empty handle, we throw an undefined exception
6415  // to deal more gracefully with out of memory situations.
6416  if (value.IsEmpty()) {
6417  isolate->ScheduleThrow(isolate->heap()->undefined_value());
6418  } else {
6419  isolate->ScheduleThrow(*Utils::OpenHandle(*value));
6420  }
6421  return v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate));
6422 }
6423 
6424 
6426  i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(this);
6427  internal_isolate->global_handles()->SetObjectGroupId(
6428  v8::internal::Handle<v8::internal::Object>(object).location(),
6429  id);
6430 }
6431 
6432 
6434  i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(this);
6435  internal_isolate->global_handles()->SetReferenceFromGroup(
6436  id,
6437  v8::internal::Handle<v8::internal::Object>(object).location());
6438 }
6439 
6440 
6442  internal::Object** child) {
6443  i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(this);
6444  i::Object** parent_location =
6445  v8::internal::Handle<v8::internal::Object>(parent).location();
6446  internal_isolate->global_handles()->SetReference(
6447  reinterpret_cast<i::HeapObject**>(parent_location),
6448  v8::internal::Handle<v8::internal::Object>(child).location());
6449 }
6450 
6451 
6453  GCType gc_type) {
6454  i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
6455  isolate->heap()->AddGCPrologueCallback(callback, gc_type);
6456 }
6457 
6458 
6460  i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
6461  isolate->heap()->RemoveGCPrologueCallback(callback);
6462 }
6463 
6464 
6466  GCType gc_type) {
6467  i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
6468  isolate->heap()->AddGCEpilogueCallback(callback, gc_type);
6469 }
6470 
6471 
6473  i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
6474  isolate->heap()->RemoveGCEpilogueCallback(callback);
6475 }
6476 
6477 
6479  i::Isolate* isolate = i::Isolate::Current();
6480  isolate->heap()->AddGCPrologueCallback(
6481  reinterpret_cast<v8::Isolate::GCPrologueCallback>(callback),
6482  gc_type,
6483  false);
6484 }
6485 
6486 
6488  i::Isolate* isolate = i::Isolate::Current();
6489  isolate->heap()->RemoveGCPrologueCallback(
6490  reinterpret_cast<v8::Isolate::GCPrologueCallback>(callback));
6491 }
6492 
6493 
6495  i::Isolate* isolate = i::Isolate::Current();
6496  isolate->heap()->AddGCEpilogueCallback(
6497  reinterpret_cast<v8::Isolate::GCEpilogueCallback>(callback),
6498  gc_type,
6499  false);
6500 }
6501 
6502 
6504  i::Isolate* isolate = i::Isolate::Current();
6505  isolate->heap()->RemoveGCEpilogueCallback(
6506  reinterpret_cast<v8::Isolate::GCEpilogueCallback>(callback));
6507 }
6508 
6509 
6512  AllocationAction action) {
6513  i::Isolate* isolate = i::Isolate::Current();
6515  callback, space, action);
6516 }
6517 
6518 
6520  i::Isolate* isolate = i::Isolate::Current();
6522  callback);
6523 }
6524 
6525 
6527  i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
6528  i_isolate->stack_guard()->RequestTerminateExecution();
6529 }
6530 
6531 
6533  i::Isolate* i_isolate = isolate != NULL ?
6534  reinterpret_cast<i::Isolate*>(isolate) : i::Isolate::Current();
6535  return IsExecutionTerminatingCheck(i_isolate);
6536 }
6537 
6538 
6540  i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
6541  i_isolate->stack_guard()->ClearTerminateExecution();
6542  i_isolate->CancelTerminateExecution();
6543 }
6544 
6545 
6546 void Isolate::RequestInterrupt(InterruptCallback callback, void* data) {
6547  i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(this);
6548  i_isolate->set_api_interrupt_callback(callback);
6549  i_isolate->set_api_interrupt_callback_data(data);
6550  i_isolate->stack_guard()->RequestApiInterrupt();
6551 }
6552 
6553 
6555  i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(this);
6556  i_isolate->stack_guard()->ClearApiInterrupt();
6557  i_isolate->set_api_interrupt_callback(NULL);
6558  i_isolate->set_api_interrupt_callback_data(NULL);
6559 }
6560 
6561 
6563  CHECK(i::FLAG_expose_gc);
6564  if (type == kMinorGarbageCollection) {
6565  reinterpret_cast<i::Isolate*>(this)->heap()->CollectGarbage(
6566  i::NEW_SPACE, "Isolate::RequestGarbageCollection",
6568  } else {
6569  DCHECK_EQ(kFullGarbageCollection, type);
6570  reinterpret_cast<i::Isolate*>(this)->heap()->CollectAllGarbage(
6572  "Isolate::RequestGarbageCollection", kGCCallbackFlagForced);
6573  }
6574 }
6575 
6576 
6578  i::Isolate* isolate = i::Isolate::Current();
6579  return reinterpret_cast<Isolate*>(isolate);
6580 }
6581 
6582 
6584  i::Isolate* isolate = new i::Isolate();
6585  Isolate* v8_isolate = reinterpret_cast<Isolate*>(isolate);
6586  if (params.entry_hook) {
6587  isolate->set_function_entry_hook(params.entry_hook);
6588  }
6589  if (params.code_event_handler) {
6590  isolate->InitializeLoggingAndCounters();
6592  params.code_event_handler);
6593  }
6594  SetResourceConstraints(isolate, params.constraints);
6595  if (params.enable_serializer) {
6596  isolate->enable_serializer();
6597  }
6598  // TODO(jochen): Once we got rid of Isolate::Current(), we can remove this.
6599  Isolate::Scope isolate_scope(v8_isolate);
6600  if (params.entry_hook || !i::Snapshot::Initialize(isolate)) {
6601  // If the isolate has a function entry hook, it needs to re-build all its
6602  // code stubs with entry hooks embedded, so don't deserialize a snapshot.
6603  isolate->Init(NULL);
6604  }
6605  return v8_isolate;
6606 }
6607 
6608 
6610  i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
6611  if (!Utils::ApiCheck(!isolate->IsInUse(),
6612  "v8::Isolate::Dispose()",
6613  "Disposing the isolate that is entered by a thread.")) {
6614  return;
6615  }
6616  isolate->TearDown();
6617 }
6618 
6619 
6621  i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
6622  isolate->Enter();
6623 }
6624 
6625 
6627  i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
6628  isolate->Exit();
6629 }
6630 
6631 
6633  Isolate* isolate,
6635  : on_failure_(on_failure) {
6636  i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
6637  if (on_failure_ == CRASH_ON_FAILURE) {
6638  internal_ = reinterpret_cast<void*>(
6639  new i::DisallowJavascriptExecution(i_isolate));
6640  } else {
6641  DCHECK_EQ(THROW_ON_FAILURE, on_failure);
6642  internal_ = reinterpret_cast<void*>(
6643  new i::ThrowOnJavascriptExecution(i_isolate));
6644  }
6645 }
6646 
6647 
6649  if (on_failure_ == CRASH_ON_FAILURE) {
6650  delete reinterpret_cast<i::DisallowJavascriptExecution*>(internal_);
6651  } else {
6652  delete reinterpret_cast<i::ThrowOnJavascriptExecution*>(internal_);
6653  }
6654 }
6655 
6656 
6658  Isolate* isolate) {
6659  i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
6660  internal_assert_ = reinterpret_cast<void*>(
6661  new i::AllowJavascriptExecution(i_isolate));
6662  internal_throws_ = reinterpret_cast<void*>(
6663  new i::NoThrowOnJavascriptExecution(i_isolate));
6664 }
6665 
6666 
6668  delete reinterpret_cast<i::AllowJavascriptExecution*>(internal_assert_);
6669  delete reinterpret_cast<i::NoThrowOnJavascriptExecution*>(internal_throws_);
6670 }
6671 
6672 
6674  Isolate* isolate)
6675  : isolate_(reinterpret_cast<i::Isolate*>(isolate)) {
6677 }
6678 
6679 
6681  isolate_->handle_scope_implementer()->DecrementCallDepth();
6682 }
6683 
6684 
6686  i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
6687  if (!isolate->IsInitialized()) {
6688  heap_statistics->total_heap_size_ = 0;
6689  heap_statistics->total_heap_size_executable_ = 0;
6690  heap_statistics->total_physical_size_ = 0;
6691  heap_statistics->used_heap_size_ = 0;
6692  heap_statistics->heap_size_limit_ = 0;
6693  return;
6694  }
6695  i::Heap* heap = isolate->heap();
6696  heap_statistics->total_heap_size_ = heap->CommittedMemory();
6697  heap_statistics->total_heap_size_executable_ =
6698  heap->CommittedMemoryExecutable();
6699  heap_statistics->total_physical_size_ = heap->CommittedPhysicalMemory();
6700  heap_statistics->used_heap_size_ = heap->SizeOfObjects();
6701  heap_statistics->heap_size_limit_ = heap->MaxReserved();
6702 }
6703 
6704 
6706  // Do not overwrite the event logger if we want to log explicitly.
6707  if (i::FLAG_log_timer_events) return;
6708  i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
6709  isolate->set_event_logger(that);
6710 }
6711 
6712 
6714  if (callback == NULL) return;
6715  i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
6716  isolate->AddCallCompletedCallback(callback);
6717 }
6718 
6719 
6721  i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
6722  isolate->RemoveCallCompletedCallback(callback);
6723 }
6724 
6725 
6727  reinterpret_cast<i::Isolate*>(this)->RunMicrotasks();
6728 }
6729 
6730 
6732  i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
6733  isolate->EnqueueMicrotask(Utils::OpenHandle(*microtask));
6734 }
6735 
6736 
6737 void Isolate::EnqueueMicrotask(MicrotaskCallback microtask, void* data) {
6738  i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
6739  i::HandleScope scope(isolate);
6740  i::Handle<i::CallHandlerInfo> callback_info =
6742  isolate->factory()->NewStruct(i::CALL_HANDLER_INFO_TYPE));
6743  SET_FIELD_WRAPPED(callback_info, set_callback, microtask);
6744  SET_FIELD_WRAPPED(callback_info, set_data, data);
6745  isolate->EnqueueMicrotask(callback_info);
6746 }
6747 
6748 
6749 void Isolate::SetAutorunMicrotasks(bool autorun) {
6750  reinterpret_cast<i::Isolate*>(this)->set_autorun_microtasks(autorun);
6751 }
6752 
6753 
6755  return reinterpret_cast<const i::Isolate*>(this)->autorun_microtasks();
6756 }
6757 
6758 
6760  reinterpret_cast<i::Isolate*>(this)->SetUseCounterCallback(callback);
6761 }
6762 
6763 
6765  i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
6766  isolate->stats_table()->SetCounterFunction(callback);
6767  isolate->InitializeLoggingAndCounters();
6768  isolate->counters()->ResetCounters();
6769 }
6770 
6771 
6773  i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
6774  isolate->stats_table()->SetCreateHistogramFunction(callback);
6775  isolate->InitializeLoggingAndCounters();
6776  isolate->counters()->ResetHistograms();
6777 }
6778 
6779 
6781  AddHistogramSampleCallback callback) {
6782  reinterpret_cast<i::Isolate*>(this)
6783  ->stats_table()
6784  ->SetAddHistogramSampleFunction(callback);
6785 }
6786 
6787 
6788 bool v8::Isolate::IdleNotification(int idle_time_in_ms) {
6789  // Returning true tells the caller that it need not
6790  // continue to call IdleNotification.
6791  i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
6792  if (!i::FLAG_use_idle_notification) return true;
6793  return isolate->heap()->IdleNotification(idle_time_in_ms);
6794 }
6795 
6796 
6798  i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
6799  {
6800  i::HistogramTimerScope idle_notification_scope(
6801  isolate->counters()->gc_low_memory_notification());
6802  isolate->heap()->CollectAllAvailableGarbage("low memory notification");
6803  }
6804 }
6805 
6806 
6808  i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
6809  return isolate->heap()->NotifyContextDisposed();
6810 }
6811 
6812 
6814  JitCodeEventHandler event_handler) {
6815  i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
6816  // Ensure that logging is initialized for our isolate.
6817  isolate->InitializeLoggingAndCounters();
6818  isolate->logger()->SetCodeEventHandler(options, event_handler);
6819 }
6820 
6821 
6823  i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
6824  CHECK(stack_limit);
6825  isolate->stack_guard()->SetStackLimit(stack_limit);
6826 }
6827 
6828 
6829 void v8::Isolate::GetCodeRange(void** start, size_t* length_in_bytes) {
6830  i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
6831  if (isolate->code_range()->valid()) {
6832  *start = isolate->code_range()->start();
6833  *length_in_bytes = isolate->code_range()->size();
6834  } else {
6835  *start = NULL;
6836  *length_in_bytes = 0;
6837  }
6838 }
6839 
6840 
6842  : str_(NULL), length_(0) {
6843  i::Isolate* isolate = i::Isolate::Current();
6844  if (obj.IsEmpty()) return;
6845  ENTER_V8(isolate);
6846  i::HandleScope scope(isolate);
6847  TryCatch try_catch;
6848  Handle<String> str = obj->ToString();
6849  if (str.IsEmpty()) return;
6851  length_ = v8::Utf8Length(*i_str, isolate);
6852  str_ = i::NewArray<char>(length_ + 1);
6853  str->WriteUtf8(str_);
6854 }
6855 
6856 
6858  i::DeleteArray(str_);
6859 }
6860 
6861 
6863  : str_(NULL), length_(0) {
6864  i::Isolate* isolate = i::Isolate::Current();
6865  if (obj.IsEmpty()) return;
6866  ENTER_V8(isolate);
6867  i::HandleScope scope(isolate);
6868  TryCatch try_catch;
6869  Handle<String> str = obj->ToString();
6870  if (str.IsEmpty()) return;
6871  length_ = str->Length();
6872  str_ = i::NewArray<uint16_t>(length_ + 1);
6873  str->Write(str_);
6874 }
6875 
6876 
6878  i::DeleteArray(str_);
6879 }
6880 
6881 
6882 #define DEFINE_ERROR(NAME) \
6883  Local<Value> Exception::NAME(v8::Handle<v8::String> raw_message) { \
6884  i::Isolate* isolate = i::Isolate::Current(); \
6885  LOG_API(isolate, #NAME); \
6886  ON_BAILOUT(isolate, "v8::Exception::" #NAME "()", return Local<Value>()); \
6887  ENTER_V8(isolate); \
6888  i::Object* error; \
6889  { \
6890  i::HandleScope scope(isolate); \
6891  i::Handle<i::String> message = Utils::OpenHandle(*raw_message); \
6892  i::Handle<i::Object> result; \
6893  EXCEPTION_PREAMBLE(isolate); \
6894  i::MaybeHandle<i::Object> maybe_result = \
6895  isolate->factory()->New##NAME(message); \
6896  has_pending_exception = !maybe_result.ToHandle(&result); \
6897  /* TODO(yangguo): crbug/403509. Return empty handle instead. */ \
6898  EXCEPTION_BAILOUT_CHECK( \
6899  isolate, v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate))); \
6900  error = *result; \
6901  } \
6902  i::Handle<i::Object> result(error, isolate); \
6903  return Utils::ToLocal(result); \
6904  }
6905 
6906 DEFINE_ERROR(RangeError)
6907 DEFINE_ERROR(ReferenceError)
6908 DEFINE_ERROR(SyntaxError)
6909 DEFINE_ERROR(TypeError)
6910 DEFINE_ERROR(Error)
6911 
6912 #undef DEFINE_ERROR
6913 
6914 
6915 // --- D e b u g S u p p o r t ---
6916 
6917 bool Debug::SetDebugEventListener(EventCallback that, Handle<Value> data) {
6918  i::Isolate* isolate = i::Isolate::Current();
6919  ON_BAILOUT(isolate, "v8::Debug::SetDebugEventListener()", return false);
6920  ENTER_V8(isolate);
6921  i::HandleScope scope(isolate);
6922  i::Handle<i::Object> foreign = isolate->factory()->undefined_value();
6923  if (that != NULL) {
6924  foreign = isolate->factory()->NewForeign(FUNCTION_ADDR(that));
6925  }
6926  isolate->debug()->SetEventListener(foreign,
6927  Utils::OpenHandle(*data, true));
6928  return true;
6929 }
6930 
6931 
6932 void Debug::DebugBreak(Isolate* isolate) {
6933  reinterpret_cast<i::Isolate*>(isolate)->stack_guard()->RequestDebugBreak();
6934 }
6935 
6936 
6938  i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
6939  internal_isolate->stack_guard()->ClearDebugBreak();
6940 }
6941 
6942 
6944  i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
6945  return internal_isolate->stack_guard()->CheckDebugBreak();
6946 }
6947 
6948 
6950  i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
6951  internal_isolate->debug()->EnqueueDebugCommand(data);
6952 }
6953 
6954 
6956  i::Isolate* isolate = i::Isolate::Current();
6957  ENTER_V8(isolate);
6958  isolate->debug()->SetMessageHandler(handler);
6959 }
6960 
6961 
6963  const uint16_t* command,
6964  int length,
6965  ClientData* client_data) {
6966  i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
6967  internal_isolate->debug()->EnqueueCommandMessage(
6968  i::Vector<const uint16_t>(command, length), client_data);
6969 }
6970 
6971 
6973  v8::Handle<v8::Value> data) {
6974  i::Isolate* isolate = i::Isolate::Current();
6975  if (!isolate->IsInitialized()) return Local<Value>();
6976  ON_BAILOUT(isolate, "v8::Debug::Call()", return Local<Value>());
6977  ENTER_V8(isolate);
6978  i::MaybeHandle<i::Object> maybe_result;
6979  EXCEPTION_PREAMBLE(isolate);
6980  if (data.IsEmpty()) {
6981  maybe_result = isolate->debug()->Call(
6982  Utils::OpenHandle(*fun), isolate->factory()->undefined_value());
6983  } else {
6984  maybe_result = isolate->debug()->Call(
6985  Utils::OpenHandle(*fun), Utils::OpenHandle(*data));
6986  }
6987  i::Handle<i::Object> result;
6988  has_pending_exception = !maybe_result.ToHandle(&result);
6990  return Utils::ToLocal(result);
6991 }
6992 
6993 
6995  i::Isolate* isolate = i::Isolate::Current();
6996  if (!isolate->IsInitialized()) return Local<Value>();
6997  ON_BAILOUT(isolate, "v8::Debug::GetMirror()", return Local<Value>());
6998  ENTER_V8(isolate);
6999  v8::EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate));
7000  i::Debug* isolate_debug = isolate->debug();
7001  EXCEPTION_PREAMBLE(isolate);
7002  has_pending_exception = !isolate_debug->Load();
7003  v8::Local<v8::Value> result;
7004  if (!has_pending_exception) {
7005  i::Handle<i::JSObject> debug(
7006  isolate_debug->debug_context()->global_object());
7007  i::Handle<i::String> name = isolate->factory()->InternalizeOneByteString(
7008  STATIC_CHAR_VECTOR("MakeMirror"));
7009  i::Handle<i::Object> fun_obj =
7010  i::Object::GetProperty(debug, name).ToHandleChecked();
7013  const int kArgc = 1;
7014  v8::Handle<v8::Value> argv[kArgc] = { obj };
7015  result = v8_fun->Call(Utils::ToLocal(debug), kArgc, argv);
7016  has_pending_exception = result.IsEmpty();
7017  }
7019  return scope.Escape(result);
7020 }
7021 
7022 
7024  i::Isolate::Current()->debug()->ProcessDebugMessages(true);
7025 }
7026 
7027 
7029  i::Isolate* isolate = i::Isolate::Current();
7030  ENTER_V8(isolate);
7031  return Utils::ToLocal(i::Isolate::Current()->debug()->GetDebugContext());
7032 }
7033 
7034 
7035 void Debug::SetLiveEditEnabled(Isolate* isolate, bool enable) {
7036  i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
7037  internal_isolate->debug()->set_live_edit_enabled(enable);
7038 }
7039 
7040 
7042  i::Isolate* isolate = i::Isolate::Current();
7043  const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this);
7044  const i::CodeEntry* entry = node->entry();
7046  isolate->factory()->InternalizeUtf8String(entry->name());
7047  if (!entry->has_name_prefix()) {
7048  return ToApiHandle<String>(name);
7049  } else {
7050  // We do not expect this to fail. Change this if it does.
7051  i::Handle<i::String> cons = isolate->factory()->NewConsString(
7052  isolate->factory()->InternalizeUtf8String(entry->name_prefix()),
7053  name).ToHandleChecked();
7054  return ToApiHandle<String>(cons);
7055  }
7056 }
7057 
7058 
7060  const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this);
7061  const i::CodeEntry* entry = node->entry();
7062  return entry->script_id();
7063 }
7064 
7065 
7067  i::Isolate* isolate = i::Isolate::Current();
7068  const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this);
7069  return ToApiHandle<String>(isolate->factory()->InternalizeUtf8String(
7070  node->entry()->resource_name()));
7071 }
7072 
7073 
7075  return reinterpret_cast<const i::ProfileNode*>(this)->entry()->line_number();
7076 }
7077 
7078 
7080  return reinterpret_cast<const i::ProfileNode*>(this)->
7081  entry()->column_number();
7082 }
7083 
7084 
7086  const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this);
7087  return node->entry()->bailout_reason();
7088 }
7089 
7090 
7092  return reinterpret_cast<const i::ProfileNode*>(this)->self_ticks();
7093 }
7094 
7095 
7096 unsigned CpuProfileNode::GetCallUid() const {
7097  return reinterpret_cast<const i::ProfileNode*>(this)->entry()->GetCallUid();
7098 }
7099 
7100 
7101 unsigned CpuProfileNode::GetNodeId() const {
7102  return reinterpret_cast<const i::ProfileNode*>(this)->id();
7103 }
7104 
7105 
7107  return reinterpret_cast<const i::ProfileNode*>(this)->children()->length();
7108 }
7109 
7110 
7111 const CpuProfileNode* CpuProfileNode::GetChild(int index) const {
7112  const i::ProfileNode* child =
7113  reinterpret_cast<const i::ProfileNode*>(this)->children()->at(index);
7114  return reinterpret_cast<const CpuProfileNode*>(child);
7115 }
7116 
7117 
7119  i::Isolate* isolate = i::Isolate::Current();
7120  i::CpuProfiler* profiler = isolate->cpu_profiler();
7121  DCHECK(profiler != NULL);
7122  profiler->DeleteProfile(reinterpret_cast<i::CpuProfile*>(this));
7123 }
7124 
7125 
7127  i::Isolate* isolate = i::Isolate::Current();
7128  const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this);
7129  return ToApiHandle<String>(isolate->factory()->InternalizeUtf8String(
7130  profile->title()));
7131 }
7132 
7133 
7135  const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this);
7136  return reinterpret_cast<const CpuProfileNode*>(profile->top_down()->root());
7137 }
7138 
7139 
7140 const CpuProfileNode* CpuProfile::GetSample(int index) const {
7141  const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this);
7142  return reinterpret_cast<const CpuProfileNode*>(profile->sample(index));
7143 }
7144 
7145 
7146 int64_t CpuProfile::GetSampleTimestamp(int index) const {
7147  const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this);
7148  return (profile->sample_timestamp(index) - base::TimeTicks())
7149  .InMicroseconds();
7150 }
7151 
7152 
7153 int64_t CpuProfile::GetStartTime() const {
7154  const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this);
7155  return (profile->start_time() - base::TimeTicks()).InMicroseconds();
7156 }
7157 
7158 
7159 int64_t CpuProfile::GetEndTime() const {
7160  const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this);
7161  return (profile->end_time() - base::TimeTicks()).InMicroseconds();
7162 }
7163 
7164 
7166  return reinterpret_cast<const i::CpuProfile*>(this)->samples_count();
7167 }
7168 
7169 
7171  DCHECK(us >= 0);
7172  return reinterpret_cast<i::CpuProfiler*>(this)->set_sampling_interval(
7173  base::TimeDelta::FromMicroseconds(us));
7174 }
7175 
7176 
7177 void CpuProfiler::StartProfiling(Handle<String> title, bool record_samples) {
7178  reinterpret_cast<i::CpuProfiler*>(this)->StartProfiling(
7179  *Utils::OpenHandle(*title), record_samples);
7180 }
7181 
7182 
7183 void CpuProfiler::StartCpuProfiling(Handle<String> title, bool record_samples) {
7184  StartProfiling(title, record_samples);
7185 }
7186 
7187 
7189  return reinterpret_cast<CpuProfile*>(
7190  reinterpret_cast<i::CpuProfiler*>(this)->StopProfiling(
7191  *Utils::OpenHandle(*title)));
7192 }
7193 
7194 
7195 const CpuProfile* CpuProfiler::StopCpuProfiling(Handle<String> title) {
7196  return StopProfiling(title);
7197 }
7198 
7199 
7200 void CpuProfiler::SetIdle(bool is_idle) {
7201  i::Isolate* isolate = reinterpret_cast<i::CpuProfiler*>(this)->isolate();
7202  i::StateTag state = isolate->current_vm_state();
7203  DCHECK(state == i::EXTERNAL || state == i::IDLE);
7204  if (isolate->js_entry_sp() != NULL) return;
7205  if (is_idle) {
7206  isolate->set_current_vm_state(i::IDLE);
7207  } else if (state == i::IDLE) {
7208  isolate->set_current_vm_state(i::EXTERNAL);
7209  }
7210 }
7211 
7212 
7213 static i::HeapGraphEdge* ToInternal(const HeapGraphEdge* edge) {
7214  return const_cast<i::HeapGraphEdge*>(
7215  reinterpret_cast<const i::HeapGraphEdge*>(edge));
7216 }
7217 
7218 
7220  return static_cast<HeapGraphEdge::Type>(ToInternal(this)->type());
7221 }
7222 
7223 
7225  i::Isolate* isolate = i::Isolate::Current();
7226  i::HeapGraphEdge* edge = ToInternal(this);
7227  switch (edge->type()) {
7228  case i::HeapGraphEdge::kContextVariable:
7229  case i::HeapGraphEdge::kInternal:
7230  case i::HeapGraphEdge::kProperty:
7231  case i::HeapGraphEdge::kShortcut:
7233  return ToApiHandle<String>(
7234  isolate->factory()->InternalizeUtf8String(edge->name()));
7235  case i::HeapGraphEdge::kElement:
7236  case i::HeapGraphEdge::kHidden:
7237  return ToApiHandle<Number>(
7238  isolate->factory()->NewNumberFromInt(edge->index()));
7239  default: UNREACHABLE();
7240  }
7241  return v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate));
7242 }
7243 
7244 
7246  const i::HeapEntry* from = ToInternal(this)->from();
7247  return reinterpret_cast<const HeapGraphNode*>(from);
7248 }
7249 
7250 
7252  const i::HeapEntry* to = ToInternal(this)->to();
7253  return reinterpret_cast<const HeapGraphNode*>(to);
7254 }
7255 
7256 
7257 static i::HeapEntry* ToInternal(const HeapGraphNode* entry) {
7258  return const_cast<i::HeapEntry*>(
7259  reinterpret_cast<const i::HeapEntry*>(entry));
7260 }
7261 
7262 
7264  return static_cast<HeapGraphNode::Type>(ToInternal(this)->type());
7265 }
7266 
7267 
7269  i::Isolate* isolate = i::Isolate::Current();
7270  return ToApiHandle<String>(
7271  isolate->factory()->InternalizeUtf8String(ToInternal(this)->name()));
7272 }
7273 
7274 
7276  return ToInternal(this)->id();
7277 }
7278 
7279 
7280 int HeapGraphNode::GetSelfSize() const {
7281  size_t size = ToInternal(this)->self_size();
7282  CHECK(size <= static_cast<size_t>(internal::kMaxInt));
7283  return static_cast<int>(size);
7284 }
7285 
7286 
7288  return ToInternal(this)->self_size();
7289 }
7290 
7291 
7293  return ToInternal(this)->children().length();
7294 }
7295 
7296 
7297 const HeapGraphEdge* HeapGraphNode::GetChild(int index) const {
7298  return reinterpret_cast<const HeapGraphEdge*>(
7299  ToInternal(this)->children()[index]);
7300 }
7301 
7302 
7304  return const_cast<i::HeapSnapshot*>(
7305  reinterpret_cast<const i::HeapSnapshot*>(snapshot));
7306 }
7307 
7308 
7310  i::Isolate* isolate = i::Isolate::Current();
7311  if (isolate->heap_profiler()->GetSnapshotsCount() > 1) {
7312  ToInternal(this)->Delete();
7313  } else {
7314  // If this is the last snapshot, clean up all accessory data as well.
7315  isolate->heap_profiler()->DeleteAllSnapshots();
7316  }
7317 }
7318 
7319 
7320 unsigned HeapSnapshot::GetUid() const {
7321  return ToInternal(this)->uid();
7322 }
7323 
7324 
7326  i::Isolate* isolate = i::Isolate::Current();
7327  return ToApiHandle<String>(
7328  isolate->factory()->InternalizeUtf8String(ToInternal(this)->title()));
7329 }
7330 
7331 
7333  return reinterpret_cast<const HeapGraphNode*>(ToInternal(this)->root());
7334 }
7335 
7336 
7338  return reinterpret_cast<const HeapGraphNode*>(
7339  ToInternal(this)->GetEntryById(id));
7340 }
7341 
7342 
7344  return ToInternal(this)->entries().length();
7345 }
7346 
7347 
7348 const HeapGraphNode* HeapSnapshot::GetNode(int index) const {
7349  return reinterpret_cast<const HeapGraphNode*>(
7350  &ToInternal(this)->entries().at(index));
7351 }
7352 
7353 
7355  return ToInternal(this)->max_snapshot_js_object_id();
7356 }
7357 
7358 
7360  HeapSnapshot::SerializationFormat format) const {
7361  Utils::ApiCheck(format == kJSON,
7362  "v8::HeapSnapshot::Serialize",
7363  "Unknown serialization format");
7364  Utils::ApiCheck(stream->GetChunkSize() > 0,
7365  "v8::HeapSnapshot::Serialize",
7366  "Invalid stream chunk size");
7367  i::HeapSnapshotJSONSerializer serializer(ToInternal(this));
7368  serializer.Serialize(stream);
7369 }
7370 
7371 
7373  return reinterpret_cast<i::HeapProfiler*>(this)->GetSnapshotsCount();
7374 }
7375 
7376 
7378  return reinterpret_cast<const HeapSnapshot*>(
7379  reinterpret_cast<i::HeapProfiler*>(this)->GetSnapshot(index));
7380 }
7381 
7382 
7385  return reinterpret_cast<i::HeapProfiler*>(this)->GetSnapshotObjectId(obj);
7386 }
7387 
7388 
7390  i::Handle<i::Object> obj =
7391  reinterpret_cast<i::HeapProfiler*>(this)->FindHeapObjectById(id);
7392  if (obj.is_null()) return Local<Value>();
7393  return Utils::ToLocal(obj);
7394 }
7395 
7396 
7398  reinterpret_cast<i::HeapProfiler*>(this)->ClearHeapObjectMap();
7399 }
7400 
7401 
7403  Handle<String> title,
7404  ActivityControl* control,
7405  ObjectNameResolver* resolver) {
7406  return reinterpret_cast<const HeapSnapshot*>(
7407  reinterpret_cast<i::HeapProfiler*>(this)->TakeSnapshot(
7408  *Utils::OpenHandle(*title), control, resolver));
7409 }
7410 
7411 
7412 void HeapProfiler::StartTrackingHeapObjects(bool track_allocations) {
7413  reinterpret_cast<i::HeapProfiler*>(this)->StartHeapObjectsTracking(
7414  track_allocations);
7415 }
7416 
7417 
7419  reinterpret_cast<i::HeapProfiler*>(this)->StopHeapObjectsTracking();
7420 }
7421 
7422 
7424  return reinterpret_cast<i::HeapProfiler*>(this)->PushHeapObjectsStats(stream);
7425 }
7426 
7427 
7429  reinterpret_cast<i::HeapProfiler*>(this)->DeleteAllSnapshots();
7430 }
7431 
7432 
7434  WrapperInfoCallback callback) {
7435  reinterpret_cast<i::HeapProfiler*>(this)->DefineWrapperClass(class_id,
7436  callback);
7437 }
7438 
7439 
7441  return reinterpret_cast<i::HeapProfiler*>(this)->
7442  GetMemorySizeUsedByProfiler();
7443 }
7444 
7445 
7447  RetainedObjectInfo* info) {
7448  reinterpret_cast<i::HeapProfiler*>(this)->SetRetainedObjectInfo(id, info);
7449 }
7450 
7451 
7454 
7455 
7458 }
7459 
7460 
7462  if (internal::FLAG_stress_runs != 0) return internal::FLAG_stress_runs;
7463 #ifdef DEBUG
7464  // In debug mode the code runs much slower so stressing will only make two
7465  // runs.
7466  return 2;
7467 #else
7468  return 5;
7469 #endif
7470 }
7471 
7472 
7473 static void SetFlagsFromString(const char* flags) {
7475 }
7476 
7477 
7479  static const char* kLazyOptimizations =
7480  "--prepare-always-opt "
7481  "--max-inlined-source-size=999999 "
7482  "--max-inlined-nodes=999999 "
7483  "--max-inlined-nodes-cumulative=999999 "
7484  "--noalways-opt";
7485  static const char* kForcedOptimizations = "--always-opt";
7486 
7487  // If deoptimization stressed turn on frequent deoptimization. If no value
7488  // is spefified through --deopt-every-n-times use a default default value.
7489  static const char* kDeoptEvery13Times = "--deopt-every-n-times=13";
7491  internal::FLAG_deopt_every_n_times == 0) {
7492  SetFlagsFromString(kDeoptEvery13Times);
7493  }
7494 
7495 #ifdef DEBUG
7496  // As stressing in debug mode only make two runs skip the deopt stressing
7497  // here.
7498  if (run == GetStressRuns() - 1) {
7499  SetFlagsFromString(kForcedOptimizations);
7500  } else {
7501  SetFlagsFromString(kLazyOptimizations);
7502  }
7503 #else
7504  if (run == GetStressRuns() - 1) {
7505  SetFlagsFromString(kForcedOptimizations);
7506  } else if (run != GetStressRuns() - 2) {
7507  SetFlagsFromString(kLazyOptimizations);
7508  }
7509 #endif
7510 }
7511 
7512 
7513 // TODO(svenpanne) Deprecate this.
7515  i::Isolate* isolate = i::Isolate::Current();
7516  i::HandleScope scope(isolate);
7518 }
7519 
7520 
7521 namespace internal {
7522 
7523 
7524 void HandleScopeImplementer::FreeThreadResources() {
7525  Free();
7526 }
7527 
7528 
7529 char* HandleScopeImplementer::ArchiveThread(char* storage) {
7530  HandleScopeData* current = isolate_->handle_scope_data();
7531  handle_scope_data_ = *current;
7532  MemCopy(storage, this, sizeof(*this));
7533 
7534  ResetAfterArchive();
7535  current->Initialize();
7536 
7537  return storage + ArchiveSpacePerThread();
7538 }
7539 
7540 
7542  return sizeof(HandleScopeImplementer);
7543 }
7544 
7545 
7546 char* HandleScopeImplementer::RestoreThread(char* storage) {
7547  MemCopy(this, storage, sizeof(*this));
7548  *isolate_->handle_scope_data() = handle_scope_data_;
7549  return storage + ArchiveSpacePerThread();
7550 }
7551 
7552 
7553 void HandleScopeImplementer::IterateThis(ObjectVisitor* v) {
7554 #ifdef DEBUG
7555  bool found_block_before_deferred = false;
7556 #endif
7557  // Iterate over all handles in the blocks except for the last.
7558  for (int i = blocks()->length() - 2; i >= 0; --i) {
7559  Object** block = blocks()->at(i);
7560  if (last_handle_before_deferred_block_ != NULL &&
7561  (last_handle_before_deferred_block_ <= &block[kHandleBlockSize]) &&
7562  (last_handle_before_deferred_block_ >= block)) {
7563  v->VisitPointers(block, last_handle_before_deferred_block_);
7564  DCHECK(!found_block_before_deferred);
7565 #ifdef DEBUG
7566  found_block_before_deferred = true;
7567 #endif
7568  } else {
7569  v->VisitPointers(block, &block[kHandleBlockSize]);
7570  }
7571  }
7572 
7573  DCHECK(last_handle_before_deferred_block_ == NULL ||
7574  found_block_before_deferred);
7575 
7576  // Iterate over live handles in the last block (if any).
7577  if (!blocks()->is_empty()) {
7578  v->VisitPointers(blocks()->last(), handle_scope_data_.next);
7579  }
7580 
7581  List<Context*>* context_lists[2] = { &saved_contexts_, &entered_contexts_};
7582  for (unsigned i = 0; i < arraysize(context_lists); i++) {
7583  if (context_lists[i]->is_empty()) continue;
7584  Object** start = reinterpret_cast<Object**>(&context_lists[i]->first());
7585  v->VisitPointers(start, start + context_lists[i]->length());
7586  }
7587 }
7588 
7589 
7590 void HandleScopeImplementer::Iterate(ObjectVisitor* v) {
7591  HandleScopeData* current = isolate_->handle_scope_data();
7592  handle_scope_data_ = *current;
7593  IterateThis(v);
7594 }
7595 
7596 
7597 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) {
7598  HandleScopeImplementer* scope_implementer =
7599  reinterpret_cast<HandleScopeImplementer*>(storage);
7600  scope_implementer->IterateThis(v);
7601  return storage + ArchiveSpacePerThread();
7602 }
7603 
7604 
7605 DeferredHandles* HandleScopeImplementer::Detach(Object** prev_limit) {
7606  DeferredHandles* deferred =
7607  new DeferredHandles(isolate()->handle_scope_data()->next, isolate());
7608 
7609  while (!blocks_.is_empty()) {
7610  Object** block_start = blocks_.last();
7611  Object** block_limit = &block_start[kHandleBlockSize];
7612  // We should not need to check for SealHandleScope here. Assert this.
7613  DCHECK(prev_limit == block_limit ||
7614  !(block_start <= prev_limit && prev_limit <= block_limit));
7615  if (prev_limit == block_limit) break;
7616  deferred->blocks_.Add(blocks_.last());
7617  blocks_.RemoveLast();
7618  }
7619 
7620  // deferred->blocks_ now contains the blocks installed on the
7621  // HandleScope stack since BeginDeferredScope was called, but in
7622  // reverse order.
7623 
7624  DCHECK(prev_limit == NULL || !blocks_.is_empty());
7625 
7626  DCHECK(!blocks_.is_empty() && prev_limit != NULL);
7627  DCHECK(last_handle_before_deferred_block_ != NULL);
7628  last_handle_before_deferred_block_ = NULL;
7629  return deferred;
7630 }
7631 
7632 
7633 void HandleScopeImplementer::BeginDeferredScope() {
7634  DCHECK(last_handle_before_deferred_block_ == NULL);
7635  last_handle_before_deferred_block_ = isolate()->handle_scope_data()->next;
7636 }
7637 
7638 
7639 DeferredHandles::~DeferredHandles() {
7640  isolate_->UnlinkDeferredHandles(this);
7641 
7642  for (int i = 0; i < blocks_.length(); i++) {
7643 #ifdef ENABLE_HANDLE_ZAPPING
7644  HandleScope::ZapRange(blocks_[i], &blocks_[i][kHandleBlockSize]);
7645 #endif
7646  isolate_->handle_scope_implementer()->ReturnBlock(blocks_[i]);
7647  }
7648 }
7649 
7650 
7651 void DeferredHandles::Iterate(ObjectVisitor* v) {
7652  DCHECK(!blocks_.is_empty());
7653 
7654  DCHECK((first_block_limit_ >= blocks_.first()) &&
7655  (first_block_limit_ <= &(blocks_.first())[kHandleBlockSize]));
7656 
7657  v->VisitPointers(blocks_.first(), first_block_limit_);
7658 
7659  for (int i = 1; i < blocks_.length(); i++) {
7660  v->VisitPointers(blocks_[i], &blocks_[i][kHandleBlockSize]);
7661  }
7662 }
7663 
7664 
7666  v8::Local<v8::Name> property,
7669  // Leaving JavaScript.
7670  Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate());
7671  Address getter_address = reinterpret_cast<Address>(reinterpret_cast<intptr_t>(
7672  getter));
7673  VMState<EXTERNAL> state(isolate);
7674  ExternalCallbackScope call_scope(isolate, getter_address);
7675  getter(property, info);
7676 }
7677 
7678 
7680  v8::FunctionCallback callback) {
7681  Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate());
7682  Address callback_address =
7683  reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
7684  VMState<EXTERNAL> state(isolate);
7685  ExternalCallbackScope call_scope(isolate, callback_address);
7686  callback(info);
7687 }
7688 
7689 
7690 } } // namespace v8::internal
#define ON_BAILOUT(isolate, location, code)
Definition: api.cc:60
#define INSTANCE_TYPE_TO_ARRAY_TYPE(Type, type, TYPE, ctype, size)
#define LOG_API(isolate, expr)
Definition: api.cc:52
#define EXCEPTION_BAILOUT_CHECK(isolate, value)
Definition: api.cc:93
#define SET_FIELD_WRAPPED(obj, setter, cdata)
Definition: api.cc:1101
#define VALUE_IS_SPECIFIC_TYPE(Type, Class)
Definition: api.cc:2478
#define VALUE_IS_TYPED_ARRAY(Type, typeName, TYPE, ctype, size)
Definition: api.cc:2451
#define ENTER_V8(isolate)
Definition: api.cc:54
#define CHECK_TYPED_ARRAY_CAST(Type, typeName, TYPE, ctype, size)
Definition: api.cc:2808
#define TYPED_ARRAY_NEW(Type, type, TYPE, ctype, size)
Definition: api.cc:6136
#define ARRAY_TYPE_TO_ELEMENTS_KIND(Type, type, TYPE, ctype, size)
#define EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, value)
Definition: api.cc:88
#define EXCEPTION_PREAMBLE(isolate)
Definition: api.cc:67
#define DEFINE_ERROR(NAME)
Definition: api.cc:6882
static const int kNoPreviousCharacter
Definition: unicode.h:97
static bool IsTrailSurrogate(int code)
Definition: unicode.h:89
static bool IsLeadSurrogate(int code)
Definition: unicode.h:85
static uchar Length(uchar chr, int previous)
Definition: unicode-inl.h:140
static const unsigned kMax16BitCodeUnitSize
Definition: unicode.h:152
static const unsigned kBytesSavedByCombiningSurrogates
Definition: unicode.h:148
static Local< AccessorSignature > New(Isolate *isolate, Handle< FunctionTemplate > receiver=Handle< FunctionTemplate >())
Definition: api.cc:941
An interface for reporting progress and controlling long-running activities.
Definition: v8-profiler.h:371
Local< ArrayBuffer > Buffer()
Returns underlying ArrayBuffer.
Definition: api.cc:6047
size_t ByteOffset()
Byte offset in |Buffer|.
Definition: api.cc:6062
size_t ByteLength()
Size of a view in bytes.
Definition: api.cc:6068
static void CheckCast(Value *obj)
Definition: api.cc:2792
Allocator that V8 uses to allocate |ArrayBuffer|'s memory.
Definition: v8.h:2859
The contents of an |ArrayBuffer|.
Definition: v8.h:2891
Contents Externalize()
Make this ArrayBuffer external.
Definition: api.cc:5992
bool IsExternal() const
Returns true if ArrayBuffer is extrenalized, that is, does not own its memory block.
Definition: api.cc:5987
static Local< ArrayBuffer > New(Isolate *isolate, size_t byte_length)
Create a new ArrayBuffer.
Definition: api.cc:6024
void Neuter()
Neuters this ArrayBuffer and all its views (typed arrays).
Definition: api.cc:6006
static void CheckCast(Value *obj)
Definition: api.cc:2784
size_t ByteLength() const
Data length in bytes.
Definition: api.cc:6018
Local< Object > CloneElementAt(uint32_t index)
Clones an element at index |index|.
Definition: api.cc:5829
static Local< Array > New(Isolate *isolate, int length=0)
Creates a JavaScript array with the given length.
Definition: api.cc:5805
uint32_t Length() const
Definition: api.cc:5818
static void CheckCast(Value *obj)
Definition: api.cc:2762
static void CheckCast(v8::Value *obj)
Definition: api.cc:2876
bool ValueOf() const
Definition: api.cc:5654
static Local< Value > New(bool value)
Definition: api.cc:5640
bool Value() const
Definition: api.cc:4950
@ OBJECT_TEMPLATE
Definition: api.h:26
@ FUNCTION_TEMPLATE
Definition: api.h:25
DISALLOW_COPY_AND_ASSIGN(ContainsOnlyOneByteHelper)
void VisitOneByteString(const uint8_t *chars, int length)
Definition: api.cc:4279
void VisitTwoByteString(const uint16_t *chars, int length)
Definition: api.cc:4282
bool CheckCons(i::ConsString *cons_string)
Definition: api.cc:4315
bool Check(i::String *string)
Definition: api.cc:4274
A sandboxed execution context with its own set of built-in objects and functions.
Definition: v8.h:5443
void SetSecurityToken(Handle< Value > token)
Sets the security token for the context.
Definition: api.cc:5235
void Exit()
Exit this context.
Definition: api.cc:623
static Local< Context > New(Isolate *isolate, ExtensionConfiguration *extensions=NULL, Handle< ObjectTemplate > global_template=Handle< ObjectTemplate >(), Handle< Value > global_object=Handle< Value >())
Creates a new context and returns a handle to the newly allocated context.
Definition: api.cc:5217
void SetAlignedPointerInEmbedderData(int index, void *value)
Sets a 2-byte-aligned native pointer in the embedder data with the given index, growing the data as n...
Definition: api.cc:702
void * SlowGetAlignedPointerFromEmbedderData(int index)
Definition: api.cc:694
Local< Value > SlowGetEmbedderData(int index)
Definition: api.cc:674
void Enter()
Enter this context.
Definition: api.cc:612
void SetErrorMessageForCodeGenerationFromStrings(Handle< String > message)
Sets the error description for the exception that is thrown when code generation from strings is not ...
Definition: api.cc:5304
void AllowCodeGenerationFromStrings(bool allow)
Control whether code generation from strings is allowed.
Definition: api.cc:5289
Handle< Value > GetSecurityToken()
Returns the security token of this context.
Definition: api.cc:5252
void DetachGlobal()
Detaches the global object from its context before the global object can be reused to create a new co...
Definition: api.cc:5281
v8::Isolate * GetIsolate()
Returns an isolate associated with a current context.
Definition: api.cc:5261
Local< Value > GetEmbedderData(int index)
Gets the embedder data with the given index, which must have been set by a previous call to SetEmbedd...
Definition: v8.h:6939
void * GetAlignedPointerFromEmbedderData(int index)
Gets a 2-byte-aligned native pointer from the embedder data with the given index, which must have bee...
Definition: v8.h:6954
Local< Object > Global()
Returns the global proxy object.
Definition: api.cc:5267
bool IsCodeGenerationFromStringsAllowed()
Returns true if code generation from strings is allowed for the context.
Definition: api.cc:5298
void UseDefaultSecurityToken()
Restores the security token to the default value.
Definition: api.cc:5244
void SetEmbedderData(int index, Handle< Value > value)
Sets the embedder data with the given index, growing the data as needed.
Definition: api.cc:683
CpuProfileNode represents a node in a call graph.
Definition: v8-profiler.h:23
const CpuProfileNode * GetChild(int index) const
Retrieves a child node by index.
Definition: api.cc:7111
unsigned GetHitCount() const
Returns the count of samples where the function was currently executing.
Definition: api.cc:7091
int GetLineNumber() const
Returns the number, 1-based, of the line where the function originates.
Definition: api.cc:7074
unsigned GetNodeId() const
Returns id of the node.
Definition: api.cc:7101
Handle< String > GetFunctionName() const
Returns function name (empty string for anonymous functions.)
Definition: api.cc:7041
unsigned GetCallUid() const
Returns function entry UID.
Definition: api.cc:7096
int GetColumnNumber() const
Returns 1-based number of the column where the function originates.
Definition: api.cc:7079
Handle< String > GetScriptResourceName() const
Returns resource name for script from where the function originates.
Definition: api.cc:7066
const char * GetBailoutReason() const
Returns bailout reason for the function if the optimization was disabled for it.
Definition: api.cc:7085
int GetScriptId() const
Returns id of the script where function is located.
Definition: api.cc:7059
int GetChildrenCount() const
Returns child nodes count of the node.
Definition: api.cc:7106
CpuProfile contains a CPU profile in a form of top-down call tree (from main() down to functions that...
Definition: v8-profiler.h:77
const CpuProfileNode * GetTopDownRoot() const
Returns the root node of the top down call tree.
Definition: api.cc:7134
int GetSamplesCount() const
Returns number of samples recorded.
Definition: api.cc:7165
int64_t GetEndTime() const
Returns time when the profile recording was stopped (in microseconds) since some unspecified starting...
Definition: api.cc:7159
void Delete()
Deletes the profile and removes it from CpuProfiler's list.
Definition: api.cc:7118
Handle< String > GetTitle() const
Returns CPU profile title.
Definition: api.cc:7126
const CpuProfileNode * GetSample(int index) const
Returns profile node corresponding to the top frame the sample at the given index.
Definition: api.cc:7140
int64_t GetSampleTimestamp(int index) const
Returns the timestamp of the sample.
Definition: api.cc:7146
int64_t GetStartTime() const
Returns time when the profile recording was started (in microseconds) since some unspecified starting...
Definition: api.cc:7153
Interface for controlling CPU profiling.
Definition: v8-profiler.h:129
void StartProfiling(Handle< String > title, bool record_samples=false)
Starts collecting CPU profile.
Definition: api.cc:7177
void SetIdle(bool is_idle)
Tells the profiler whether the embedder is idle.
Definition: api.cc:7200
CpuProfile * StopProfiling(Handle< String > title)
Stops collecting CPU profile with a given title and returns it.
Definition: api.cc:7188
void SetSamplingInterval(int us)
Changes default CPU profiler sampling interval to the specified number of microseconds.
Definition: api.cc:7170
static Local< DataView > New(Handle< ArrayBuffer > array_buffer, size_t byte_offset, size_t length)
Definition: api.cc:6159
static void CheckCast(Value *obj)
Definition: api.cc:2824
The superclass of values and API object templates.
Definition: v8.h:913
static void CheckCast(v8::Value *obj)
Definition: api.cc:2832
double ValueOf() const
A specialization of Value::NumberValue that is more efficient because we know the structure of this o...
Definition: api.cc:5721
static void DateTimeConfigurationChangeNotification(Isolate *isolate)
Notification that the embedder has changed the time zone, daylight savings time, or other date / time...
Definition: api.cc:5730
static Local< Value > New(Isolate *isolate, double time)
Definition: api.cc:5704
A client object passed to the v8 debugger whose ownership will be taken by it.
Definition: v8-debug.h:35
static void DebugBreak(Isolate *isolate)
Definition: api.cc:6932
static void CancelDebugBreak(Isolate *isolate)
Definition: api.cc:6937
static Local< Value > GetMirror(v8::Handle< v8::Value > obj)
Returns a mirror object for the given object.
Definition: api.cc:6994
static bool SetDebugEventListener(EventCallback that, Handle< Value > data=Handle< Value >())
Definition: api.cc:6917
static void SetLiveEditEnabled(Isolate *isolate, bool enable)
Enable/disable LiveEdit functionality for the given Isolate (default Isolate if not provided).
Definition: api.cc:7035
static void SetMessageHandler(MessageHandler handler)
Definition: api.cc:6955
void(* MessageHandler)(const Message &message)
Debug message callback function.
Definition: v8-debug.h:152
static void SendCommand(Isolate *isolate, const uint16_t *command, int length, ClientData *client_data=NULL)
Definition: api.cc:6962
static bool CheckDebugBreak(Isolate *isolate)
Definition: api.cc:6943
static void ProcessDebugMessages()
Makes V8 process all pending debug messages.
Definition: api.cc:7023
static Local< Value > Call(v8::Handle< v8::Function > fun, Handle< Value > data=Handle< Value >())
Run a JavaScript function in the debugger.
Definition: api.cc:6972
static Local< Context > GetDebugContext()
Debugger is running in its own context which is entered while debugger messages are being dispatched.
Definition: api.cc:7028
static void DebugBreakForCommand(Isolate *isolate, ClientData *data)
Definition: api.cc:6949
A HandleScope which first allocates a handle in the current scope which will be later filled with the...
Definition: v8.h:855
Local< T > Escape(Local< T > value)
Pushes the value into the previous scope and returns a handle to it.
Definition: v8.h:865
internal::Object ** escape_slot_
Definition: v8.h:881
EscapableHandleScope(Isolate *isolate)
Definition: api.cc:591
A container for extension names.
Definition: v8.h:5424
Ignore.
Definition: v8.h:4008
Extension(const char *name, const char *source=0, int dep_count=0, const char **deps=0, int source_length=-1)
Definition: api.cc:404
const String::ExternalOneByteStringResource * source() const
Definition: v8.h:4025
size_t source_length_
Definition: v8.h:4034
Interface for iterating through all external resources in the heap.
Definition: v8.h:4943
void * Value() const
Definition: api.cc:5360
static Local< External > New(Isolate *isolate, void *value)
Definition: api.cc:5350
static void CheckCast(v8::Value *obj)
Definition: api.cc:2699
The argument information given to function call callbacks.
Definition: v8.h:2650
Isolate * GetIsolate() const
Definition: v8.h:6342
Local< ObjectTemplate > PrototypeTemplate()
A PrototypeTemplate is the template used to create the prototype object of the function created by th...
Definition: api.cc:850
void SetClassName(Handle< String > name)
Set the class name of the FunctionTemplate.
Definition: api.cc:1208
void Inherit(Handle< FunctionTemplate > parent)
Causes the function template to inherit from a parent function template.
Definition: api.cc:864
static Local< FunctionTemplate > New(Isolate *isolate, FunctionCallback callback=0, Handle< Value > data=Handle< Value >(), Handle< Signature > signature=Handle< Signature >(), int length=0)
Creates a function template.
Definition: api.cc:904
void SetCallHandler(FunctionCallback callback, Handle< Value > data=Handle< Value >())
Set the call-handler callback for a FunctionTemplate.
Definition: api.cc:1107
void RemovePrototype()
Removes the prototype property from functions created from this FunctionTemplate.
Definition: api.cc:1229
void SetLength(int length)
Set the predefined length property for the FunctionTemplate.
Definition: api.cc:1201
void ReadOnlyPrototype()
Sets the ReadOnly flag in the attributes of the 'prototype' property of functions created from this F...
Definition: api.cc:1222
bool HasInstance(Handle< Value > object)
Returns true if the given object is an instance of this function template.
Definition: api.cc:5342
Local< ObjectTemplate > InstanceTemplate()
Get the InstanceTemplate.
Definition: api.cc:1181
Local< Function > GetFunction()
Returns the unique function instance in the current execution context.
Definition: api.cc:5327
void SetHiddenPrototype(bool value)
Determines whether the proto accessor ignores instances of the function template.
Definition: api.cc:1215
Local< Object > NewInstance() const
Definition: api.cc:4078
bool IsBuiltin() const
Tells whether this function is builtin.
Definition: api.cc:4209
int ScriptId() const
Returns scriptId.
Definition: api.cc:4215
void SetName(Handle< String > name)
Definition: api.cc:4125
int GetScriptLineNumber() const
Returns zero based line number of function body and kLineOffsetNotFound if no information available.
Definition: api.cc:4189
Handle< Value > GetName() const
Definition: api.cc:4134
ScriptOrigin GetScriptOrigin() const
Definition: api.cc:4170
Handle< Value > GetInferredName() const
Name inferred from variable or property assignment of this function.
Definition: api.cc:4141
int GetScriptColumnNumber() const
Returns zero based column number of function body and kLineOffsetNotFound if no information available...
Definition: api.cc:4199
static void CheckCast(Value *obj)
Definition: api.cc:2714
Local< Value > GetBoundFunction() const
Returns the original function if this function is bound, else returns v8::Undefined.
Definition: api.cc:4225
static const int kLineOffsetNotFound
Definition: v8.h:2783
static Local< Function > New(Isolate *isolate, FunctionCallback callback, Local< Value > data=Local< Value >(), int length=0)
Create a function in the current execution context for a given FunctionCallback.
Definition: api.cc:4065
Local< Value > Call(Handle< Value > recv, int argc, Handle< Value > argv[])
Definition: api.cc:4104
Handle< Value > GetDisplayName() const
User-defined name assigned to the "displayName" property of this function.
Definition: api.cc:4148
A stack-allocated class that governs a number of local handles.
Definition: v8.h:802
internal::Isolate * isolate_
Definition: v8.h:837
internal::Object ** prev_next_
Definition: v8.h:838
HandleScope()
Definition: v8.h:818
void Initialize(Isolate *isolate)
Definition: api.cc:551
static internal::Object ** CreateHandle(internal::Isolate *isolate, internal::Object *value)
Definition: api.cc:579
internal::Object ** prev_limit_
Definition: v8.h:839
static int NumberOfHandles(Isolate *isolate)
Counts the number of allocated handles.
Definition: api.cc:573
~HandleScope()
Definition: api.cc:568
Isolate * GetIsolate() const
Definition: v8.h:813
An object reference managed by the v8 garbage collector.
Definition: v8.h:198
bool IsEmpty() const
Returns true if the handle is empty.
Definition: v8.h:228
HeapSnapshotEdge represents a directed connection between heap graph nodes: from retainers to retaine...
Definition: v8-profiler.h:183
const HeapGraphNode * GetToNode() const
Returns destination node.
Definition: api.cc:7251
const HeapGraphNode * GetFromNode() const
Returns origin node.
Definition: api.cc:7245
Type GetType() const
Returns edge type (see HeapGraphEdge::Type).
Definition: api.cc:7219
Handle< Value > GetName() const
Returns edge name.
Definition: api.cc:7224
HeapGraphNode represents a node in a heap graph.
Definition: v8-profiler.h:219
Handle< String > GetName() const
Returns node name.
Definition: api.cc:7268
SnapshotObjectId GetId() const
Returns node id.
Definition: api.cc:7275
Type GetType() const
Returns node type (see HeapGraphNode::Type).
Definition: api.cc:7263
const HeapGraphEdge * GetChild(int index) const
Retrieves a child by index.
Definition: api.cc:7297
size_t GetShallowSize() const
Returns node's own size, in bytes.
Definition: api.cc:7287
int GetChildrenCount() const
Returns child nodes count of the node.
Definition: api.cc:7292
Callback interface for retrieving user friendly names of global objects.
Definition: v8-profiler.h:436
Interface for controlling heap profiling.
Definition: v8-profiler.h:390
void StartTrackingHeapObjects(bool track_allocations=false)
Starts tracking of heap objects population statistics.
Definition: api.cc:7412
SnapshotObjectId GetObjectId(Handle< Value > value)
Returns SnapshotObjectId for a heap object referenced by |value| if it has been seen by the heap prof...
Definition: api.cc:7383
int GetSnapshotCount()
Returns the number of snapshots taken.
Definition: api.cc:7372
void DeleteAllHeapSnapshots()
Deletes all snapshots taken.
Definition: api.cc:7428
void SetRetainedObjectInfo(UniqueId id, RetainedObjectInfo *info)
Sets a RetainedObjectInfo for an object group (see V8::SetObjectGroupId).
Definition: api.cc:7446
const HeapSnapshot * TakeHeapSnapshot(Handle< String > title, ActivityControl *control=NULL, ObjectNameResolver *global_object_name_resolver=NULL)
Takes a heap snapshot and returns it.
Definition: api.cc:7402
size_t GetProfilerMemorySize()
Returns memory used for profiler internal data and snapshots.
Definition: api.cc:7440
void SetWrapperClassInfoProvider(uint16_t class_id, WrapperInfoCallback callback)
Binds a callback to embedder's class ID.
Definition: api.cc:7433
SnapshotObjectId GetHeapStats(OutputStream *stream)
Adds a new time interval entry to the aggregated statistics array.
Definition: api.cc:7423
void ClearObjectIds()
Clears internal map from SnapshotObjectId to heap object.
Definition: api.cc:7397
const HeapSnapshot * GetHeapSnapshot(int index)
Returns a snapshot by index.
Definition: api.cc:7377
void StopTrackingHeapObjects()
Stops tracking of heap objects population statistics, cleans up all collected data.
Definition: api.cc:7418
Handle< Value > FindObjectById(SnapshotObjectId id)
Returns heap object with given SnapshotObjectId if the object is alive, otherwise empty handle is ret...
Definition: api.cc:7389
HeapSnapshots record the state of the JS heap at some moment.
Definition: v8-profiler.h:303
const HeapGraphNode * GetNodeById(SnapshotObjectId id) const
Returns a node by its id.
Definition: api.cc:7337
int GetNodesCount() const
Returns total nodes count in the snapshot.
Definition: api.cc:7343
Handle< String > GetTitle() const
Returns heap snapshot title.
Definition: api.cc:7325
unsigned GetUid() const
Returns heap snapshot UID (assigned by the profiler.)
Definition: api.cc:7320
const HeapGraphNode * GetRoot() const
Returns the root node of the heap graph.
Definition: api.cc:7332
SnapshotObjectId GetMaxSnapshotJSObjectId() const
Returns a max seen JS object Id.
Definition: api.cc:7354
const HeapGraphNode * GetNode(int index) const
Returns a node by index.
Definition: api.cc:7348
void Delete()
Deletes the snapshot and removes it from HeapProfiler's list.
Definition: api.cc:7309
void Serialize(OutputStream *stream, SerializationFormat format) const
Prepare a serialized representation of the snapshot.
Definition: api.cc:7359
Collection of V8 heap information.
Definition: v8.h:4228
size_t total_heap_size_executable_
Definition: v8.h:4239
size_t used_heap_size_
Definition: v8.h:4241
size_t total_physical_size_
Definition: v8.h:4240
size_t heap_size_limit_
Definition: v8.h:4242
size_t total_heap_size_
Definition: v8.h:4238
int32_t Value() const
Definition: api.cc:4966
static Local< Integer > New(Isolate *isolate, int32_t value)
Definition: api.cc:6281
static void CheckCast(v8::Value *obj)
Definition: api.cc:2754
int64_t Value() const
Definition: api.cc:4956
static Local< Integer > NewFromUnsigned(Isolate *isolate, uint32_t value)
Definition: api.cc:6294
AllowJavascriptExecutionScope(Isolate *isolate)
Definition: api.cc:6657
DisallowJavascriptExecutionScope(Isolate *isolate, OnFailure on_failure)
Definition: api.cc:6632
Stack-allocated class which sets the isolate for all operations executed within a local scope.
Definition: v8.h:4398
SuppressMicrotaskExecutionScope(Isolate *isolate)
Definition: api.cc:6673
Isolate represents an isolated instance of the V8 engine.
Definition: v8.h:4356
void ClearInterrupt()
Clear interrupt request created by |RequestInterrupt|.
Definition: api.cc:6554
void SetReference(const Persistent< T > &parent, const Persistent< S > &child)
Allows the host application to declare implicit references from an object to another object.
Definition: v8.h:6930
Local< Context > GetEnteredContext()
Returns the last entered context.
Definition: api.cc:6402
int ContextDisposedNotification()
Optional notification that a context has been disposed.
Definition: api.cc:6807
void SetReferenceFromGroup(UniqueId id, const Persistent< T > &child)
Allows the host application to declare implicit references from an object group to an object.
Definition: v8.h:6921
Local< Context > GetCallingContext()
Returns the context of the calling JavaScript code.
Definition: api.cc:6394
HeapProfiler * GetHeapProfiler()
Returns heap profiler for this isolate.
Definition: api.cc:6364
void Dispose()
Disposes the isolate.
Definition: api.cc:6609
void RemoveGCEpilogueCallback(GCEpilogueCallback callback)
This function removes callback which was installed by AddGCEpilogueCallback function.
Definition: api.cc:6472
void SetEventLogger(LogEventCallback that)
Set the callback to invoke for logging event.
Definition: api.cc:6705
CpuProfiler * GetCpuProfiler()
Returns CPU profiler for this isolate.
Definition: api.cc:6371
void EnqueueMicrotask(Handle< Function > microtask)
Experimental: Enqueues the callback to the Microtask Work Queue.
Definition: api.cc:6731
void(* GCEpilogueCallback)(Isolate *isolate, GCType type, GCCallbackFlags flags)
Definition: v8.h:4651
void GetCodeRange(void **start, size_t *length_in_bytes)
Returns a memory range that can potentially contain jitted code.
Definition: api.cc:6829
void RemoveCallCompletedCallback(CallCompletedCallback callback)
Removes callback that was installed by AddCallCompletedCallback.
Definition: api.cc:6720
void RequestGarbageCollectionForTesting(GarbageCollectionType type)
Request garbage collection in this Isolate.
Definition: api.cc:6562
GarbageCollectionType
Types of garbage collections that can be requested via RequestGarbageCollectionForTesting.
Definition: v8.h:4476
void Exit()
Exits this isolate by restoring the previously entered one in the current thread.
Definition: api.cc:6626
bool WillAutorunMicrotasks() const
Experimental: Returns whether the Microtask Work Queue is automatically run when the script call dept...
Definition: api.cc:6754
void SetAutorunMicrotasks(bool autorun)
Experimental: Controls whether the Microtask Work Queue is automatically run when the script call dep...
Definition: api.cc:6749
void SetJitCodeEventHandler(JitCodeEventOptions options, JitCodeEventHandler event_handler)
Allows the host application to provide the address of a function that is notified each time code is a...
Definition: api.cc:6813
void(* UseCounterCallback)(Isolate *isolate, UseCounterFeature feature)
Definition: v8.h:4491
void RemoveGCPrologueCallback(GCPrologueCallback callback)
This function removes callback which was installed by AddGCPrologueCallback function.
Definition: api.cc:6459
void CollectAllGarbage(const char *gc_reason)
Definition: api.cc:6358
static Isolate * New(const CreateParams &params=CreateParams())
Creates a new isolate.
Definition: api.cc:6583
void AddCallCompletedCallback(CallCompletedCallback callback)
Adds a callback to notify the host application when a script finished running.
Definition: api.cc:6713
void RequestInterrupt(InterruptCallback callback, void *data)
Request V8 to interrupt long running JavaScript code and invoke the given |callback| passing the give...
Definition: api.cc:6546
void LowMemoryNotification()
Optional notification that the system is running low on memory.
Definition: api.cc:6797
void(* GCPrologueCallback)(Isolate *isolate, GCType type, GCCallbackFlags flags)
Definition: v8.h:4648
void SetCounterFunction(CounterLookupCallback)
Enables the host application to provide a mechanism for recording statistics counters.
Definition: api.cc:6764
void RunMicrotasks()
Experimental: Runs the Microtask Work Queue until empty Any exceptions thrown by microtask callbacks ...
Definition: api.cc:6726
void AddGCPrologueCallback(GCPrologueCallback callback, GCType gc_type_filter=kGCTypeAll)
Enables the host application to receive a notification before a garbage collection.
Definition: api.cc:6452
Local< Value > ThrowException(Local< Value > exception)
Schedules an exception to be thrown when returning to JavaScript.
Definition: api.cc:6411
void SetUseCounterCallback(UseCounterCallback callback)
Sets a callback for counting the number of times a feature of V8 is used.
Definition: api.cc:6759
void GetHeapStatistics(HeapStatistics *heap_statistics)
Get statistics about the heap memory usage.
Definition: api.cc:6685
void AddGCEpilogueCallback(GCEpilogueCallback callback, GCType gc_type_filter=kGCTypeAll)
Enables the host application to receive a notification after a garbage collection.
Definition: api.cc:6465
void SetStackLimit(uintptr_t stack_limit)
Modifies the stack limit for this Isolate.
Definition: api.cc:6822
void SetObjectGroupId(const Persistent< T > &object, UniqueId id)
Allows the host application to group objects together.
Definition: v8.h:6913
void SetAddHistogramSampleFunction(AddHistogramSampleCallback)
Definition: api.cc:6780
bool IdleNotification(int idle_time_in_ms)
Optional notification that the embedder is idle.
Definition: api.cc:6788
void Enter()
Methods below this point require holding a lock (using Locker) in a multi-threaded environment.
Definition: api.cc:6620
Local< Context > GetCurrentContext()
Returns the context that is on the top of the stack.
Definition: api.cc:6384
bool InContext()
Returns true if this isolate has a current context.
Definition: api.cc:6378
void SetCreateHistogramFunction(CreateHistogramCallback)
Enables the host application to provide a mechanism for recording histograms.
Definition: api.cc:6772
static Isolate * GetCurrent()
Returns the entered isolate for the current thread or NULL in case there is no current isolate.
Definition: api.cc:6577
static Local< Value > Parse(Local< String > json_string)
Tries to parse the string |json_string| and returns it as value if successful.
Definition: api.cc:2365
A light-weight stack-allocated object handle.
Definition: v8.h:334
static Local< T > Cast(Local< S > that)
Definition: v8.h:348
static Local< T > New(Isolate *isolate, Handle< T > that)
Create a local handle for the content of another handle.
Definition: v8.h:5987
static bool IsActive()
Returns whether v8::Locker is being used by this V8 instance.
Definition: v8threads.cc:66
Local< String > GetSourceLine() const
Definition: api.cc:2219
ScriptOrigin GetScriptOrigin() const
Returns the origin for the script from where the function causing the error originates.
Definition: api.cc:2071
static const int kNoLineNumberInfo
Definition: v8.h:1295
int GetStartColumn() const
Returns the index within the line of the first character where the error occurred.
Definition: api.cc:2172
static const int kNoScriptIdInfo
Definition: v8.h:1297
Local< String > Get() const
Definition: api.cc:2059
bool IsSharedCrossOrigin() const
Passes on the value set by the embedder when it fed the script from which this Message was generated ...
Definition: api.cc:2206
Handle< StackTrace > GetStackTrace() const
Exception stack trace.
Definition: api.cc:2098
int GetStartPosition() const
Returns the index within the script of the first character where the error occurred.
Definition: api.cc:2152
static const int kNoColumnInfo
Definition: v8.h:1296
int GetEndPosition() const
Returns the index within the script of the last character where the error occurred.
Definition: api.cc:2162
static void PrintCurrentStackTrace(Isolate *isolate, FILE *out)
Definition: api.cc:2237
int GetEndColumn() const
Returns the index within the line of the last character where the error occurred.
Definition: api.cc:2187
int GetLineNumber() const
Returns the number, 1-based, of the line where the error occurred.
Definition: api.cc:2137
Handle< Value > GetScriptResourceName() const
Returns the resource name for the script from where the function causing the error originates.
Definition: api.cc:2093
A superclass for symbols and strings.
Definition: v8.h:1741
static void CheckCast(v8::Value *obj)
Definition: api.cc:2722
void add(v8::internal::Handle< v8::internal::Object > value)
Definition: api.cc:753
int length()
Definition: api.cc:736
void set(int index, v8::internal::Object *value)
Definition: api.cc:768
NeanderArray(v8::internal::Isolate *isolate)
Definition: api.cc:731
NeanderObject obj_
Definition: api.h:66
v8::internal::Object * get(int index)
Definition: api.cc:741
v8::internal::Handle< v8::internal::JSObject > value()
Definition: api.h:53
v8::internal::Handle< v8::internal::JSObject > value_
Definition: api.h:43
v8::internal::Object * get(int index)
Definition: api.h:83
v8::internal::Handle< v8::internal::JSObject > value()
Definition: api.h:40
NeanderObject(v8::internal::Isolate *isolate, int size)
Definition: api.cc:718
int size()
Definition: api.cc:726
void set(int index, v8::internal::Object *value)
Definition: api.h:89
double ValueOf() const
Definition: api.cc:5631
static void CheckCast(v8::Value *obj)
Definition: api.cc:2865
static Local< Value > New(Isolate *isolate, double value)
Definition: api.cc:5620
static void CheckCast(v8::Value *obj)
Definition: api.cc:2746
static Local< Number > New(Isolate *isolate, double value)
Definition: api.cc:6268
double Value() const
Definition: api.cc:4944
static Local< RawOperationDescriptor > NewInternalFieldDereference(Isolate *isolate, int internal_field)
Definition: api.cc:967
An ObjectTemplate is used to create objects at runtime.
Definition: v8.h:3728
Local< Object > NewInstance()
Creates a new instance of this template.
Definition: api.cc:5312
static Local< ObjectTemplate > New()
Definition: api.cc:1244
int InternalFieldCount()
Gets the number of internal fields for objects generated from this template.
Definition: api.cc:1528
void SetIndexedPropertyHandler(IndexedPropertyGetterCallback getter, IndexedPropertySetterCallback setter=0, IndexedPropertyQueryCallback query=0, IndexedPropertyDeleterCallback deleter=0, IndexedPropertyEnumeratorCallback enumerator=0, Handle< Value > data=Handle< Value >())
Sets an indexed property handler on the object template.
Definition: api.cc:1473
void SetCallAsFunctionHandler(FunctionCallback callback, Handle< Value > data=Handle< Value >())
Sets the callback to be used when calling instances created from this template as a function.
Definition: api.cc:1506
void MarkAsUndetectable()
Mark object instances of the template as undetectable.
Definition: api.cc:1430
void SetInternalFieldCount(int value)
Sets the number of internal fields for objects generated from this template.
Definition: api.cc:1533
void SetNamedPropertyHandler(NamedPropertyGetterCallback getter, NamedPropertySetterCallback setter=0, NamedPropertyQueryCallback query=0, NamedPropertyDeleterCallback deleter=0, NamedPropertyEnumeratorCallback enumerator=0, Handle< Value > data=Handle< Value >())
Sets a named property handler on the object template.
Definition: api.cc:1397
void SetAccessCheckCallbacks(NamedSecurityCallback named_handler, IndexedSecurityCallback indexed_handler, Handle< Value > data=Handle< Value >(), bool turned_on_by_default=true)
Sets access check callbacks on the object template.
Definition: api.cc:1442
void SetAccessor(Handle< String > name, AccessorGetterCallback getter, AccessorSetterCallback setter=0, Handle< Value > data=Handle< Value >(), AccessControl settings=DEFAULT, PropertyAttribute attribute=None, Handle< AccessorSignature > signature=Handle< AccessorSignature >())
Sets an accessor on the object template.
Definition: api.cc:1373
A JavaScript object (ECMA-262, 4.3.3)
Definition: v8.h:2283
ExternalArrayType GetIndexedPropertiesExternalArrayDataType()
Definition: api.cc:3949
Local< Value > GetPrivate(Handle< Private > key)
Definition: api.cc:3232
void * SlowGetAlignedPointerFromInternalField(int index)
Definition: api.cc:5020
void SetAlignedPointerInInternalField(int index, void *value)
Sets a 2-byte-aligned native pointer in an internal field.
Definition: api.cc:5028
Local< Value > Get(Handle< Value > key)
Definition: api.cc:3203
Local< Value > CallAsFunction(Handle< Value > recv, int argc, Handle< Value > argv[])
Call an Object as a function if a callback is set by the ObjectTemplate::SetCallAsFunctionHandler met...
Definition: api.cc:3989
bool HasNamedLookupInterceptor()
Tests for a named lookup interceptor.
Definition: api.cc:3649
bool SetHiddenValue(Handle< String > key, Handle< Value > value)
Access hidden properties on JavaScript objects.
Definition: api.cc:3767
bool IsCallable()
Checks whether a callback is set by the ObjectTemplate::SetCallAsFunctionHandler method.
Definition: api.cc:3979
bool HasIndexedLookupInterceptor()
Tests for an index lookup interceptor.
Definition: api.cc:3657
bool HasRealIndexedProperty(uint32_t index)
Definition: api.cc:3621
static Local< Object > New(Isolate *isolate)
Definition: api.cc:5610
bool Has(Handle< Value > key)
Definition: api.cc:3462
void SetInternalField(int index, Handle< Value > value)
Sets the value in an internal field.
Definition: api.cc:5010
bool IsDirty()
Returns true if this is an instance of an api function (one created from a function created from a fu...
Definition: api.cc:3728
bool HasOwnProperty(Handle< String > key)
Definition: api.cc:3595
PropertyAttribute GetPropertyAttributes(Handle< Value > key)
Gets the property attributes of a property which can be None or any combination of ReadOnly,...
Definition: api.cc:3237
Local< Value > GetHiddenValue(Handle< String > key)
Definition: api.cc:3785
bool DeletePrivate(Handle< Private > key)
Definition: api.cc:3457
void SetAccessorProperty(Local< Name > name, Local< Function > getter, Handle< Function > setter=Handle< Function >(), PropertyAttribute attribute=None, AccessControl settings=DEFAULT)
Definition: api.cc:3573
void SetIndexedPropertiesToExternalArrayData(void *data, ExternalArrayType array_type, int number_of_elements)
Set the backing store of the indexed properties to be managed by the embedding layer.
Definition: api.cc:3904
Local< Value > CallAsConstructor(int argc, Handle< Value > argv[])
Call an Object as a constructor if a callback is set by the ObjectTemplate::SetCallAsFunctionHandler ...
Definition: api.cc:4024
Local< Object > FindInstanceInPrototypeChain(Handle< FunctionTemplate > tmpl)
Finds an instance of the given function template in the prototype chain.
Definition: api.cc:3310
bool HasPrivate(Handle< Private > key)
Functionality for private properties.
Definition: api.cc:3477
bool HasRealNamedProperty(Handle< String > key)
Definition: api.cc:3608
Local< Value > GetPrototype()
Get the prototype object.
Definition: api.cc:3282
bool Delete(Handle< Value > key)
Definition: api.cc:3441
Local< Object > Clone()
Clone this object with a fast but shallow copy.
Definition: api.cc:3733
void SetIndexedPropertiesToPixelData(uint8_t *data, int length)
Set the backing store of the indexed properties to be managed by the embedding layer.
Definition: api.cc:3850
void TurnOnAccessCheck()
Turns on access check on the object if the object is an instance of a template that has access check ...
Definition: api.cc:3711
Local< Value > SlowGetInternalField(int index)
Definition: api.cc:5001
Local< Array > GetOwnPropertyNames()
This function has the same functionality as GetPropertyNames but the returned array doesn't contain t...
Definition: api.cc:3353
bool SetAccessor(Handle< String > name, AccessorGetterCallback getter, AccessorSetterCallback setter=0, Handle< Value > data=Handle< Value >(), AccessControl settings=DEFAULT, PropertyAttribute attribute=None)
Definition: api.cc:3541
bool ForceDelete(Handle< Value > key)
Definition: api.cc:3178
uint8_t * GetIndexedPropertiesPixelData()
Definition: api.cc:3879
bool HasIndexedPropertiesInPixelData()
Definition: api.cc:3871
Local< String > ObjectProtoToString()
Call builtin Object.prototype.toString on this object.
Definition: api.cc:3375
int GetIndexedPropertiesExternalArrayDataLength()
Definition: api.cc:3966
bool HasRealNamedCallbackProperty(Handle< String > key)
Definition: api.cc:3634
bool ForceSet(Handle< Value > key, Handle< Value > value, PropertyAttribute attribs=None)
Definition: api.cc:3151
int InternalFieldCount()
Gets the number of internal fields for this Object.
Definition: api.cc:4986
bool DeleteHiddenValue(Handle< String > key)
Definition: api.cc:3800
bool SetPrototype(Handle< Value > prototype)
Set the prototype object.
Definition: api.cc:3292
Local< Value > GetOwnPropertyDescriptor(Local< String > key)
Returns Object.getOwnPropertyDescriptor as per ES5 section 15.2.3.3.
Definition: api.cc:3262
bool SetPrivate(Handle< Private > key, Handle< Value > value)
Definition: api.cc:3172
int GetIdentityHash()
Returns the identity hash for this object.
Definition: api.cc:3757
int GetIndexedPropertiesPixelDataLength()
Definition: api.cc:3892
Local< Context > CreationContext()
Returns the context in which the object was created.
Definition: api.cc:3746
Local< Value > GetRealNamedPropertyInPrototypeChain(Handle< String > key)
If result.IsEmpty() no real property was located in the prototype chain.
Definition: api.cc:3677
bool SetDeclaredAccessor(Local< Name > name, Local< DeclaredAccessorDescriptor > descriptor, PropertyAttribute attribute=None, AccessControl settings=DEFAULT)
Definition: api.cc:3563
Local< String > GetConstructorName()
Returns the name of the function invoked as a constructor for this object.
Definition: api.cc:3430
bool Set(Handle< Value > key, Handle< Value > value)
Definition: api.cc:3119
bool HasIndexedPropertiesInExternalArrayData()
Definition: api.cc:3927
static void CheckCast(Value *obj)
Definition: api.cc:2706
void * GetIndexedPropertiesExternalArrayData()
Definition: api.cc:3936
Local< Array > GetPropertyNames()
Returns an array containing the names of the enumerable properties of this object,...
Definition: api.cc:3331
Local< Value > GetRealNamedProperty(Handle< String > key)
If result.IsEmpty() no real property was located on the object or in the prototype chain.
Definition: api.cc:3695
An interface for exporting data from V8, using "push" model.
Definition: v8-profiler.h:272
virtual int GetChunkSize()
Get preferred output chunk size.
Definition: v8-profiler.h:282
Interface for iterating through all the persistent handles in the heap.
Definition: v8.h:4953
virtual void VisitPersistentHandle(Persistent< Value > *value, uint16_t class_id)
Definition: v8.h:4956
A PersistentBase which allows copy and assignment.
Definition: v8.h:627
V8 Platform abstraction layer.
Definition: v8-platform.h:28
A private symbol.
Definition: v8.h:2136
static Local< Private > ForApi(Isolate *isolate, Local< String > name)
Definition: api.cc:6247
Local< Value > Name() const
Definition: api.cc:4939
static Local< Private > New(Isolate *isolate, Local< String > name=Local< String >())
Definition: api.cc:6236
void Reject(Handle< Value > value)
Definition: api.cc:5913
Local< Promise > GetPromise()
Extract the associated promise.
Definition: api.cc:5890
static Local< Resolver > New(Isolate *isolate)
Create a new resolver, along with an associated promise in pending state.
Definition: api.cc:5873
void Resolve(Handle< Value > value)
Resolve/reject the associated promise with a given value.
Definition: api.cc:5896
static void CheckCast(Value *obj)
Definition: api.cc:2777
Local< Promise > Catch(Handle< Function > handler)
Definition: api.cc:5949
Local< Promise > Chain(Handle< Function > handler)
Register a resolution/rejection handler with a promise.
Definition: api.cc:5930
Local< Promise > Then(Handle< Function > handler)
Definition: api.cc:5968
static void CheckCast(Value *obj)
Definition: api.cc:2770
The information passed to a property callback about the context of the property access.
Definition: v8.h:2691
Isolate * GetIsolate() const
Definition: v8.h:6807
Local< DeclaredAccessorDescriptor > NewPrimitiveValue(Isolate *isolate, DeclaredAccessorDescriptorDataType data_type, uint8_t bool_offset=0)
Definition: api.cc:1013
Local< DeclaredAccessorDescriptor > NewBitmaskCompare16(Isolate *isolate, uint16_t bitmask, uint16_t compare_value)
Definition: api.cc:1048
Local< RawOperationDescriptor > NewRawDereference(Isolate *isolate)
Definition: api.cc:995
Local< DeclaredAccessorDescriptor > NewBitmaskCompare8(Isolate *isolate, uint8_t bitmask, uint8_t compare_value)
Definition: api.cc:1040
Local< DeclaredAccessorDescriptor > NewHandleDereference(Isolate *isolate)
Definition: api.cc:987
Local< DeclaredAccessorDescriptor > NewPointerCompare(Isolate *isolate, void *compare_value)
Definition: api.cc:1003
Local< RawOperationDescriptor > NewRawShift(Isolate *isolate, int16_t byte_offset)
Definition: api.cc:977
Local< DeclaredAccessorDescriptor > NewBitmaskCompare32(Isolate *isolate, uint32_t bitmask, uint32_t compare_value)
Definition: api.cc:1056
Flags GetFlags() const
Returns the flags bit field.
Definition: api.cc:5799
Local< String > GetSource() const
Returns the value of the source property: a string representing the regular expression.
Definition: api.cc:5783
static void CheckCast(v8::Value *obj)
Definition: api.cc:2887
Flags
Regular expression flag bits.
Definition: v8.h:3290
@ kGlobal
Definition: v8.h:3292
@ kIgnoreCase
Definition: v8.h:3293
@ kMultiline
Definition: v8.h:3294
static Local< RegExp > New(Handle< String > pattern, Flags flags)
Creates a regular expression from the given pattern string and the flags bit field.
Definition: api.cc:5768
RegisteredExtension * next()
Definition: api.h:128
static void Register(RegisteredExtension *that)
Definition: api.cc:381
static void UnregisterAll()
Definition: api.cc:387
RegisteredExtension * next_
Definition: api.h:132
RegisteredExtension(Extension *extension)
Definition: api.cc:377
static RegisteredExtension * first_extension_
Definition: api.h:133
A set of constraints that specifies the limits of the runtime's memory use.
Definition: v8.h:4066
void set_max_available_threads(int value)
Definition: v8.h:4096
int max_semi_space_size() const
Definition: v8.h:4085
void set_max_executable_size(int value)
Definition: v8.h:4090
int max_old_space_size() const
Definition: v8.h:4087
void ConfigureDefaults(uint64_t physical_memory, uint64_t virtual_memory_limit, uint32_t number_of_processors)
Configures the constraints with reasonable default values based on the capabilities of the current de...
Definition: api.cc:429
void set_max_old_space_size(int value)
Definition: v8.h:4088
int max_available_threads() const
Definition: v8.h:4094
int max_executable_size() const
Definition: v8.h:4089
uint32_t * stack_limit() const
Definition: v8.h:4091
void set_max_semi_space_size(int value)
Definition: v8.h:4086
size_t code_range_size() const
Definition: v8.h:4099
void set_code_range_size(size_t value)
Definition: v8.h:4100
Interface for providing information about embedder's objects held by global handles.
Definition: v8-profiler.h:545
For streaming incomplete script data to V8.
Definition: v8.h:1096
A streaming task which the embedder must run on a background thread to stream scripts into V8.
Definition: v8.h:1153
Source code which can be then compiled to a UnboundScript or Script.
Definition: v8.h:1058
Local< String > source_string
Definition: v8.h:1078
CachedData * cached_data
Definition: v8.h:1089
Handle< Integer > resource_column_offset
Definition: v8.h:1083
Handle< Value > resource_name
Definition: v8.h:1081
Handle< Integer > resource_line_offset
Definition: v8.h:1082
Handle< Boolean > resource_is_shared_cross_origin
Definition: v8.h:1084
Source code which can be streamed into V8 in pieces.
Definition: v8.h:1127
StreamedSource(ExternalSourceStream *source_stream, Encoding encoding)
Definition: api.cc:1569
internal::StreamedSource * impl() const
Definition: v8.h:1139
const CachedData * GetCachedData() const
Definition: api.cc:1578
static ScriptStreamingTask * StartStreamingScript(Isolate *isolate, StreamedSource *source, CompileOptions options=kNoCompileOptions)
Returns a task which streams script data into V8, or NULL if the script cannot be streamed.
Definition: api.cc:1797
@ kProduceParserCache
Definition: v8.h:1161
@ kConsumeParserCache
Definition: v8.h:1162
@ kProduceCodeCache
Definition: v8.h:1163
@ kNoCompileOptions
Definition: v8.h:1160
@ kProduceDataToCache
Definition: v8.h:1167
@ kConsumeCodeCache
Definition: v8.h:1164
static Local< UnboundScript > CompileUnbound(Isolate *isolate, Source *source, CompileOptions options=kNoCompileOptions)
Compiles the specified script (context-independent).
Definition: api.cc:1703
static Local< Script > Compile(Isolate *isolate, Source *source, CompileOptions options=kNoCompileOptions)
Compiles the specified script (bound to current context).
Definition: api.cc:1783
The origin, within a file, of a script.
Definition: v8.h:922
Handle< Boolean > ResourceIsSharedCrossOrigin() const
Definition: v8.h:6380
Handle< Integer > ResourceColumnOffset() const
Definition: v8.h:6375
Handle< Integer > ResourceLineOffset() const
Definition: v8.h:6370
Handle< Value > ResourceName() const
Definition: v8.h:6365
static Local< Script > Compile(Handle< String > source, ScriptOrigin *origin=NULL)
A shorthand for ScriptCompiler::Compile().
Definition: api.cc:1880
Local< UnboundScript > GetUnboundScript()
Returns the corresponding context-unbound script.
Definition: api.cc:1696
Local< Value > Run()
Runs the script returning the resulting value.
Definition: api.cc:1674
static Local< Signature > New(Isolate *isolate, Handle< FunctionTemplate > receiver=Handle< FunctionTemplate >(), int argc=0, Handle< FunctionTemplate > argv[]=0)
Definition: api.cc:918
A single JavaScript stack frame.
Definition: v8.h:1358
int GetLineNumber() const
Returns the number, 1-based, of the line for the associate function call.
Definition: api.cc:2301
int GetColumn() const
Returns the 1-based column offset on the line for the associated function call.
Definition: api.cc:2306
Local< String > GetScriptName() const
Returns the name of the resource that contains the script for the function for this StackFrame.
Definition: api.cc:2330
Local< String > GetScriptNameOrSourceURL() const
Returns the name of the resource that contains the script for the function for this StackFrame or sou...
Definition: api.cc:2335
bool IsConstructor() const
Returns whether or not the associated function is called as a constructor via "new".
Definition: api.cc:2358
bool IsEval() const
Returns whether or not the associated function is compiled via a call to eval().
Definition: api.cc:2355
Local< String > GetFunctionName() const
Returns the name of the function associated with this stack frame.
Definition: api.cc:2340
int GetScriptId() const
Returns the id of the script for the function for this StackFrame.
Definition: api.cc:2311
Local< StackFrame > GetFrame(uint32_t index) const
Returns a StackFrame at a particular index.
Definition: api.cc:2246
StackTraceOptions
Flags that determine what information is placed captured for each StackFrame when grabbing the curren...
Definition: v8.h:1312
@ kExposeFramesAcrossSecurityOrigins
Definition: v8.h:1321
int GetFrameCount() const
Returns the number of StackFrames.
Definition: api.cc:2258
static Local< StackTrace > CurrentStackTrace(Isolate *isolate, int frame_limit, StackTraceOptions options=kOverview)
Grab a snapshot of the current JavaScript execution stack.
Definition: api.cc:2272
Local< Array > AsArray()
Returns StackTrace as a v8::Array that contains StackFrame objects.
Definition: api.cc:2265
virtual int DecompressData(char *raw_data, int *raw_data_size, const char *compressed_data, int compressed_data_size)=0
virtual ~StartupDataDecompressor()
Definition: api.cc:213
int raw_size
Definition: v8.h:4887
int compressed_size
Definition: v8.h:4886
const char * data
Definition: v8.h:4885
CompressionAlgorithm
Definition: v8.h:4880
@ kUncompressed
Definition: v8.h:4881
Local< String > ValueOf() const
Definition: api.cc:5674
static void CheckCast(v8::Value *obj)
Definition: api.cc:2843
static Local< Value > New(Handle< String > value)
Definition: api.cc:5663
An ExternalOneByteStringResource is a wrapper around an one-byte string buffer that resides outside V...
Definition: v8.h:1918
virtual const char * data() const =0
The string data from the underlying buffer.
An ExternalStringResource is a wrapper around a two-byte string buffer that resides outside V8's heap...
Definition: v8.h:1885
virtual const uint16_t * data() const =0
The string data from the underlying buffer.
Utf8Value(Handle< v8::Value > obj)
Definition: api.cc:6841
Value(Handle< v8::Value > obj)
Definition: api.cc:6862
uint16_t * str_
Definition: v8.h:2078
A JavaScript string value (ECMA-262, 4.3.17).
Definition: v8.h:1752
int Utf8Length() const
Returns the number of bytes in the UTF-8 encoded representation of this string.
Definition: api.cc:4560
bool CanMakeExternal()
Returns true if this string can be made external.
Definition: api.cc:5597
static Local< String > NewFromOneByte(Isolate *isolate, const uint8_t *data, NewStringType type=kNormalString, int length=-1)
Allocates a new string from Latin-1 data.
Definition: api.cc:5460
bool IsExternal() const
Returns true if the string is external.
Definition: api.cc:4869
int WriteOneByte(uint8_t *buffer, int start=0, int length=-1, int options=NO_OPTIONS) const
Definition: api.cc:4853
bool IsExternalOneByte() const
Returns true if the string is both external and one-byte.
Definition: api.cc:4875
bool ContainsOnlyOneByte() const
Returns whether this string contain only one byte data.
Definition: api.cc:4360
Encoding
Definition: v8.h:1754
NewStringType
Definition: v8.h:1962
@ kInternalizedString
Definition: v8.h:1963
@ kNormalString
Definition: v8.h:1963
@ kUndetectableString
Definition: v8.h:1963
int Write(uint16_t *buffer, int start=0, int length=-1, int options=NO_OPTIONS) const
Definition: api.cc:4861
bool MakeExternal(ExternalStringResource *resource)
Associate an external string resource with this string by transforming it in place so that existing r...
Definition: api.cc:5528
static Local< String > NewFromTwoByte(Isolate *isolate, const uint16_t *data, NewStringType type=kNormalString, int length=-1)
Allocates a new string from UTF-16 data.
Definition: api.cc:5473
static Local< String > Concat(Handle< String > left, Handle< String > right)
Creates a new string by concatenating the left and the right strings passed in as parameters.
Definition: api.cc:5486
bool IsOneByte() const
Returns whether this string is known to contain only one byte data.
Definition: api.cc:4245
@ NO_NULL_TERMINATION
Definition: v8.h:1812
@ HINT_MANY_WRITES_EXPECTED
Definition: v8.h:1811
int WriteUtf8(char *buffer, int length=-1, int *nchars_ref=NULL, int options=NO_OPTIONS) const
Definition: api.cc:4772
static v8::Local< v8::String > Empty(Isolate *isolate)
A zero length string.
Definition: v8.h:6469
static void CheckCast(v8::Value *obj)
Definition: api.cc:2730
static Local< String > NewExternal(Isolate *isolate, ExternalStringResource *resource)
Creates a new external string using the data defined in the given resource.
Definition: api.cc:5511
static Local< String > NewFromUtf8(Isolate *isolate, const char *data, NewStringType type=kNormalString, int length=-1)
Allocates a new string from UTF-8 data.
Definition: api.cc:5447
const ExternalOneByteStringResource * GetExternalOneByteStringResource() const
Get the ExternalOneByteStringResource for an external one-byte string.
Definition: api.cc:4920
void VerifyExternalStringResource(ExternalStringResource *val) const
Definition: api.cc:4881
void VerifyExternalStringResourceBase(ExternalStringResourceBase *v, Encoding encoding) const
Definition: api.cc:4895
int Length() const
Returns the number of characters in this string.
Definition: api.cc:4239
static Local< Value > New(Isolate *isolate, Handle< Symbol > value)
Definition: api.cc:5684
Local< Symbol > ValueOf() const
Definition: api.cc:5694
static void CheckCast(v8::Value *obj)
Definition: api.cc:2854
A JavaScript symbol (ECMA-262 edition 6)
Definition: v8.h:2099
static Local< Symbol > GetUnscopables(Isolate *isolate)
Definition: api.cc:6231
static Local< Symbol > GetIterator(Isolate *isolate)
Definition: api.cc:6226
static Local< Symbol > For(Isolate *isolate, Local< String > name)
Definition: api.cc:6201
static void CheckCast(v8::Value *obj)
Definition: api.cc:2738
Local< Value > Name() const
Definition: api.cc:4932
static Local< Symbol > New(Isolate *isolate, Local< String > name=Local< String >())
Definition: api.cc:6172
static Local< Symbol > ForApi(Isolate *isolate, Local< String > name)
Definition: api.cc:6209
The superclass of object and function templates.
Definition: v8.h:3347
void SetAccessorProperty(Local< Name > name, Local< FunctionTemplate > getter=Local< FunctionTemplate >(), Local< FunctionTemplate > setter=Local< FunctionTemplate >(), PropertyAttribute attribute=None, AccessControl settings=DEFAULT)
Definition: api.cc:818
bool SetDeclaredAccessor(Local< Name > name, Local< DeclaredAccessorDescriptor > descriptor, PropertyAttribute attribute=None, Local< AccessorSignature > signature=Local< AccessorSignature >(), AccessControl settings=DEFAULT)
Definition: api.cc:1337
void Set(Handle< Name > name, Handle< Data > value, PropertyAttribute attributes=None)
Adds a property to each instance created by this template.
Definition: api.cc:802
void SetNativeDataProperty(Local< String > name, AccessorGetterCallback getter, AccessorSetterCallback setter=0, Handle< Value > data=Handle< Value >(), PropertyAttribute attribute=None, Local< AccessorSignature > signature=Local< AccessorSignature >(), AccessControl settings=DEFAULT)
Whenever the property with the given name is accessed on objects created from this Template the gette...
Definition: api.cc:1349
@ kStressTypeDeopt
Definition: v8-testing.h:19
@ kStressTypeOpt
Definition: v8-testing.h:18
static int GetStressRuns()
Get the number of runs of a given test that is required to get the full stress coverage.
Definition: api.cc:7461
static void DeoptimizeAll()
Force deoptimization of all functions.
Definition: api.cc:7514
static void PrepareStressRun(int run)
Indicate the number of the run which is about to start.
Definition: api.cc:7478
static void SetStressRunType(StressType type)
Set the type of stressing to do.
Definition: api.cc:7456
An external exception handler.
Definition: v8.h:5271
void SetVerbose(bool value)
Set verbosity of the external exception handler.
Definition: api.cc:2046
Local< v8::Message > Message() const
Returns the message associated with this exception.
Definition: api.cc:2012
void * js_stack_comparable_address_
Definition: v8.h:5405
~TryCatch()
Unregisters and deletes this try/catch block.
Definition: api.cc:1923
bool HasTerminated() const
Returns true if an exception has been caught due to script execution being terminated.
Definition: api.cc:1964
void Reset()
Clears any exceptions that may have been caught by this try/catch block.
Definition: api.cc:2024
v8::internal::Isolate * isolate_
Definition: v8.h:5400
void SetCaptureMessage(bool value)
Set whether or not this TryCatch should capture a Message object which holds source information about...
Definition: api.cc:2051
Local< Value > Exception() const
Returns the exception caught by this try/catch block.
Definition: api.cc:1976
Handle< Value > ReThrow()
Throws the exception caught by this TryCatch in a way that avoids it being caught again by this same ...
Definition: api.cc:1969
Local< Value > StackTrace() const
Returns the .stack property of the thrown object.
Definition: api.cc:1988
bool HasCaught() const
Returns true if an exception has been caught by this try/catch block.
Definition: api.cc:1954
TryCatch()
Creates a new try/catch block and registers it with v8.
Definition: api.cc:1906
void ResetInternal()
Definition: api.cc:2036
bool CanContinue() const
For certain types of exceptions, it makes no sense to continue execution.
Definition: api.cc:1959
static Local< TypeSwitch > New(Handle< FunctionTemplate > type)
Definition: api.cc:1064
int match(Handle< Value > value)
Definition: api.cc:1086
static void CheckCast(Value *obj)
Definition: api.cc:2800
size_t Length()
Number of elements in this typed array (e.g.
Definition: api.cc:6074
uint32_t Value() const
Definition: api.cc:4976
int GetLineNumber(int code_pos)
Returns zero based line number of the code_pos location in the script.
Definition: api.cc:1611
Handle< Value > GetScriptName()
Definition: api.cc:1626
Handle< Value > GetSourceURL()
Data read from magic sourceURL comments.
Definition: api.cc:1642
static const int kNoScriptId
Definition: v8.h:977
Handle< Value > GetSourceMappingURL()
Data read from magic sourceMappingURL comments.
Definition: api.cc:1658
Local< Script > BindToCurrentContext()
Binds the script to the currently entered context.
Definition: api.cc:1583
General purpose unique identifier.
Definition: v8.h:144
void VisitTwoByteString(const uint16_t *chars, int length)
Definition: api.cc:4404
static i::ConsString * VisitFlat(i::String *string, int *length, uint8_t *state)
Definition: api.cc:4423
void VisitOneByteString(const uint8_t *chars, int length)
Definition: api.cc:4393
static bool StartsWithSurrogate(uint8_t state)
Definition: api.cc:4385
static int Calculate(i::ConsString *current, uint8_t *state_out)
Definition: api.cc:4488
static const uint8_t kInitialState
Definition: api.cc:4379
static void MergeTerminal(int *length, uint8_t state, uint8_t *state_out)
Definition: api.cc:4475
static void MergeLeafLeft(int *length, uint8_t *state, uint8_t leaf_state)
Definition: api.cc:4439
@ kLeftmostEdgeIsSurrogate
Definition: api.cc:4375
@ kEndsWithLeadingSurrogate
Definition: api.cc:4371
@ kStartsWithTrailingSurrogate
Definition: api.cc:4372
@ kRightmostEdgeIsSurrogate
Definition: api.cc:4376
@ kRightmostEdgeIsCalculated
Definition: api.cc:4374
@ kLeftmostEdgeIsCalculated
Definition: api.cc:4373
DISALLOW_IMPLICIT_CONSTRUCTORS(Utf8LengthHelper)
static int Calculate(i::ConsString *current)
Definition: api.cc:4539
static void MergeLeafRight(int *length, uint8_t *state, uint8_t leaf_state)
Definition: api.cc:4457
static bool EndsWithSurrogate(uint8_t state)
Definition: api.cc:4381
static int WriteEndCharacter(uint16_t character, int last_character, int remaining, char *const buffer, bool replace_invalid_utf8)
Definition: api.cc:4584
Utf8WriterVisitor(char *buffer, int capacity, bool skip_capacity_check, bool replace_invalid_utf8)
Definition: api.cc:4569
int CompleteWrite(bool write_null, int *utf16_chars_read_out)
Definition: api.cc:4725
void Visit(const Char *chars, const int length)
Definition: api.cc:4629
bool const skip_capacity_check_
Definition: api.cc:4745
void VisitOneByteString(const uint8_t *chars, int length)
Definition: api.cc:4717
bool const replace_invalid_utf8_
Definition: api.cc:4746
bool early_termination_
Definition: api.cc:4740
char *const start_
Definition: api.cc:4743
void VisitTwoByteString(const uint16_t *chars, int length)
Definition: api.cc:4721
DISALLOW_IMPLICIT_CONSTRUCTORS(Utf8WriterVisitor)
static bool ApiCheck(bool condition, const char *location, const char *message)
Definition: api.h:177
static Local< Context > ToLocal(v8::internal::Handle< v8::internal::Context > obj)
static v8::internal::Handle< To > OpenHandle(v8::Local< From > handle)
Definition: api.h:288
static Local< AccessorSignature > AccessorSignatureToLocal(v8::internal::Handle< v8::internal::FunctionTemplateInfo > obj)
static Local< Uint32 > Uint32ToLocal(v8::internal::Handle< v8::internal::Object > obj)
static Local< External > ExternalToLocal(v8::internal::Handle< v8::internal::JSObject > obj)
static Local< Integer > IntegerToLocal(v8::internal::Handle< v8::internal::Object > obj)
static Local< Message > MessageToLocal(v8::internal::Handle< v8::internal::Object > obj)
static Local< StackTrace > StackTraceToLocal(v8::internal::Handle< v8::internal::JSArray > obj)
static void ReportApiFailure(const char *location, const char *message)
Definition: api.cc:175
static Local< StackFrame > StackFrameToLocal(v8::internal::Handle< v8::internal::JSObject > obj)
static Local< Number > NumberToLocal(v8::internal::Handle< v8::internal::Object > obj)
Container class for static utility functions.
Definition: v8.h:4964
WeakCallbackData< Value, void >::Callback WeakCallback
Definition: v8.h:5249
static Local< Value > GetEternal(Isolate *isolate, int index)
Definition: api.cc:537
static void RemoveMessageListeners(MessageCallback that)
Remove all message listeners from the specified callback function.
Definition: api.cc:6322
static void Eternalize(Isolate *isolate, Value *handle, int *index)
Definition: api.cc:530
static void TerminateExecution(Isolate *isolate)
Forcefully terminate the current thread of JavaScript execution in the given isolate.
Definition: api.cc:6526
static void SetReturnAddressLocationResolver(ReturnAddressLocationResolver return_address_resolver)
Allows the host application to provide a callback that allows v8 to cooperate with a profiler that re...
Definition: api.cc:5069
static void SetFatalErrorHandler(FatalErrorCallback that)
Set the callback to invoke in case of fatal errors.
Definition: api.cc:351
static void RemoveMemoryAllocationCallback(MemoryAllocationCallback callback)
Removes callback that was installed by AddMemoryAllocationCallback.
Definition: api.cc:6519
static bool InitializeICU(const char *icu_data_file=NULL)
Initialize the ICU library bundled with V8.
Definition: api.cc:5141
static void AddGCPrologueCallback(GCPrologueCallback callback, GCType gc_type_filter=kGCTypeAll)
Enables the host application to receive a notification before a garbage collection.
Definition: api.cc:6478
static const char * GetVersion()
Get the version string.
Definition: api.cc:5146
static bool AddMessageListener(MessageCallback that, Handle< Value > data=Handle< Value >())
Adds a message listener.
Definition: api.cc:6307
static internal::Object ** GlobalizeReference(internal::Isolate *isolate, internal::Object **handle)
Definition: api.cc:494
static StartupData::CompressionAlgorithm GetCompressedStartupDataAlgorithm()
The following 4 functions are to be used when V8 is built with the 'compress_startup_data' flag enabl...
Definition: api.cc:246
static void SetFlagsFromString(const char *str, int length)
Sets V8 flags from a string.
Definition: api.cc:364
static void MakeWeak(internal::Object **global_handle, void *data, WeakCallback weak_callback)
Definition: api.cc:513
static void SetAllowCodeGenerationFromStringsCallback(AllowCodeGenerationFromStringsCallback that)
Set the callback to invoke to check if code generation from strings should be allowed.
Definition: api.cc:357
static void GetCompressedStartupData(StartupData *compressed_data)
Definition: api.cc:273
static void SetCaptureStackTraceForUncaughtExceptions(bool capture, int frame_limit=10, StackTrace::StackTraceOptions options=StackTrace::kOverview)
Tells V8 to capture current stack trace when uncaught exception occurs and report it to the message l...
Definition: api.cc:6340
static void SetDecompressedStartupData(StartupData *decompressed_data)
Definition: api.cc:304
static void InitializePlatform(Platform *platform)
Sets the v8::Platform to use.
Definition: api.cc:5048
static int GetCompressedStartupDataCount()
Definition: api.cc:264
static void VisitExternalResources(ExternalResourceVisitor *visitor)
Iterates through all external resources referenced from current isolate heap.
Definition: api.cc:5097
static void VisitHandlesWithClassIds(PersistentHandleVisitor *visitor)
Iterates through all the persistent handles in the current isolate's heap that have class_ids.
Definition: api.cc:5120
static void AddGCEpilogueCallback(GCEpilogueCallback callback, GCType gc_type_filter=kGCTypeAll)
Enables the host application to receive a notification after a garbage collection.
Definition: api.cc:6494
static void SetSnapshotDataBlob(StartupData *startup_blob)
Definition: api.cc:342
static void SetFlagsFromCommandLine(int *argc, char **argv, bool remove_flags)
Sets V8 flags from the command line.
Definition: api.cc:369
static bool IsExecutionTerminating(Isolate *isolate=NULL)
Is V8 terminating JavaScript execution.
Definition: api.cc:6532
static void DisposeGlobal(internal::Object **global_handle)
Definition: api.cc:525
static void SetArrayBufferAllocator(ArrayBuffer::Allocator *allocator)
Set allocator to use for ArrayBuffer memory.
Definition: api.cc:5074
static void SetNativesDataBlob(StartupData *startup_blob)
Hand startup data to V8, in case the embedder has chosen to build V8 with external startup data.
Definition: api.cc:333
static void AddMemoryAllocationCallback(MemoryAllocationCallback callback, ObjectSpace space, AllocationAction action)
Enables the host application to provide a mechanism to be notified and perform custom logging when V8...
Definition: api.cc:6510
static internal::Object ** CopyPersistent(internal::Object **handle)
Definition: api.cc:504
static void * ClearWeak(internal::Object **global_handle)
Definition: api.cc:520
static void RemoveGCPrologueCallback(GCPrologueCallback callback)
This function removes callback which was installed by AddGCPrologueCallback function.
Definition: api.cc:6487
static bool IsDead()
Check if V8 is dead and therefore unusable.
Definition: api.cc:189
static void SetEntropySource(EntropySource source)
Allows the host application to provide a callback which can be used as a source of entropy for random...
Definition: api.cc:5064
static void RemoveGCEpilogueCallback(GCEpilogueCallback callback)
This function removes callback which was installed by AddGCEpilogueCallback function.
Definition: api.cc:6503
static void ShutdownPlatform()
Clears all references to the v8::Platform.
Definition: api.cc:5053
static void VisitHandlesForPartialDependence(Isolate *isolate, PersistentHandleVisitor *visitor)
Iterates through all the persistent handles in the current isolate's heap that have class_ids and are...
Definition: api.cc:5129
static void CancelTerminateExecution(Isolate *isolate)
Resume execution capability in the given isolate, whose execution was previously forcefully terminate...
Definition: api.cc:6539
static bool Dispose()
Releases any resources used by v8 and stops any utility threads that may be running.
Definition: api.cc:5084
static bool Initialize()
Initializes V8.
Definition: api.cc:5058
static void SetFailedAccessCheckCallbackFunction(FailedAccessCheckCallback)
Callback function for reporting failed access checks.
Definition: api.cc:6351
The superclass of all JavaScript values and objects.
Definition: v8.h:1440
bool IsRegExp() const
Returns true if this value is a RegExp.
Definition: api.cc:2565
bool IsTypedArray() const
Returns true if this value is one of TypedArrays.
Definition: api.cc:2446
double NumberValue() const
Definition: api.cc:2900
bool IsSymbol() const
Returns true if this value is a symbol.
Definition: api.cc:2426
Local< Uint32 > ToArrayIndex() const
Attempts to convert a string to an array index.
Definition: api.cc:2975
Local< Boolean > ToBoolean() const
Definition: api.cc:2638
Local< String > ToString() const
Definition: api.cc:2584
bool IsName() const
Returns true if this value is a symbol or a string.
Definition: api.cc:2414
Local< String > ToDetailString() const
Definition: api.cc:2602
bool StrictEquals(Handle< Value > that) const
Definition: api.cc:3052
bool BooleanValue() const
Definition: api.cc:2895
bool FullIsUndefined() const
Definition: api.cc:2385
bool IsTrue() const
Returns true if this value is true.
Definition: api.cc:2399
bool IsArray() const
Returns true if this value is an array.
Definition: api.cc:2431
bool IsPromise() const
Returns true if this value is a Promise.
Definition: api.cc:5852
bool QuickIsUndefined() const
Definition: v8.h:6524
Local< Integer > ToInteger() const
Definition: api.cc:2671
bool IsArrayBuffer() const
Returns true if this value is an ArrayBuffer.
Definition: api.cc:2436
Local< Uint32 > ToUint32() const
Definition: api.cc:2957
bool IsString() const
Returns true if this value is an instance of the String type.
Definition: v8.h:6552
bool IsNumber() const
Returns true if this value is a number.
Definition: api.cc:2473
bool IsObject() const
Returns true if this value is an object.
Definition: api.cc:2468
int64_t IntegerValue() const
Definition: api.cc:2918
bool IsBoolean() const
Returns true if this value is boolean.
Definition: api.cc:2500
bool IsNativeError() const
Returns true if this value is a NativeError.
Definition: api.cc:2547
bool IsFalse() const
Returns true if this value is false.
Definition: api.cc:2404
bool IsExternal() const
Returns true if this value is external.
Definition: api.cc:2505
bool QuickIsString() const
Definition: v8.h:6560
bool FullIsString() const
Definition: api.cc:2419
Local< Int32 > ToInt32() const
Definition: api.cc:2940
int32_t Int32Value() const
Definition: api.cc:3004
bool IsArrayBufferView() const
Returns true if this value is an ArrayBufferView.
Definition: api.cc:2441
bool Equals(Handle< Value > that) const
JS ==.
Definition: api.cc:3025
bool IsGeneratorFunction() const
Returns true if this value is a Generator function.
Definition: api.cc:2571
bool SameValue(Handle< Value > that) const
Definition: api.cc:3085
bool IsFunction() const
Returns true if this value is a function.
Definition: api.cc:2409
bool FullIsNull() const
Definition: api.cc:2392
bool QuickIsNull() const
Definition: v8.h:6542
bool IsInt32() const
Returns true if this value is a 32-bit signed integer.
Definition: api.cc:2510
bool IsDataView() const
Returns true if this value is a DataView.
Definition: api.cc:2463
bool IsUint32() const
Returns true if this value is a 32-bit unsigned integer.
Definition: api.cc:2520
uint32_t Uint32Value() const
Definition: api.cc:3097
Local< Object > ToObject() const
Definition: api.cc:2620
Local< Number > ToNumber() const
Definition: api.cc:2653
bool IsGeneratorObject() const
Returns true if this value is a Generator object (iterator).
Definition: api.cc:2579
virtual void VisitPointers(i::Object **start, i::Object **end)
Definition: api.cc:5107
VisitorAdapter(PersistentHandleVisitor *visitor)
Definition: api.cc:5105
virtual void VisitEmbedderReference(i::Object **p, uint16_t class_id)
Definition: api.cc:5110
PersistentHandleVisitor * visitor_
Definition: api.cc:5116
static double nan_value()
static void Abort()
static void PrintError(const char *format,...)
const char * bailout_reason() const
const char * name_prefix() const
const char * resource_name() const
const char * name() const
static Handle< SharedFunctionInfo > CompileStreamedScript(CompilationInfo *info, int source_length)
Definition: compiler.cc:1230
static Handle< SharedFunctionInfo > CompileScript(Handle< String > source, Handle< Object > script_name, int line_offset, int column_offset, bool is_shared_cross_origin, Handle< Context > context, v8::Extension *extension, ScriptData **cached_data, ScriptCompiler::CompileOptions compile_options, NativesFlag is_natives_code)
Definition: compiler.cc:1134
Context * native_context()
Definition: contexts.cc:44
const ProfileTree * top_down() const
base::TimeTicks sample_timestamp(int index) const
base::TimeTicks start_time() const
const char * title() const
base::TimeTicks end_time() const
ProfileNode * sample(int index) const
void ResetDateCache()
Definition: date.cc:27
void EnqueueCommandMessage(Vector< const uint16_t > command, v8::Debug::ClientData *client_data=NULL)
Definition: debug.cc:2979
MUST_USE_RESULT MaybeHandle< Object > Call(Handle< JSFunction > fun, Handle< Object > data)
Definition: debug.cc:3004
void SetMessageHandler(v8::Debug::MessageHandler handler)
Definition: debug.cc:2942
void SetEventListener(Handle< Object > callback, Handle< Object > data)
Definition: debug.cc:2921
void set_live_edit_enabled(bool v)
Definition: debug.h:460
Handle< Context > debug_context()
Definition: debug.h:459
void EnqueueDebugCommand(v8::Debug::ClientData *client_data=NULL)
Definition: debug.cc:2995
static Handle< DeclaredAccessorDescriptor > Create(Isolate *isolate, const DeclaredAccessorDescriptorData &data, Handle< DeclaredAccessorDescriptor > previous)
Definition: objects.cc:15836
List< Object ** > blocks_
Definition: api.h:472
static void DeoptimizeGlobalObject(JSObject *object)
Definition: deoptimizer.cc:470
static void DeoptimizeAll(Isolate *isolate)
Definition: deoptimizer.cc:437
bool Exists(SingletonHandle singleton)
Handle< Object > Get(int index)
void Create(Isolate *isolate, Object *object, int *index)
Handle< Object > GetSingleton(SingletonHandle singleton)
void AddString(String *string)
Definition: heap-inl.h:644
static const int kShortSize
Definition: objects.h:9137
static Handle< FixedArray > CopySize(Handle< FixedArray > array, int new_length, PretenureFlag pretenure=NOT_TENURED)
Definition: objects.cc:7749
Object * get(int index)
Definition: objects-inl.h:2165
static int SetFlagsFromCommandLine(int *argc, char **argv, bool remove_flags)
Definition: flags.cc:334
static int SetFlagsFromString(const char *str, int len)
Definition: flags.cc:472
bool IsTemplateFor(Object *object)
Definition: objects.cc:210
void IterateAllRootsInNewSpaceWithClassIds(ObjectVisitor *v)
static void MakeWeak(Object **location, void *parameter, WeakCallback weak_callback)
static void * ClearWeakness(Object **location)
void SetReference(HeapObject **parent, Object **child)
void IterateAllRootsWithClassIds(ObjectVisitor *v)
void SetReferenceFromGroup(UniqueId id, Object **child)
static Handle< Object > CopyGlobal(Object **location)
void SetObjectGroupId(Object **handle, UniqueId id)
static void Destroy(Object **location)
Handle< Object > Create(Object *value)
void EnterContext(Handle< Context > context)
Definition: api.h:614
Handle< Context > LastEnteredContext()
Definition: api.h:629
bool LastEnteredContextWas(Handle< Context > context)
Definition: api.h:624
void IterateThis(ObjectVisitor *v)
Definition: api.cc:7553
void SaveContext(Context *context)
Definition: api.h:599
static int NumberOfHandles(Isolate *isolate)
Definition: handles.cc:13
Handle< T > CloseAndEscape(Handle< T > handle_value)
Definition: handles-inl.h:119
static void CloseScope(Isolate *isolate, Object **prev_next, Object **prev_limit)
Definition: handles-inl.h:99
static T ** CreateHandle(Isolate *isolate, T *value)
Definition: handles-inl.h:138
static Handle< T > cast(Handle< S > that)
Definition: handles.h:116
bool is_null() const
Definition: handles.h:124
static Handle< T > null()
Definition: handles.h:123
Isolate * GetIsolate() const
Definition: objects-inl.h:1387
size_t CommittedPhysicalMemory()
Definition: heap.cc:180
static const int kMaxSemiSpaceSizeHighMemoryDevice
Definition: heap.h:1019
void VisitExternalResources(v8::ExternalResourceVisitor *visitor)
Definition: heap.cc:1707
intptr_t CommittedMemoryExecutable()
Definition: heap.cc:194
ExternalStringTable * external_string_table()
Definition: heap.h:1207
void RemoveGCPrologueCallback(v8::Isolate::GCPrologueCallback callback)
Definition: heap.cc:5307
static const int kMaxOldSpaceSizeHighMemoryDevice
Definition: heap.h:1027
void AddGCPrologueCallback(v8::Isolate::GCPrologueCallback callback, GCType gc_type_filter, bool pass_isolate=true)
Definition: heap.cc:5298
static const int kMaxExecutableSizeHighMemoryDevice
Definition: heap.h:1035
static const int kMaxOldSpaceSizeMediumMemoryDevice
Definition: heap.h:1025
intptr_t MaxReserved()
Definition: heap.h:549
static const int kAbortIncrementalMarkingMask
Definition: heap.h:718
void AddGCEpilogueCallback(v8::Isolate::GCEpilogueCallback callback, GCType gc_type_filter, bool pass_isolate=true)
Definition: heap.cc:5319
bool ConfigureHeap(int max_semi_space_size, int max_old_space_size, int max_executable_size, size_t code_range_size)
Definition: heap.cc:4827
static const int kMaxExecutableSizeHugeMemoryDevice
Definition: heap.h:1037
static const int kNoGCFlags
Definition: heap.h:716
bool IsInGCPostProcessing()
Definition: heap.h:957
static const int kMaxExecutableSizeMediumMemoryDevice
Definition: heap.h:1033
bool HasBeenSetUp()
Definition: heap.cc:221
void RecordStats(HeapStats *stats, bool take_snapshot=false)
Definition: heap.cc:4929
bool IdleNotification(int idle_time_in_ms)
Definition: heap.cc:4296
intptr_t CommittedMemory()
Definition: heap.cc:170
static const int kMaxOldSpaceSizeHugeMemoryDevice
Definition: heap.h:1028
static const int kMaxOldSpaceSizeLowMemoryDevice
Definition: heap.h:1024
static const int kMaxSemiSpaceSizeHugeMemoryDevice
Definition: heap.h:1020
void RemoveGCEpilogueCallback(v8::Isolate::GCEpilogueCallback callback)
Definition: heap.cc:5328
static const int kMaxSemiSpaceSizeMediumMemoryDevice
Definition: heap.h:1018
void CollectAllAvailableGarbage(const char *gc_reason=NULL)
Definition: heap.cc:735
static const int kMaxExecutableSizeLowMemoryDevice
Definition: heap.h:1032
intptr_t SizeOfObjects()
Definition: heap.cc:460
static const int kMaxSemiSpaceSizeLowMemoryDevice
Definition: heap.h:1017
int NotifyContextDisposed()
Definition: heap.cc:857
static void CheckInitializedImpl(v8::Isolate *isolate)
bool has_scheduled_exception()
Definition: isolate.h:627
Object * scheduled_exception()
Definition: isolate.h:622
void PrintCurrentStackTrace(FILE *out)
Definition: isolate.cc:904
CodeRange * code_range()
Definition: isolate.h:863
HandleScopeImplementer * handle_scope_implementer()
Definition: isolate.h:901
void EnqueueMicrotask(Handle< Object > microtask)
Definition: isolate.cc:2281
void SetFailedAccessCheckCallback(v8::FailedAccessCheckCallback callback)
Definition: isolate.cc:615
StackGuard * stack_guard()
Definition: isolate.h:872
Handle< Context > GetCallingNativeContext()
Definition: isolate.cc:1349
void RemoveCallCompletedCallback(CallCompletedCallback callback)
Definition: isolate.cc:2256
void enable_serializer()
Definition: isolate.h:1001
void CancelTerminateExecution()
Definition: isolate.cc:795
DateCache * date_cache()
Definition: isolate.h:1020
void ScheduleThrow(Object *exception)
Definition: isolate.cc:858
HeapProfiler * heap_profiler() const
Definition: isolate.h:972
MemoryAllocator * memory_allocator()
Definition: isolate.h:883
void set_context(Context *context)
Definition: isolate.h:549
Address js_entry_sp()
Definition: isolate.h:658
void InitializeLoggingAndCounters()
Definition: isolate.cc:1818
HandleScopeData * handle_scope_data()
Definition: isolate.h:899
Context * context()
Definition: isolate.h:548
Handle< JSBuiltinsObject > js_builtins_object()
Definition: isolate.h:679
Handle< Context > global_context()
Definition: isolate.cc:1344
Counters * counters()
Definition: isolate.h:857
void ReportPendingMessages()
Definition: isolate.cc:1194
ThreadManager * thread_manager()
Definition: isolate.h:921
void AddCallCompletedCallback(CallCompletedCallback callback)
Definition: isolate.cc:2248
Handle< JSObject > GetSymbolRegistry()
Definition: isolate.cc:2228
Handle< JSArray > CaptureCurrentStackTrace(int frame_limit, StackTrace::StackTraceOptions options)
Definition: isolate.cc:439
void set_function_entry_hook(FunctionEntryHook function_entry_hook)
Definition: isolate.h:1079
StringTracker * string_tracker()
Definition: isolate.h:923
JSObject * global_proxy()
Definition: isolate.h:675
bool Init(Deserializer *des)
Definition: isolate.cc:1828
CpuProfiler * cpu_profiler() const
Definition: isolate.h:971
StatsTable * stats_table()
Definition: isolate.cc:2039
void RegisterTryCatchHandler(v8::TryCatch *that)
Definition: isolate.cc:244
Logger * logger()
Definition: isolate.h:866
EternalHandles * eternal_handles()
Definition: isolate.h:919
Factory * factory()
Definition: isolate.h:982
GlobalHandles * global_handles()
Definition: isolate.h:917
Bootstrapper * bootstrapper()
Definition: isolate.h:856
static const int kBoundFunctionIndex
Definition: objects.h:7392
static void SetMapAndElements(Handle< JSObject > object, Handle< Map > map, Handle< FixedArrayBase > elements)
Definition: objects-inl.h:1814
static void MigrateSlowToFast(Handle< JSObject > object, int unused_property_fields)
Definition: objects.cc:4279
static MUST_USE_RESULT MaybeHandle< Object > SetAccessor(Handle< JSObject > object, Handle< AccessorInfo > info)
Definition: objects.cc:6188
static void DeleteHiddenProperty(Handle< JSObject > object, Handle< Name > key)
Definition: objects.cc:4673
static MUST_USE_RESULT Maybe< bool > HasRealNamedCallbackProperty(Handle< JSObject > object, Handle< Name > key)
Definition: objects.cc:13243
static MUST_USE_RESULT Maybe< bool > HasRealNamedProperty(Handle< JSObject > object, Handle< Name > key)
Definition: objects.cc:13205
static MUST_USE_RESULT MaybeHandle< Object > SetElement(Handle< JSObject > object, uint32_t index, Handle< Object > value, PropertyAttributes attributes, StrictMode strict_mode, bool check_prototype=true, SetPropertyMode set_mode=SET_PROPERTY)
Definition: objects.cc:12336
static void MigrateToMap(Handle< JSObject > object, Handle< Map > new_map)
Definition: objects.cc:1886
static MUST_USE_RESULT Maybe< bool > HasRealElementProperty(Handle< JSObject > object, uint32_t index)
Definition: objects.cc:13214
static Handle< Object > GetDataProperty(Handle< JSObject > object, Handle< Name > key)
Definition: objects.cc:140
static Handle< Map > GetElementsTransitionMap(Handle< JSObject > object, ElementsKind to_kind)
Definition: objects.cc:3385
static MUST_USE_RESULT MaybeHandle< Object > SetPrototype(Handle< JSObject > object, Handle< Object > value, bool from_javascript)
Definition: objects.cc:11658
static Handle< Object > SetHiddenProperty(Handle< JSObject > object, Handle< Name > key, Handle< Object > value)
Definition: objects.cc:4627
static MaybeHandle< Object > DefineAccessor(Handle< JSObject > object, Handle< Name > name, Handle< Object > getter, Handle< Object > setter, PropertyAttributes attributes)
Definition: objects.cc:6095
static MUST_USE_RESULT Maybe< PropertyAttributes > GetPropertyAttributes(Handle< JSReceiver > object, Handle< Name > name)
Definition: objects-inl.h:6670
static MUST_USE_RESULT Maybe< bool > HasElement(Handle< JSReceiver > object, uint32_t index)
Definition: objects-inl.h:6718
static Handle< Smi > GetOrCreateIdentityHash(Handle< JSReceiver > object)
Definition: objects-inl.h:6704
static MUST_USE_RESULT MaybeHandle< Object > DeleteElement(Handle< JSReceiver > object, uint32_t index, DeleteMode mode=NORMAL_DELETION)
Definition: objects.cc:5002
static MUST_USE_RESULT Maybe< bool > HasOwnProperty(Handle< JSReceiver >, Handle< Name > name)
Definition: objects-inl.h:6658
static MUST_USE_RESULT MaybeHandle< FixedArray > GetKeys(Handle< JSReceiver > object, KeyCollectionType type)
Definition: objects.cc:5797
static MUST_USE_RESULT Maybe< bool > HasProperty(Handle< JSReceiver > object, Handle< Name > name)
Definition: objects-inl.h:6646
T & first() const
Definition: list.h:71
void SetCodeEventHandler(uint32_t options, JitCodeEventHandler event_handler)
Definition: log.cc:1877
static Handle< Map > Copy(Handle< Map > map)
Definition: objects.cc:6664
bool is_null() const
Definition: handles.h:66
void RemoveMemoryAllocationCallback(MemoryAllocationCallback callback)
Definition: spaces.cc:782
void AddMemoryAllocationCallback(MemoryAllocationCallback callback, ObjectSpace space, AllocationAction action)
Definition: spaces.cc:772
static Handle< String > GetMessage(Isolate *isolate, Handle< Object > data)
Definition: messages.cc:129
static Vector< const byte > GetScriptsSource()
static void SetRawScriptsSource(Vector< const char > raw_source)
static MUST_USE_RESULT MaybeHandle< Object > GetPropertyOrElement(Handle< Object > object, Handle< Name > key)
Definition: objects-inl.h:1124
static MaybeHandle< JSReceiver > ToObject(Isolate *isolate, Handle< Object > object)
Definition: objects-inl.h:1094
static MUST_USE_RESULT MaybeHandle< Object > GetElement(Isolate *isolate, Handle< Object > object, uint32_t index)
Definition: objects-inl.h:1113
static MUST_USE_RESULT MaybeHandle< Object > GetProperty(LookupIterator *it)
Definition: objects.cc:109
static MUST_USE_RESULT MaybeHandle< Object > SetProperty(Handle< Object > object, Handle< Name > key, Handle< Object > value, StrictMode strict_mode, StoreFromKeyed store_mode=MAY_BE_STORE_FROM_KEYED)
Definition: objects.cc:2798
CodeEntry * entry() const
ProfileNode * root() const
A class to uniformly access the prototype of any Object and walk its prototype chain.
Definition: prototype.h:25
bool IsAtEnd(WhereToEnd where_to_end=END_AT_NULL) const
Definition: prototype.h:99
Object * GetCurrent() const
Definition: prototype.h:62
static MUST_USE_RESULT MaybeHandle< Object > HasObjectProperty(Isolate *isolate, Handle< JSReceiver > object, Handle< Object > key)
Definition: runtime.cc:1891
static MUST_USE_RESULT MaybeHandle< Object > SetObjectProperty(Isolate *isolate, Handle< Object > object, Handle< Object > key, Handle< Object > value, StrictMode strict_mode)
Definition: runtime.cc:2181
static void NeuterArrayBuffer(Handle< JSArrayBuffer > array_buffer)
static void SetupArrayBuffer(Isolate *isolate, Handle< JSArrayBuffer > array_buffer, bool is_external, void *data, size_t allocated_length)
static MUST_USE_RESULT MaybeHandle< Object > GetObjectProperty(Isolate *isolate, Handle< Object > object, Handle< Object > key)
Definition: runtime.cc:1912
static MUST_USE_RESULT MaybeHandle< Object > DefineObjectProperty(Handle< JSObject > object, Handle< Object > key, Handle< Object > value, PropertyAttributes attr)
Definition: runtime.cc:2277
static MUST_USE_RESULT MaybeHandle< Object > DeleteObjectProperty(Isolate *isolate, Handle< JSReceiver > object, Handle< Object > key, JSReceiver::DeleteMode mode)
Definition: runtime.cc:2328
static bool SetupArrayBufferAllocatingData(Isolate *isolate, Handle< JSArrayBuffer > array_buffer, size_t allocated_length, bool initialize=true)
const byte * data() const
Definition: compiler.h:40
int length() const
Definition: compiler.h:41
static Handle< Object > GetNameOrSourceURL(Handle< Script > script)
Definition: objects.cc:9697
static int GetColumnNumber(Handle< Script > script, int code_pos)
Definition: objects.cc:9635
static int GetLineNumber(Handle< Script > script, int code_pos)
Definition: objects.cc:9673
static void UnregisterCTryCatch()
Definition: simulator-arm.h:55
static uintptr_t RegisterCTryCatch(uintptr_t try_catch_address)
Definition: simulator-arm.h:51
static const int kMaxValue
Definition: objects.h:1272
static Smi * FromInt(int value)
Definition: objects-inl.h:1321
static bool IsValid(intptr_t value)
Definition: objects-inl.h:1334
static int size()
Definition: snapshot.h:26
static bool Initialize(Isolate *isolate)
static const byte * context_data()
Definition: snapshot.h:31
static int raw_size()
Definition: snapshot.h:27
static void set_context_raw_data(const byte *context_raw_data)
Definition: snapshot.h:34
static void set_raw_data(const byte *raw_data)
Definition: snapshot.h:28
static const byte * data()
Definition: snapshot.h:25
static int context_size()
Definition: snapshot.h:32
static int context_raw_size()
Definition: snapshot.h:33
void SetCounterFunction(CounterLookupCallback f)
Definition: counters.h:25
void SetCreateHistogramFunction(CreateHistogramCallback f)
Definition: counters.h:31
void RecordWrite(Handle< String > string)
Definition: api.h:400
bool IsFreshUnusedString(Handle< String > string)
Definition: api.h:411
static void WriteToFlat(String *source, sinkchar *sink, int from, int to)
Definition: objects.cc:8370
static ConsString * VisitFlat(Visitor *visitor, String *string, int offset=0)
Definition: objects-inl.h:3416
static Handle< String > Flatten(Handle< String > string, PretenureFlag pretenure=NOT_TENURED)
Definition: objects-inl.h:3354
bool Equals(String *other)
Definition: objects-inl.h:3336
static void set_stress_type(v8::Testing::StressType stress_type)
Definition: api.h:688
static v8::Testing::StressType stress_type()
Definition: api.h:687
static v8::Testing::StressType stress_type_
Definition: api.h:693
static void ShutdownPlatform()
Definition: v8.cc:109
static void SetArrayBufferAllocator(v8::ArrayBuffer::Allocator *allocator)
Definition: v8.h:76
static void TearDown()
Definition: v8.cc:42
static bool Initialize()
Definition: v8.cc:36
static void InitializePlatform(v8::Platform *platform)
Definition: v8.cc:102
static void FatalProcessOutOfMemory(const char *location, bool take_snapshot=false)
static v8::ArrayBuffer::Allocator * ArrayBufferAllocator()
Definition: v8.h:72
static void SetReturnAddressLocationResolver(ReturnAddressLocationResolver resolver)
Definition: v8.cc:55
T * start() const
Definition: vector.h:47
int length() const
Definition: vector.h:41
static const char * GetVersion()
Definition: version.h:27
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf map
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be expose gc extension under the specified name show built in functions in stack traces use random jit cookie to mask large constants minimum length for automatic enable preparsing CPU profiler sampling interval in microseconds trace out of bounds accesses to external arrays default size of stack region v8 is allowed to maximum length of function source code printed in a stack trace min size of a semi the new space consists of two semi spaces print one trace line following each garbage collection do not print trace line after scavenger collection print cumulative GC statistics in only print modified registers Trace simulator debug messages Implied by trace sim abort randomize hashes to avoid predictable hash Fixed seed to use to hash property Print the time it takes to deserialize the snapshot A filename with extra code to be included in the A file to write the raw snapshot bytes A file to write the raw context snapshot bytes Write V8 startup blob Print the time it takes to lazily compile hydrogen code stubs dump only objects containing this substring stress the GC compactor to flush out pretty print source code for builtins print C code to recreate TurboFan graphs report heap spill statistics along with enable possessive quantifier syntax for testing Minimal Log code events to the log file without profiling log positions Log statistical profiling Used with turns on browser compatible mode for profiling Enable perf linux profiler(experimental annotate support).") DEFINE_STRING(gc_fake_mmap
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be expose gc extension under the specified name show built in functions in stack traces use random jit cookie to mask large constants minimum length for automatic enable preparsing CPU profiler sampling interval in microseconds trace out of bounds accesses to external arrays default size of stack region v8 is allowed to maximum length of function source code printed in a stack trace min size of a semi the new space consists of two semi spaces print one trace line following each garbage collection do not print trace line after scavenger collection print cumulative GC statistics in only print modified registers Trace simulator debug messages Implied by trace sim abort randomize hashes to avoid predictable hash Fixed seed to use to hash property Print the time it takes to deserialize the snapshot A filename with extra code to be included in the A file to write the raw snapshot bytes to(mksnapshot only)") DEFINE_STRING(raw_context_file
enable harmony numeric enable harmony object literal extensions Optimize object size
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be expose gc extension under the specified name show built in functions in stack traces use random jit cookie to mask large constants minimum length for automatic enable preparsing CPU profiler sampling interval in microseconds trace out of bounds accesses to external arrays default size of stack region v8 is allowed to maximum length of function source code printed in a stack trace min size of a semi the new space consists of two semi spaces print one trace line following each garbage collection do not print trace line after scavenger collection print cumulative GC statistics in name
enable harmony numeric enable harmony object literal extensions true
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be expose gc extension under the specified name show built in functions in stack traces use random jit cookie to mask large constants minimum length for automatic enable preparsing CPU profiler sampling interval in microseconds trace out of bounds accesses to external arrays default size of stack region v8 is allowed to maximum length of function source code printed in a stack trace min size of a semi space(in MBytes)
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be expose gc extension under the specified name show built in functions in stack traces use random jit cookie to mask large constants minimum length for automatic enable preparsing CPU profiler sampling interval in microseconds trace out of bounds accesses to external arrays default size of stack region v8 is allowed to maximum length of function source code printed in a stack trace min size of a semi the new space consists of two semi spaces print one trace line following each garbage collection do not print trace line after scavenger collection print cumulative GC statistics in only print modified registers Trace simulator debug messages Implied by trace sim abort randomize hashes to avoid predictable hash Fixed seed to use to hash property Print the time it takes to deserialize the snapshot A filename with extra code to be included in the A file to write the raw snapshot bytes A file to write the raw context snapshot bytes Write V8 startup blob Print the time it takes to lazily compile hydrogen code stubs dump only objects containing this substring stress the GC compactor to flush out pretty print source code for builtins print C code to recreate TurboFan graphs report heap spill statistics along with heap_stats(requires heap_stats)") DEFINE_BOOL(regexp_possessive_quantifier
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be expose gc extension under the specified name show built in functions in stack traces use random jit cookie to mask large constants minimum length for automatic enable preparsing CPU profiler sampling interval in microseconds trace out of bounds accesses to external arrays default size of stack region v8 is allowed to maximum length of function source code printed in a stack trace min size of a semi the new space consists of two semi spaces print one trace line following each garbage collection do not print trace line after scavenger collection print cumulative GC statistics in only print modified registers Trace simulator debug messages Implied by trace sim abort randomize hashes to avoid predictable hash Fixed seed to use to hash property Print the time it takes to deserialize the snapshot A filename with extra code to be included in the snapshot(mksnapshot only)") DEFINE_STRING(raw_file
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be NULL
#define FUNCTION_ADDR(f)
Definition: globals.h:195
#define GLOBAL
#define ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, dst, call, value)
Definition: isolate.h:123
#define UNREACHABLE()
Definition: logging.h:30
#define CHECK_EQ(expected, value)
Definition: logging.h:169
#define CHECK(condition)
Definition: logging.h:36
#define FATAL(msg)
Definition: logging.h:26
#define DCHECK(condition)
Definition: logging.h:205
#define DCHECK_EQ(v1, v2)
Definition: logging.h:206
void USE(T)
Definition: macros.h:322
#define V8_2PART_UINT64_C(a, b)
Definition: macros.h:376
#define STATIC_ASSERT(test)
Definition: macros.h:311
#define arraysize(array)
Definition: macros.h:86
#define MUST_USE_RESULT
Definition: macros.h:266
unsigned short uint16_t
Definition: unicode.cc:23
signed short int16_t
Definition: unicode.cc:22
int int32_t
Definition: unicode.cc:24
Local< String > NewString(Isolate *v8_isolate, const char *location, const char *env, const Char *data, String::NewStringType type, int length)
Definition: api.cc:5420
static i::ElementsKind GetElementsKindFromExternalArrayType(ExternalArrayType array_type)
Definition: api.cc:3816
void PrepareExternalArrayElements(i::Handle< i::JSObject > object, void *data, ExternalArrayType array_type, int length)
Definition: api.cc:3831
int StringLength(const uint16_t *string)
Definition: api.cc:5378
static RandomNumberGenerator::EntropySource entropy_source
IN DWORD64 OUT PDWORD64 OUT PIMAGEHLP_SYMBOL64 Symbol
static void Parse(Handle< JSFunction > function, CompilationInfoWithZone *info)
Definition: js-inlining.cc:56
static LifetimePosition Max(LifetimePosition a, LifetimePosition b)
static LifetimePosition Min(LifetimePosition a, LifetimePosition b)
void DeleteArray(T *array)
Definition: allocation.h:68
T * NewArray(size_t size)
Definition: allocation.h:60
kSerializedDataOffset kPrototypeTemplateOffset kIndexedPropertyHandlerOffset kInstanceCallHandlerOffset internal_field_count
Definition: objects-inl.h:5340
bool InitializeICU(const char *icu_data_file)
Definition: icu_util.cc:41
PerIsolateAssertScope< JAVASCRIPT_EXECUTION_ASSERT, true > AllowJavascriptExecution
Definition: assert-scope.h:149
static bool IsInt32Double(double value)
Definition: conversions.h:169
unsigned int FastD2UI(double x)
const size_t kMaximalCodeRangeSize
Definition: globals.h:156
int ToNumber(Register reg)
const int kMaxInt
Definition: globals.h:109
@ OBJECT_TEMPLATE_INFO_TYPE
Definition: objects.h:704
@ INTERCEPTOR_INFO_TYPE
Definition: objects.h:701
@ TYPE_SWITCH_INFO_TYPE
Definition: objects.h:706
@ SIGNATURE_INFO_TYPE
Definition: objects.h:705
@ FUNCTION_TEMPLATE_INFO_TYPE
Definition: objects.h:703
@ CALL_HANDLER_INFO_TYPE
Definition: objects.h:702
@ ACCESS_CHECK_INFO_TYPE
Definition: objects.h:700
Handle< T > handle(T *t, Isolate *isolate)
Definition: handles.h:146
const int kHandleBlockSize
Definition: api.h:596
PerIsolateAssertScope< JAVASCRIPT_EXECUTION_THROWS, false > ThrowOnJavascriptExecution
Definition: assert-scope.h:153
DISABLE_ASAN uintptr_t GetCurrentStackPosition()
Definition: utils.h:1460
const bool kRequiresCodeRange
Definition: globals.h:155
PerIsolateAssertScope< JAVASCRIPT_EXECUTION_ASSERT, false > DisallowJavascriptExecution
Definition: assert-scope.h:145
void InvokeFunctionCallback(const v8::FunctionCallbackInfo< v8::Value > &info, v8::FunctionCallback callback)
Definition: api.cc:7679
byte * Address
Definition: globals.h:101
void SetNativesFromFile(StartupData *natives_blob)
Read the Natives (library sources) blob, as generated by js2c + the build system.
static int ArchiveSpacePerThread()
Definition: v8threads.cc:171
kFeedbackVectorOffset kHiddenPrototypeBit kReadOnlyPrototypeBit do_not_cache
Definition: objects-inl.h:5427
@ kDescriptorBitmaskCompare
Definition: objects.h:10155
@ kDescriptorPointerDereference
Definition: objects.h:10159
@ kDescriptorPointerShift
Definition: objects.h:10160
@ kDescriptorObjectDereference
Definition: objects.h:10158
@ kDescriptorPrimitiveValue
Definition: objects.h:10157
@ kDescriptorReturnObject
Definition: objects.h:10161
@ kDescriptorPointerCompare
Definition: objects.h:10156
kSerializedDataOffset prototype_template
Definition: objects-inl.h:5322
double FastUI2D(unsigned x)
Definition: conversions.h:72
static bool IsMinusZero(double value)
Definition: conversions.h:154
void FatalProcessOutOfMemory(const char *message)
const uint32_t kMaxUInt32
Definition: globals.h:120
void InvokeAccessorGetterCallback(v8::Local< v8::Name > property, const v8::PropertyCallbackInfo< v8::Value > &info, v8::AccessorNameGetterCallback getter)
Definition: api.cc:7665
@ NOT_NATIVES_CODE
Definition: globals.h:401
const int GB
Definition: globals.h:108
const int kCharSize
Definition: globals.h:122
int StrLength(const char *string)
Definition: vector.h:147
void MemCopy(void *dest, const void *src, size_t size)
Definition: utils.h:350
void SetSnapshotFromFile(StartupData *snapshot_blob)
PerIsolateAssertScope< JAVASCRIPT_EXECUTION_THROWS, true > NoThrowOnJavascriptExecution
Definition: assert-scope.h:157
static intptr_t Free(PagedSpace *space, FreeList *free_list, Address start, int size)
uint8_t byte
Definition: globals.h:100
Debugger support for the V8 JavaScript engine.
Definition: accessors.cc:20
PropertyAttribute
Definition: v8.h:2210
@ DontEnum
Definition: v8.h:2213
JitCodeEventOptions
Option flags passed to the SetJitCodeEventHandler function.
Definition: v8.h:4333
@ kJitCodeEventDefault
Definition: v8.h:4334
void(* GCPrologueCallback)(GCType type, GCCallbackFlags flags)
Definition: v8.h:4216
static void SetFlagsFromString(const char *flags)
Definition: api.cc:7473
static int Utf8Length(i::String *str, i::Isolate *isolate)
Definition: api.cc:4549
static bool CheckConstructor(i::Isolate *isolate, i::Handle< i::JSObject > obj, const char *class_name)
Definition: api.cc:2534
void(* FailedAccessCheckCallback)(Local< Object > target, AccessType type, Local< Value > data)
Definition: v8.h:4182
static i::Handle< i::Context > CreateEnvironment(i::Isolate *isolate, v8::ExtensionConfiguration *extensions, v8::Handle< ObjectTemplate > global_template, v8::Handle< Value > maybe_global_proxy)
Definition: api.cc:5151
void(* LogEventCallback)(const char *name, int event)
Definition: v8.h:4124
void(* MemoryAllocationCallback)(ObjectSpace space, AllocationAction action, int size)
Definition: v8.h:4171
@ kGCCallbackFlagForced
Definition: v8.h:4213
void(* MessageCallback)(Handle< Message > message, Handle< Value > error)
Definition: v8.h:4120
i::Handle< i::JSTypedArray > NewTypedArray(i::Isolate *isolate, Handle< ArrayBuffer > array_buffer, size_t byte_offset, size_t length)
Definition: api.cc:6106
static bool RecursivelySerializeToUtf8(i::String *current, Utf8WriterVisitor *writer, int recursion_budget)
Definition: api.cc:4752
AccessControl
Access control specifications.
Definition: v8.h:2272
@ ALL_CAN_WRITE
Definition: v8.h:2275
@ ALL_CAN_READ
Definition: v8.h:2274
@ DEFAULT
Definition: v8.h:2273
static i::Handle< i::TemplateInfo > GetTemplateInfo(i::Isolate *isolate, Template *template_obj)
Definition: api.cc:1299
static Local< FunctionTemplate > FunctionTemplateNew(i::Isolate *isolate, FunctionCallback callback, v8::Handle< Value > data, v8::Handle< Signature > signature, int length, bool do_not_cache)
Definition: api.cc:871
static void TemplateSet(i::Isolate *isolate, v8::Template *templ, int length, v8::Handle< v8::Data > *data)
Definition: api.cc:782
void(* JitCodeEventHandler)(const JitCodeEvent *event)
Callback function passed to SetJitCodeEventHandler.
Definition: v8.h:4345
static MUST_USE_RESULT i::MaybeHandle< i::Object > CallV8HeapFunction(const char *name, i::Handle< i::Object > recv, int argc, i::Handle< i::Object > argv[])
Definition: api.cc:2112
@ Exception
Definition: v8-debug.h:18
void SetResourceConstraints(i::Isolate *isolate, const ResourceConstraints &constraints)
Definition: api.cc:474
DeclaredAccessorDescriptorDataType
Definition: v8.h:3937
void(* AccessorNameSetterCallback)(Local< Name > property, Local< Value > value, const PropertyCallbackInfo< void > &info)
Definition: v8.h:2257
void(* IndexedPropertyGetterCallback)(uint32_t index, const PropertyCallbackInfo< Value > &info)
Returns the value of the property if the getter intercepts the request.
Definition: v8.h:3474
void(* GCEpilogueCallback)(GCType type, GCCallbackFlags flags)
Definition: v8.h:4217
void(* IndexedPropertySetterCallback)(uint32_t index, Local< Value > value, const PropertyCallbackInfo< Value > &info)
Returns the value if the setter intercepts the request.
Definition: v8.h:3483
static Local< String > getStringProperty(const StackFrame *f, const char *propertyName)
Definition: api.cc:2316
static i::Smi * EncodeAlignedAsSmi(void *value, const char *location)
Definition: api.cc:644
void(* NamedPropertyGetterCallback)(Local< String > property, const PropertyCallbackInfo< Value > &info)
NamedProperty[Getter|Setter] are used as interceptors on object.
Definition: v8.h:3427
static i::Handle< i::FunctionTemplateInfo > EnsureConstructor(i::Isolate *isolate, ObjectTemplate *object_template)
Definition: api.cc:1268
bool(* AllowCodeGenerationFromStringsCallback)(Local< Context > context)
Callback to check if code generation from strings is allowed.
Definition: v8.h:4192
void(* IndexedPropertyDeleterCallback)(uint32_t index, const PropertyCallbackInfo< Boolean > &info)
Returns a non-empty handle if the deleter intercepts the request.
Definition: v8.h:3503
static bool InternalFieldOK(i::Handle< i::JSObject > obj, int index, const char *location)
Definition: api.cc:4992
void(* AddHistogramSampleCallback)(void *histogram, int sample)
Definition: v8.h:4149
static const uintptr_t kAlignmentMask
Definition: api.cc:4260
int *(* CounterLookupCallback)(const char *name)
Definition: v8.h:4142
void(* NamedPropertyEnumeratorCallback)(const PropertyCallbackInfo< Array > &info)
Returns an array containing the names of the properties the named property getter intercepts.
Definition: v8.h:3466
static i::MaybeHandle< i::String > NewExternalOneByteStringHandle(i::Isolate *isolate, v8::String::ExternalOneByteStringResource *resource)
Definition: api.cc:5505
static i::Handle< i::AccessorInfo > SetAccessorInfoProperties(i::Handle< i::AccessorInfo > obj, v8::Handle< Name > name, v8::AccessControl settings, v8::PropertyAttribute attributes, v8::Handle< AccessorSignature > signature)
Definition: api.cc:1125
void(* MicrotaskCallback)(void *data)
Definition: v8.h:4179
static Local< DeclaredAccessorDescriptor > NewBitmaskCompare(Isolate *isolate, T bitmask, T compare_value, RawOperationDescriptor *operation)
Definition: api.cc:1026
static void InitializeTemplate(i::Handle< i::TemplateInfo > that, int type)
Definition: api.cc:777
void(* AccessorGetterCallback)(Local< String > property, const PropertyCallbackInfo< Value > &info)
Accessor[Getter|Setter] are used as callback functions when setting|getting a particular property.
Definition: v8.h:2245
static i::MaybeHandle< i::String > NewExternalStringHandle(i::Isolate *isolate, v8::String::ExternalStringResource *resource)
Definition: api.cc:5499
static void * ExternalValue(i::Object *obj)
Definition: api.cc:5037
uintptr_t(* ReturnAddressLocationResolver)(uintptr_t return_addr_location)
ReturnAddressLocationResolver is used as a callback function when v8 is resolving the location of a r...
Definition: v8.h:4936
void(* CallCompletedCallback)()
Definition: v8.h:4176
static int WriteHelper(const String *string, CharType *buffer, int start, int length, int options)
Definition: api.cc:4824
void(* AccessorSetterCallback)(Local< String > property, Local< Value > value, const PropertyCallbackInfo< void > &info)
Definition: v8.h:2253
Maybe< T > maybe(T t)
Definition: v8.h:902
void(* AccessorNameGetterCallback)(Local< Name > property, const PropertyCallbackInfo< Value > &info)
Definition: v8.h:2248
void(* NamedPropertySetterCallback)(Local< String > property, Local< Value > value, const PropertyCallbackInfo< Value > &info)
Returns the value if the setter intercepts the request.
Definition: v8.h:3436
void(* IndexedPropertyQueryCallback)(uint32_t index, const PropertyCallbackInfo< Integer > &info)
Returns a non-empty handle if the interceptor intercepts the request.
Definition: v8.h:3493
static i::Handle< i::FixedArray > EmbedderDataFor(Context *context, int index, bool can_grow, const char *location)
Definition: api.cc:651
static const uint16_t * Align(const uint16_t *chars)
Definition: api.cc:4266
void(* FunctionCallback)(const FunctionCallbackInfo< Value > &info)
Definition: v8.h:2717
static bool getBoolProperty(const StackFrame *f, const char *propertyName)
Definition: api.cc:2345
static bool IsExecutionTerminatingCheck(i::Isolate *isolate)
Definition: api.cc:195
void RegisterExtension(Extension *that)
Definition: api.cc:398
static i::HeapGraphEdge * ToInternal(const HeapGraphEdge *edge)
Definition: api.cc:7213
void(* NamedPropertyDeleterCallback)(Local< String > property, const PropertyCallbackInfo< Boolean > &info)
Returns a non-empty handle if the deleter intercepts the request.
Definition: v8.h:3457
ExternalArrayType
Definition: v8.h:2217
@ kExternalUint8ClampedArray
Definition: v8.h:2226
static i::Handle< i::String > RegExpFlagsToString(RegExp::Flags flags)
Definition: api.cc:5755
void *(* CreateHistogramCallback)(const char *name, int min, int max, size_t buckets)
Definition: v8.h:4144
CompressedStartupDataItems
Definition: api.cc:255
@ kLibraries
Definition: api.cc:258
@ kSnapshotContext
Definition: api.cc:257
@ kExperimentalLibraries
Definition: api.cc:259
@ kCompressedStartupDataCount
Definition: api.cc:260
@ kSnapshot
Definition: api.cc:256
bool(* NamedSecurityCallback)(Local< Object > host, Local< Value > key, AccessType type, Local< Value > data)
Returns true if cross-context access should be allowed to the named property with the given key on th...
Definition: v8.h:3532
bool(* EntropySource)(unsigned char *buffer, size_t length)
EntropySource is used as a callback function when v8 needs a source of entropy.
Definition: v8.h:4920
static Local< Value > GetPropertyByLookup(i::LookupIterator *it)
Definition: api.cc:3665
void(* FatalErrorCallback)(const char *location, const char *message)
Definition: v8.h:4117
REGEXP_FLAG_ASSERT_EQ(kNone, NONE)
static Local< Symbol > GetWellKnownSymbol(Isolate *isolate, const char *name)
Definition: api.cc:6217
GCType
Applications can register callback functions which will be called before and after a garbage collecti...
Definition: v8.h:4203
void(* NamedPropertyQueryCallback)(Local< String > property, const PropertyCallbackInfo< Integer > &info)
Returns a non-empty handle if the interceptor intercepts the request.
Definition: v8.h:3447
static bool TemplateSetAccessor(Template *template_obj, v8::Local< Name > name, Getter getter, Setter setter, Data data, AccessControl settings, PropertyAttribute attribute, v8::Local< AccessorSignature > signature)
Definition: api.cc:1316
Handle< Boolean > True(Isolate *isolate)
Definition: v8.h:6854
static Local< Operation > NewDescriptor(Isolate *isolate, const i::DeclaredAccessorDescriptorData &data, Data *previous_descriptor)
Definition: api.cc:949
static bool ObjectSetAccessor(Object *obj, Handle< Name > name, Getter getter, Setter setter, Data data, AccessControl settings, PropertyAttribute attributes)
Definition: api.cc:3514
static const uintptr_t kOneByteMask
Definition: api.cc:4259
@ kWeak
Definition: v8-util.h:25
void(* IndexedPropertyEnumeratorCallback)(const PropertyCallbackInfo< Array > &info)
Returns an array containing the indices of the properties the indexed property getter intercepts.
Definition: v8.h:3512
static void SetupArrayBufferView(i::Isolate *isolate, i::Handle< i::JSArrayBufferView > obj, i::Handle< i::JSArrayBuffer > buffer, size_t byte_offset, size_t byte_length)
Definition: api.cc:6080
static i::Handle< i::AccessorInfo > MakeAccessorInfo(v8::Handle< Name > name, Getter getter, Setter setter, v8::Handle< Value > data, v8::AccessControl settings, v8::PropertyAttribute attributes, v8::Handle< AccessorSignature > signature)
Definition: api.cc:1143
AllocationAction
Definition: v8.h:4165
ObjectSpace
Definition: v8.h:4152
static bool Unaligned(const uint16_t *chars)
Definition: api.cc:4261
static void InitializeFunctionTemplate(i::Handle< i::FunctionTemplateInfo > info)
Definition: api.cc:843
bool(* IndexedSecurityCallback)(Local< Object > host, uint32_t index, AccessType type, Local< Value > data)
Returns true if cross-context access should be allowed to the indexed property with the given index o...
Definition: v8.h:3542
static i::Handle< i::Symbol > SymbolFor(i::Isolate *isolate, i::Handle< i::String > name, i::Handle< i::String > part)
Definition: api.cc:6182
static void AddPropertyToTemplate(i::Handle< i::TemplateInfo > info, i::Handle< i::AccessorInfo > obj)
Definition: api.cc:1285
void(* InterruptCallback)(Isolate *isolate, void *data)
Definition: v8.h:4219
static void * DecodeSmiToAligned(i::Object *value, const char *location)
Definition: api.cc:638
Handle< Primitive > Undefined(Isolate *isolate)
Definition: v8.h:6836
static int getIntProperty(const StackFrame *f, const char *propertyName, int defaultValue)
Definition: api.cc:2289
const int MB
Definition: d8.cc:164
#define TYPED_ARRAYS(V)
Definition: objects.h:4433
PropertyAttributes
@ ABSENT
@ NONE
Initial configuration parameters for a new Isolate.
Definition: v8.h:4361
ResourceConstraints constraints
ResourceConstraints to use for the new Isolate.
Definition: v8.h:4385
bool enable_serializer
This flag currently renders the Isolate unusable.
Definition: v8.h:4390
JitCodeEventHandler code_event_handler
Allows the host application to provide the address of a function that is notified each time code is a...
Definition: v8.h:4380
FunctionEntryHook entry_hook
The optional entry_hook allows the host application to provide the address of a function that's invok...
Definition: v8.h:4374
A simple Maybe type, representing an object which may or may not have a value.
Definition: v8.h:890
T value
Definition: v8.h:896
bool has_value
Definition: v8.h:895
Compilation data that the embedder can cache and pass back to speed up future compilations.
Definition: v8.h:1028
const uint8_t * data
Definition: v8.h:1045
struct BitmaskCompareDescriptor bitmask_compare_descriptor
Definition: objects.h:10196
struct PrimitiveValueDescriptor primitive_value_descriptor
Definition: objects.h:10198
struct PointerCompareDescriptor pointer_compare_descriptor
Definition: objects.h:10197
struct PointerShiftDescriptor pointer_shift_descriptor
Definition: objects.h:10200
struct ObjectDerefenceDescriptor object_dereference_descriptor
Definition: objects.h:10199
internal::Object ** next
Definition: handles.h:285
internal::Object ** limit
Definition: handles.h:286
v8::DeclaredAccessorDescriptorDataType data_type
Definition: objects.h:10178
SmartPointer< CompilationInfo > info
#define T(name, string, precedence)
Definition: token.cc:25
#define STATIC_CHAR_VECTOR(x)
Definition: vector.h:154