v8  3.14.5(node0.10.28)
V8 is Google's open source JavaScript engine
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
api.cc
Go to the documentation of this file.
1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 #include "api.h"
29 
30 #include <math.h> // For isnan.
31 #include <string.h> // For memcpy, strlen.
32 #include "../include/v8-debug.h"
33 #include "../include/v8-profiler.h"
34 #include "../include/v8-testing.h"
35 #include "bootstrapper.h"
36 #include "code-stubs.h"
37 #include "compiler.h"
38 #include "conversions-inl.h"
39 #include "counters.h"
40 #include "debug.h"
41 #include "deoptimizer.h"
42 #include "execution.h"
43 #include "global-handles.h"
44 #include "heap-profiler.h"
45 #include "messages.h"
46 #ifdef COMPRESS_STARTUP_DATA_BZ2
47 #include "natives.h"
48 #endif
49 #include "parser.h"
50 #include "platform.h"
51 #include "profile-generator-inl.h"
52 #include "property-details.h"
53 #include "property.h"
54 #include "runtime-profiler.h"
56 #include "snapshot.h"
57 #include "unicode-inl.h"
58 #include "v8threads.h"
59 #include "version.h"
60 #include "vm-state-inl.h"
61 
62 
63 #define LOG_API(isolate, expr) LOG(isolate, ApiEntryCall(expr))
64 
65 #define ENTER_V8(isolate) \
66  ASSERT((isolate)->IsInitialized()); \
67  i::VMState __state__((isolate), i::OTHER)
68 #define LEAVE_V8(isolate) \
69  i::VMState __state__((isolate), i::EXTERNAL)
70 
71 namespace v8 {
72 
73 #define ON_BAILOUT(isolate, location, code) \
74  if (IsDeadCheck(isolate, location) || \
75  IsExecutionTerminatingCheck(isolate)) { \
76  code; \
77  UNREACHABLE(); \
78  }
79 
80 
81 #define EXCEPTION_PREAMBLE(isolate) \
82  (isolate)->handle_scope_implementer()->IncrementCallDepth(); \
83  ASSERT(!(isolate)->external_caught_exception()); \
84  bool has_pending_exception = false
85 
86 
87 #define EXCEPTION_BAILOUT_CHECK_GENERIC(isolate, value, do_callback) \
88  do { \
89  i::HandleScopeImplementer* handle_scope_implementer = \
90  (isolate)->handle_scope_implementer(); \
91  handle_scope_implementer->DecrementCallDepth(); \
92  if (has_pending_exception) { \
93  if (handle_scope_implementer->CallDepthIsZero() && \
94  (isolate)->is_out_of_memory()) { \
95  if (!(isolate)->ignore_out_of_memory()) \
96  i::V8::FatalProcessOutOfMemory(NULL); \
97  } \
98  bool call_depth_is_zero = handle_scope_implementer->CallDepthIsZero(); \
99  (isolate)->OptionalRescheduleException(call_depth_is_zero); \
100  do_callback \
101  return value; \
102  } \
103  do_callback \
104  } while (false)
105 
106 
107 #define EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, value) \
108  EXCEPTION_BAILOUT_CHECK_GENERIC( \
109  isolate, value, i::V8::FireCallCompletedCallback(isolate);)
110 
111 
112 #define EXCEPTION_BAILOUT_CHECK(isolate, value) \
113  EXCEPTION_BAILOUT_CHECK_GENERIC(isolate, value, ;)
114 
115 
116 #define API_ENTRY_CHECK(isolate, msg) \
117  do { \
118  if (v8::Locker::IsActive()) { \
119  ApiCheck(isolate->thread_manager()->IsLockedByCurrentThread(), \
120  msg, \
121  "Entering the V8 API without proper locking in place"); \
122  } \
123  } while (false)
124 
125 
126 // --- E x c e p t i o n B e h a v i o r ---
127 
128 
129 static void DefaultFatalErrorHandler(const char* location,
130  const char* message) {
131  i::VMState __state__(i::Isolate::Current(), i::OTHER);
132  API_Fatal(location, message);
133 }
134 
135 
136 static FatalErrorCallback GetFatalErrorHandler() {
137  i::Isolate* isolate = i::Isolate::Current();
138  if (isolate->exception_behavior() == NULL) {
139  isolate->set_exception_behavior(DefaultFatalErrorHandler);
140  }
141  return isolate->exception_behavior();
142 }
143 
144 
145 void i::FatalProcessOutOfMemory(const char* location) {
146  i::V8::FatalProcessOutOfMemory(location, false);
147 }
148 
149 
150 // When V8 cannot allocated memory FatalProcessOutOfMemory is called.
151 // The default fatal error handler is called and execution is stopped.
152 void i::V8::FatalProcessOutOfMemory(const char* location, bool take_snapshot) {
153  i::HeapStats heap_stats;
154  int start_marker;
155  heap_stats.start_marker = &start_marker;
156  int new_space_size;
157  heap_stats.new_space_size = &new_space_size;
158  int new_space_capacity;
159  heap_stats.new_space_capacity = &new_space_capacity;
160  intptr_t old_pointer_space_size;
161  heap_stats.old_pointer_space_size = &old_pointer_space_size;
162  intptr_t old_pointer_space_capacity;
163  heap_stats.old_pointer_space_capacity = &old_pointer_space_capacity;
164  intptr_t old_data_space_size;
165  heap_stats.old_data_space_size = &old_data_space_size;
166  intptr_t old_data_space_capacity;
167  heap_stats.old_data_space_capacity = &old_data_space_capacity;
168  intptr_t code_space_size;
169  heap_stats.code_space_size = &code_space_size;
170  intptr_t code_space_capacity;
171  heap_stats.code_space_capacity = &code_space_capacity;
172  intptr_t map_space_size;
173  heap_stats.map_space_size = &map_space_size;
174  intptr_t map_space_capacity;
175  heap_stats.map_space_capacity = &map_space_capacity;
176  intptr_t cell_space_size;
177  heap_stats.cell_space_size = &cell_space_size;
178  intptr_t cell_space_capacity;
179  heap_stats.cell_space_capacity = &cell_space_capacity;
180  intptr_t lo_space_size;
181  heap_stats.lo_space_size = &lo_space_size;
182  int global_handle_count;
183  heap_stats.global_handle_count = &global_handle_count;
184  int weak_global_handle_count;
185  heap_stats.weak_global_handle_count = &weak_global_handle_count;
186  int pending_global_handle_count;
187  heap_stats.pending_global_handle_count = &pending_global_handle_count;
188  int near_death_global_handle_count;
189  heap_stats.near_death_global_handle_count = &near_death_global_handle_count;
190  int free_global_handle_count;
191  heap_stats.free_global_handle_count = &free_global_handle_count;
192  intptr_t memory_allocator_size;
193  heap_stats.memory_allocator_size = &memory_allocator_size;
194  intptr_t memory_allocator_capacity;
195  heap_stats.memory_allocator_capacity = &memory_allocator_capacity;
196  int objects_per_type[LAST_TYPE + 1] = {0};
197  heap_stats.objects_per_type = objects_per_type;
198  int size_per_type[LAST_TYPE + 1] = {0};
199  heap_stats.size_per_type = size_per_type;
200  int os_error;
201  heap_stats.os_error = &os_error;
202  int end_marker;
203  heap_stats.end_marker = &end_marker;
204  i::Isolate* isolate = i::Isolate::Current();
205  // BUG(1718):
206  // Don't use the take_snapshot since we don't support HeapIterator here
207  // without doing a special GC.
208  isolate->heap()->RecordStats(&heap_stats, false);
210  FatalErrorCallback callback = GetFatalErrorHandler();
211  {
212  LEAVE_V8(isolate);
213  callback(location, "Allocation failed - process out of memory");
214  }
215  // If the callback returns, we stop execution.
216  UNREACHABLE();
217 }
218 
219 
220 bool Utils::ReportApiFailure(const char* location, const char* message) {
221  FatalErrorCallback callback = GetFatalErrorHandler();
222  callback(location, message);
224  return false;
225 }
226 
227 
228 bool V8::IsDead() {
229  return i::V8::IsDead();
230 }
231 
232 
233 static inline bool ApiCheck(bool condition,
234  const char* location,
235  const char* message) {
236  return condition ? true : Utils::ReportApiFailure(location, message);
237 }
238 
239 
240 static bool ReportV8Dead(const char* location) {
241  FatalErrorCallback callback = GetFatalErrorHandler();
242  callback(location, "V8 is no longer usable");
243  return true;
244 }
245 
246 
247 static bool ReportEmptyHandle(const char* location) {
248  FatalErrorCallback callback = GetFatalErrorHandler();
249  callback(location, "Reading from empty handle");
250  return true;
251 }
252 
253 
266 static inline bool IsDeadCheck(i::Isolate* isolate, const char* location) {
267  return !isolate->IsInitialized()
268  && i::V8::IsDead() ? ReportV8Dead(location) : false;
269 }
270 
271 
272 static inline bool IsExecutionTerminatingCheck(i::Isolate* isolate) {
273  if (!isolate->IsInitialized()) return false;
274  if (isolate->has_scheduled_exception()) {
275  return isolate->scheduled_exception() ==
276  isolate->heap()->termination_exception();
277  }
278  return false;
279 }
280 
281 
282 static inline bool EmptyCheck(const char* location, v8::Handle<v8::Data> obj) {
283  return obj.IsEmpty() ? ReportEmptyHandle(location) : false;
284 }
285 
286 
287 static inline bool EmptyCheck(const char* location, const v8::Data* obj) {
288  return (obj == 0) ? ReportEmptyHandle(location) : false;
289 }
290 
291 // --- S t a t i c s ---
292 
293 
294 static bool InitializeHelper() {
295  if (i::Snapshot::Initialize()) return true;
296  return i::V8::Initialize(NULL);
297 }
298 
299 
300 static inline bool EnsureInitializedForIsolate(i::Isolate* isolate,
301  const char* location) {
302  if (IsDeadCheck(isolate, location)) return false;
303  if (isolate != NULL) {
304  if (isolate->IsInitialized()) return true;
305  }
306  ASSERT(isolate == i::Isolate::Current());
307  return ApiCheck(InitializeHelper(), location, "Error initializing V8");
308 }
309 
310 // Some initializing API functions are called early and may be
311 // called on a thread different from static initializer thread.
312 // If Isolate API is used, Isolate::Enter() will initialize TLS so
313 // Isolate::Current() works. If it's a legacy case, then the thread
314 // may not have TLS initialized yet. However, in initializing APIs it
315 // may be too early to call EnsureInitialized() - some pre-init
316 // parameters still have to be configured.
317 static inline i::Isolate* EnterIsolateIfNeeded() {
318  i::Isolate* isolate = i::Isolate::UncheckedCurrent();
319  if (isolate != NULL)
320  return isolate;
321 
323  isolate = i::Isolate::Current();
324  return isolate;
325 }
326 
327 
329  : raw_data(i::NewArray<char*>(V8::GetCompressedStartupDataCount())) {
330  for (int i = 0; i < V8::GetCompressedStartupDataCount(); ++i) {
331  raw_data[i] = NULL;
332  }
333 }
334 
335 
337  for (int i = 0; i < V8::GetCompressedStartupDataCount(); ++i) {
338  i::DeleteArray(raw_data[i]);
339  }
340  i::DeleteArray(raw_data);
341 }
342 
343 
345  int compressed_data_count = V8::GetCompressedStartupDataCount();
346  StartupData* compressed_data =
347  i::NewArray<StartupData>(compressed_data_count);
348  V8::GetCompressedStartupData(compressed_data);
349  for (int i = 0; i < compressed_data_count; ++i) {
350  char* decompressed = raw_data[i] =
351  i::NewArray<char>(compressed_data[i].raw_size);
352  if (compressed_data[i].compressed_size != 0) {
353  int result = DecompressData(decompressed,
354  &compressed_data[i].raw_size,
355  compressed_data[i].data,
356  compressed_data[i].compressed_size);
357  if (result != 0) return result;
358  } else {
359  ASSERT_EQ(0, compressed_data[i].raw_size);
360  }
361  compressed_data[i].data = decompressed;
362  }
363  V8::SetDecompressedStartupData(compressed_data);
364  i::DeleteArray(compressed_data);
365  return 0;
366 }
367 
368 
370 #ifdef COMPRESS_STARTUP_DATA_BZ2
371  return StartupData::kBZip2;
372 #else
374 #endif
375 }
376 
377 
384 };
385 
387 #ifdef COMPRESS_STARTUP_DATA_BZ2
389 #else
390  return 0;
391 #endif
392 }
393 
394 
396 #ifdef COMPRESS_STARTUP_DATA_BZ2
397  compressed_data[kSnapshot].data =
398  reinterpret_cast<const char*>(i::Snapshot::data());
399  compressed_data[kSnapshot].compressed_size = i::Snapshot::size();
400  compressed_data[kSnapshot].raw_size = i::Snapshot::raw_size();
401 
402  compressed_data[kSnapshotContext].data =
403  reinterpret_cast<const char*>(i::Snapshot::context_data());
404  compressed_data[kSnapshotContext].compressed_size =
407 
409  compressed_data[kLibraries].data =
410  reinterpret_cast<const char*>(libraries_source.start());
411  compressed_data[kLibraries].compressed_size = libraries_source.length();
413 
414  i::Vector<const i::byte> exp_libraries_source =
416  compressed_data[kExperimentalLibraries].data =
417  reinterpret_cast<const char*>(exp_libraries_source.start());
418  compressed_data[kExperimentalLibraries].compressed_size =
419  exp_libraries_source.length();
420  compressed_data[kExperimentalLibraries].raw_size =
422 #endif
423 }
424 
425 
426 void V8::SetDecompressedStartupData(StartupData* decompressed_data) {
427 #ifdef COMPRESS_STARTUP_DATA_BZ2
428  ASSERT_EQ(i::Snapshot::raw_size(), decompressed_data[kSnapshot].raw_size);
430  reinterpret_cast<const i::byte*>(decompressed_data[kSnapshot].data));
431 
433  decompressed_data[kSnapshotContext].raw_size);
435  reinterpret_cast<const i::byte*>(
436  decompressed_data[kSnapshotContext].data));
437 
439  decompressed_data[kLibraries].raw_size);
440  i::Vector<const char> libraries_source(
441  decompressed_data[kLibraries].data,
442  decompressed_data[kLibraries].raw_size);
443  i::Natives::SetRawScriptsSource(libraries_source);
444 
446  decompressed_data[kExperimentalLibraries].raw_size);
447  i::Vector<const char> exp_libraries_source(
448  decompressed_data[kExperimentalLibraries].data,
449  decompressed_data[kExperimentalLibraries].raw_size);
450  i::ExperimentalNatives::SetRawScriptsSource(exp_libraries_source);
451 #endif
452 }
453 
454 
456  i::Isolate* isolate = EnterIsolateIfNeeded();
457  isolate->set_exception_behavior(that);
458 }
459 
460 
463  i::Isolate* isolate = EnterIsolateIfNeeded();
464  isolate->set_allow_code_gen_callback(callback);
465 }
466 
467 
468 #ifdef DEBUG
469 void ImplementationUtilities::ZapHandleRange(i::Object** begin,
470  i::Object** end) {
471  i::HandleScope::ZapRange(begin, end);
472 }
473 #endif
474 
475 
476 void V8::SetFlagsFromString(const char* str, int length) {
477  i::FlagList::SetFlagsFromString(str, length);
478 }
479 
480 
481 void V8::SetFlagsFromCommandLine(int* argc, char** argv, bool remove_flags) {
482  i::FlagList::SetFlagsFromCommandLine(argc, argv, remove_flags);
483 }
484 
485 
487  i::Isolate* isolate = i::Isolate::Current();
488  if (IsDeadCheck(isolate, "v8::ThrowException()")) {
489  return v8::Handle<Value>();
490  }
491  ENTER_V8(isolate);
492  // If we're passed an empty handle, we throw an undefined exception
493  // to deal more gracefully with out of memory situations.
494  if (value.IsEmpty()) {
495  isolate->ScheduleThrow(isolate->heap()->undefined_value());
496  } else {
497  isolate->ScheduleThrow(*Utils::OpenHandle(*value));
498  }
499  return v8::Undefined();
500 }
501 
502 
503 RegisteredExtension* RegisteredExtension::first_extension_ = NULL;
504 
505 
507  : extension_(extension) { }
508 
509 
511  that->next_ = first_extension_;
512  first_extension_ = that;
513 }
514 
515 
517  RegisteredExtension* re = first_extension_;
518  while (re != NULL) {
519  RegisteredExtension* next = re->next();
520  delete re;
521  re = next;
522  }
523 }
524 
525 
527  RegisteredExtension* extension = new RegisteredExtension(that);
529 }
530 
531 
532 Extension::Extension(const char* name,
533  const char* source,
534  int dep_count,
535  const char** deps,
536  int source_length)
537  : name_(name),
538  source_length_(source_length >= 0 ?
539  source_length :
540  (source ? static_cast<int>(strlen(source)) : 0)),
541  source_(source, source_length_),
542  dep_count_(dep_count),
543  deps_(deps),
544  auto_enable_(false) {
545  CHECK(source != NULL || source_length_ == 0);
546 }
547 
548 
550  i::Isolate* isolate = i::Isolate::Current();
551  if (!EnsureInitializedForIsolate(isolate, "v8::Undefined()")) {
552  return v8::Handle<v8::Primitive>();
553  }
554  return v8::Handle<Primitive>(ToApi<Primitive>(
555  isolate->factory()->undefined_value()));
556 }
557 
558 
560  i::Isolate* isolate = i::Isolate::Current();
561  if (!EnsureInitializedForIsolate(isolate, "v8::Null()")) {
562  return v8::Handle<v8::Primitive>();
563  }
564  return v8::Handle<Primitive>(
565  ToApi<Primitive>(isolate->factory()->null_value()));
566 }
567 
568 
570  i::Isolate* isolate = i::Isolate::Current();
571  if (!EnsureInitializedForIsolate(isolate, "v8::True()")) {
572  return v8::Handle<Boolean>();
573  }
574  return v8::Handle<Boolean>(
575  ToApi<Boolean>(isolate->factory()->true_value()));
576 }
577 
578 
580  i::Isolate* isolate = i::Isolate::Current();
581  if (!EnsureInitializedForIsolate(isolate, "v8::False()")) {
582  return v8::Handle<Boolean>();
583  }
584  return v8::Handle<Boolean>(
585  ToApi<Boolean>(isolate->factory()->false_value()));
586 }
587 
588 
590  : max_young_space_size_(0),
591  max_old_space_size_(0),
592  max_executable_size_(0),
593  stack_limit_(NULL) { }
594 
595 
597  i::Isolate* isolate = EnterIsolateIfNeeded();
598 
599  int young_space_size = constraints->max_young_space_size();
600  int old_gen_size = constraints->max_old_space_size();
601  int max_executable_size = constraints->max_executable_size();
602  if (young_space_size != 0 || old_gen_size != 0 || max_executable_size != 0) {
603  // After initialization it's too late to change Heap constraints.
604  ASSERT(!isolate->IsInitialized());
605  bool result = isolate->heap()->ConfigureHeap(young_space_size / 2,
606  old_gen_size,
607  max_executable_size);
608  if (!result) return false;
609  }
610  if (constraints->stack_limit() != NULL) {
611  uintptr_t limit = reinterpret_cast<uintptr_t>(constraints->stack_limit());
612  isolate->stack_guard()->SetStackLimit(limit);
613  }
614  return true;
615 }
616 
617 
618 i::Object** V8::GlobalizeReference(i::Object** obj) {
619  i::Isolate* isolate = i::Isolate::Current();
620  if (IsDeadCheck(isolate, "V8::Persistent::New")) return NULL;
621  LOG_API(isolate, "Persistent::New");
622  i::Handle<i::Object> result =
623  isolate->global_handles()->Create(*obj);
624  return result.location();
625 }
626 
627 
628 void V8::MakeWeak(i::Object** object, void* parameters,
629  WeakReferenceCallback callback) {
630  i::Isolate* isolate = i::Isolate::Current();
631  LOG_API(isolate, "MakeWeak");
632  isolate->global_handles()->MakeWeak(object, parameters,
633  callback);
634 }
635 
636 
637 void V8::ClearWeak(i::Object** obj) {
638  i::Isolate* isolate = i::Isolate::Current();
639  LOG_API(isolate, "ClearWeak");
640  isolate->global_handles()->ClearWeakness(obj);
641 }
642 
643 
644 void V8::MarkIndependent(i::Object** object) {
645  i::Isolate* isolate = i::Isolate::Current();
646  LOG_API(isolate, "MakeIndependent");
647  isolate->global_handles()->MarkIndependent(object);
648 }
649 
650 
651 bool V8::IsGlobalIndependent(i::Object** obj) {
652  i::Isolate* isolate = i::Isolate::Current();
653  LOG_API(isolate, "IsGlobalIndependent");
654  if (!isolate->IsInitialized()) return false;
656 }
657 
658 
659 bool V8::IsGlobalNearDeath(i::Object** obj) {
660  i::Isolate* isolate = i::Isolate::Current();
661  LOG_API(isolate, "IsGlobalNearDeath");
662  if (!isolate->IsInitialized()) return false;
663  return i::GlobalHandles::IsNearDeath(obj);
664 }
665 
666 
667 bool V8::IsGlobalWeak(i::Object** obj) {
668  i::Isolate* isolate = i::Isolate::Current();
669  LOG_API(isolate, "IsGlobalWeak");
670  if (!isolate->IsInitialized()) return false;
671  return i::GlobalHandles::IsWeak(obj);
672 }
673 
674 
675 void V8::DisposeGlobal(i::Object** obj) {
676  i::Isolate* isolate = i::Isolate::Current();
677  LOG_API(isolate, "DisposeGlobal");
678  if (!isolate->IsInitialized()) return;
679  isolate->global_handles()->Destroy(obj);
680 }
681 
682 // --- H a n d l e s ---
683 
684 
686  i::Isolate* isolate = i::Isolate::Current();
687  API_ENTRY_CHECK(isolate, "HandleScope::HandleScope");
689  isolate->handle_scope_data();
690  isolate_ = isolate;
691  prev_next_ = current->next;
692  prev_limit_ = current->limit;
693  is_closed_ = false;
694  current->level++;
695 }
696 
697 
699  if (!is_closed_) {
700  Leave();
701  }
702 }
703 
704 
705 void HandleScope::Leave() {
706  ASSERT(isolate_ == i::Isolate::Current());
708  isolate_->handle_scope_data();
709  current->level--;
710  ASSERT(current->level >= 0);
711  current->next = prev_next_;
712  if (current->limit != prev_limit_) {
713  current->limit = prev_limit_;
715  }
716 
717 #ifdef DEBUG
718  i::HandleScope::ZapRange(prev_next_, prev_limit_);
719 #endif
720 }
721 
722 
724  EnsureInitializedForIsolate(
725  i::Isolate::Current(), "HandleScope::NumberOfHandles");
727 }
728 
729 
731  return i::HandleScope::CreateHandle(value, i::Isolate::Current());
732 }
733 
734 
736  ASSERT(value->IsHeapObject());
737  return reinterpret_cast<i::Object**>(
738  i::HandleScope::CreateHandle(value, value->GetIsolate()));
739 }
740 
741 
743  i::Handle<i::Context> env = Utils::OpenHandle(this);
744  i::Isolate* isolate = env->GetIsolate();
745  if (IsDeadCheck(isolate, "v8::Context::Enter()")) return;
746  ENTER_V8(isolate);
747 
748  isolate->handle_scope_implementer()->EnterContext(env);
749 
750  isolate->handle_scope_implementer()->SaveContext(isolate->context());
751  isolate->set_context(*env);
752 }
753 
754 
756  // Exit is essentially a static function and doesn't use the
757  // receiver, so we have to get the current isolate from the thread
758  // local.
759  i::Isolate* isolate = i::Isolate::Current();
760  if (!isolate->IsInitialized()) return;
761 
762  if (!ApiCheck(isolate->handle_scope_implementer()->LeaveLastContext(),
763  "v8::Context::Exit()",
764  "Cannot exit non-entered context")) {
765  return;
766  }
767 
768  // Content of 'last_context' could be NULL.
769  i::Context* last_context =
771  isolate->set_context(last_context);
772  isolate->set_context_exit_happened(true);
773 }
774 
775 
777  i::Handle<i::Context> env = Utils::OpenHandle(this);
778  i::Isolate* isolate = env->GetIsolate();
779  if (IsDeadCheck(isolate, "v8::Context::SetData()")) return;
780  i::Handle<i::Object> raw_data = Utils::OpenHandle(*data);
781  ASSERT(env->IsNativeContext());
782  if (env->IsNativeContext()) {
783  env->set_data(*raw_data);
784  }
785 }
786 
787 
789  i::Handle<i::Context> env = Utils::OpenHandle(this);
790  i::Isolate* isolate = env->GetIsolate();
791  if (IsDeadCheck(isolate, "v8::Context::GetData()")) {
792  return Local<Value>();
793  }
794  ASSERT(env->IsNativeContext());
795  if (!env->IsNativeContext()) {
796  return Local<Value>();
797  }
798  i::Handle<i::Object> result(env->data(), isolate);
799  return Utils::ToLocal(result);
800 }
801 
802 
803 i::Object** v8::HandleScope::RawClose(i::Object** value) {
804  if (!ApiCheck(!is_closed_,
805  "v8::HandleScope::Close()",
806  "Local scope has already been closed")) {
807  return 0;
808  }
809  LOG_API(isolate_, "CloseHandleScope");
810 
811  // Read the result before popping the handle block.
812  i::Object* result = NULL;
813  if (value != NULL) {
814  result = *value;
815  }
816  is_closed_ = true;
817  Leave();
818 
819  if (value == NULL) {
820  return NULL;
821  }
822 
823  // Allocate a new handle on the previous handle block.
824  i::Handle<i::Object> handle(result);
825  return handle.location();
826 }
827 
828 
829 // --- N e a n d e r ---
830 
831 
832 // A constructor cannot easily return an error value, therefore it is necessary
833 // to check for a dead VM with ON_BAILOUT before constructing any Neander
834 // objects. To remind you about this there is no HandleScope in the
835 // NeanderObject constructor. When you add one to the site calling the
836 // constructor you should check that you ensured the VM was not dead first.
838  i::Isolate* isolate = i::Isolate::Current();
839  EnsureInitializedForIsolate(isolate, "v8::Nowhere");
840  ENTER_V8(isolate);
841  value_ = isolate->factory()->NewNeanderObject();
842  i::Handle<i::FixedArray> elements = isolate->factory()->NewFixedArray(size);
843  value_->set_elements(*elements);
844 }
845 
846 
848  return i::FixedArray::cast(value_->elements())->length();
849 }
850 
851 
853  obj_.set(0, i::Smi::FromInt(0));
854 }
855 
856 
858  return i::Smi::cast(obj_.get(0))->value();
859 }
860 
861 
863  ASSERT(0 <= offset);
864  ASSERT(offset < length());
865  return obj_.get(offset + 1);
866 }
867 
868 
869 // This method cannot easily return an error value, therefore it is necessary
870 // to check for a dead VM with ON_BAILOUT before calling it. To remind you
871 // about this there is no HandleScope in this method. When you add one to the
872 // site calling this method you should check that you ensured the VM was not
873 // dead first.
875  int length = this->length();
876  int size = obj_.size();
877  if (length == size - 1) {
878  i::Handle<i::FixedArray> new_elms = FACTORY->NewFixedArray(2 * size);
879  for (int i = 0; i < length; i++)
880  new_elms->set(i + 1, get(i));
881  obj_.value()->set_elements(*new_elms);
882  }
883  obj_.set(length + 1, *value);
884  obj_.set(0, i::Smi::FromInt(length + 1));
885 }
886 
887 
888 void NeanderArray::set(int index, i::Object* value) {
889  if (index < 0 || index >= this->length()) return;
890  obj_.set(index + 1, value);
891 }
892 
893 
894 // --- T e m p l a t e ---
895 
896 
897 static void InitializeTemplate(i::Handle<i::TemplateInfo> that, int type) {
898  that->set_tag(i::Smi::FromInt(type));
899 }
900 
901 
903  v8::PropertyAttribute attribute) {
904  i::Isolate* isolate = i::Isolate::Current();
905  if (IsDeadCheck(isolate, "v8::Template::Set()")) return;
906  ENTER_V8(isolate);
907  i::HandleScope scope(isolate);
908  i::Handle<i::Object> list(Utils::OpenHandle(this)->property_list());
909  if (list->IsUndefined()) {
910  list = NeanderArray().value();
911  Utils::OpenHandle(this)->set_property_list(*list);
912  }
913  NeanderArray array(list);
914  array.add(Utils::OpenHandle(*name));
915  array.add(Utils::OpenHandle(*value));
916  array.add(Utils::OpenHandle(*v8::Integer::New(attribute)));
917 }
918 
919 
920 // --- F u n c t i o n T e m p l a t e ---
921 static void InitializeFunctionTemplate(
924  info->set_flag(0);
925 }
926 
927 
929  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
930  if (IsDeadCheck(isolate, "v8::FunctionTemplate::PrototypeTemplate()")) {
931  return Local<ObjectTemplate>();
932  }
933  ENTER_V8(isolate);
934  i::Handle<i::Object> result(Utils::OpenHandle(this)->prototype_template());
935  if (result->IsUndefined()) {
936  result = Utils::OpenHandle(*ObjectTemplate::New());
937  Utils::OpenHandle(this)->set_prototype_template(*result);
938  }
939  return Local<ObjectTemplate>(ToApi<ObjectTemplate>(result));
940 }
941 
942 
944  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
945  if (IsDeadCheck(isolate, "v8::FunctionTemplate::Inherit()")) return;
946  ENTER_V8(isolate);
947  Utils::OpenHandle(this)->set_parent_template(*Utils::OpenHandle(*value));
948 }
949 
950 
952  v8::Handle<Value> data, v8::Handle<Signature> signature) {
953  i::Isolate* isolate = i::Isolate::Current();
954  EnsureInitializedForIsolate(isolate, "v8::FunctionTemplate::New()");
955  LOG_API(isolate, "FunctionTemplate::New");
956  ENTER_V8(isolate);
957  i::Handle<i::Struct> struct_obj =
961  InitializeFunctionTemplate(obj);
962  int next_serial_number = isolate->next_serial_number();
963  isolate->set_next_serial_number(next_serial_number + 1);
964  obj->set_serial_number(i::Smi::FromInt(next_serial_number));
965  if (callback != 0) {
966  if (data.IsEmpty()) data = v8::Undefined();
967  Utils::ToLocal(obj)->SetCallHandler(callback, data);
968  }
969  obj->set_undetectable(false);
970  obj->set_needs_access_check(false);
971 
972  if (!signature.IsEmpty())
973  obj->set_signature(*Utils::OpenHandle(*signature));
974  return Utils::ToLocal(obj);
975 }
976 
977 
979  int argc, Handle<FunctionTemplate> argv[]) {
980  i::Isolate* isolate = i::Isolate::Current();
981  EnsureInitializedForIsolate(isolate, "v8::Signature::New()");
982  LOG_API(isolate, "Signature::New");
983  ENTER_V8(isolate);
984  i::Handle<i::Struct> struct_obj =
988  if (!receiver.IsEmpty()) obj->set_receiver(*Utils::OpenHandle(*receiver));
989  if (argc > 0) {
990  i::Handle<i::FixedArray> args = isolate->factory()->NewFixedArray(argc);
991  for (int i = 0; i < argc; i++) {
992  if (!argv[i].IsEmpty())
993  args->set(i, *Utils::OpenHandle(*argv[i]));
994  }
995  obj->set_args(*args);
996  }
997  return Utils::ToLocal(obj);
998 }
999 
1000 
1002  Handle<FunctionTemplate> receiver) {
1003  return Utils::AccessorSignatureToLocal(Utils::OpenHandle(*receiver));
1004 }
1005 
1006 
1008  Handle<FunctionTemplate> types[1] = { type };
1009  return TypeSwitch::New(1, types);
1010 }
1011 
1012 
1014  i::Isolate* isolate = i::Isolate::Current();
1015  EnsureInitializedForIsolate(isolate, "v8::TypeSwitch::New()");
1016  LOG_API(isolate, "TypeSwitch::New");
1017  ENTER_V8(isolate);
1018  i::Handle<i::FixedArray> vector = isolate->factory()->NewFixedArray(argc);
1019  for (int i = 0; i < argc; i++)
1020  vector->set(i, *Utils::OpenHandle(*types[i]));
1021  i::Handle<i::Struct> struct_obj =
1025  obj->set_types(*vector);
1026  return Utils::ToLocal(obj);
1027 }
1028 
1029 
1031  i::Isolate* isolate = i::Isolate::Current();
1032  LOG_API(isolate, "TypeSwitch::match");
1033  USE(isolate);
1034  i::Handle<i::Object> obj = Utils::OpenHandle(*value);
1035  i::Handle<i::TypeSwitchInfo> info = Utils::OpenHandle(this);
1036  i::FixedArray* types = i::FixedArray::cast(info->types());
1037  for (int i = 0; i < types->length(); i++) {
1038  if (obj->IsInstanceOf(i::FunctionTemplateInfo::cast(types->get(i))))
1039  return i + 1;
1040  }
1041  return 0;
1042 }
1043 
1044 
1045 #define SET_FIELD_WRAPPED(obj, setter, cdata) do { \
1046  i::Handle<i::Object> foreign = FromCData(cdata); \
1047  (obj)->setter(*foreign); \
1048  } while (false)
1049 
1050 
1052  v8::Handle<Value> data) {
1053  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
1054  if (IsDeadCheck(isolate, "v8::FunctionTemplate::SetCallHandler()")) return;
1055  ENTER_V8(isolate);
1056  i::HandleScope scope(isolate);
1057  i::Handle<i::Struct> struct_obj =
1061  SET_FIELD_WRAPPED(obj, set_callback, callback);
1062  if (data.IsEmpty()) data = v8::Undefined();
1063  obj->set_data(*Utils::OpenHandle(*data));
1064  Utils::OpenHandle(this)->set_call_code(*obj);
1065 }
1066 
1067 
1068 static i::Handle<i::AccessorInfo> MakeAccessorInfo(
1069  v8::Handle<String> name,
1070  AccessorGetter getter,
1071  AccessorSetter setter,
1072  v8::Handle<Value> data,
1073  v8::AccessControl settings,
1074  v8::PropertyAttribute attributes,
1075  v8::Handle<AccessorSignature> signature) {
1076  i::Handle<i::AccessorInfo> obj = FACTORY->NewAccessorInfo();
1077  SET_FIELD_WRAPPED(obj, set_getter, getter);
1078  SET_FIELD_WRAPPED(obj, set_setter, setter);
1079  if (data.IsEmpty()) data = v8::Undefined();
1080  obj->set_data(*Utils::OpenHandle(*data));
1081  obj->set_name(*Utils::OpenHandle(*name));
1082  if (settings & ALL_CAN_READ) obj->set_all_can_read(true);
1083  if (settings & ALL_CAN_WRITE) obj->set_all_can_write(true);
1084  if (settings & PROHIBITS_OVERWRITING) obj->set_prohibits_overwriting(true);
1085  obj->set_property_attributes(static_cast<PropertyAttributes>(attributes));
1086  if (!signature.IsEmpty()) {
1087  obj->set_expected_receiver_type(*Utils::OpenHandle(*signature));
1088  }
1089  return obj;
1090 }
1091 
1092 
1093 void FunctionTemplate::AddInstancePropertyAccessor(
1094  v8::Handle<String> name,
1095  AccessorGetter getter,
1096  AccessorSetter setter,
1097  v8::Handle<Value> data,
1098  v8::AccessControl settings,
1099  v8::PropertyAttribute attributes,
1100  v8::Handle<AccessorSignature> signature) {
1101  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
1102  if (IsDeadCheck(isolate,
1103  "v8::FunctionTemplate::AddInstancePropertyAccessor()")) {
1104  return;
1105  }
1106  ENTER_V8(isolate);
1107  i::HandleScope scope(isolate);
1108 
1109  i::Handle<i::AccessorInfo> obj = MakeAccessorInfo(name, getter, setter, data,
1110  settings, attributes,
1111  signature);
1112  i::Handle<i::Object> list(Utils::OpenHandle(this)->property_accessors());
1113  if (list->IsUndefined()) {
1114  list = NeanderArray().value();
1115  Utils::OpenHandle(this)->set_property_accessors(*list);
1116  }
1117  NeanderArray array(list);
1118  array.add(obj);
1119 }
1120 
1121 
1123  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
1124  if (IsDeadCheck(isolate, "v8::FunctionTemplate::InstanceTemplate()")
1125  || EmptyCheck("v8::FunctionTemplate::InstanceTemplate()", this))
1126  return Local<ObjectTemplate>();
1127  ENTER_V8(isolate);
1128  if (Utils::OpenHandle(this)->instance_template()->IsUndefined()) {
1129  Local<ObjectTemplate> templ =
1131  Utils::OpenHandle(this)->set_instance_template(*Utils::OpenHandle(*templ));
1132  }
1134  Utils::OpenHandle(this)->instance_template()));
1135  return Utils::ToLocal(result);
1136 }
1137 
1138 
1140  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
1141  if (IsDeadCheck(isolate, "v8::FunctionTemplate::SetClassName()")) return;
1142  ENTER_V8(isolate);
1143  Utils::OpenHandle(this)->set_class_name(*Utils::OpenHandle(*name));
1144 }
1145 
1146 
1148  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
1149  if (IsDeadCheck(isolate, "v8::FunctionTemplate::SetHiddenPrototype()")) {
1150  return;
1151  }
1152  ENTER_V8(isolate);
1153  Utils::OpenHandle(this)->set_hidden_prototype(value);
1154 }
1155 
1156 
1158  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
1159  if (IsDeadCheck(isolate, "v8::FunctionTemplate::SetPrototypeAttributes()")) {
1160  return;
1161  }
1162  ENTER_V8(isolate);
1163  Utils::OpenHandle(this)->set_read_only_prototype(true);
1164 }
1165 
1166 
1167 void FunctionTemplate::SetNamedInstancePropertyHandler(
1168  NamedPropertyGetter getter,
1169  NamedPropertySetter setter,
1170  NamedPropertyQuery query,
1171  NamedPropertyDeleter remover,
1172  NamedPropertyEnumerator enumerator,
1173  Handle<Value> data) {
1174  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
1175  if (IsDeadCheck(isolate,
1176  "v8::FunctionTemplate::SetNamedInstancePropertyHandler()")) {
1177  return;
1178  }
1179  ENTER_V8(isolate);
1180  i::HandleScope scope(isolate);
1181  i::Handle<i::Struct> struct_obj =
1185 
1186  if (getter != 0) SET_FIELD_WRAPPED(obj, set_getter, getter);
1187  if (setter != 0) SET_FIELD_WRAPPED(obj, set_setter, setter);
1188  if (query != 0) SET_FIELD_WRAPPED(obj, set_query, query);
1189  if (remover != 0) SET_FIELD_WRAPPED(obj, set_deleter, remover);
1190  if (enumerator != 0) SET_FIELD_WRAPPED(obj, set_enumerator, enumerator);
1191 
1192  if (data.IsEmpty()) data = v8::Undefined();
1193  obj->set_data(*Utils::OpenHandle(*data));
1194  Utils::OpenHandle(this)->set_named_property_handler(*obj);
1195 }
1196 
1197 
1198 void FunctionTemplate::SetIndexedInstancePropertyHandler(
1199  IndexedPropertyGetter getter,
1200  IndexedPropertySetter setter,
1201  IndexedPropertyQuery query,
1202  IndexedPropertyDeleter remover,
1203  IndexedPropertyEnumerator enumerator,
1204  Handle<Value> data) {
1205  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
1206  if (IsDeadCheck(isolate,
1207  "v8::FunctionTemplate::SetIndexedInstancePropertyHandler()")) {
1208  return;
1209  }
1210  ENTER_V8(isolate);
1211  i::HandleScope scope(isolate);
1212  i::Handle<i::Struct> struct_obj =
1216 
1217  if (getter != 0) SET_FIELD_WRAPPED(obj, set_getter, getter);
1218  if (setter != 0) SET_FIELD_WRAPPED(obj, set_setter, setter);
1219  if (query != 0) SET_FIELD_WRAPPED(obj, set_query, query);
1220  if (remover != 0) SET_FIELD_WRAPPED(obj, set_deleter, remover);
1221  if (enumerator != 0) SET_FIELD_WRAPPED(obj, set_enumerator, enumerator);
1222 
1223  if (data.IsEmpty()) data = v8::Undefined();
1224  obj->set_data(*Utils::OpenHandle(*data));
1225  Utils::OpenHandle(this)->set_indexed_property_handler(*obj);
1226 }
1227 
1228 
1229 void FunctionTemplate::SetInstanceCallAsFunctionHandler(
1230  InvocationCallback callback,
1231  Handle<Value> data) {
1232  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
1233  if (IsDeadCheck(isolate,
1234  "v8::FunctionTemplate::SetInstanceCallAsFunctionHandler()")) {
1235  return;
1236  }
1237  ENTER_V8(isolate);
1238  i::HandleScope scope(isolate);
1239  i::Handle<i::Struct> struct_obj =
1243  SET_FIELD_WRAPPED(obj, set_callback, callback);
1244  if (data.IsEmpty()) data = v8::Undefined();
1245  obj->set_data(*Utils::OpenHandle(*data));
1246  Utils::OpenHandle(this)->set_instance_call_handler(*obj);
1247 }
1248 
1249 
1250 // --- O b j e c t T e m p l a t e ---
1251 
1252 
1254  return New(Local<FunctionTemplate>());
1255 }
1256 
1257 
1259  v8::Handle<FunctionTemplate> constructor) {
1260  i::Isolate* isolate = i::Isolate::Current();
1261  if (IsDeadCheck(isolate, "v8::ObjectTemplate::New()")) {
1262  return Local<ObjectTemplate>();
1263  }
1264  EnsureInitializedForIsolate(isolate, "v8::ObjectTemplate::New()");
1265  LOG_API(isolate, "ObjectTemplate::New");
1266  ENTER_V8(isolate);
1267  i::Handle<i::Struct> struct_obj =
1271  InitializeTemplate(obj, Consts::OBJECT_TEMPLATE);
1272  if (!constructor.IsEmpty())
1273  obj->set_constructor(*Utils::OpenHandle(*constructor));
1274  obj->set_internal_field_count(i::Smi::FromInt(0));
1275  return Utils::ToLocal(obj);
1276 }
1277 
1278 
1279 // Ensure that the object template has a constructor. If no
1280 // constructor is available we create one.
1281 static void EnsureConstructor(ObjectTemplate* object_template) {
1282  if (Utils::OpenHandle(object_template)->constructor()->IsUndefined()) {
1283  Local<FunctionTemplate> templ = FunctionTemplate::New();
1284  i::Handle<i::FunctionTemplateInfo> constructor = Utils::OpenHandle(*templ);
1285  constructor->set_instance_template(*Utils::OpenHandle(object_template));
1286  Utils::OpenHandle(object_template)->set_constructor(*constructor);
1287  }
1288 }
1289 
1290 
1292  AccessorGetter getter,
1293  AccessorSetter setter,
1294  v8::Handle<Value> data,
1295  AccessControl settings,
1296  PropertyAttribute attribute,
1297  v8::Handle<AccessorSignature> signature) {
1298  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
1299  if (IsDeadCheck(isolate, "v8::ObjectTemplate::SetAccessor()")) return;
1300  ENTER_V8(isolate);
1301  i::HandleScope scope(isolate);
1302  EnsureConstructor(this);
1303  i::FunctionTemplateInfo* constructor =
1304  i::FunctionTemplateInfo::cast(Utils::OpenHandle(this)->constructor());
1305  i::Handle<i::FunctionTemplateInfo> cons(constructor);
1306  Utils::ToLocal(cons)->AddInstancePropertyAccessor(name,
1307  getter,
1308  setter,
1309  data,
1310  settings,
1311  attribute,
1312  signature);
1313 }
1314 
1315 
1317  NamedPropertySetter setter,
1318  NamedPropertyQuery query,
1319  NamedPropertyDeleter remover,
1320  NamedPropertyEnumerator enumerator,
1321  Handle<Value> data) {
1322  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
1323  if (IsDeadCheck(isolate, "v8::ObjectTemplate::SetNamedPropertyHandler()")) {
1324  return;
1325  }
1326  ENTER_V8(isolate);
1327  i::HandleScope scope(isolate);
1328  EnsureConstructor(this);
1329  i::FunctionTemplateInfo* constructor =
1330  i::FunctionTemplateInfo::cast(Utils::OpenHandle(this)->constructor());
1331  i::Handle<i::FunctionTemplateInfo> cons(constructor);
1332  Utils::ToLocal(cons)->SetNamedInstancePropertyHandler(getter,
1333  setter,
1334  query,
1335  remover,
1336  enumerator,
1337  data);
1338 }
1339 
1340 
1342  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
1343  if (IsDeadCheck(isolate, "v8::ObjectTemplate::MarkAsUndetectable()")) return;
1344  ENTER_V8(isolate);
1345  i::HandleScope scope(isolate);
1346  EnsureConstructor(this);
1347  i::FunctionTemplateInfo* constructor =
1348  i::FunctionTemplateInfo::cast(Utils::OpenHandle(this)->constructor());
1349  i::Handle<i::FunctionTemplateInfo> cons(constructor);
1350  cons->set_undetectable(true);
1351 }
1352 
1353 
1355  NamedSecurityCallback named_callback,
1356  IndexedSecurityCallback indexed_callback,
1357  Handle<Value> data,
1358  bool turned_on_by_default) {
1359  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
1360  if (IsDeadCheck(isolate, "v8::ObjectTemplate::SetAccessCheckCallbacks()")) {
1361  return;
1362  }
1363  ENTER_V8(isolate);
1364  i::HandleScope scope(isolate);
1365  EnsureConstructor(this);
1366 
1367  i::Handle<i::Struct> struct_info =
1371 
1372  SET_FIELD_WRAPPED(info, set_named_callback, named_callback);
1373  SET_FIELD_WRAPPED(info, set_indexed_callback, indexed_callback);
1374 
1375  if (data.IsEmpty()) data = v8::Undefined();
1376  info->set_data(*Utils::OpenHandle(*data));
1377 
1378  i::FunctionTemplateInfo* constructor =
1379  i::FunctionTemplateInfo::cast(Utils::OpenHandle(this)->constructor());
1380  i::Handle<i::FunctionTemplateInfo> cons(constructor);
1381  cons->set_access_check_info(*info);
1382  cons->set_needs_access_check(turned_on_by_default);
1383 }
1384 
1385 
1387  IndexedPropertyGetter getter,
1388  IndexedPropertySetter setter,
1389  IndexedPropertyQuery query,
1390  IndexedPropertyDeleter remover,
1391  IndexedPropertyEnumerator enumerator,
1392  Handle<Value> data) {
1393  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
1394  if (IsDeadCheck(isolate, "v8::ObjectTemplate::SetIndexedPropertyHandler()")) {
1395  return;
1396  }
1397  ENTER_V8(isolate);
1398  i::HandleScope scope(isolate);
1399  EnsureConstructor(this);
1400  i::FunctionTemplateInfo* constructor =
1401  i::FunctionTemplateInfo::cast(Utils::OpenHandle(this)->constructor());
1402  i::Handle<i::FunctionTemplateInfo> cons(constructor);
1403  Utils::ToLocal(cons)->SetIndexedInstancePropertyHandler(getter,
1404  setter,
1405  query,
1406  remover,
1407  enumerator,
1408  data);
1409 }
1410 
1411 
1413  Handle<Value> data) {
1414  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
1415  if (IsDeadCheck(isolate,
1416  "v8::ObjectTemplate::SetCallAsFunctionHandler()")) {
1417  return;
1418  }
1419  ENTER_V8(isolate);
1420  i::HandleScope scope(isolate);
1421  EnsureConstructor(this);
1422  i::FunctionTemplateInfo* constructor =
1423  i::FunctionTemplateInfo::cast(Utils::OpenHandle(this)->constructor());
1424  i::Handle<i::FunctionTemplateInfo> cons(constructor);
1425  Utils::ToLocal(cons)->SetInstanceCallAsFunctionHandler(callback, data);
1426 }
1427 
1428 
1430  if (IsDeadCheck(Utils::OpenHandle(this)->GetIsolate(),
1431  "v8::ObjectTemplate::InternalFieldCount()")) {
1432  return 0;
1433  }
1434  return i::Smi::cast(Utils::OpenHandle(this)->internal_field_count())->value();
1435 }
1436 
1437 
1439  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
1440  if (IsDeadCheck(isolate, "v8::ObjectTemplate::SetInternalFieldCount()")) {
1441  return;
1442  }
1443  if (!ApiCheck(i::Smi::IsValid(value),
1444  "v8::ObjectTemplate::SetInternalFieldCount()",
1445  "Invalid internal field count")) {
1446  return;
1447  }
1448  ENTER_V8(isolate);
1449  if (value > 0) {
1450  // The internal field count is set by the constructor function's
1451  // construct code, so we ensure that there is a constructor
1452  // function to do the setting.
1453  EnsureConstructor(this);
1454  }
1455  Utils::OpenHandle(this)->set_internal_field_count(i::Smi::FromInt(value));
1456 }
1457 
1458 
1459 // --- S c r i p t D a t a ---
1460 
1461 
1462 ScriptData* ScriptData::PreCompile(const char* input, int length) {
1464  reinterpret_cast<const unsigned char*>(input), length);
1465  return i::ParserApi::PreParse(&stream, NULL, i::FLAG_harmony_scoping);
1466 }
1467 
1468 
1470  i::Handle<i::String> str = Utils::OpenHandle(*source);
1471  if (str->IsExternalTwoByteString()) {
1473  i::Handle<i::ExternalTwoByteString>::cast(str), 0, str->length());
1474  return i::ParserApi::PreParse(&stream, NULL, i::FLAG_harmony_scoping);
1475  } else {
1476  i::GenericStringUtf16CharacterStream stream(str, 0, str->length());
1477  return i::ParserApi::PreParse(&stream, NULL, i::FLAG_harmony_scoping);
1478  }
1479 }
1480 
1481 
1482 ScriptData* ScriptData::New(const char* data, int length) {
1483  // Return an empty ScriptData if the length is obviously invalid.
1484  if (length % sizeof(unsigned) != 0) {
1485  return new i::ScriptDataImpl();
1486  }
1487 
1488  // Copy the data to ensure it is properly aligned.
1489  int deserialized_data_length = length / sizeof(unsigned);
1490  // If aligned, don't create a copy of the data.
1491  if (reinterpret_cast<intptr_t>(data) % sizeof(unsigned) == 0) {
1492  return new i::ScriptDataImpl(data, length);
1493  }
1494  // Copy the data to align it.
1495  unsigned* deserialized_data = i::NewArray<unsigned>(deserialized_data_length);
1496  i::OS::MemCopy(deserialized_data, data, length);
1497 
1498  return new i::ScriptDataImpl(
1499  i::Vector<unsigned>(deserialized_data, deserialized_data_length));
1500 }
1501 
1502 
1503 // --- S c r i p t ---
1504 
1505 
1507  v8::ScriptOrigin* origin,
1508  v8::ScriptData* pre_data,
1509  v8::Handle<String> script_data) {
1510  i::Isolate* isolate = i::Isolate::Current();
1511  ON_BAILOUT(isolate, "v8::Script::New()", return Local<Script>());
1512  LOG_API(isolate, "Script::New");
1513  ENTER_V8(isolate);
1514  i::SharedFunctionInfo* raw_result = NULL;
1515  { i::HandleScope scope(isolate);
1516  i::Handle<i::String> str = Utils::OpenHandle(*source);
1517  i::Handle<i::Object> name_obj;
1518  int line_offset = 0;
1519  int column_offset = 0;
1520  if (origin != NULL) {
1521  if (!origin->ResourceName().IsEmpty()) {
1522  name_obj = Utils::OpenHandle(*origin->ResourceName());
1523  }
1524  if (!origin->ResourceLineOffset().IsEmpty()) {
1525  line_offset = static_cast<int>(origin->ResourceLineOffset()->Value());
1526  }
1527  if (!origin->ResourceColumnOffset().IsEmpty()) {
1528  column_offset =
1529  static_cast<int>(origin->ResourceColumnOffset()->Value());
1530  }
1531  }
1532  EXCEPTION_PREAMBLE(isolate);
1533  i::ScriptDataImpl* pre_data_impl =
1534  static_cast<i::ScriptDataImpl*>(pre_data);
1535  // We assert that the pre-data is sane, even though we can actually
1536  // handle it if it turns out not to be in release mode.
1537  ASSERT(pre_data_impl == NULL || pre_data_impl->SanityCheck());
1538  // If the pre-data isn't sane we simply ignore it
1539  if (pre_data_impl != NULL && !pre_data_impl->SanityCheck()) {
1540  pre_data_impl = NULL;
1541  }
1544  name_obj,
1545  line_offset,
1546  column_offset,
1547  isolate->global_context(),
1548  NULL,
1549  pre_data_impl,
1550  Utils::OpenHandle(*script_data, true),
1552  has_pending_exception = result.is_null();
1554  raw_result = *result;
1555  }
1556  i::Handle<i::SharedFunctionInfo> result(raw_result, isolate);
1557  return Local<Script>(ToApi<Script>(result));
1558 }
1559 
1560 
1562  v8::Handle<Value> file_name) {
1563  ScriptOrigin origin(file_name);
1564  return New(source, &origin);
1565 }
1566 
1567 
1569  v8::ScriptOrigin* origin,
1570  v8::ScriptData* pre_data,
1571  v8::Handle<String> script_data) {
1572  i::Isolate* isolate = i::Isolate::Current();
1573  ON_BAILOUT(isolate, "v8::Script::Compile()", return Local<Script>());
1574  LOG_API(isolate, "Script::Compile");
1575  ENTER_V8(isolate);
1576  Local<Script> generic = New(source, origin, pre_data, script_data);
1577  if (generic.IsEmpty())
1578  return generic;
1579  i::Handle<i::Object> obj = Utils::OpenHandle(*generic);
1582  i::Handle<i::JSFunction> result =
1584  function,
1585  isolate->global_context());
1586  return Local<Script>(ToApi<Script>(result));
1587 }
1588 
1589 
1591  v8::Handle<Value> file_name,
1592  v8::Handle<String> script_data) {
1593  ScriptOrigin origin(file_name);
1594  return Compile(source, &origin, 0, script_data);
1595 }
1596 
1597 
1599  i::Isolate* isolate = i::Isolate::Current();
1600  ON_BAILOUT(isolate, "v8::Script::Run()", return Local<Value>());
1601  LOG_API(isolate, "Script::Run");
1602  ENTER_V8(isolate);
1603  i::Object* raw_result = NULL;
1604  {
1605  i::HandleScope scope(isolate);
1606  i::Handle<i::Object> obj = Utils::OpenHandle(this);
1608  if (obj->IsSharedFunctionInfo()) {
1610  function_info(i::SharedFunctionInfo::cast(*obj), isolate);
1611  fun = isolate->factory()->NewFunctionFromSharedFunctionInfo(
1612  function_info, isolate->global_context());
1613  } else {
1614  fun = i::Handle<i::JSFunction>(i::JSFunction::cast(*obj), isolate);
1615  }
1616  EXCEPTION_PREAMBLE(isolate);
1617  i::Handle<i::Object> receiver(
1618  isolate->context()->global_proxy(), isolate);
1619  i::Handle<i::Object> result =
1620  i::Execution::Call(fun, receiver, 0, NULL, &has_pending_exception);
1622  raw_result = *result;
1623  }
1624  i::Handle<i::Object> result(raw_result, isolate);
1625  return Utils::ToLocal(result);
1626 }
1627 
1628 
1629 static i::Handle<i::SharedFunctionInfo> OpenScript(Script* script) {
1630  i::Handle<i::Object> obj = Utils::OpenHandle(script);
1632  if (obj->IsSharedFunctionInfo()) {
1633  result =
1635  } else {
1636  result =
1638  }
1639  return result;
1640 }
1641 
1642 
1644  i::Isolate* isolate = i::Isolate::Current();
1645  ON_BAILOUT(isolate, "v8::Script::Id()", return Local<Value>());
1646  LOG_API(isolate, "Script::Id");
1647  i::Object* raw_id = NULL;
1648  {
1649  i::HandleScope scope(isolate);
1650  i::Handle<i::SharedFunctionInfo> function_info = OpenScript(this);
1651  i::Handle<i::Script> script(i::Script::cast(function_info->script()));
1652  i::Handle<i::Object> id(script->id());
1653  raw_id = *id;
1654  }
1655  i::Handle<i::Object> id(raw_id);
1656  return Utils::ToLocal(id);
1657 }
1658 
1659 
1661  i::Isolate* isolate = i::Isolate::Current();
1662  ON_BAILOUT(isolate, "v8::Script::SetData()", return);
1663  LOG_API(isolate, "Script::SetData");
1664  {
1665  i::HandleScope scope(isolate);
1666  i::Handle<i::SharedFunctionInfo> function_info = OpenScript(this);
1667  i::Handle<i::Object> raw_data = Utils::OpenHandle(*data);
1668  i::Handle<i::Script> script(i::Script::cast(function_info->script()));
1669  script->set_data(*raw_data);
1670  }
1671 }
1672 
1673 
1674 // --- E x c e p t i o n s ---
1675 
1676 
1678  : isolate_(i::Isolate::Current()),
1679  next_(isolate_->try_catch_handler_address()),
1680  exception_(isolate_->heap()->the_hole_value()),
1681  message_(i::Smi::FromInt(0)),
1682  is_verbose_(false),
1683  can_continue_(true),
1684  capture_message_(true),
1685  rethrow_(false) {
1686  isolate_->RegisterTryCatchHandler(this);
1687 }
1688 
1689 
1691  ASSERT(isolate_ == i::Isolate::Current());
1692  if (rethrow_) {
1693  v8::HandleScope scope;
1695  isolate_->UnregisterTryCatchHandler(this);
1696  v8::ThrowException(exc);
1697  } else {
1698  isolate_->UnregisterTryCatchHandler(this);
1699  }
1700 }
1701 
1702 
1704  return !reinterpret_cast<i::Object*>(exception_)->IsTheHole();
1705 }
1706 
1707 
1709  return can_continue_;
1710 }
1711 
1712 
1714  if (!HasCaught()) return v8::Local<v8::Value>();
1715  rethrow_ = true;
1716  return v8::Undefined();
1717 }
1718 
1719 
1721  ASSERT(isolate_ == i::Isolate::Current());
1722  if (HasCaught()) {
1723  // Check for out of memory exception.
1724  i::Object* exception = reinterpret_cast<i::Object*>(exception_);
1725  return v8::Utils::ToLocal(i::Handle<i::Object>(exception, isolate_));
1726  } else {
1727  return v8::Local<Value>();
1728  }
1729 }
1730 
1731 
1733  ASSERT(isolate_ == i::Isolate::Current());
1734  if (HasCaught()) {
1735  i::Object* raw_obj = reinterpret_cast<i::Object*>(exception_);
1736  if (!raw_obj->IsJSObject()) return v8::Local<Value>();
1737  i::HandleScope scope(isolate_);
1738  i::Handle<i::JSObject> obj(i::JSObject::cast(raw_obj), isolate_);
1739  i::Handle<i::String> name = isolate_->factory()->LookupAsciiSymbol("stack");
1740  if (!obj->HasProperty(*name)) return v8::Local<Value>();
1741  i::Handle<i::Object> value = i::GetProperty(obj, name);
1742  if (value.is_null()) return v8::Local<Value>();
1743  return v8::Utils::ToLocal(scope.CloseAndEscape(value));
1744  } else {
1745  return v8::Local<Value>();
1746  }
1747 }
1748 
1749 
1751  ASSERT(isolate_ == i::Isolate::Current());
1752  if (HasCaught() && message_ != i::Smi::FromInt(0)) {
1753  i::Object* message = reinterpret_cast<i::Object*>(message_);
1754  return v8::Utils::MessageToLocal(i::Handle<i::Object>(message, isolate_));
1755  } else {
1756  return v8::Local<v8::Message>();
1757  }
1758 }
1759 
1760 
1762  ASSERT(isolate_ == i::Isolate::Current());
1763  exception_ = isolate_->heap()->the_hole_value();
1764  message_ = i::Smi::FromInt(0);
1765 }
1766 
1767 
1768 void v8::TryCatch::SetVerbose(bool value) {
1769  is_verbose_ = value;
1770 }
1771 
1772 
1774  capture_message_ = value;
1775 }
1776 
1777 
1778 // --- M e s s a g e ---
1779 
1780 
1782  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
1783  ON_BAILOUT(isolate, "v8::Message::Get()", return Local<String>());
1784  ENTER_V8(isolate);
1785  HandleScope scope;
1786  i::Handle<i::Object> obj = Utils::OpenHandle(this);
1788  Local<String> result = Utils::ToLocal(raw_result);
1789  return scope.Close(result);
1790 }
1791 
1792 
1794  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
1795  if (IsDeadCheck(isolate, "v8::Message::GetScriptResourceName()")) {
1796  return Local<String>();
1797  }
1798  ENTER_V8(isolate);
1799  HandleScope scope;
1801  i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this));
1802  // Return this.script.name.
1803  i::Handle<i::JSValue> script =
1805  i::Handle<i::Object> resource_name(i::Script::cast(script->value())->name());
1806  return scope.Close(Utils::ToLocal(resource_name));
1807 }
1808 
1809 
1811  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
1812  if (IsDeadCheck(isolate, "v8::Message::GetScriptResourceData()")) {
1813  return Local<Value>();
1814  }
1815  ENTER_V8(isolate);
1816  HandleScope scope;
1818  i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this));
1819  // Return this.script.data.
1820  i::Handle<i::JSValue> script =
1822  i::Handle<i::Object> data(i::Script::cast(script->value())->data());
1823  return scope.Close(Utils::ToLocal(data));
1824 }
1825 
1826 
1828  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
1829  if (IsDeadCheck(isolate, "v8::Message::GetStackTrace()")) {
1830  return Local<v8::StackTrace>();
1831  }
1832  ENTER_V8(isolate);
1833  HandleScope scope;
1835  i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this));
1836  i::Handle<i::Object> stackFramesObj(message->stack_frames());
1837  if (!stackFramesObj->IsJSArray()) return v8::Handle<v8::StackTrace>();
1838  i::Handle<i::JSArray> stackTrace =
1839  i::Handle<i::JSArray>::cast(stackFramesObj);
1840  return scope.Close(Utils::StackTraceToLocal(stackTrace));
1841 }
1842 
1843 
1844 static i::Handle<i::Object> CallV8HeapFunction(const char* name,
1845  i::Handle<i::Object> recv,
1846  int argc,
1847  i::Handle<i::Object> argv[],
1848  bool* has_pending_exception) {
1849  i::Isolate* isolate = i::Isolate::Current();
1850  i::Handle<i::String> fmt_str = isolate->factory()->LookupAsciiSymbol(name);
1851  i::Object* object_fun =
1852  isolate->js_builtins_object()->GetPropertyNoExceptionThrown(*fmt_str);
1855  i::Handle<i::Object> value =
1856  i::Execution::Call(fun, recv, argc, argv, has_pending_exception);
1857  return value;
1858 }
1859 
1860 
1861 static i::Handle<i::Object> CallV8HeapFunction(const char* name,
1862  i::Handle<i::Object> data,
1863  bool* has_pending_exception) {
1864  i::Handle<i::Object> argv[] = { data };
1865  return CallV8HeapFunction(name,
1866  i::Isolate::Current()->js_builtins_object(),
1867  ARRAY_SIZE(argv),
1868  argv,
1869  has_pending_exception);
1870 }
1871 
1872 
1874  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
1875  ON_BAILOUT(isolate, "v8::Message::GetLineNumber()", return kNoLineNumberInfo);
1876  ENTER_V8(isolate);
1877  i::HandleScope scope(isolate);
1878 
1879  EXCEPTION_PREAMBLE(isolate);
1880  i::Handle<i::Object> result = CallV8HeapFunction("GetLineNumber",
1881  Utils::OpenHandle(this),
1882  &has_pending_exception);
1883  EXCEPTION_BAILOUT_CHECK(isolate, 0);
1884  return static_cast<int>(result->Number());
1885 }
1886 
1887 
1889  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
1890  if (IsDeadCheck(isolate, "v8::Message::GetStartPosition()")) return 0;
1891  ENTER_V8(isolate);
1892  i::HandleScope scope(isolate);
1894  i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this));
1895  return message->start_position();
1896 }
1897 
1898 
1900  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
1901  if (IsDeadCheck(isolate, "v8::Message::GetEndPosition()")) return 0;
1902  ENTER_V8(isolate);
1903  i::HandleScope scope(isolate);
1905  i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this));
1906  return message->end_position();
1907 }
1908 
1909 
1911  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
1912  if (IsDeadCheck(isolate, "v8::Message::GetStartColumn()")) {
1913  return kNoColumnInfo;
1914  }
1915  ENTER_V8(isolate);
1916  i::HandleScope scope(isolate);
1917  i::Handle<i::JSObject> data_obj = Utils::OpenHandle(this);
1918  EXCEPTION_PREAMBLE(isolate);
1919  i::Handle<i::Object> start_col_obj = CallV8HeapFunction(
1920  "GetPositionInLine",
1921  data_obj,
1922  &has_pending_exception);
1923  EXCEPTION_BAILOUT_CHECK(isolate, 0);
1924  return static_cast<int>(start_col_obj->Number());
1925 }
1926 
1927 
1929  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
1930  if (IsDeadCheck(isolate, "v8::Message::GetEndColumn()")) return kNoColumnInfo;
1931  ENTER_V8(isolate);
1932  i::HandleScope scope(isolate);
1933  i::Handle<i::JSObject> data_obj = Utils::OpenHandle(this);
1934  EXCEPTION_PREAMBLE(isolate);
1935  i::Handle<i::Object> start_col_obj = CallV8HeapFunction(
1936  "GetPositionInLine",
1937  data_obj,
1938  &has_pending_exception);
1939  EXCEPTION_BAILOUT_CHECK(isolate, 0);
1942  int start = message->start_position();
1943  int end = message->end_position();
1944  return static_cast<int>(start_col_obj->Number()) + (end - start);
1945 }
1946 
1947 
1949  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
1950  ON_BAILOUT(isolate, "v8::Message::GetSourceLine()", return Local<String>());
1951  ENTER_V8(isolate);
1952  HandleScope scope;
1953  EXCEPTION_PREAMBLE(isolate);
1954  i::Handle<i::Object> result = CallV8HeapFunction("GetSourceLine",
1955  Utils::OpenHandle(this),
1956  &has_pending_exception);
1958  if (result->IsString()) {
1959  return scope.Close(Utils::ToLocal(i::Handle<i::String>::cast(result)));
1960  } else {
1961  return Local<String>();
1962  }
1963 }
1964 
1965 
1967  i::Isolate* isolate = i::Isolate::Current();
1968  if (IsDeadCheck(isolate, "v8::Message::PrintCurrentStackTrace()")) return;
1969  ENTER_V8(isolate);
1970  isolate->PrintCurrentStackTrace(out);
1971 }
1972 
1973 
1974 // --- S t a c k T r a c e ---
1975 
1977  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
1978  if (IsDeadCheck(isolate, "v8::StackTrace::GetFrame()")) {
1979  return Local<StackFrame>();
1980  }
1981  ENTER_V8(isolate);
1982  HandleScope scope;
1983  i::Handle<i::JSArray> self = Utils::OpenHandle(this);
1984  i::Object* raw_object = self->GetElementNoExceptionThrown(index);
1985  i::Handle<i::JSObject> obj(i::JSObject::cast(raw_object));
1986  return scope.Close(Utils::StackFrameToLocal(obj));
1987 }
1988 
1989 
1991  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
1992  if (IsDeadCheck(isolate, "v8::StackTrace::GetFrameCount()")) return -1;
1993  ENTER_V8(isolate);
1994  return i::Smi::cast(Utils::OpenHandle(this)->length())->value();
1995 }
1996 
1997 
1999  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
2000  if (IsDeadCheck(isolate, "v8::StackTrace::AsArray()")) Local<Array>();
2001  ENTER_V8(isolate);
2002  return Utils::ToLocal(Utils::OpenHandle(this));
2003 }
2004 
2005 
2007  StackTraceOptions options) {
2008  i::Isolate* isolate = i::Isolate::Current();
2009  if (IsDeadCheck(isolate, "v8::StackTrace::CurrentStackTrace()")) {
2011  }
2012  ENTER_V8(isolate);
2013  i::Handle<i::JSArray> stackTrace =
2014  isolate->CaptureCurrentStackTrace(frame_limit, options);
2015  return Utils::StackTraceToLocal(stackTrace);
2016 }
2017 
2018 
2019 // --- S t a c k F r a m e ---
2020 
2022  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
2023  if (IsDeadCheck(isolate, "v8::StackFrame::GetLineNumber()")) {
2025  }
2026  ENTER_V8(isolate);
2027  i::HandleScope scope(isolate);
2028  i::Handle<i::JSObject> self = Utils::OpenHandle(this);
2029  i::Handle<i::Object> line = GetProperty(self, "lineNumber");
2030  if (!line->IsSmi()) {
2032  }
2033  return i::Smi::cast(*line)->value();
2034 }
2035 
2036 
2038  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
2039  if (IsDeadCheck(isolate, "v8::StackFrame::GetColumn()")) {
2040  return Message::kNoColumnInfo;
2041  }
2042  ENTER_V8(isolate);
2043  i::HandleScope scope(isolate);
2044  i::Handle<i::JSObject> self = Utils::OpenHandle(this);
2045  i::Handle<i::Object> column = GetProperty(self, "column");
2046  if (!column->IsSmi()) {
2047  return Message::kNoColumnInfo;
2048  }
2049  return i::Smi::cast(*column)->value();
2050 }
2051 
2052 
2054  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
2055  if (IsDeadCheck(isolate, "v8::StackFrame::GetScriptName()")) {
2056  return Local<String>();
2057  }
2058  ENTER_V8(isolate);
2059  HandleScope scope;
2060  i::Handle<i::JSObject> self = Utils::OpenHandle(this);
2061  i::Handle<i::Object> name = GetProperty(self, "scriptName");
2062  if (!name->IsString()) {
2063  return Local<String>();
2064  }
2065  return scope.Close(Local<String>::Cast(Utils::ToLocal(name)));
2066 }
2067 
2068 
2070  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
2071  if (IsDeadCheck(isolate, "v8::StackFrame::GetScriptNameOrSourceURL()")) {
2072  return Local<String>();
2073  }
2074  ENTER_V8(isolate);
2075  HandleScope scope;
2076  i::Handle<i::JSObject> self = Utils::OpenHandle(this);
2077  i::Handle<i::Object> name = GetProperty(self, "scriptNameOrSourceURL");
2078  if (!name->IsString()) {
2079  return Local<String>();
2080  }
2081  return scope.Close(Local<String>::Cast(Utils::ToLocal(name)));
2082 }
2083 
2084 
2086  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
2087  if (IsDeadCheck(isolate, "v8::StackFrame::GetFunctionName()")) {
2088  return Local<String>();
2089  }
2090  ENTER_V8(isolate);
2091  HandleScope scope;
2092  i::Handle<i::JSObject> self = Utils::OpenHandle(this);
2093  i::Handle<i::Object> name = GetProperty(self, "functionName");
2094  if (!name->IsString()) {
2095  return Local<String>();
2096  }
2097  return scope.Close(Local<String>::Cast(Utils::ToLocal(name)));
2098 }
2099 
2100 
2101 bool StackFrame::IsEval() const {
2102  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
2103  if (IsDeadCheck(isolate, "v8::StackFrame::IsEval()")) return false;
2104  ENTER_V8(isolate);
2105  i::HandleScope scope(isolate);
2106  i::Handle<i::JSObject> self = Utils::OpenHandle(this);
2107  i::Handle<i::Object> is_eval = GetProperty(self, "isEval");
2108  return is_eval->IsTrue();
2109 }
2110 
2111 
2113  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
2114  if (IsDeadCheck(isolate, "v8::StackFrame::IsConstructor()")) return false;
2115  ENTER_V8(isolate);
2116  i::HandleScope scope(isolate);
2117  i::Handle<i::JSObject> self = Utils::OpenHandle(this);
2118  i::Handle<i::Object> is_constructor = GetProperty(self, "isConstructor");
2119  return is_constructor->IsTrue();
2120 }
2121 
2122 
2123 // --- D a t a ---
2124 
2125 bool Value::FullIsUndefined() const {
2126  if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsUndefined()")) {
2127  return false;
2128  }
2129  bool result = Utils::OpenHandle(this)->IsUndefined();
2130  ASSERT_EQ(result, QuickIsUndefined());
2131  return result;
2132 }
2133 
2134 
2135 bool Value::FullIsNull() const {
2136  if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsNull()")) return false;
2137  bool result = Utils::OpenHandle(this)->IsNull();
2138  ASSERT_EQ(result, QuickIsNull());
2139  return result;
2140 }
2141 
2142 
2143 bool Value::IsTrue() const {
2144  if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsTrue()")) return false;
2145  return Utils::OpenHandle(this)->IsTrue();
2146 }
2147 
2148 
2149 bool Value::IsFalse() const {
2150  if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsFalse()")) return false;
2151  return Utils::OpenHandle(this)->IsFalse();
2152 }
2153 
2154 
2155 bool Value::IsFunction() const {
2156  if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsFunction()")) {
2157  return false;
2158  }
2159  return Utils::OpenHandle(this)->IsJSFunction();
2160 }
2161 
2162 
2163 bool Value::FullIsString() const {
2164  if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsString()")) return false;
2165  bool result = Utils::OpenHandle(this)->IsString();
2166  ASSERT_EQ(result, QuickIsString());
2167  return result;
2168 }
2169 
2170 
2171 bool Value::IsArray() const {
2172  if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsArray()")) return false;
2173  return Utils::OpenHandle(this)->IsJSArray();
2174 }
2175 
2176 
2177 bool Value::IsObject() const {
2178  if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsObject()")) return false;
2179  return Utils::OpenHandle(this)->IsJSObject();
2180 }
2181 
2182 
2183 bool Value::IsNumber() const {
2184  if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsNumber()")) return false;
2185  return Utils::OpenHandle(this)->IsNumber();
2186 }
2187 
2188 
2189 bool Value::IsBoolean() const {
2190  if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsBoolean()")) {
2191  return false;
2192  }
2193  return Utils::OpenHandle(this)->IsBoolean();
2194 }
2195 
2196 
2197 bool Value::IsExternal() const {
2198  if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsExternal()")) {
2199  return false;
2200  }
2201  return Utils::OpenHandle(this)->IsForeign();
2202 }
2203 
2204 
2205 bool Value::IsInt32() const {
2206  if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsInt32()")) return false;
2207  i::Handle<i::Object> obj = Utils::OpenHandle(this);
2208  if (obj->IsSmi()) return true;
2209  if (obj->IsNumber()) {
2210  double value = obj->Number();
2211  static const i::DoubleRepresentation minus_zero(-0.0);
2212  i::DoubleRepresentation rep(value);
2213  if (rep.bits == minus_zero.bits) {
2214  return false;
2215  }
2216  return i::FastI2D(i::FastD2I(value)) == value;
2217  }
2218  return false;
2219 }
2220 
2221 
2222 bool Value::IsUint32() const {
2223  if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsUint32()")) return false;
2224  i::Handle<i::Object> obj = Utils::OpenHandle(this);
2225  if (obj->IsSmi()) return i::Smi::cast(*obj)->value() >= 0;
2226  if (obj->IsNumber()) {
2227  double value = obj->Number();
2228  static const i::DoubleRepresentation minus_zero(-0.0);
2229  i::DoubleRepresentation rep(value);
2230  if (rep.bits == minus_zero.bits) {
2231  return false;
2232  }
2233  return i::FastUI2D(i::FastD2UI(value)) == value;
2234  }
2235  return false;
2236 }
2237 
2238 
2239 bool Value::IsDate() const {
2240  i::Isolate* isolate = i::Isolate::Current();
2241  if (IsDeadCheck(isolate, "v8::Value::IsDate()")) return false;
2242  i::Handle<i::Object> obj = Utils::OpenHandle(this);
2243  return obj->HasSpecificClassOf(isolate->heap()->Date_symbol());
2244 }
2245 
2246 
2248  i::Isolate* isolate = i::Isolate::Current();
2249  if (IsDeadCheck(isolate, "v8::Value::IsStringObject()")) return false;
2250  i::Handle<i::Object> obj = Utils::OpenHandle(this);
2251  return obj->HasSpecificClassOf(isolate->heap()->String_symbol());
2252 }
2253 
2254 
2256  i::Isolate* isolate = i::Isolate::Current();
2257  if (IsDeadCheck(isolate, "v8::Value::IsNumberObject()")) return false;
2258  i::Handle<i::Object> obj = Utils::OpenHandle(this);
2259  return obj->HasSpecificClassOf(isolate->heap()->Number_symbol());
2260 }
2261 
2262 
2263 static i::Object* LookupBuiltin(i::Isolate* isolate,
2264  const char* builtin_name) {
2265  i::Handle<i::String> symbol =
2266  isolate->factory()->LookupAsciiSymbol(builtin_name);
2267  i::Handle<i::JSBuiltinsObject> builtins = isolate->js_builtins_object();
2268  return builtins->GetPropertyNoExceptionThrown(*symbol);
2269 }
2270 
2271 
2272 static bool CheckConstructor(i::Isolate* isolate,
2274  const char* class_name) {
2275  return obj->map()->constructor() == LookupBuiltin(isolate, class_name);
2276 }
2277 
2278 
2279 bool Value::IsNativeError() const {
2280  i::Isolate* isolate = i::Isolate::Current();
2281  if (IsDeadCheck(isolate, "v8::Value::IsNativeError()")) return false;
2282  i::Handle<i::Object> obj = Utils::OpenHandle(this);
2283  if (obj->IsJSObject()) {
2285  return CheckConstructor(isolate, js_obj, "$Error") ||
2286  CheckConstructor(isolate, js_obj, "$EvalError") ||
2287  CheckConstructor(isolate, js_obj, "$RangeError") ||
2288  CheckConstructor(isolate, js_obj, "$ReferenceError") ||
2289  CheckConstructor(isolate, js_obj, "$SyntaxError") ||
2290  CheckConstructor(isolate, js_obj, "$TypeError") ||
2291  CheckConstructor(isolate, js_obj, "$URIError");
2292  } else {
2293  return false;
2294  }
2295 }
2296 
2297 
2299  i::Isolate* isolate = i::Isolate::Current();
2300  if (IsDeadCheck(isolate, "v8::Value::IsBooleanObject()")) return false;
2301  i::Handle<i::Object> obj = Utils::OpenHandle(this);
2302  return obj->HasSpecificClassOf(isolate->heap()->Boolean_symbol());
2303 }
2304 
2305 
2306 bool Value::IsRegExp() const {
2307  if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsRegExp()")) return false;
2308  i::Handle<i::Object> obj = Utils::OpenHandle(this);
2309  return obj->IsJSRegExp();
2310 }
2311 
2312 
2314  i::Handle<i::Object> obj = Utils::OpenHandle(this);
2316  if (obj->IsString()) {
2317  str = obj;
2318  } else {
2319  i::Isolate* isolate = i::Isolate::Current();
2320  if (IsDeadCheck(isolate, "v8::Value::ToString()")) {
2321  return Local<String>();
2322  }
2323  LOG_API(isolate, "ToString");
2324  ENTER_V8(isolate);
2325  EXCEPTION_PREAMBLE(isolate);
2326  str = i::Execution::ToString(obj, &has_pending_exception);
2328  }
2329  return Local<String>(ToApi<String>(str));
2330 }
2331 
2332 
2334  i::Handle<i::Object> obj = Utils::OpenHandle(this);
2336  if (obj->IsString()) {
2337  str = obj;
2338  } else {
2339  i::Isolate* isolate = i::Isolate::Current();
2340  if (IsDeadCheck(isolate, "v8::Value::ToDetailString()")) {
2341  return Local<String>();
2342  }
2343  LOG_API(isolate, "ToDetailString");
2344  ENTER_V8(isolate);
2345  EXCEPTION_PREAMBLE(isolate);
2346  str = i::Execution::ToDetailString(obj, &has_pending_exception);
2348  }
2349  return Local<String>(ToApi<String>(str));
2350 }
2351 
2352 
2354  i::Handle<i::Object> obj = Utils::OpenHandle(this);
2356  if (obj->IsJSObject()) {
2357  val = obj;
2358  } else {
2359  i::Isolate* isolate = i::Isolate::Current();
2360  if (IsDeadCheck(isolate, "v8::Value::ToObject()")) {
2361  return Local<v8::Object>();
2362  }
2363  LOG_API(isolate, "ToObject");
2364  ENTER_V8(isolate);
2365  EXCEPTION_PREAMBLE(isolate);
2366  val = i::Execution::ToObject(obj, &has_pending_exception);
2368  }
2369  return Local<v8::Object>(ToApi<Object>(val));
2370 }
2371 
2372 
2374  i::Handle<i::Object> obj = Utils::OpenHandle(this);
2375  if (obj->IsBoolean()) {
2376  return Local<Boolean>(ToApi<Boolean>(obj));
2377  } else {
2378  i::Isolate* isolate = i::Isolate::Current();
2379  if (IsDeadCheck(isolate, "v8::Value::ToBoolean()")) {
2380  return Local<Boolean>();
2381  }
2382  LOG_API(isolate, "ToBoolean");
2383  ENTER_V8(isolate);
2385  return Local<Boolean>(ToApi<Boolean>(val));
2386  }
2387 }
2388 
2389 
2391  i::Handle<i::Object> obj = Utils::OpenHandle(this);
2393  if (obj->IsNumber()) {
2394  num = obj;
2395  } else {
2396  i::Isolate* isolate = i::Isolate::Current();
2397  if (IsDeadCheck(isolate, "v8::Value::ToNumber()")) {
2398  return Local<Number>();
2399  }
2400  LOG_API(isolate, "ToNumber");
2401  ENTER_V8(isolate);
2402  EXCEPTION_PREAMBLE(isolate);
2403  num = i::Execution::ToNumber(obj, &has_pending_exception);
2405  }
2406  return Local<Number>(ToApi<Number>(num));
2407 }
2408 
2409 
2411  i::Handle<i::Object> obj = Utils::OpenHandle(this);
2413  if (obj->IsSmi()) {
2414  num = obj;
2415  } else {
2416  i::Isolate* isolate = i::Isolate::Current();
2417  if (IsDeadCheck(isolate, "v8::Value::ToInteger()")) return Local<Integer>();
2418  LOG_API(isolate, "ToInteger");
2419  ENTER_V8(isolate);
2420  EXCEPTION_PREAMBLE(isolate);
2421  num = i::Execution::ToInteger(obj, &has_pending_exception);
2423  }
2424  return Local<Integer>(ToApi<Integer>(num));
2425 }
2426 
2427 
2428 void External::CheckCast(v8::Value* that) {
2429  if (IsDeadCheck(i::Isolate::Current(), "v8::External::Cast()")) return;
2430  i::Handle<i::Object> obj = Utils::OpenHandle(that);
2431  ApiCheck(obj->IsForeign(),
2432  "v8::External::Cast()",
2433  "Could not convert to external");
2434 }
2435 
2436 
2437 void v8::Object::CheckCast(Value* that) {
2438  if (IsDeadCheck(i::Isolate::Current(), "v8::Object::Cast()")) return;
2439  i::Handle<i::Object> obj = Utils::OpenHandle(that);
2440  ApiCheck(obj->IsJSObject(),
2441  "v8::Object::Cast()",
2442  "Could not convert to object");
2443 }
2444 
2445 
2446 void v8::Function::CheckCast(Value* that) {
2447  if (IsDeadCheck(i::Isolate::Current(), "v8::Function::Cast()")) return;
2448  i::Handle<i::Object> obj = Utils::OpenHandle(that);
2449  ApiCheck(obj->IsJSFunction(),
2450  "v8::Function::Cast()",
2451  "Could not convert to function");
2452 }
2453 
2454 
2455 void v8::String::CheckCast(v8::Value* that) {
2456  if (IsDeadCheck(i::Isolate::Current(), "v8::String::Cast()")) return;
2457  i::Handle<i::Object> obj = Utils::OpenHandle(that);
2458  ApiCheck(obj->IsString(),
2459  "v8::String::Cast()",
2460  "Could not convert to string");
2461 }
2462 
2463 
2464 void v8::Number::CheckCast(v8::Value* that) {
2465  if (IsDeadCheck(i::Isolate::Current(), "v8::Number::Cast()")) return;
2466  i::Handle<i::Object> obj = Utils::OpenHandle(that);
2467  ApiCheck(obj->IsNumber(),
2468  "v8::Number::Cast()",
2469  "Could not convert to number");
2470 }
2471 
2472 
2473 void v8::Integer::CheckCast(v8::Value* that) {
2474  if (IsDeadCheck(i::Isolate::Current(), "v8::Integer::Cast()")) return;
2475  i::Handle<i::Object> obj = Utils::OpenHandle(that);
2476  ApiCheck(obj->IsNumber(),
2477  "v8::Integer::Cast()",
2478  "Could not convert to number");
2479 }
2480 
2481 
2482 void v8::Array::CheckCast(Value* that) {
2483  if (IsDeadCheck(i::Isolate::Current(), "v8::Array::Cast()")) return;
2484  i::Handle<i::Object> obj = Utils::OpenHandle(that);
2485  ApiCheck(obj->IsJSArray(),
2486  "v8::Array::Cast()",
2487  "Could not convert to array");
2488 }
2489 
2490 
2491 void v8::Date::CheckCast(v8::Value* that) {
2492  i::Isolate* isolate = i::Isolate::Current();
2493  if (IsDeadCheck(isolate, "v8::Date::Cast()")) return;
2494  i::Handle<i::Object> obj = Utils::OpenHandle(that);
2495  ApiCheck(obj->HasSpecificClassOf(isolate->heap()->Date_symbol()),
2496  "v8::Date::Cast()",
2497  "Could not convert to date");
2498 }
2499 
2500 
2501 void v8::StringObject::CheckCast(v8::Value* that) {
2502  i::Isolate* isolate = i::Isolate::Current();
2503  if (IsDeadCheck(isolate, "v8::StringObject::Cast()")) return;
2504  i::Handle<i::Object> obj = Utils::OpenHandle(that);
2505  ApiCheck(obj->HasSpecificClassOf(isolate->heap()->String_symbol()),
2506  "v8::StringObject::Cast()",
2507  "Could not convert to StringObject");
2508 }
2509 
2510 
2511 void v8::NumberObject::CheckCast(v8::Value* that) {
2512  i::Isolate* isolate = i::Isolate::Current();
2513  if (IsDeadCheck(isolate, "v8::NumberObject::Cast()")) return;
2514  i::Handle<i::Object> obj = Utils::OpenHandle(that);
2515  ApiCheck(obj->HasSpecificClassOf(isolate->heap()->Number_symbol()),
2516  "v8::NumberObject::Cast()",
2517  "Could not convert to NumberObject");
2518 }
2519 
2520 
2521 void v8::BooleanObject::CheckCast(v8::Value* that) {
2522  i::Isolate* isolate = i::Isolate::Current();
2523  if (IsDeadCheck(isolate, "v8::BooleanObject::Cast()")) return;
2524  i::Handle<i::Object> obj = Utils::OpenHandle(that);
2525  ApiCheck(obj->HasSpecificClassOf(isolate->heap()->Boolean_symbol()),
2526  "v8::BooleanObject::Cast()",
2527  "Could not convert to BooleanObject");
2528 }
2529 
2530 
2531 void v8::RegExp::CheckCast(v8::Value* that) {
2532  if (IsDeadCheck(i::Isolate::Current(), "v8::RegExp::Cast()")) return;
2533  i::Handle<i::Object> obj = Utils::OpenHandle(that);
2534  ApiCheck(obj->IsJSRegExp(),
2535  "v8::RegExp::Cast()",
2536  "Could not convert to regular expression");
2537 }
2538 
2539 
2540 bool Value::BooleanValue() const {
2541  i::Handle<i::Object> obj = Utils::OpenHandle(this);
2542  if (obj->IsBoolean()) {
2543  return obj->IsTrue();
2544  } else {
2545  i::Isolate* isolate = i::Isolate::Current();
2546  if (IsDeadCheck(isolate, "v8::Value::BooleanValue()")) return false;
2547  LOG_API(isolate, "BooleanValue");
2548  ENTER_V8(isolate);
2550  return value->IsTrue();
2551  }
2552 }
2553 
2554 
2555 double Value::NumberValue() const {
2556  i::Handle<i::Object> obj = Utils::OpenHandle(this);
2558  if (obj->IsNumber()) {
2559  num = obj;
2560  } else {
2561  i::Isolate* isolate = i::Isolate::Current();
2562  if (IsDeadCheck(isolate, "v8::Value::NumberValue()")) {
2563  return i::OS::nan_value();
2564  }
2565  LOG_API(isolate, "NumberValue");
2566  ENTER_V8(isolate);
2567  EXCEPTION_PREAMBLE(isolate);
2568  num = i::Execution::ToNumber(obj, &has_pending_exception);
2570  }
2571  return num->Number();
2572 }
2573 
2574 
2575 int64_t Value::IntegerValue() const {
2576  i::Handle<i::Object> obj = Utils::OpenHandle(this);
2578  if (obj->IsNumber()) {
2579  num = obj;
2580  } else {
2581  i::Isolate* isolate = i::Isolate::Current();
2582  if (IsDeadCheck(isolate, "v8::Value::IntegerValue()")) return 0;
2583  LOG_API(isolate, "IntegerValue");
2584  ENTER_V8(isolate);
2585  EXCEPTION_PREAMBLE(isolate);
2586  num = i::Execution::ToInteger(obj, &has_pending_exception);
2587  EXCEPTION_BAILOUT_CHECK(isolate, 0);
2588  }
2589  if (num->IsSmi()) {
2590  return i::Smi::cast(*num)->value();
2591  } else {
2592  return static_cast<int64_t>(num->Number());
2593  }
2594 }
2595 
2596 
2598  i::Handle<i::Object> obj = Utils::OpenHandle(this);
2600  if (obj->IsSmi()) {
2601  num = obj;
2602  } else {
2603  i::Isolate* isolate = i::Isolate::Current();
2604  if (IsDeadCheck(isolate, "v8::Value::ToInt32()")) return Local<Int32>();
2605  LOG_API(isolate, "ToInt32");
2606  ENTER_V8(isolate);
2607  EXCEPTION_PREAMBLE(isolate);
2608  num = i::Execution::ToInt32(obj, &has_pending_exception);
2610  }
2611  return Local<Int32>(ToApi<Int32>(num));
2612 }
2613 
2614 
2616  i::Handle<i::Object> obj = Utils::OpenHandle(this);
2618  if (obj->IsSmi()) {
2619  num = obj;
2620  } else {
2621  i::Isolate* isolate = i::Isolate::Current();
2622  if (IsDeadCheck(isolate, "v8::Value::ToUint32()")) return Local<Uint32>();
2623  LOG_API(isolate, "ToUInt32");
2624  ENTER_V8(isolate);
2625  EXCEPTION_PREAMBLE(isolate);
2626  num = i::Execution::ToUint32(obj, &has_pending_exception);
2628  }
2629  return Local<Uint32>(ToApi<Uint32>(num));
2630 }
2631 
2632 
2634  i::Handle<i::Object> obj = Utils::OpenHandle(this);
2635  if (obj->IsSmi()) {
2636  if (i::Smi::cast(*obj)->value() >= 0) return Utils::Uint32ToLocal(obj);
2637  return Local<Uint32>();
2638  }
2639  i::Isolate* isolate = i::Isolate::Current();
2640  if (IsDeadCheck(isolate, "v8::Value::ToArrayIndex()")) return Local<Uint32>();
2641  LOG_API(isolate, "ToArrayIndex");
2642  ENTER_V8(isolate);
2643  EXCEPTION_PREAMBLE(isolate);
2644  i::Handle<i::Object> string_obj =
2645  i::Execution::ToString(obj, &has_pending_exception);
2648  uint32_t index;
2649  if (str->AsArrayIndex(&index)) {
2650  i::Handle<i::Object> value;
2651  if (index <= static_cast<uint32_t>(i::Smi::kMaxValue)) {
2652  value = i::Handle<i::Object>(i::Smi::FromInt(index));
2653  } else {
2654  value = isolate->factory()->NewNumber(index);
2655  }
2656  return Utils::Uint32ToLocal(value);
2657  }
2658  return Local<Uint32>();
2659 }
2660 
2661 
2663  i::Handle<i::Object> obj = Utils::OpenHandle(this);
2664  if (obj->IsSmi()) {
2665  return i::Smi::cast(*obj)->value();
2666  } else {
2667  i::Isolate* isolate = i::Isolate::Current();
2668  if (IsDeadCheck(isolate, "v8::Value::Int32Value()")) return 0;
2669  LOG_API(isolate, "Int32Value (slow)");
2670  ENTER_V8(isolate);
2671  EXCEPTION_PREAMBLE(isolate);
2672  i::Handle<i::Object> num =
2673  i::Execution::ToInt32(obj, &has_pending_exception);
2674  EXCEPTION_BAILOUT_CHECK(isolate, 0);
2675  if (num->IsSmi()) {
2676  return i::Smi::cast(*num)->value();
2677  } else {
2678  return static_cast<int32_t>(num->Number());
2679  }
2680  }
2681 }
2682 
2683 
2684 bool Value::Equals(Handle<Value> that) const {
2685  i::Isolate* isolate = i::Isolate::Current();
2686  if (IsDeadCheck(isolate, "v8::Value::Equals()")
2687  || EmptyCheck("v8::Value::Equals()", this)
2688  || EmptyCheck("v8::Value::Equals()", that)) {
2689  return false;
2690  }
2691  LOG_API(isolate, "Equals");
2692  ENTER_V8(isolate);
2693  i::Handle<i::Object> obj = Utils::OpenHandle(this);
2694  i::Handle<i::Object> other = Utils::OpenHandle(*that);
2695  // If both obj and other are JSObjects, we'd better compare by identity
2696  // immediately when going into JS builtin. The reason is Invoke
2697  // would overwrite global object receiver with global proxy.
2698  if (obj->IsJSObject() && other->IsJSObject()) {
2699  return *obj == *other;
2700  }
2701  i::Handle<i::Object> args[] = { other };
2702  EXCEPTION_PREAMBLE(isolate);
2703  i::Handle<i::Object> result =
2704  CallV8HeapFunction("EQUALS", obj, ARRAY_SIZE(args), args,
2705  &has_pending_exception);
2706  EXCEPTION_BAILOUT_CHECK(isolate, false);
2707  return *result == i::Smi::FromInt(i::EQUAL);
2708 }
2709 
2710 
2712  i::Isolate* isolate = i::Isolate::Current();
2713  if (IsDeadCheck(isolate, "v8::Value::StrictEquals()")
2714  || EmptyCheck("v8::Value::StrictEquals()", this)
2715  || EmptyCheck("v8::Value::StrictEquals()", that)) {
2716  return false;
2717  }
2718  LOG_API(isolate, "StrictEquals");
2719  i::Handle<i::Object> obj = Utils::OpenHandle(this);
2720  i::Handle<i::Object> other = Utils::OpenHandle(*that);
2721  // Must check HeapNumber first, since NaN !== NaN.
2722  if (obj->IsHeapNumber()) {
2723  if (!other->IsNumber()) return false;
2724  double x = obj->Number();
2725  double y = other->Number();
2726  // Must check explicitly for NaN:s on Windows, but -0 works fine.
2727  return x == y && !isnan(x) && !isnan(y);
2728  } else if (*obj == *other) { // Also covers Booleans.
2729  return true;
2730  } else if (obj->IsSmi()) {
2731  return other->IsNumber() && obj->Number() == other->Number();
2732  } else if (obj->IsString()) {
2733  return other->IsString() &&
2734  i::String::cast(*obj)->Equals(i::String::cast(*other));
2735  } else if (obj->IsUndefined() || obj->IsUndetectableObject()) {
2736  return other->IsUndefined() || other->IsUndetectableObject();
2737  } else {
2738  return false;
2739  }
2740 }
2741 
2742 
2743 uint32_t Value::Uint32Value() const {
2744  i::Handle<i::Object> obj = Utils::OpenHandle(this);
2745  if (obj->IsSmi()) {
2746  return i::Smi::cast(*obj)->value();
2747  } else {
2748  i::Isolate* isolate = i::Isolate::Current();
2749  if (IsDeadCheck(isolate, "v8::Value::Uint32Value()")) return 0;
2750  LOG_API(isolate, "Uint32Value");
2751  ENTER_V8(isolate);
2752  EXCEPTION_PREAMBLE(isolate);
2753  i::Handle<i::Object> num =
2754  i::Execution::ToUint32(obj, &has_pending_exception);
2755  EXCEPTION_BAILOUT_CHECK(isolate, 0);
2756  if (num->IsSmi()) {
2757  return i::Smi::cast(*num)->value();
2758  } else {
2759  return static_cast<uint32_t>(num->Number());
2760  }
2761  }
2762 }
2763 
2764 
2766  v8::PropertyAttribute attribs) {
2767  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
2768  ON_BAILOUT(isolate, "v8::Object::Set()", return false);
2769  ENTER_V8(isolate);
2770  i::HandleScope scope(isolate);
2771  i::Handle<i::Object> self = Utils::OpenHandle(this);
2772  i::Handle<i::Object> key_obj = Utils::OpenHandle(*key);
2773  i::Handle<i::Object> value_obj = Utils::OpenHandle(*value);
2774  EXCEPTION_PREAMBLE(isolate);
2776  self,
2777  key_obj,
2778  value_obj,
2779  static_cast<PropertyAttributes>(attribs),
2781  has_pending_exception = obj.is_null();
2782  EXCEPTION_BAILOUT_CHECK(isolate, false);
2783  return true;
2784 }
2785 
2786 
2787 bool v8::Object::Set(uint32_t index, v8::Handle<Value> value) {
2788  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
2789  ON_BAILOUT(isolate, "v8::Object::Set()", return false);
2790  ENTER_V8(isolate);
2791  i::HandleScope scope(isolate);
2792  i::Handle<i::JSObject> self = Utils::OpenHandle(this);
2793  i::Handle<i::Object> value_obj = Utils::OpenHandle(*value);
2794  EXCEPTION_PREAMBLE(isolate);
2796  self,
2797  index,
2798  value_obj,
2799  NONE,
2801  has_pending_exception = obj.is_null();
2802  EXCEPTION_BAILOUT_CHECK(isolate, false);
2803  return true;
2804 }
2805 
2806 
2808  v8::Handle<Value> value,
2809  v8::PropertyAttribute attribs) {
2810  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
2811  ON_BAILOUT(isolate, "v8::Object::ForceSet()", return false);
2812  ENTER_V8(isolate);
2813  i::HandleScope scope(isolate);
2814  i::Handle<i::JSObject> self = Utils::OpenHandle(this);
2815  i::Handle<i::Object> key_obj = Utils::OpenHandle(*key);
2816  i::Handle<i::Object> value_obj = Utils::OpenHandle(*value);
2817  EXCEPTION_PREAMBLE(isolate);
2819  self,
2820  key_obj,
2821  value_obj,
2822  static_cast<PropertyAttributes>(attribs));
2823  has_pending_exception = obj.is_null();
2824  EXCEPTION_BAILOUT_CHECK(isolate, false);
2825  return true;
2826 }
2827 
2828 
2830  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
2831  ON_BAILOUT(isolate, "v8::Object::ForceDelete()", return false);
2832  ENTER_V8(isolate);
2833  i::HandleScope scope(isolate);
2834  i::Handle<i::JSObject> self = Utils::OpenHandle(this);
2835  i::Handle<i::Object> key_obj = Utils::OpenHandle(*key);
2836 
2837  // When deleting a property on the global object using ForceDelete
2838  // deoptimize all functions as optimized code does not check for the hole
2839  // value with DontDelete properties. We have to deoptimize all contexts
2840  // because of possible cross-context inlined functions.
2841  if (self->IsJSGlobalProxy() || self->IsGlobalObject()) {
2843  }
2844 
2845  EXCEPTION_PREAMBLE(isolate);
2846  i::Handle<i::Object> obj = i::ForceDeleteProperty(self, key_obj);
2847  has_pending_exception = obj.is_null();
2848  EXCEPTION_BAILOUT_CHECK(isolate, false);
2849  return obj->IsTrue();
2850 }
2851 
2852 
2854  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
2855  ON_BAILOUT(isolate, "v8::Object::Get()", return Local<v8::Value>());
2856  ENTER_V8(isolate);
2857  i::Handle<i::Object> self = Utils::OpenHandle(this);
2858  i::Handle<i::Object> key_obj = Utils::OpenHandle(*key);
2859  EXCEPTION_PREAMBLE(isolate);
2860  i::Handle<i::Object> result = i::GetProperty(self, key_obj);
2861  has_pending_exception = result.is_null();
2863  return Utils::ToLocal(result);
2864 }
2865 
2866 
2868  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
2869  ON_BAILOUT(isolate, "v8::Object::Get()", return Local<v8::Value>());
2870  ENTER_V8(isolate);
2871  i::Handle<i::JSObject> self = Utils::OpenHandle(this);
2872  EXCEPTION_PREAMBLE(isolate);
2873  i::Handle<i::Object> result = i::Object::GetElement(self, index);
2874  has_pending_exception = result.is_null();
2876  return Utils::ToLocal(result);
2877 }
2878 
2879 
2881  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
2882  ON_BAILOUT(isolate, "v8::Object::GetPropertyAttribute()",
2883  return static_cast<PropertyAttribute>(NONE));
2884  ENTER_V8(isolate);
2885  i::HandleScope scope(isolate);
2886  i::Handle<i::JSObject> self = Utils::OpenHandle(this);
2887  i::Handle<i::Object> key_obj = Utils::OpenHandle(*key);
2888  if (!key_obj->IsString()) {
2889  EXCEPTION_PREAMBLE(isolate);
2890  key_obj = i::Execution::ToString(key_obj, &has_pending_exception);
2891  EXCEPTION_BAILOUT_CHECK(isolate, static_cast<PropertyAttribute>(NONE));
2892  }
2893  i::Handle<i::String> key_string = i::Handle<i::String>::cast(key_obj);
2894  PropertyAttributes result = self->GetPropertyAttribute(*key_string);
2895  if (result == ABSENT) return static_cast<PropertyAttribute>(NONE);
2896  return static_cast<PropertyAttribute>(result);
2897 }
2898 
2899 
2901  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
2902  ON_BAILOUT(isolate, "v8::Object::GetPrototype()",
2903  return Local<v8::Value>());
2904  ENTER_V8(isolate);
2905  i::Handle<i::Object> self = Utils::OpenHandle(this);
2906  i::Handle<i::Object> result(self->GetPrototype());
2907  return Utils::ToLocal(result);
2908 }
2909 
2910 
2912  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
2913  ON_BAILOUT(isolate, "v8::Object::SetPrototype()", return false);
2914  ENTER_V8(isolate);
2915  i::Handle<i::JSObject> self = Utils::OpenHandle(this);
2916  i::Handle<i::Object> value_obj = Utils::OpenHandle(*value);
2917  // We do not allow exceptions thrown while setting the prototype
2918  // to propagate outside.
2919  TryCatch try_catch;
2920  EXCEPTION_PREAMBLE(isolate);
2921  i::Handle<i::Object> result = i::SetPrototype(self, value_obj);
2922  has_pending_exception = result.is_null();
2923  EXCEPTION_BAILOUT_CHECK(isolate, false);
2924  return true;
2925 }
2926 
2927 
2930  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
2931  ON_BAILOUT(isolate,
2932  "v8::Object::FindInstanceInPrototypeChain()",
2933  return Local<v8::Object>());
2934  ENTER_V8(isolate);
2935  i::JSObject* object = *Utils::OpenHandle(this);
2936  i::FunctionTemplateInfo* tmpl_info = *Utils::OpenHandle(*tmpl);
2937  while (!object->IsInstanceOf(tmpl_info)) {
2938  i::Object* prototype = object->GetPrototype();
2939  if (!prototype->IsJSObject()) return Local<Object>();
2940  object = i::JSObject::cast(prototype);
2941  }
2942  return Utils::ToLocal(i::Handle<i::JSObject>(object));
2943 }
2944 
2945 
2947  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
2948  ON_BAILOUT(isolate, "v8::Object::GetPropertyNames()",
2949  return Local<v8::Array>());
2950  ENTER_V8(isolate);
2951  i::HandleScope scope(isolate);
2952  i::Handle<i::JSObject> self = Utils::OpenHandle(this);
2953  bool threw = false;
2954  i::Handle<i::FixedArray> value =
2956  if (threw) return Local<v8::Array>();
2957  // Because we use caching to speed up enumeration it is important
2958  // to never change the result of the basic enumeration function so
2959  // we clone the result.
2960  i::Handle<i::FixedArray> elms = isolate->factory()->CopyFixedArray(value);
2961  i::Handle<i::JSArray> result =
2962  isolate->factory()->NewJSArrayWithElements(elms);
2963  return Utils::ToLocal(scope.CloseAndEscape(result));
2964 }
2965 
2966 
2968  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
2969  ON_BAILOUT(isolate, "v8::Object::GetOwnPropertyNames()",
2970  return Local<v8::Array>());
2971  ENTER_V8(isolate);
2972  i::HandleScope scope(isolate);
2973  i::Handle<i::JSObject> self = Utils::OpenHandle(this);
2974  bool threw = false;
2975  i::Handle<i::FixedArray> value =
2977  if (threw) return Local<v8::Array>();
2978  // Because we use caching to speed up enumeration it is important
2979  // to never change the result of the basic enumeration function so
2980  // we clone the result.
2981  i::Handle<i::FixedArray> elms = isolate->factory()->CopyFixedArray(value);
2982  i::Handle<i::JSArray> result =
2983  isolate->factory()->NewJSArrayWithElements(elms);
2984  return Utils::ToLocal(scope.CloseAndEscape(result));
2985 }
2986 
2987 
2989  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
2990  ON_BAILOUT(isolate, "v8::Object::ObjectProtoToString()",
2991  return Local<v8::String>());
2992  ENTER_V8(isolate);
2993  i::Handle<i::JSObject> self = Utils::OpenHandle(this);
2994 
2995  i::Handle<i::Object> name(self->class_name());
2996 
2997  // Native implementation of Object.prototype.toString (v8natives.js):
2998  // var c = %ClassOf(this);
2999  // if (c === 'Arguments') c = 'Object';
3000  // return "[object " + c + "]";
3001 
3002  if (!name->IsString()) {
3003  return v8::String::New("[object ]");
3004 
3005  } else {
3007  if (class_name->IsEqualTo(i::CStrVector("Arguments"))) {
3008  return v8::String::New("[object Object]");
3009 
3010  } else {
3011  const char* prefix = "[object ";
3012  Local<String> str = Utils::ToLocal(class_name);
3013  const char* postfix = "]";
3014 
3015  int prefix_len = i::StrLength(prefix);
3016  int str_len = str->Length();
3017  int postfix_len = i::StrLength(postfix);
3018 
3019  int buf_len = prefix_len + str_len + postfix_len;
3020  i::ScopedVector<char> buf(buf_len);
3021 
3022  // Write prefix.
3023  char* ptr = buf.start();
3024  memcpy(ptr, prefix, prefix_len * v8::internal::kCharSize);
3025  ptr += prefix_len;
3026 
3027  // Write real content.
3028  str->WriteAscii(ptr, 0, str_len);
3029  ptr += str_len;
3030 
3031  // Write postfix.
3032  memcpy(ptr, postfix, postfix_len * v8::internal::kCharSize);
3033 
3034  // Copy the buffer into a heap-allocated string and return it.
3035  Local<String> result = v8::String::New(buf.start(), buf_len);
3036  return result;
3037  }
3038  }
3039 }
3040 
3041 
3043  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3044  ON_BAILOUT(isolate, "v8::Object::GetConstructor()",
3045  return Local<v8::Function>());
3046  ENTER_V8(isolate);
3047  i::Handle<i::JSObject> self = Utils::OpenHandle(this);
3048  i::Handle<i::Object> constructor(self->GetConstructor());
3049  return Utils::ToLocal(constructor);
3050 }
3051 
3052 
3054  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3055  ON_BAILOUT(isolate, "v8::Object::GetConstructorName()",
3056  return Local<v8::String>());
3057  ENTER_V8(isolate);
3058  i::Handle<i::JSObject> self = Utils::OpenHandle(this);
3059  i::Handle<i::String> name(self->constructor_name());
3060  return Utils::ToLocal(name);
3061 }
3062 
3063 
3065  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3066  ON_BAILOUT(isolate, "v8::Object::Delete()", return false);
3067  ENTER_V8(isolate);
3068  i::HandleScope scope(isolate);
3069  i::Handle<i::JSObject> self = Utils::OpenHandle(this);
3070  i::Handle<i::String> key_obj = Utils::OpenHandle(*key);
3071  return i::JSObject::DeleteProperty(self, key_obj)->IsTrue();
3072 }
3073 
3074 
3076  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3077  ON_BAILOUT(isolate, "v8::Object::Has()", return false);
3078  ENTER_V8(isolate);
3079  i::Handle<i::JSObject> self = Utils::OpenHandle(this);
3080  i::Handle<i::String> key_obj = Utils::OpenHandle(*key);
3081  return self->HasProperty(*key_obj);
3082 }
3083 
3084 
3085 bool v8::Object::Delete(uint32_t index) {
3086  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3087  ON_BAILOUT(isolate, "v8::Object::DeleteProperty()",
3088  return false);
3089  ENTER_V8(isolate);
3090  HandleScope scope;
3091  i::Handle<i::JSObject> self = Utils::OpenHandle(this);
3092  return i::JSObject::DeleteElement(self, index)->IsTrue();
3093 }
3094 
3095 
3096 bool v8::Object::Has(uint32_t index) {
3097  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3098  ON_BAILOUT(isolate, "v8::Object::HasProperty()", return false);
3099  i::Handle<i::JSObject> self = Utils::OpenHandle(this);
3100  return self->HasElement(index);
3101 }
3102 
3103 
3105  AccessorGetter getter,
3106  AccessorSetter setter,
3107  v8::Handle<Value> data,
3108  AccessControl settings,
3109  PropertyAttribute attributes) {
3110  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3111  ON_BAILOUT(isolate, "v8::Object::SetAccessor()", return false);
3112  ENTER_V8(isolate);
3113  i::HandleScope scope(isolate);
3115  i::Handle<i::AccessorInfo> info = MakeAccessorInfo(name, getter, setter, data,
3116  settings, attributes,
3117  signature);
3118  bool fast = Utils::OpenHandle(this)->HasFastProperties();
3119  i::Handle<i::Object> result = i::SetAccessor(Utils::OpenHandle(this), info);
3120  if (result.is_null() || result->IsUndefined()) return false;
3121  if (fast) i::JSObject::TransformToFastProperties(Utils::OpenHandle(this), 0);
3122  return true;
3123 }
3124 
3125 
3127  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3128  ON_BAILOUT(isolate, "v8::Object::HasOwnProperty()",
3129  return false);
3130  return Utils::OpenHandle(this)->HasLocalProperty(
3131  *Utils::OpenHandle(*key));
3132 }
3133 
3134 
3136  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3137  ON_BAILOUT(isolate, "v8::Object::HasRealNamedProperty()",
3138  return false);
3139  return Utils::OpenHandle(this)->HasRealNamedProperty(
3140  *Utils::OpenHandle(*key));
3141 }
3142 
3143 
3145  ON_BAILOUT(Utils::OpenHandle(this)->GetIsolate(),
3146  "v8::Object::HasRealIndexedProperty()",
3147  return false);
3148  return Utils::OpenHandle(this)->HasRealElementProperty(index);
3149 }
3150 
3151 
3153  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3154  ON_BAILOUT(isolate,
3155  "v8::Object::HasRealNamedCallbackProperty()",
3156  return false);
3157  ENTER_V8(isolate);
3158  return Utils::OpenHandle(this)->HasRealNamedCallbackProperty(
3159  *Utils::OpenHandle(*key));
3160 }
3161 
3162 
3164  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3165  ON_BAILOUT(isolate, "v8::Object::HasNamedLookupInterceptor()",
3166  return false);
3167  return Utils::OpenHandle(this)->HasNamedInterceptor();
3168 }
3169 
3170 
3172  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3173  ON_BAILOUT(isolate, "v8::Object::HasIndexedLookupInterceptor()",
3174  return false);
3175  return Utils::OpenHandle(this)->HasIndexedInterceptor();
3176 }
3177 
3178 
3179 static Local<Value> GetPropertyByLookup(i::Isolate* isolate,
3180  i::Handle<i::JSObject> receiver,
3181  i::Handle<i::String> name,
3182  i::LookupResult* lookup) {
3183  if (!lookup->IsProperty()) {
3184  // No real property was found.
3185  return Local<Value>();
3186  }
3187 
3188  // If the property being looked up is a callback, it can throw
3189  // an exception.
3190  EXCEPTION_PREAMBLE(isolate);
3191  PropertyAttributes ignored;
3192  i::Handle<i::Object> result =
3193  i::Object::GetProperty(receiver, receiver, lookup, name,
3194  &ignored);
3195  has_pending_exception = result.is_null();
3196  EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>());
3197 
3198  return Utils::ToLocal(result);
3199 }
3200 
3201 
3203  Handle<String> key) {
3204  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3205  ON_BAILOUT(isolate,
3206  "v8::Object::GetRealNamedPropertyInPrototypeChain()",
3207  return Local<Value>());
3208  ENTER_V8(isolate);
3209  i::Handle<i::JSObject> self_obj = Utils::OpenHandle(this);
3210  i::Handle<i::String> key_obj = Utils::OpenHandle(*key);
3211  i::LookupResult lookup(isolate);
3212  self_obj->LookupRealNamedPropertyInPrototypes(*key_obj, &lookup);
3213  return GetPropertyByLookup(isolate, self_obj, key_obj, &lookup);
3214 }
3215 
3216 
3218  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3219  ON_BAILOUT(isolate, "v8::Object::GetRealNamedProperty()",
3220  return Local<Value>());
3221  ENTER_V8(isolate);
3222  i::Handle<i::JSObject> self_obj = Utils::OpenHandle(this);
3223  i::Handle<i::String> key_obj = Utils::OpenHandle(*key);
3224  i::LookupResult lookup(isolate);
3225  self_obj->LookupRealNamedProperty(*key_obj, &lookup);
3226  return GetPropertyByLookup(isolate, self_obj, key_obj, &lookup);
3227 }
3228 
3229 
3230 // Turns on access checks by copying the map and setting the check flag.
3231 // Because the object gets a new map, existing inline cache caching
3232 // the old map of this object will fail.
3234  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3235  ON_BAILOUT(isolate, "v8::Object::TurnOnAccessCheck()", return);
3236  ENTER_V8(isolate);
3237  i::HandleScope scope(isolate);
3238  i::Handle<i::JSObject> obj = Utils::OpenHandle(this);
3239 
3240  // When turning on access checks for a global object deoptimize all functions
3241  // as optimized code does not always handle access checks.
3243 
3244  i::Handle<i::Map> new_map =
3245  isolate->factory()->CopyMap(i::Handle<i::Map>(obj->map()));
3246  new_map->set_is_access_check_needed(true);
3247  obj->set_map(*new_map);
3248 }
3249 
3250 
3252  return Utils::OpenHandle(this)->IsDirty();
3253 }
3254 
3255 
3257  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3258  ON_BAILOUT(isolate, "v8::Object::Clone()", return Local<Object>());
3259  ENTER_V8(isolate);
3260  i::Handle<i::JSObject> self = Utils::OpenHandle(this);
3261  EXCEPTION_PREAMBLE(isolate);
3262  i::Handle<i::JSObject> result = i::Copy(self);
3263  has_pending_exception = result.is_null();
3265  return Utils::ToLocal(result);
3266 }
3267 
3268 
3269 static i::Context* GetCreationContext(i::JSObject* object) {
3270  i::Object* constructor = object->map()->constructor();
3271  i::JSFunction* function;
3272  if (!constructor->IsJSFunction()) {
3273  // Functions have null as a constructor,
3274  // but any JSFunction knows its context immediately.
3275  ASSERT(object->IsJSFunction());
3276  function = i::JSFunction::cast(object);
3277  } else {
3278  function = i::JSFunction::cast(constructor);
3279  }
3280  return function->context()->native_context();
3281 }
3282 
3283 
3285  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3286  ON_BAILOUT(isolate,
3287  "v8::Object::CreationContext()", return Local<v8::Context>());
3288  ENTER_V8(isolate);
3289  i::Handle<i::JSObject> self = Utils::OpenHandle(this);
3290  i::Context* context = GetCreationContext(*self);
3291  return Utils::ToLocal(i::Handle<i::Context>(context));
3292 }
3293 
3294 
3296  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3297  ON_BAILOUT(isolate, "v8::Object::GetIdentityHash()", return 0);
3298  ENTER_V8(isolate);
3299  i::HandleScope scope(isolate);
3300  i::Handle<i::JSObject> self = Utils::OpenHandle(this);
3301  return i::JSObject::GetIdentityHash(self);
3302 }
3303 
3304 
3306  v8::Handle<v8::Value> value) {
3307  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3308  ON_BAILOUT(isolate, "v8::Object::SetHiddenValue()", return false);
3309  if (value.IsEmpty()) return DeleteHiddenValue(key);
3310  ENTER_V8(isolate);
3311  i::HandleScope scope(isolate);
3312  i::Handle<i::JSObject> self = Utils::OpenHandle(this);
3313  i::Handle<i::String> key_obj = Utils::OpenHandle(*key);
3314  i::Handle<i::String> key_symbol = FACTORY->LookupSymbol(key_obj);
3315  i::Handle<i::Object> value_obj = Utils::OpenHandle(*value);
3316  i::Handle<i::Object> result =
3317  i::JSObject::SetHiddenProperty(self, key_symbol, value_obj);
3318  return *result == *self;
3319 }
3320 
3321 
3323  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3324  ON_BAILOUT(isolate, "v8::Object::GetHiddenValue()",
3325  return Local<v8::Value>());
3326  ENTER_V8(isolate);
3327  i::Handle<i::JSObject> self = Utils::OpenHandle(this);
3328  i::Handle<i::String> key_obj = Utils::OpenHandle(*key);
3329  i::Handle<i::String> key_symbol = FACTORY->LookupSymbol(key_obj);
3330  i::Handle<i::Object> result(self->GetHiddenProperty(*key_symbol));
3331  if (result->IsUndefined()) return v8::Local<v8::Value>();
3332  return Utils::ToLocal(result);
3333 }
3334 
3335 
3337  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3338  ON_BAILOUT(isolate, "v8::DeleteHiddenValue()", return false);
3339  ENTER_V8(isolate);
3340  i::HandleScope scope(isolate);
3341  i::Handle<i::JSObject> self = Utils::OpenHandle(this);
3342  i::Handle<i::String> key_obj = Utils::OpenHandle(*key);
3343  i::Handle<i::String> key_symbol = FACTORY->LookupSymbol(key_obj);
3344  self->DeleteHiddenProperty(*key_symbol);
3345  return true;
3346 }
3347 
3348 
3349 namespace {
3350 
3351 static i::ElementsKind GetElementsKindFromExternalArrayType(
3352  ExternalArrayType array_type) {
3353  switch (array_type) {
3354  case kExternalByteArray:
3356  break;
3359  break;
3360  case kExternalShortArray:
3362  break;
3365  break;
3366  case kExternalIntArray:
3367  return i::EXTERNAL_INT_ELEMENTS;
3368  break;
3371  break;
3372  case kExternalFloatArray:
3374  break;
3375  case kExternalDoubleArray:
3377  break;
3378  case kExternalPixelArray:
3380  break;
3381  }
3382  UNREACHABLE();
3383  return i::DICTIONARY_ELEMENTS;
3384 }
3385 
3386 
3387 void PrepareExternalArrayElements(i::Handle<i::JSObject> object,
3388  void* data,
3389  ExternalArrayType array_type,
3390  int length) {
3391  i::Isolate* isolate = object->GetIsolate();
3393  isolate->factory()->NewExternalArray(length, array_type, data);
3394 
3395  i::Handle<i::Map> external_array_map =
3396  isolate->factory()->GetElementsTransitionMap(
3397  object,
3398  GetElementsKindFromExternalArrayType(array_type));
3399 
3400  object->set_map(*external_array_map);
3401  object->set_elements(*array);
3402 }
3403 
3404 } // namespace
3405 
3406 
3407 void v8::Object::SetIndexedPropertiesToPixelData(uint8_t* data, int length) {
3408  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3409  ON_BAILOUT(isolate, "v8::SetElementsToPixelData()", return);
3410  ENTER_V8(isolate);
3411  i::HandleScope scope(isolate);
3412  if (!ApiCheck(length >= 0 && length <= i::ExternalPixelArray::kMaxLength,
3413  "v8::Object::SetIndexedPropertiesToPixelData()",
3414  "length exceeds max acceptable value")) {
3415  return;
3416  }
3417  i::Handle<i::JSObject> self = Utils::OpenHandle(this);
3418  if (!ApiCheck(!self->IsJSArray(),
3419  "v8::Object::SetIndexedPropertiesToPixelData()",
3420  "JSArray is not supported")) {
3421  return;
3422  }
3423  PrepareExternalArrayElements(self, data, kExternalPixelArray, length);
3424 }
3425 
3426 
3428  i::Handle<i::JSObject> self = Utils::OpenHandle(this);
3429  ON_BAILOUT(self->GetIsolate(), "v8::HasIndexedPropertiesInPixelData()",
3430  return false);
3431  return self->HasExternalPixelElements();
3432 }
3433 
3434 
3436  i::Handle<i::JSObject> self = Utils::OpenHandle(this);
3437  ON_BAILOUT(self->GetIsolate(), "v8::GetIndexedPropertiesPixelData()",
3438  return NULL);
3439  if (self->HasExternalPixelElements()) {
3440  return i::ExternalPixelArray::cast(self->elements())->
3441  external_pixel_pointer();
3442  } else {
3443  return NULL;
3444  }
3445 }
3446 
3447 
3449  i::Handle<i::JSObject> self = Utils::OpenHandle(this);
3450  ON_BAILOUT(self->GetIsolate(), "v8::GetIndexedPropertiesPixelDataLength()",
3451  return -1);
3452  if (self->HasExternalPixelElements()) {
3453  return i::ExternalPixelArray::cast(self->elements())->length();
3454  } else {
3455  return -1;
3456  }
3457 }
3458 
3459 
3461  void* data,
3462  ExternalArrayType array_type,
3463  int length) {
3464  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3465  ON_BAILOUT(isolate, "v8::SetIndexedPropertiesToExternalArrayData()", return);
3466  ENTER_V8(isolate);
3467  i::HandleScope scope(isolate);
3468  if (!ApiCheck(length >= 0 && length <= i::ExternalArray::kMaxLength,
3469  "v8::Object::SetIndexedPropertiesToExternalArrayData()",
3470  "length exceeds max acceptable value")) {
3471  return;
3472  }
3473  i::Handle<i::JSObject> self = Utils::OpenHandle(this);
3474  if (!ApiCheck(!self->IsJSArray(),
3475  "v8::Object::SetIndexedPropertiesToExternalArrayData()",
3476  "JSArray is not supported")) {
3477  return;
3478  }
3479  PrepareExternalArrayElements(self, data, array_type, length);
3480 }
3481 
3482 
3484  i::Handle<i::JSObject> self = Utils::OpenHandle(this);
3485  ON_BAILOUT(self->GetIsolate(),
3486  "v8::HasIndexedPropertiesInExternalArrayData()",
3487  return false);
3488  return self->HasExternalArrayElements();
3489 }
3490 
3491 
3493  i::Handle<i::JSObject> self = Utils::OpenHandle(this);
3494  ON_BAILOUT(self->GetIsolate(),
3495  "v8::GetIndexedPropertiesExternalArrayData()",
3496  return NULL);
3497  if (self->HasExternalArrayElements()) {
3498  return i::ExternalArray::cast(self->elements())->external_pointer();
3499  } else {
3500  return NULL;
3501  }
3502 }
3503 
3504 
3506  i::Handle<i::JSObject> self = Utils::OpenHandle(this);
3507  ON_BAILOUT(self->GetIsolate(),
3508  "v8::GetIndexedPropertiesExternalArrayDataType()",
3509  return static_cast<ExternalArrayType>(-1));
3510  switch (self->elements()->map()->instance_type()) {
3512  return kExternalByteArray;
3516  return kExternalShortArray;
3520  return kExternalIntArray;
3524  return kExternalFloatArray;
3526  return kExternalDoubleArray;
3528  return kExternalPixelArray;
3529  default:
3530  return static_cast<ExternalArrayType>(-1);
3531  }
3532 }
3533 
3534 
3536  i::Handle<i::JSObject> self = Utils::OpenHandle(this);
3537  ON_BAILOUT(self->GetIsolate(),
3538  "v8::GetIndexedPropertiesExternalArrayDataLength()",
3539  return 0);
3540  if (self->HasExternalArrayElements()) {
3541  return i::ExternalArray::cast(self->elements())->length();
3542  } else {
3543  return -1;
3544  }
3545 }
3546 
3547 
3549  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3550  ON_BAILOUT(isolate, "v8::Object::IsCallable()", return false);
3551  ENTER_V8(isolate);
3552  i::HandleScope scope(isolate);
3553  i::Handle<i::JSObject> obj = Utils::OpenHandle(this);
3554  if (obj->IsJSFunction()) return true;
3555  return i::Execution::GetFunctionDelegate(obj)->IsJSFunction();
3556 }
3557 
3558 
3560  int argc,
3561  v8::Handle<v8::Value> argv[]) {
3562  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3563  ON_BAILOUT(isolate, "v8::Object::CallAsFunction()",
3564  return Local<v8::Value>());
3565  LOG_API(isolate, "Object::CallAsFunction");
3566  ENTER_V8(isolate);
3567  i::HandleScope scope(isolate);
3568  i::Handle<i::JSObject> obj = Utils::OpenHandle(this);
3569  i::Handle<i::Object> recv_obj = Utils::OpenHandle(*recv);
3570  STATIC_ASSERT(sizeof(v8::Handle<v8::Value>) == sizeof(i::Object**));
3571  i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv);
3573  if (obj->IsJSFunction()) {
3574  fun = i::Handle<i::JSFunction>::cast(obj);
3575  } else {
3576  EXCEPTION_PREAMBLE(isolate);
3577  i::Handle<i::Object> delegate =
3578  i::Execution::TryGetFunctionDelegate(obj, &has_pending_exception);
3580  fun = i::Handle<i::JSFunction>::cast(delegate);
3581  recv_obj = obj;
3582  }
3583  EXCEPTION_PREAMBLE(isolate);
3584  i::Handle<i::Object> returned =
3585  i::Execution::Call(fun, recv_obj, argc, args, &has_pending_exception);
3587  return Utils::ToLocal(scope.CloseAndEscape(returned));
3588 }
3589 
3590 
3592  v8::Handle<v8::Value> argv[]) {
3593  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3594  ON_BAILOUT(isolate, "v8::Object::CallAsConstructor()",
3595  return Local<v8::Object>());
3596  LOG_API(isolate, "Object::CallAsConstructor");
3597  ENTER_V8(isolate);
3598  i::HandleScope scope(isolate);
3599  i::Handle<i::JSObject> obj = Utils::OpenHandle(this);
3600  STATIC_ASSERT(sizeof(v8::Handle<v8::Value>) == sizeof(i::Object**));
3601  i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv);
3602  if (obj->IsJSFunction()) {
3604  EXCEPTION_PREAMBLE(isolate);
3605  i::Handle<i::Object> returned =
3606  i::Execution::New(fun, argc, args, &has_pending_exception);
3608  return Utils::ToLocal(scope.CloseAndEscape(
3609  i::Handle<i::JSObject>::cast(returned)));
3610  }
3611  EXCEPTION_PREAMBLE(isolate);
3612  i::Handle<i::Object> delegate =
3613  i::Execution::TryGetConstructorDelegate(obj, &has_pending_exception);
3615  if (!delegate->IsUndefined()) {
3617  EXCEPTION_PREAMBLE(isolate);
3618  i::Handle<i::Object> returned =
3619  i::Execution::Call(fun, obj, argc, args, &has_pending_exception);
3621  ASSERT(!delegate->IsUndefined());
3622  return Utils::ToLocal(scope.CloseAndEscape(returned));
3623  }
3624  return Local<v8::Object>();
3625 }
3626 
3627 
3629  return NewInstance(0, NULL);
3630 }
3631 
3632 
3634  v8::Handle<v8::Value> argv[]) const {
3635  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3636  ON_BAILOUT(isolate, "v8::Function::NewInstance()",
3637  return Local<v8::Object>());
3638  LOG_API(isolate, "Function::NewInstance");
3639  ENTER_V8(isolate);
3640  HandleScope scope;
3641  i::Handle<i::JSFunction> function = Utils::OpenHandle(this);
3642  STATIC_ASSERT(sizeof(v8::Handle<v8::Value>) == sizeof(i::Object**));
3643  i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv);
3644  EXCEPTION_PREAMBLE(isolate);
3645  i::Handle<i::Object> returned =
3646  i::Execution::New(function, argc, args, &has_pending_exception);
3648  return scope.Close(Utils::ToLocal(i::Handle<i::JSObject>::cast(returned)));
3649 }
3650 
3651 
3653  v8::Handle<v8::Value> argv[]) {
3654  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3655  ON_BAILOUT(isolate, "v8::Function::Call()", return Local<v8::Value>());
3656  LOG_API(isolate, "Function::Call");
3657  ENTER_V8(isolate);
3658  i::Object* raw_result = NULL;
3659  {
3660  i::HandleScope scope(isolate);
3661  i::Handle<i::JSFunction> fun = Utils::OpenHandle(this);
3662  i::Handle<i::Object> recv_obj = Utils::OpenHandle(*recv);
3663  STATIC_ASSERT(sizeof(v8::Handle<v8::Value>) == sizeof(i::Object**));
3664  i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv);
3665  EXCEPTION_PREAMBLE(isolate);
3666  i::Handle<i::Object> returned =
3667  i::Execution::Call(fun, recv_obj, argc, args, &has_pending_exception);
3669  raw_result = *returned;
3670  }
3671  i::Handle<i::Object> result(raw_result);
3672  return Utils::ToLocal(result);
3673 }
3674 
3675 
3677  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3678  ENTER_V8(isolate);
3679  USE(isolate);
3680  i::Handle<i::JSFunction> func = Utils::OpenHandle(this);
3681  func->shared()->set_name(*Utils::OpenHandle(*name));
3682 }
3683 
3684 
3686  i::Handle<i::JSFunction> func = Utils::OpenHandle(this);
3687  return Utils::ToLocal(i::Handle<i::Object>(func->shared()->name()));
3688 }
3689 
3690 
3692  i::Handle<i::JSFunction> func = Utils::OpenHandle(this);
3693  return Utils::ToLocal(i::Handle<i::Object>(func->shared()->inferred_name()));
3694 }
3695 
3696 
3698  i::Handle<i::JSFunction> func = Utils::OpenHandle(this);
3699  if (func->shared()->script()->IsScript()) {
3700  i::Handle<i::Script> script(i::Script::cast(func->shared()->script()));
3701  v8::ScriptOrigin origin(
3702  Utils::ToLocal(i::Handle<i::Object>(script->name())),
3703  v8::Integer::New(script->line_offset()->value()),
3704  v8::Integer::New(script->column_offset()->value()));
3705  return origin;
3706  }
3707  return v8::ScriptOrigin(Handle<Value>());
3708 }
3709 
3710 
3711 const int Function::kLineOffsetNotFound = -1;
3712 
3713 
3715  i::Handle<i::JSFunction> func = Utils::OpenHandle(this);
3716  if (func->shared()->script()->IsScript()) {
3717  i::Handle<i::Script> script(i::Script::cast(func->shared()->script()));
3718  return i::GetScriptLineNumber(script, func->shared()->start_position());
3719  }
3720  return kLineOffsetNotFound;
3721 }
3722 
3723 
3725  i::Handle<i::JSFunction> func = Utils::OpenHandle(this);
3726  if (func->shared()->script()->IsScript()) {
3727  i::Handle<i::Script> script(i::Script::cast(func->shared()->script()));
3728  return i::GetScriptColumnNumber(script, func->shared()->start_position());
3729  }
3730  return kLineOffsetNotFound;
3731 }
3732 
3734  i::Handle<i::JSFunction> func = Utils::OpenHandle(this);
3735  if (!func->shared()->script()->IsScript())
3736  return v8::Undefined();
3737  i::Handle<i::Script> script(i::Script::cast(func->shared()->script()));
3738  return Utils::ToLocal(i::Handle<i::Object>(script->id()));
3739 }
3740 
3741 int String::Length() const {
3742  i::Handle<i::String> str = Utils::OpenHandle(this);
3743  if (IsDeadCheck(str->GetIsolate(), "v8::String::Length()")) return 0;
3744  return str->length();
3745 }
3746 
3747 
3748 int String::Utf8Length() const {
3749  i::Handle<i::String> str = Utils::OpenHandle(this);
3750  if (IsDeadCheck(str->GetIsolate(), "v8::String::Utf8Length()")) return 0;
3751  return i::Utf8Length(str);
3752 }
3753 
3754 
3755 // Will fail with a negative answer if the recursion depth is too high.
3756 static int RecursivelySerializeToUtf8(i::String* string,
3757  char* buffer,
3758  int start,
3759  int end,
3760  int recursion_budget,
3761  int32_t previous_character,
3762  int32_t* last_character) {
3763  int utf8_bytes = 0;
3764  while (true) {
3765  if (string->IsAsciiRepresentation()) {
3766  i::String::WriteToFlat(string, buffer, start, end);
3767  *last_character = unibrow::Utf16::kNoPreviousCharacter;
3768  return utf8_bytes + end - start;
3769  }
3770  switch (i::StringShape(string).representation_tag()) {
3771  case i::kExternalStringTag: {
3772  const uint16_t* data = i::ExternalTwoByteString::cast(string)->
3773  ExternalTwoByteStringGetData(0);
3774  char* current = buffer;
3775  for (int i = start; i < end; i++) {
3776  uint16_t character = data[i];
3777  current +=
3778  unibrow::Utf8::Encode(current, character, previous_character);
3779  previous_character = character;
3780  }
3781  *last_character = previous_character;
3782  return static_cast<int>(utf8_bytes + current - buffer);
3783  }
3784  case i::kSeqStringTag: {
3785  const uint16_t* data =
3787  char* current = buffer;
3788  for (int i = start; i < end; i++) {
3789  uint16_t character = data[i];
3790  current +=
3791  unibrow::Utf8::Encode(current, character, previous_character);
3792  previous_character = character;
3793  }
3794  *last_character = previous_character;
3795  return static_cast<int>(utf8_bytes + current - buffer);
3796  }
3797  case i::kSlicedStringTag: {
3798  i::SlicedString* slice = i::SlicedString::cast(string);
3799  unsigned offset = slice->offset();
3800  string = slice->parent();
3801  start += offset;
3802  end += offset;
3803  continue;
3804  }
3805  case i::kConsStringTag: {
3806  i::ConsString* cons_string = i::ConsString::cast(string);
3807  i::String* first = cons_string->first();
3808  int boundary = first->length();
3809  if (start >= boundary) {
3810  // Only need RHS.
3811  string = cons_string->second();
3812  start -= boundary;
3813  end -= boundary;
3814  continue;
3815  } else if (end <= boundary) {
3816  // Only need LHS.
3817  string = first;
3818  } else {
3819  if (recursion_budget == 0) return -1;
3820  int extra_utf8_bytes =
3821  RecursivelySerializeToUtf8(first,
3822  buffer,
3823  start,
3824  boundary,
3825  recursion_budget - 1,
3826  previous_character,
3827  &previous_character);
3828  if (extra_utf8_bytes < 0) return extra_utf8_bytes;
3829  buffer += extra_utf8_bytes;
3830  utf8_bytes += extra_utf8_bytes;
3831  string = cons_string->second();
3832  start = 0;
3833  end -= boundary;
3834  }
3835  }
3836  }
3837  }
3838  UNREACHABLE();
3839  return 0;
3840 }
3841 
3842 
3844  i::Handle<i::String> str = Utils::OpenHandle(this);
3845  if (IsDeadCheck(str->GetIsolate(), "v8::String::MayContainNonAscii()")) {
3846  return false;
3847  }
3848  return !str->HasOnlyAsciiChars();
3849 }
3850 
3851 
3852 int String::WriteUtf8(char* buffer,
3853  int capacity,
3854  int* nchars_ref,
3855  int options) const {
3856  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3857  if (IsDeadCheck(isolate, "v8::String::WriteUtf8()")) return 0;
3858  LOG_API(isolate, "String::WriteUtf8");
3859  ENTER_V8(isolate);
3860  i::Handle<i::String> str = Utils::OpenHandle(this);
3861  if (options & HINT_MANY_WRITES_EXPECTED) {
3862  FlattenString(str); // Flatten the string for efficiency.
3863  }
3864  int string_length = str->length();
3865  if (str->IsAsciiRepresentation()) {
3866  int len;
3867  if (capacity == -1) {
3868  capacity = str->length() + 1;
3869  len = string_length;
3870  } else {
3871  len = i::Min(capacity, str->length());
3872  }
3873  i::String::WriteToFlat(*str, buffer, 0, len);
3874  if (nchars_ref != NULL) *nchars_ref = len;
3875  if (!(options & NO_NULL_TERMINATION) && capacity > len) {
3876  buffer[len] = '\0';
3877  return len + 1;
3878  }
3879  return len;
3880  }
3881 
3882  if (capacity == -1 || capacity / 3 >= string_length) {
3884  const int kMaxRecursion = 100;
3885  int utf8_bytes =
3886  RecursivelySerializeToUtf8(*str,
3887  buffer,
3888  0,
3889  string_length,
3890  kMaxRecursion,
3891  previous,
3892  &previous);
3893  if (utf8_bytes >= 0) {
3894  // Success serializing with recursion.
3895  if ((options & NO_NULL_TERMINATION) == 0 &&
3896  (capacity > utf8_bytes || capacity == -1)) {
3897  buffer[utf8_bytes++] = '\0';
3898  }
3899  if (nchars_ref != NULL) *nchars_ref = string_length;
3900  return utf8_bytes;
3901  }
3902  FlattenString(str);
3903  // Recurse once. This time around the string is flat and the serializing
3904  // with recursion will certainly succeed.
3905  return WriteUtf8(buffer, capacity, nchars_ref, options);
3906  } else if (capacity >= string_length) {
3907  // First check that the buffer is large enough. If it is, then recurse
3908  // once without a capacity limit, which will get into the other branch of
3909  // this 'if'.
3910  int utf8_bytes = i::Utf8Length(str);
3911  if ((options & NO_NULL_TERMINATION) == 0) utf8_bytes++;
3912  if (utf8_bytes <= capacity) {
3913  return WriteUtf8(buffer, -1, nchars_ref, options);
3914  }
3915  }
3916 
3917  // Slow case.
3918  i::StringInputBuffer& write_input_buffer = *isolate->write_input_buffer();
3919  isolate->string_tracker()->RecordWrite(str);
3920 
3921  write_input_buffer.Reset(0, *str);
3922  int len = str->length();
3923  // Encode the first K - 3 bytes directly into the buffer since we
3924  // know there's room for them. If no capacity is given we copy all
3925  // of them here.
3926  int fast_end = capacity - (unibrow::Utf8::kMaxEncodedSize - 1);
3927  int i;
3928  int pos = 0;
3929  int nchars = 0;
3930  int previous = unibrow::Utf16::kNoPreviousCharacter;
3931  for (i = 0; i < len && (capacity == -1 || pos < fast_end); i++) {
3932  i::uc32 c = write_input_buffer.GetNext();
3933  int written = unibrow::Utf8::Encode(buffer + pos, c, previous);
3934  pos += written;
3935  nchars++;
3936  previous = c;
3937  }
3938  if (i < len) {
3939  // For the last characters we need to check the length for each one
3940  // because they may be longer than the remaining space in the
3941  // buffer.
3942  char intermediate[unibrow::Utf8::kMaxEncodedSize];
3943  for (; i < len && pos < capacity; i++) {
3944  i::uc32 c = write_input_buffer.GetNext();
3946  unibrow::Utf16::IsLeadSurrogate(previous)) {
3947  // We can't use the intermediate buffer here because the encoding
3948  // of surrogate pairs is done under assumption that you can step
3949  // back and fix the UTF8 stream. Luckily we only need space for one
3950  // more byte, so there is always space.
3951  ASSERT(pos < capacity);
3952  int written = unibrow::Utf8::Encode(buffer + pos, c, previous);
3953  ASSERT(written == 1);
3954  pos += written;
3955  nchars++;
3956  } else {
3957  int written =
3958  unibrow::Utf8::Encode(intermediate,
3959  c,
3961  if (pos + written <= capacity) {
3962  for (int j = 0; j < written; j++) {
3963  buffer[pos + j] = intermediate[j];
3964  }
3965  pos += written;
3966  nchars++;
3967  } else {
3968  // We've reached the end of the buffer
3969  break;
3970  }
3971  }
3972  previous = c;
3973  }
3974  }
3975  if (nchars_ref != NULL) *nchars_ref = nchars;
3976  if (!(options & NO_NULL_TERMINATION) &&
3977  (i == len && (capacity == -1 || pos < capacity))) {
3978  buffer[pos++] = '\0';
3979  }
3980  return pos;
3981 }
3982 
3983 
3984 int String::WriteAscii(char* buffer,
3985  int start,
3986  int length,
3987  int options) const {
3988  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3989  if (IsDeadCheck(isolate, "v8::String::WriteAscii()")) return 0;
3990  LOG_API(isolate, "String::WriteAscii");
3991  ENTER_V8(isolate);
3992  ASSERT(start >= 0 && length >= -1);
3993  i::Handle<i::String> str = Utils::OpenHandle(this);
3994  isolate->string_tracker()->RecordWrite(str);
3995  if (options & HINT_MANY_WRITES_EXPECTED) {
3996  FlattenString(str); // Flatten the string for efficiency.
3997  }
3998 
3999  if (str->IsAsciiRepresentation()) {
4000  // WriteToFlat is faster than using the StringInputBuffer.
4001  if (length == -1) length = str->length() + 1;
4002  int len = i::Min(length, str->length() - start);
4003  i::String::WriteToFlat(*str, buffer, start, start + len);
4004  if (!(options & PRESERVE_ASCII_NULL)) {
4005  for (int i = 0; i < len; i++) {
4006  if (buffer[i] == '\0') buffer[i] = ' ';
4007  }
4008  }
4009  if (!(options & NO_NULL_TERMINATION) && length > len) {
4010  buffer[len] = '\0';
4011  }
4012  return len;
4013  }
4014 
4015  i::StringInputBuffer& write_input_buffer = *isolate->write_input_buffer();
4016  int end = length;
4017  if ((length == -1) || (length > str->length() - start)) {
4018  end = str->length() - start;
4019  }
4020  if (end < 0) return 0;
4021  write_input_buffer.Reset(start, *str);
4022  int i;
4023  for (i = 0; i < end; i++) {
4024  char c = static_cast<char>(write_input_buffer.GetNext());
4025  if (c == '\0' && !(options & PRESERVE_ASCII_NULL)) c = ' ';
4026  buffer[i] = c;
4027  }
4028  if (!(options & NO_NULL_TERMINATION) && (length == -1 || i < length)) {
4029  buffer[i] = '\0';
4030  }
4031  return i;
4032 }
4033 
4034 
4036  int start,
4037  int length,
4038  int options) const {
4039  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
4040  if (IsDeadCheck(isolate, "v8::String::Write()")) return 0;
4041  LOG_API(isolate, "String::Write");
4042  ENTER_V8(isolate);
4043  ASSERT(start >= 0 && length >= -1);
4044  i::Handle<i::String> str = Utils::OpenHandle(this);
4045  isolate->string_tracker()->RecordWrite(str);
4046  if (options & HINT_MANY_WRITES_EXPECTED) {
4047  // Flatten the string for efficiency. This applies whether we are
4048  // using StringInputBuffer or Get(i) to access the characters.
4049  FlattenString(str);
4050  }
4051  int end = start + length;
4052  if ((length == -1) || (length > str->length() - start) )
4053  end = str->length();
4054  if (end < 0) return 0;
4055  i::String::WriteToFlat(*str, buffer, start, end);
4056  if (!(options & NO_NULL_TERMINATION) &&
4057  (length == -1 || end - start < length)) {
4058  buffer[end - start] = '\0';
4059  }
4060  return end - start;
4061 }
4062 
4063 
4065  i::Handle<i::String> str = Utils::OpenHandle(this);
4066  if (IsDeadCheck(str->GetIsolate(), "v8::String::IsExternal()")) {
4067  return false;
4068  }
4069  EnsureInitializedForIsolate(str->GetIsolate(), "v8::String::IsExternal()");
4070  return i::StringShape(*str).IsExternalTwoByte();
4071 }
4072 
4073 
4075  i::Handle<i::String> str = Utils::OpenHandle(this);
4076  if (IsDeadCheck(str->GetIsolate(), "v8::String::IsExternalAscii()")) {
4077  return false;
4078  }
4079  return i::StringShape(*str).IsExternalAscii();
4080 }
4081 
4082 
4083 void v8::String::VerifyExternalStringResource(
4084  v8::String::ExternalStringResource* value) const {
4085  i::Handle<i::String> str = Utils::OpenHandle(this);
4086  const v8::String::ExternalStringResource* expected;
4087  if (i::StringShape(*str).IsExternalTwoByte()) {
4088  const void* resource =
4090  expected = reinterpret_cast<const ExternalStringResource*>(resource);
4091  } else {
4092  expected = NULL;
4093  }
4094  CHECK_EQ(expected, value);
4095 }
4096 
4097 void v8::String::VerifyExternalStringResourceBase(
4098  v8::String::ExternalStringResourceBase* value, Encoding encoding) const {
4099  i::Handle<i::String> str = Utils::OpenHandle(this);
4101  Encoding expectedEncoding;
4102  if (i::StringShape(*str).IsExternalAscii()) {
4103  const void* resource =
4104  i::Handle<i::ExternalAsciiString>::cast(str)->resource();
4105  expected = reinterpret_cast<const ExternalStringResourceBase*>(resource);
4106  expectedEncoding = ASCII_ENCODING;
4107  } else if (i::StringShape(*str).IsExternalTwoByte()) {
4108  const void* resource =
4110  expected = reinterpret_cast<const ExternalStringResourceBase*>(resource);
4111  expectedEncoding = TWO_BYTE_ENCODING;
4112  } else {
4113  expected = NULL;
4114  expectedEncoding = str->IsAsciiRepresentation() ? ASCII_ENCODING
4115  : TWO_BYTE_ENCODING;
4116  }
4117  CHECK_EQ(expected, value);
4118  CHECK_EQ(expectedEncoding, encoding);
4119 }
4120 
4123  i::Handle<i::String> str = Utils::OpenHandle(this);
4124  if (IsDeadCheck(str->GetIsolate(),
4125  "v8::String::GetExternalAsciiStringResource()")) {
4126  return NULL;
4127  }
4128  if (i::StringShape(*str).IsExternalAscii()) {
4129  const void* resource =
4130  i::Handle<i::ExternalAsciiString>::cast(str)->resource();
4131  return reinterpret_cast<const ExternalAsciiStringResource*>(resource);
4132  } else {
4133  return NULL;
4134  }
4135 }
4136 
4137 
4138 double Number::Value() const {
4139  if (IsDeadCheck(i::Isolate::Current(), "v8::Number::Value()")) return 0;
4140  i::Handle<i::Object> obj = Utils::OpenHandle(this);
4141  return obj->Number();
4142 }
4143 
4144 
4145 bool Boolean::Value() const {
4146  if (IsDeadCheck(i::Isolate::Current(), "v8::Boolean::Value()")) return false;
4147  i::Handle<i::Object> obj = Utils::OpenHandle(this);
4148  return obj->IsTrue();
4149 }
4150 
4151 
4152 int64_t Integer::Value() const {
4153  if (IsDeadCheck(i::Isolate::Current(), "v8::Integer::Value()")) return 0;
4154  i::Handle<i::Object> obj = Utils::OpenHandle(this);
4155  if (obj->IsSmi()) {
4156  return i::Smi::cast(*obj)->value();
4157  } else {
4158  return static_cast<int64_t>(obj->Number());
4159  }
4160 }
4161 
4162 
4164  if (IsDeadCheck(i::Isolate::Current(), "v8::Int32::Value()")) return 0;
4165  i::Handle<i::Object> obj = Utils::OpenHandle(this);
4166  if (obj->IsSmi()) {
4167  return i::Smi::cast(*obj)->value();
4168  } else {
4169  return static_cast<int32_t>(obj->Number());
4170  }
4171 }
4172 
4173 
4174 uint32_t Uint32::Value() const {
4175  if (IsDeadCheck(i::Isolate::Current(), "v8::Uint32::Value()")) return 0;
4176  i::Handle<i::Object> obj = Utils::OpenHandle(this);
4177  if (obj->IsSmi()) {
4178  return i::Smi::cast(*obj)->value();
4179  } else {
4180  return static_cast<uint32_t>(obj->Number());
4181  }
4182 }
4183 
4184 
4186  i::Handle<i::JSObject> obj = Utils::OpenHandle(this);
4187  if (IsDeadCheck(obj->GetIsolate(), "v8::Object::InternalFieldCount()")) {
4188  return 0;
4189  }
4190  return obj->GetInternalFieldCount();
4191 }
4192 
4193 
4194 Local<Value> v8::Object::CheckedGetInternalField(int index) {
4195  i::Handle<i::JSObject> obj = Utils::OpenHandle(this);
4196  if (IsDeadCheck(obj->GetIsolate(), "v8::Object::GetInternalField()")) {
4197  return Local<Value>();
4198  }
4199  if (!ApiCheck(index < obj->GetInternalFieldCount(),
4200  "v8::Object::GetInternalField()",
4201  "Reading internal field out of bounds")) {
4202  return Local<Value>();
4203  }
4204  i::Handle<i::Object> value(obj->GetInternalField(index));
4205  Local<Value> result = Utils::ToLocal(value);
4206 #ifdef DEBUG
4207  Local<Value> unchecked = UncheckedGetInternalField(index);
4208  ASSERT(unchecked.IsEmpty() || (unchecked == result));
4209 #endif
4210  return result;
4211 }
4212 
4213 
4215  i::Handle<i::JSObject> obj = Utils::OpenHandle(this);
4216  i::Isolate* isolate = obj->GetIsolate();
4217  if (IsDeadCheck(isolate, "v8::Object::SetInternalField()")) {
4218  return;
4219  }
4220  if (!ApiCheck(index < obj->GetInternalFieldCount(),
4221  "v8::Object::SetInternalField()",
4222  "Writing internal field out of bounds")) {
4223  return;
4224  }
4225  ENTER_V8(isolate);
4226  i::Handle<i::Object> val = Utils::OpenHandle(*value);
4227  obj->SetInternalField(index, *val);
4228 }
4229 
4230 
4231 static bool CanBeEncodedAsSmi(void* ptr) {
4232  const uintptr_t address = reinterpret_cast<uintptr_t>(ptr);
4233  return ((address & i::kEncodablePointerMask) == 0);
4234 }
4235 
4236 
4237 static i::Smi* EncodeAsSmi(void* ptr) {
4238  ASSERT(CanBeEncodedAsSmi(ptr));
4239  const uintptr_t address = reinterpret_cast<uintptr_t>(ptr);
4240  i::Smi* result = reinterpret_cast<i::Smi*>(address << i::kPointerToSmiShift);
4242  ASSERT_EQ(result, i::Smi::FromInt(result->value()));
4244  return result;
4245 }
4246 
4247 
4248 void v8::Object::SetPointerInInternalField(int index, void* value) {
4249  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
4250  ENTER_V8(isolate);
4251  if (CanBeEncodedAsSmi(value)) {
4252  Utils::OpenHandle(this)->SetInternalField(index, EncodeAsSmi(value));
4253  } else {
4254  HandleScope scope;
4255  i::Handle<i::Foreign> foreign =
4256  isolate->factory()->NewForeign(
4257  reinterpret_cast<i::Address>(value), i::TENURED);
4258  if (!foreign.is_null()) {
4259  Utils::OpenHandle(this)->SetInternalField(index, *foreign);
4260  }
4261  }
4262  ASSERT_EQ(value, GetPointerFromInternalField(index));
4263 }
4264 
4265 
4266 // --- E n v i r o n m e n t ---
4267 
4268 
4270  i::Isolate* isolate = i::Isolate::UncheckedCurrent();
4271  if (isolate != NULL && isolate->IsInitialized()) {
4272  return true;
4273  }
4274  return InitializeHelper();
4275 }
4276 
4277 
4279  i::V8::SetEntropySource(source);
4280 }
4281 
4282 
4284  ReturnAddressLocationResolver return_address_resolver) {
4285  i::V8::SetReturnAddressLocationResolver(return_address_resolver);
4286 }
4287 
4288 
4291 }
4292 
4293 
4295  JitCodeEventOptions options, JitCodeEventHandler event_handler) {
4296  i::Isolate* isolate = i::Isolate::Current();
4297  // Ensure that logging is initialized for our isolate.
4298  isolate->InitializeLoggingAndCounters();
4299  isolate->logger()->SetCodeEventHandler(options, event_handler);
4300 }
4301 
4302 
4304  i::Isolate* isolate = i::Isolate::Current();
4305  if (!ApiCheck(isolate != NULL && isolate->IsDefaultIsolate(),
4306  "v8::V8::Dispose()",
4307  "Use v8::Isolate::Dispose() for a non-default isolate.")) {
4308  return false;
4309  }
4310  i::V8::TearDown();
4311  return true;
4312 }
4313 
4314 
4315 HeapStatistics::HeapStatistics(): total_heap_size_(0),
4316  total_heap_size_executable_(0),
4317  used_heap_size_(0),
4318  heap_size_limit_(0) { }
4319 
4320 
4322  if (!i::Isolate::Current()->IsInitialized()) {
4323  // Isolate is unitialized thus heap is not configured yet.
4324  heap_statistics->set_total_heap_size(0);
4325  heap_statistics->set_total_heap_size_executable(0);
4326  heap_statistics->set_used_heap_size(0);
4327  heap_statistics->set_heap_size_limit(0);
4328  return;
4329  }
4330 
4331  i::Heap* heap = i::Isolate::Current()->heap();
4332  heap_statistics->set_total_heap_size(heap->CommittedMemory());
4333  heap_statistics->set_total_heap_size_executable(
4334  heap->CommittedMemoryExecutable());
4335  heap_statistics->set_used_heap_size(heap->SizeOfObjects());
4336  heap_statistics->set_heap_size_limit(heap->MaxReserved());
4337 }
4338 
4339 
4341  i::Isolate* isolate = i::Isolate::Current();
4342  IsDeadCheck(isolate, "v8::V8::VisitExternalResources");
4343  isolate->heap()->VisitExternalResources(visitor);
4344 }
4345 
4346 
4348  i::Isolate* isolate = i::Isolate::Current();
4349  IsDeadCheck(isolate, "v8::V8::VisitHandlesWithClassId");
4350 
4351  i::AssertNoAllocation no_allocation;
4352 
4353  class VisitorAdapter : public i::ObjectVisitor {
4354  public:
4355  explicit VisitorAdapter(PersistentHandleVisitor* visitor)
4356  : visitor_(visitor) {}
4357  virtual void VisitPointers(i::Object** start, i::Object** end) {
4358  UNREACHABLE();
4359  }
4360  virtual void VisitEmbedderReference(i::Object** p, uint16_t class_id) {
4361  visitor_->VisitPersistentHandle(ToApi<Value>(i::Handle<i::Object>(p)),
4362  class_id);
4363  }
4364  private:
4365  PersistentHandleVisitor* visitor_;
4366  } visitor_adapter(visitor);
4367  isolate->global_handles()->IterateAllRootsWithClassIds(&visitor_adapter);
4368 }
4369 
4370 
4372  // Returning true tells the caller that it need not
4373  // continue to call IdleNotification.
4374  i::Isolate* isolate = i::Isolate::Current();
4375  if (isolate == NULL || !isolate->IsInitialized()) return true;
4376  return i::V8::IdleNotification(hint);
4377 }
4378 
4379 
4381  i::Isolate* isolate = i::Isolate::Current();
4382  if (isolate == NULL || !isolate->IsInitialized()) return;
4383  isolate->heap()->CollectAllAvailableGarbage("low memory notification");
4384 }
4385 
4386 
4388  i::Isolate* isolate = i::Isolate::Current();
4389  if (!isolate->IsInitialized()) return 0;
4390  return isolate->heap()->NotifyContextDisposed();
4391 }
4392 
4393 
4394 const char* v8::V8::GetVersion() {
4395  return i::Version::GetVersion();
4396 }
4397 
4398 
4400  EnsureConstructor(i::Handle<i::ObjectTemplateInfo> templ) {
4401  if (templ->constructor()->IsUndefined()) {
4403  Utils::OpenHandle(*constructor)->set_instance_template(*templ);
4404  templ->set_constructor(*Utils::OpenHandle(*constructor));
4405  }
4407  i::FunctionTemplateInfo::cast(templ->constructor()));
4408 }
4409 
4410 
4412  v8::ExtensionConfiguration* extensions,
4413  v8::Handle<ObjectTemplate> global_template,
4414  v8::Handle<Value> global_object) {
4416  i::Isolate* isolate = i::Isolate::Current();
4417  EnsureInitializedForIsolate(isolate, "v8::Context::New()");
4418  LOG_API(isolate, "Context::New");
4419  ON_BAILOUT(isolate, "v8::Context::New()", return Persistent<Context>());
4420 
4421  // Enter V8 via an ENTER_V8 scope.
4423  {
4424  ENTER_V8(isolate);
4425  v8::Handle<ObjectTemplate> proxy_template = global_template;
4426  i::Handle<i::FunctionTemplateInfo> proxy_constructor;
4427  i::Handle<i::FunctionTemplateInfo> global_constructor;
4428 
4429  if (!global_template.IsEmpty()) {
4430  // Make sure that the global_template has a constructor.
4431  global_constructor =
4432  EnsureConstructor(Utils::OpenHandle(*global_template));
4433 
4434  // Create a fresh template for the global proxy object.
4435  proxy_template = ObjectTemplate::New();
4436  proxy_constructor =
4437  EnsureConstructor(Utils::OpenHandle(*proxy_template));
4438 
4439  // Set the global template to be the prototype template of
4440  // global proxy template.
4441  proxy_constructor->set_prototype_template(
4442  *Utils::OpenHandle(*global_template));
4443 
4444  // Migrate security handlers from global_template to
4445  // proxy_template. Temporarily removing access check
4446  // information from the global template.
4447  if (!global_constructor->access_check_info()->IsUndefined()) {
4448  proxy_constructor->set_access_check_info(
4449  global_constructor->access_check_info());
4450  proxy_constructor->set_needs_access_check(
4451  global_constructor->needs_access_check());
4452  global_constructor->set_needs_access_check(false);
4453  global_constructor->set_access_check_info(
4454  isolate->heap()->undefined_value());
4455  }
4456  }
4457 
4458  // Create the environment.
4459  env = isolate->bootstrapper()->CreateEnvironment(
4460  isolate,
4461  Utils::OpenHandle(*global_object, true),
4462  proxy_template,
4463  extensions);
4464 
4465  // Restore the access check info on the global template.
4466  if (!global_template.IsEmpty()) {
4467  ASSERT(!global_constructor.is_null());
4468  ASSERT(!proxy_constructor.is_null());
4469  global_constructor->set_access_check_info(
4470  proxy_constructor->access_check_info());
4471  global_constructor->set_needs_access_check(
4472  proxy_constructor->needs_access_check());
4473  }
4474  isolate->runtime_profiler()->Reset();
4475  }
4476  // Leave V8.
4477 
4478  if (env.is_null()) {
4479  return Persistent<Context>();
4480  }
4481  return Persistent<Context>(Utils::ToLocal(env));
4482 }
4483 
4484 
4486  i::Isolate* isolate = i::Isolate::Current();
4487  if (IsDeadCheck(isolate, "v8::Context::SetSecurityToken()")) {
4488  return;
4489  }
4490  ENTER_V8(isolate);
4491  i::Handle<i::Context> env = Utils::OpenHandle(this);
4492  i::Handle<i::Object> token_handle = Utils::OpenHandle(*token);
4493  env->set_security_token(*token_handle);
4494 }
4495 
4496 
4498  i::Isolate* isolate = i::Isolate::Current();
4499  if (IsDeadCheck(isolate,
4500  "v8::Context::UseDefaultSecurityToken()")) {
4501  return;
4502  }
4503  ENTER_V8(isolate);
4504  i::Handle<i::Context> env = Utils::OpenHandle(this);
4505  env->set_security_token(env->global_object());
4506 }
4507 
4508 
4510  i::Isolate* isolate = i::Isolate::Current();
4511  if (IsDeadCheck(isolate, "v8::Context::GetSecurityToken()")) {
4512  return Handle<Value>();
4513  }
4514  i::Handle<i::Context> env = Utils::OpenHandle(this);
4515  i::Object* security_token = env->security_token();
4516  i::Handle<i::Object> token_handle(security_token);
4517  return Utils::ToLocal(token_handle);
4518 }
4519 
4520 
4522  i::Handle<i::Context> env = Utils::OpenHandle(this);
4523  return env->has_out_of_memory();
4524 }
4525 
4526 
4528  return i::Isolate::Current()->context() != NULL;
4529 }
4530 
4531 
4533  i::Isolate* isolate = i::Isolate::Current();
4534  if (!EnsureInitializedForIsolate(isolate, "v8::Context::GetEntered()")) {
4535  return Local<Context>();
4536  }
4537  i::Handle<i::Object> last =
4539  if (last.is_null()) return Local<Context>();
4541  return Utils::ToLocal(context);
4542 }
4543 
4544 
4546  i::Isolate* isolate = i::Isolate::Current();
4547  if (IsDeadCheck(isolate, "v8::Context::GetCurrent()")) {
4548  return Local<Context>();
4549  }
4550  i::Handle<i::Object> current = isolate->native_context();
4551  if (current.is_null()) return Local<Context>();
4553  return Utils::ToLocal(context);
4554 }
4555 
4556 
4558  i::Isolate* isolate = i::Isolate::Current();
4559  if (IsDeadCheck(isolate, "v8::Context::GetCalling()")) {
4560  return Local<Context>();
4561  }
4562  i::Handle<i::Object> calling =
4563  isolate->GetCallingNativeContext();
4564  if (calling.is_null()) return Local<Context>();
4566  return Utils::ToLocal(context);
4567 }
4568 
4569 
4571  if (IsDeadCheck(i::Isolate::Current(), "v8::Context::Global()")) {
4572  return Local<v8::Object>();
4573  }
4574  i::Object** ctx = reinterpret_cast<i::Object**>(this);
4575  i::Handle<i::Context> context =
4577  i::Handle<i::Object> global(context->global_proxy());
4579 }
4580 
4581 
4583  i::Isolate* isolate = i::Isolate::Current();
4584  if (IsDeadCheck(isolate, "v8::Context::DetachGlobal()")) return;
4585  ENTER_V8(isolate);
4586  i::Object** ctx = reinterpret_cast<i::Object**>(this);
4587  i::Handle<i::Context> context =
4589  isolate->bootstrapper()->DetachGlobal(context);
4590 }
4591 
4592 
4594  i::Isolate* isolate = i::Isolate::Current();
4595  if (IsDeadCheck(isolate, "v8::Context::ReattachGlobal()")) return;
4596  ENTER_V8(isolate);
4597  i::Object** ctx = reinterpret_cast<i::Object**>(this);
4598  i::Handle<i::Context> context =
4600  i::Handle<i::JSGlobalProxy> global_proxy =
4601  i::Handle<i::JSGlobalProxy>::cast(Utils::OpenHandle(*global_object));
4602  isolate->bootstrapper()->ReattachGlobal(context, global_proxy);
4603 }
4604 
4605 
4607  i::Isolate* isolate = i::Isolate::Current();
4608  if (IsDeadCheck(isolate, "v8::Context::AllowCodeGenerationFromStrings()")) {
4609  return;
4610  }
4611  ENTER_V8(isolate);
4612  i::Object** ctx = reinterpret_cast<i::Object**>(this);
4613  i::Handle<i::Context> context =
4615  context->set_allow_code_gen_from_strings(
4616  allow ? isolate->heap()->true_value() : isolate->heap()->false_value());
4617 }
4618 
4619 
4621  i::Isolate* isolate = i::Isolate::Current();
4622  if (IsDeadCheck(isolate,
4623  "v8::Context::IsCodeGenerationFromStringsAllowed()")) {
4624  return false;
4625  }
4626  ENTER_V8(isolate);
4627  i::Object** ctx = reinterpret_cast<i::Object**>(this);
4628  i::Handle<i::Context> context =
4630  return !context->allow_code_gen_from_strings()->IsFalse();
4631 }
4632 
4633 
4635  Handle<String> error) {
4636  i::Isolate* isolate = i::Isolate::Current();
4637  if (IsDeadCheck(isolate,
4638  "v8::Context::SetErrorMessageForCodeGenerationFromStrings()")) {
4639  return;
4640  }
4641  ENTER_V8(isolate);
4642  i::Object** ctx = reinterpret_cast<i::Object**>(this);
4643  i::Handle<i::Context> context =
4645  i::Handle<i::Object> error_handle = Utils::OpenHandle(*error);
4646  context->set_error_message_for_code_gen_from_strings(*error_handle);
4647 }
4648 
4649 
4650 void V8::SetWrapperClassId(i::Object** global_handle, uint16_t class_id) {
4651  i::GlobalHandles::SetWrapperClassId(global_handle, class_id);
4652 }
4653 
4654 
4655 uint16_t V8::GetWrapperClassId(internal::Object** global_handle) {
4656  return i::GlobalHandles::GetWrapperClassId(global_handle);
4657 }
4658 
4659 
4661  i::Isolate* isolate = i::Isolate::Current();
4662  ON_BAILOUT(isolate, "v8::ObjectTemplate::NewInstance()",
4663  return Local<v8::Object>());
4664  LOG_API(isolate, "ObjectTemplate::NewInstance");
4665  ENTER_V8(isolate);
4666  EXCEPTION_PREAMBLE(isolate);
4667  i::Handle<i::Object> obj =
4668  i::Execution::InstantiateObject(Utils::OpenHandle(this),
4669  &has_pending_exception);
4672 }
4673 
4674 
4676  i::Isolate* isolate = i::Isolate::Current();
4677  ON_BAILOUT(isolate, "v8::FunctionTemplate::GetFunction()",
4678  return Local<v8::Function>());
4679  LOG_API(isolate, "FunctionTemplate::GetFunction");
4680  ENTER_V8(isolate);
4681  EXCEPTION_PREAMBLE(isolate);
4682  i::Handle<i::Object> obj =
4683  i::Execution::InstantiateFunction(Utils::OpenHandle(this),
4684  &has_pending_exception);
4687 }
4688 
4689 
4691  ON_BAILOUT(i::Isolate::Current(), "v8::FunctionTemplate::HasInstanceOf()",
4692  return false);
4693  i::Object* obj = *Utils::OpenHandle(*value);
4694  return obj->IsInstanceOf(*Utils::OpenHandle(this));
4695 }
4696 
4697 
4698 static Local<External> ExternalNewImpl(void* data) {
4699  return Utils::ToLocal(FACTORY->NewForeign(static_cast<i::Address>(data)));
4700 }
4701 
4702 static void* ExternalValueImpl(i::Handle<i::Object> obj) {
4703  return reinterpret_cast<void*>(i::Foreign::cast(*obj)->foreign_address());
4704 }
4705 
4706 
4708  i::Isolate* isolate = i::Isolate::Current();
4709  STATIC_ASSERT(sizeof(data) == sizeof(i::Address));
4710  EnsureInitializedForIsolate(isolate, "v8::External::Wrap()");
4711  LOG_API(isolate, "External::Wrap");
4712  ENTER_V8(isolate);
4713 
4714  v8::Local<v8::Value> result = CanBeEncodedAsSmi(data)
4715  ? Utils::ToLocal(i::Handle<i::Object>(EncodeAsSmi(data)))
4716  : v8::Local<v8::Value>(ExternalNewImpl(data));
4717 
4718  ASSERT_EQ(data, Unwrap(result));
4719  return result;
4720 }
4721 
4722 
4723 void* v8::Object::SlowGetPointerFromInternalField(int index) {
4724  i::Handle<i::JSObject> obj = Utils::OpenHandle(this);
4725  i::Object* value = obj->GetInternalField(index);
4726  if (value->IsSmi()) {
4728  } else if (value->IsForeign()) {
4729  return reinterpret_cast<void*>(i::Foreign::cast(value)->foreign_address());
4730  } else {
4731  return NULL;
4732  }
4733 }
4734 
4735 
4736 void* v8::External::FullUnwrap(v8::Handle<v8::Value> wrapper) {
4737  if (IsDeadCheck(i::Isolate::Current(), "v8::External::Unwrap()")) return 0;
4738  i::Handle<i::Object> obj = Utils::OpenHandle(*wrapper);
4739  void* result;
4740  if (obj->IsSmi()) {
4742  } else if (obj->IsForeign()) {
4743  result = ExternalValueImpl(obj);
4744  } else {
4745  result = NULL;
4746  }
4747  ASSERT_EQ(result, QuickUnwrap(wrapper));
4748  return result;
4749 }
4750 
4751 
4753  STATIC_ASSERT(sizeof(data) == sizeof(i::Address));
4754  i::Isolate* isolate = i::Isolate::Current();
4755  EnsureInitializedForIsolate(isolate, "v8::External::New()");
4756  LOG_API(isolate, "External::New");
4757  ENTER_V8(isolate);
4758  return ExternalNewImpl(data);
4759 }
4760 
4761 
4762 void* External::Value() const {
4763  if (IsDeadCheck(i::Isolate::Current(), "v8::External::Value()")) return 0;
4764  i::Handle<i::Object> obj = Utils::OpenHandle(this);
4765  return ExternalValueImpl(obj);
4766 }
4767 
4768 
4770  i::Isolate* isolate = i::Isolate::Current();
4771  if (!EnsureInitializedForIsolate(isolate, "v8::String::Empty()")) {
4772  return v8::Local<String>();
4773  }
4774  LOG_API(isolate, "String::Empty()");
4775  return Utils::ToLocal(isolate->factory()->empty_symbol());
4776 }
4777 
4778 
4779 Local<String> v8::String::New(const char* data, int length) {
4780  i::Isolate* isolate = i::Isolate::Current();
4781  EnsureInitializedForIsolate(isolate, "v8::String::New()");
4782  LOG_API(isolate, "String::New(char)");
4783  if (length == 0) return Empty();
4784  ENTER_V8(isolate);
4785  if (length == -1) length = i::StrLength(data);
4786  i::Handle<i::String> result =
4787  isolate->factory()->NewStringFromUtf8(
4788  i::Vector<const char>(data, length));
4789  return Utils::ToLocal(result);
4790 }
4791 
4792 
4794  i::Handle<i::String> left_string = Utils::OpenHandle(*left);
4795  i::Isolate* isolate = left_string->GetIsolate();
4796  EnsureInitializedForIsolate(isolate, "v8::String::New()");
4797  LOG_API(isolate, "String::New(char)");
4798  ENTER_V8(isolate);
4799  i::Handle<i::String> right_string = Utils::OpenHandle(*right);
4800  i::Handle<i::String> result = isolate->factory()->NewConsString(left_string,
4801  right_string);
4802  return Utils::ToLocal(result);
4803 }
4804 
4805 
4806 Local<String> v8::String::NewUndetectable(const char* data, int length) {
4807  i::Isolate* isolate = i::Isolate::Current();
4808  EnsureInitializedForIsolate(isolate, "v8::String::NewUndetectable()");
4809  LOG_API(isolate, "String::NewUndetectable(char)");
4810  ENTER_V8(isolate);
4811  if (length == -1) length = i::StrLength(data);
4812  i::Handle<i::String> result =
4813  isolate->factory()->NewStringFromUtf8(
4814  i::Vector<const char>(data, length));
4815  result->MarkAsUndetectable();
4816  return Utils::ToLocal(result);
4817 }
4818 
4819 
4820 static int TwoByteStringLength(const uint16_t* data) {
4821  int length = 0;
4822  while (data[length] != '\0') length++;
4823  return length;
4824 }
4825 
4826 
4827 Local<String> v8::String::New(const uint16_t* data, int length) {
4828  i::Isolate* isolate = i::Isolate::Current();
4829  EnsureInitializedForIsolate(isolate, "v8::String::New()");
4830  LOG_API(isolate, "String::New(uint16_)");
4831  if (length == 0) return Empty();
4832  ENTER_V8(isolate);
4833  if (length == -1) length = TwoByteStringLength(data);
4834  i::Handle<i::String> result =
4835  isolate->factory()->NewStringFromTwoByte(
4836  i::Vector<const uint16_t>(data, length));
4837  return Utils::ToLocal(result);
4838 }
4839 
4840 
4842  i::Isolate* isolate = i::Isolate::Current();
4843  EnsureInitializedForIsolate(isolate, "v8::String::NewUndetectable()");
4844  LOG_API(isolate, "String::NewUndetectable(uint16_)");
4845  ENTER_V8(isolate);
4846  if (length == -1) length = TwoByteStringLength(data);
4847  i::Handle<i::String> result =
4848  isolate->factory()->NewStringFromTwoByte(
4849  i::Vector<const uint16_t>(data, length));
4850  result->MarkAsUndetectable();
4851  return Utils::ToLocal(result);
4852 }
4853 
4854 
4857  i::Handle<i::String> result =
4858  isolate->factory()->NewExternalStringFromTwoByte(resource);
4859  return result;
4860 }
4861 
4862 
4865  i::Handle<i::String> result =
4866  isolate->factory()->NewExternalStringFromAscii(resource);
4867  return result;
4868 }
4869 
4870 
4873  i::Isolate* isolate = i::Isolate::Current();
4874  EnsureInitializedForIsolate(isolate, "v8::String::NewExternal()");
4875  LOG_API(isolate, "String::NewExternal");
4876  ENTER_V8(isolate);
4877  CHECK(resource && resource->data());
4878  i::Handle<i::String> result = NewExternalStringHandle(isolate, resource);
4879  isolate->heap()->external_string_table()->AddString(*result);
4880  return Utils::ToLocal(result);
4881 }
4882 
4883 
4885  i::Handle<i::String> obj = Utils::OpenHandle(this);
4886  i::Isolate* isolate = obj->GetIsolate();
4887  if (IsDeadCheck(isolate, "v8::String::MakeExternal()")) return false;
4888  if (i::StringShape(*obj).IsExternalTwoByte()) {
4889  return false; // Already an external string.
4890  }
4891  ENTER_V8(isolate);
4892  if (isolate->string_tracker()->IsFreshUnusedString(obj)) {
4893  return false;
4894  }
4895  if (isolate->heap()->IsInGCPostProcessing()) {
4896  return false;
4897  }
4898  CHECK(resource && resource->data());
4899  bool result = obj->MakeExternal(resource);
4900  if (result && !obj->IsSymbol()) {
4901  isolate->heap()->external_string_table()->AddString(*obj);
4902  }
4903  return result;
4904 }
4905 
4906 
4909  i::Isolate* isolate = i::Isolate::Current();
4910  EnsureInitializedForIsolate(isolate, "v8::String::NewExternal()");
4911  LOG_API(isolate, "String::NewExternal");
4912  ENTER_V8(isolate);
4913  CHECK(resource && resource->data());
4914  i::Handle<i::String> result = NewExternalAsciiStringHandle(isolate, resource);
4915  isolate->heap()->external_string_table()->AddString(*result);
4916  return Utils::ToLocal(result);
4917 }
4918 
4919 
4922  i::Handle<i::String> obj = Utils::OpenHandle(this);
4923  i::Isolate* isolate = obj->GetIsolate();
4924  if (IsDeadCheck(isolate, "v8::String::MakeExternal()")) return false;
4925  if (i::StringShape(*obj).IsExternalTwoByte()) {
4926  return false; // Already an external string.
4927  }
4928  ENTER_V8(isolate);
4929  if (isolate->string_tracker()->IsFreshUnusedString(obj)) {
4930  return false;
4931  }
4932  if (isolate->heap()->IsInGCPostProcessing()) {
4933  return false;
4934  }
4935  CHECK(resource && resource->data());
4936  bool result = obj->MakeExternal(resource);
4937  if (result && !obj->IsSymbol()) {
4938  isolate->heap()->external_string_table()->AddString(*obj);
4939  }
4940  return result;
4941 }
4942 
4943 
4945  if (!internal::FLAG_clever_optimizations) return false;
4946  i::Handle<i::String> obj = Utils::OpenHandle(this);
4947  i::Isolate* isolate = obj->GetIsolate();
4948  if (IsDeadCheck(isolate, "v8::String::CanMakeExternal()")) return false;
4949  if (isolate->string_tracker()->IsFreshUnusedString(obj)) return false;
4950  int size = obj->Size(); // Byte size of the original string.
4951  if (size < i::ExternalString::kShortSize) return false;
4952  i::StringShape shape(*obj);
4953  return !shape.IsExternal();
4954 }
4955 
4956 
4958  i::Isolate* isolate = i::Isolate::Current();
4959  EnsureInitializedForIsolate(isolate, "v8::Object::New()");
4960  LOG_API(isolate, "Object::New");
4961  ENTER_V8(isolate);
4963  isolate->factory()->NewJSObject(isolate->object_function());
4964  return Utils::ToLocal(obj);
4965 }
4966 
4967 
4969  i::Isolate* isolate = i::Isolate::Current();
4970  EnsureInitializedForIsolate(isolate, "v8::NumberObject::New()");
4971  LOG_API(isolate, "NumberObject::New");
4972  ENTER_V8(isolate);
4973  i::Handle<i::Object> number = isolate->factory()->NewNumber(value);
4974  i::Handle<i::Object> obj = isolate->factory()->ToObject(number);
4975  return Utils::ToLocal(obj);
4976 }
4977 
4978 
4980  i::Isolate* isolate = i::Isolate::Current();
4981  if (IsDeadCheck(isolate, "v8::NumberObject::NumberValue()")) return 0;
4982  LOG_API(isolate, "NumberObject::NumberValue");
4983  i::Handle<i::Object> obj = Utils::OpenHandle(this);
4985  return jsvalue->value()->Number();
4986 }
4987 
4988 
4990  i::Isolate* isolate = i::Isolate::Current();
4991  EnsureInitializedForIsolate(isolate, "v8::BooleanObject::New()");
4992  LOG_API(isolate, "BooleanObject::New");
4993  ENTER_V8(isolate);
4994  i::Handle<i::Object> boolean(value ? isolate->heap()->true_value()
4995  : isolate->heap()->false_value());
4996  i::Handle<i::Object> obj = isolate->factory()->ToObject(boolean);
4997  return Utils::ToLocal(obj);
4998 }
4999 
5000 
5002  i::Isolate* isolate = i::Isolate::Current();
5003  if (IsDeadCheck(isolate, "v8::BooleanObject::BooleanValue()")) return 0;
5004  LOG_API(isolate, "BooleanObject::BooleanValue");
5005  i::Handle<i::Object> obj = Utils::OpenHandle(this);
5007  return jsvalue->value()->IsTrue();
5008 }
5009 
5010 
5012  i::Isolate* isolate = i::Isolate::Current();
5013  EnsureInitializedForIsolate(isolate, "v8::StringObject::New()");
5014  LOG_API(isolate, "StringObject::New");
5015  ENTER_V8(isolate);
5016  i::Handle<i::Object> obj =
5017  isolate->factory()->ToObject(Utils::OpenHandle(*value));
5018  return Utils::ToLocal(obj);
5019 }
5020 
5021 
5023  i::Isolate* isolate = i::Isolate::Current();
5024  if (IsDeadCheck(isolate, "v8::StringObject::StringValue()")) {
5025  return Local<v8::String>();
5026  }
5027  LOG_API(isolate, "StringObject::StringValue");
5028  i::Handle<i::Object> obj = Utils::OpenHandle(this);
5030  return Utils::ToLocal(
5031  i::Handle<i::String>(i::String::cast(jsvalue->value())));
5032 }
5033 
5034 
5036  i::Isolate* isolate = i::Isolate::Current();
5037  EnsureInitializedForIsolate(isolate, "v8::Date::New()");
5038  LOG_API(isolate, "Date::New");
5039  if (isnan(time)) {
5040  // Introduce only canonical NaN value into the VM, to avoid signaling NaNs.
5041  time = i::OS::nan_value();
5042  }
5043  ENTER_V8(isolate);
5044  EXCEPTION_PREAMBLE(isolate);
5045  i::Handle<i::Object> obj =
5046  i::Execution::NewDate(time, &has_pending_exception);
5048  return Utils::ToLocal(obj);
5049 }
5050 
5051 
5052 double v8::Date::NumberValue() const {
5053  i::Isolate* isolate = i::Isolate::Current();
5054  if (IsDeadCheck(isolate, "v8::Date::NumberValue()")) return 0;
5055  LOG_API(isolate, "Date::NumberValue");
5056  i::Handle<i::Object> obj = Utils::OpenHandle(this);
5058  return jsdate->value()->Number();
5059 }
5060 
5061 
5063  i::Isolate* isolate = i::Isolate::Current();
5064  ON_BAILOUT(isolate, "v8::Date::DateTimeConfigurationChangeNotification()",
5065  return);
5066  LOG_API(isolate, "Date::DateTimeConfigurationChangeNotification");
5067  ENTER_V8(isolate);
5068 
5069  isolate->date_cache()->ResetDateCache();
5070 
5071  i::HandleScope scope(isolate);
5072  // Get the function ResetDateCache (defined in date.js).
5073  i::Handle<i::String> func_name_str =
5074  isolate->factory()->LookupAsciiSymbol("ResetDateCache");
5075  i::MaybeObject* result =
5076  isolate->js_builtins_object()->GetProperty(*func_name_str);
5077  i::Object* object_func;
5078  if (!result->ToObject(&object_func)) {
5079  return;
5080  }
5081 
5082  if (object_func->IsJSFunction()) {
5085 
5086  // Call ResetDateCache(0 but expect no exceptions:
5087  bool caught_exception = false;
5088  i::Execution::TryCall(func,
5089  isolate->js_builtins_object(),
5090  0,
5091  NULL,
5092  &caught_exception);
5093  }
5094 }
5095 
5096 
5097 static i::Handle<i::String> RegExpFlagsToString(RegExp::Flags flags) {
5098  char flags_buf[3];
5099  int num_flags = 0;
5100  if ((flags & RegExp::kGlobal) != 0) flags_buf[num_flags++] = 'g';
5101  if ((flags & RegExp::kMultiline) != 0) flags_buf[num_flags++] = 'm';
5102  if ((flags & RegExp::kIgnoreCase) != 0) flags_buf[num_flags++] = 'i';
5103  ASSERT(num_flags <= static_cast<int>(ARRAY_SIZE(flags_buf)));
5104  return FACTORY->LookupSymbol(
5105  i::Vector<const char>(flags_buf, num_flags));
5106 }
5107 
5108 
5110  Flags flags) {
5111  i::Isolate* isolate = Utils::OpenHandle(*pattern)->GetIsolate();
5112  EnsureInitializedForIsolate(isolate, "v8::RegExp::New()");
5113  LOG_API(isolate, "RegExp::New");
5114  ENTER_V8(isolate);
5115  EXCEPTION_PREAMBLE(isolate);
5117  Utils::OpenHandle(*pattern),
5118  RegExpFlagsToString(flags),
5119  &has_pending_exception);
5122 }
5123 
5124 
5126  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
5127  if (IsDeadCheck(isolate, "v8::RegExp::GetSource()")) {
5128  return Local<v8::String>();
5129  }
5130  i::Handle<i::JSRegExp> obj = Utils::OpenHandle(this);
5131  return Utils::ToLocal(i::Handle<i::String>(obj->Pattern()));
5132 }
5133 
5134 
5135 // Assert that the static flags cast in GetFlags is valid.
5136 #define REGEXP_FLAG_ASSERT_EQ(api_flag, internal_flag) \
5137  STATIC_ASSERT(static_cast<int>(v8::RegExp::api_flag) == \
5138  static_cast<int>(i::JSRegExp::internal_flag))
5139 REGEXP_FLAG_ASSERT_EQ(kNone, NONE);
5140 REGEXP_FLAG_ASSERT_EQ(kGlobal, GLOBAL);
5141 REGEXP_FLAG_ASSERT_EQ(kIgnoreCase, IGNORE_CASE);
5142 REGEXP_FLAG_ASSERT_EQ(kMultiline, MULTILINE);
5143 #undef REGEXP_FLAG_ASSERT_EQ
5144 
5146  if (IsDeadCheck(i::Isolate::Current(), "v8::RegExp::GetFlags()")) {
5147  return v8::RegExp::kNone;
5148  }
5149  i::Handle<i::JSRegExp> obj = Utils::OpenHandle(this);
5150  return static_cast<RegExp::Flags>(obj->GetFlags().value());
5151 }
5152 
5153 
5155  i::Isolate* isolate = i::Isolate::Current();
5156  EnsureInitializedForIsolate(isolate, "v8::Array::New()");
5157  LOG_API(isolate, "Array::New");
5158  ENTER_V8(isolate);
5159  int real_length = length > 0 ? length : 0;
5160  i::Handle<i::JSArray> obj = isolate->factory()->NewJSArray(real_length);
5161  i::Handle<i::Object> length_obj =
5162  isolate->factory()->NewNumberFromInt(real_length);
5163  obj->set_length(*length_obj);
5164  return Utils::ToLocal(obj);
5165 }
5166 
5167 
5168 uint32_t v8::Array::Length() const {
5169  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
5170  if (IsDeadCheck(isolate, "v8::Array::Length()")) return 0;
5171  i::Handle<i::JSArray> obj = Utils::OpenHandle(this);
5172  i::Object* length = obj->length();
5173  if (length->IsSmi()) {
5174  return i::Smi::cast(length)->value();
5175  } else {
5176  return static_cast<uint32_t>(length->Number());
5177  }
5178 }
5179 
5180 
5182  i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
5183  ON_BAILOUT(isolate, "v8::Array::CloneElementAt()", return Local<Object>());
5184  i::Handle<i::JSObject> self = Utils::OpenHandle(this);
5185  if (!self->HasFastObjectElements()) {
5186  return Local<Object>();
5187  }
5188  i::FixedArray* elms = i::FixedArray::cast(self->elements());
5189  i::Object* paragon = elms->get(index);
5190  if (!paragon->IsJSObject()) {
5191  return Local<Object>();
5192  }
5193  i::Handle<i::JSObject> paragon_handle(i::JSObject::cast(paragon));
5194  EXCEPTION_PREAMBLE(isolate);
5195  ENTER_V8(isolate);
5196  i::Handle<i::JSObject> result = i::Copy(paragon_handle);
5197  has_pending_exception = result.is_null();
5199  return Utils::ToLocal(result);
5200 }
5201 
5202 
5203 Local<String> v8::String::NewSymbol(const char* data, int length) {
5204  i::Isolate* isolate = i::Isolate::Current();
5205  EnsureInitializedForIsolate(isolate, "v8::String::NewSymbol()");
5206  LOG_API(isolate, "String::NewSymbol(char)");
5207  ENTER_V8(isolate);
5208  if (length == -1) length = i::StrLength(data);
5209  i::Handle<i::String> result =
5210  isolate->factory()->LookupSymbol(i::Vector<const char>(data, length));
5211  return Utils::ToLocal(result);
5212 }
5213 
5214 
5216  i::Isolate* isolate = i::Isolate::Current();
5217  EnsureInitializedForIsolate(isolate, "v8::Number::New()");
5218  if (isnan(value)) {
5219  // Introduce only canonical NaN value into the VM, to avoid signaling NaNs.
5220  value = i::OS::nan_value();
5221  }
5222  ENTER_V8(isolate);
5223  i::Handle<i::Object> result = isolate->factory()->NewNumber(value);
5224  return Utils::NumberToLocal(result);
5225 }
5226 
5227 
5229  i::Isolate* isolate = i::Isolate::UncheckedCurrent();
5230  EnsureInitializedForIsolate(isolate, "v8::Integer::New()");
5231  return v8::Integer::New(value, reinterpret_cast<Isolate*>(isolate));
5232 }
5233 
5234 
5236  i::Isolate* isolate = i::Isolate::Current();
5237  EnsureInitializedForIsolate(isolate, "v8::Integer::NewFromUnsigned()");
5238  return Integer::NewFromUnsigned(value, reinterpret_cast<Isolate*>(isolate));
5239 }
5240 
5241 
5243  i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
5244  ASSERT(internal_isolate->IsInitialized());
5245  if (i::Smi::IsValid(value)) {
5247  internal_isolate));
5248  }
5249  ENTER_V8(internal_isolate);
5250  i::Handle<i::Object> result = internal_isolate->factory()->NewNumber(value);
5251  return Utils::IntegerToLocal(result);
5252 }
5253 
5254 
5256  i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
5257  ASSERT(internal_isolate->IsInitialized());
5258  bool fits_into_int32_t = (value & (1 << 31)) == 0;
5259  if (fits_into_int32_t) {
5260  return Integer::New(static_cast<int32_t>(value), isolate);
5261  }
5262  ENTER_V8(internal_isolate);
5263  i::Handle<i::Object> result = internal_isolate->factory()->NewNumber(value);
5264  return Utils::IntegerToLocal(result);
5265 }
5266 
5267 
5269  EnterIsolateIfNeeded()->set_ignore_out_of_memory(true);
5270 }
5271 
5272 
5274  i::Isolate* isolate = i::Isolate::Current();
5275  EnsureInitializedForIsolate(isolate, "v8::V8::AddMessageListener()");
5276  ON_BAILOUT(isolate, "v8::V8::AddMessageListener()", return false);
5277  ENTER_V8(isolate);
5278  i::HandleScope scope(isolate);
5279  NeanderArray listeners(isolate->factory()->message_listeners());
5280  listeners.add(isolate->factory()->NewForeign(FUNCTION_ADDR(that)));
5281  return true;
5282 }
5283 
5284 
5286  i::Isolate* isolate = i::Isolate::Current();
5287  EnsureInitializedForIsolate(isolate, "v8::V8::RemoveMessageListener()");
5288  ON_BAILOUT(isolate, "v8::V8::RemoveMessageListeners()", return);
5289  ENTER_V8(isolate);
5290  i::HandleScope scope(isolate);
5291  NeanderArray listeners(isolate->factory()->message_listeners());
5292  for (int i = 0; i < listeners.length(); i++) {
5293  if (listeners.get(i)->IsUndefined()) continue; // skip deleted ones
5294 
5295  i::Handle<i::Foreign> callback_obj(i::Foreign::cast(listeners.get(i)));
5296  if (callback_obj->foreign_address() == FUNCTION_ADDR(that)) {
5297  listeners.set(i, isolate->heap()->undefined_value());
5298  }
5299  }
5300 }
5301 
5302 
5304  bool capture,
5305  int frame_limit,
5307  i::Isolate::Current()->SetCaptureStackTraceForUncaughtExceptions(
5308  capture,
5309  frame_limit,
5310  options);
5311 }
5312 
5313 
5315  i::Isolate* isolate = EnterIsolateIfNeeded();
5316  if (IsDeadCheck(isolate, "v8::V8::SetCounterFunction()")) return;
5317  isolate->stats_table()->SetCounterFunction(callback);
5318 }
5319 
5321  i::Isolate* isolate = EnterIsolateIfNeeded();
5322  if (IsDeadCheck(isolate, "v8::V8::SetCreateHistogramFunction()")) return;
5323  isolate->stats_table()->SetCreateHistogramFunction(callback);
5324  isolate->InitializeLoggingAndCounters();
5325  isolate->counters()->ResetHistograms();
5326 }
5327 
5329  i::Isolate* isolate = EnterIsolateIfNeeded();
5330  if (IsDeadCheck(isolate, "v8::V8::SetAddHistogramSampleFunction()")) return;
5331  isolate->stats_table()->
5333 }
5334 
5336  i::Isolate* isolate = i::Isolate::Current();
5337  if (IsDeadCheck(isolate, "v8::V8::EnableSlidingStateWindow()")) return;
5338  isolate->logger()->EnableSlidingStateWindow();
5339 }
5340 
5341 
5343  FailedAccessCheckCallback callback) {
5344  i::Isolate* isolate = i::Isolate::Current();
5345  if (IsDeadCheck(isolate, "v8::V8::SetFailedAccessCheckCallbackFunction()")) {
5346  return;
5347  }
5348  isolate->SetFailedAccessCheckCallback(callback);
5349 }
5350 
5352  size_t length,
5353  RetainedObjectInfo* info) {
5354  i::Isolate* isolate = i::Isolate::Current();
5355  if (IsDeadCheck(isolate, "v8::V8::AddObjectGroup()")) return;
5356  STATIC_ASSERT(sizeof(Persistent<Value>) == sizeof(i::Object**));
5357  isolate->global_handles()->AddObjectGroup(
5358  reinterpret_cast<i::Object***>(objects), length, info);
5359 }
5360 
5361 
5363  Persistent<Value>* children,
5364  size_t length) {
5365  i::Isolate* isolate = i::Isolate::Current();
5366  if (IsDeadCheck(isolate, "v8::V8::AddImplicitReferences()")) return;
5367  STATIC_ASSERT(sizeof(Persistent<Value>) == sizeof(i::Object**));
5369  i::Handle<i::HeapObject>::cast(Utils::OpenHandle(*parent)).location(),
5370  reinterpret_cast<i::Object***>(children), length);
5371 }
5372 
5373 
5374 intptr_t V8::AdjustAmountOfExternalAllocatedMemory(intptr_t change_in_bytes) {
5375  i::Isolate* isolate = i::Isolate::UncheckedCurrent();
5376  if (isolate == NULL || !isolate->IsInitialized() ||
5377  IsDeadCheck(isolate, "v8::V8::AdjustAmountOfExternalAllocatedMemory()")) {
5378  return 0;
5379  }
5380  return isolate->heap()->AdjustAmountOfExternalAllocatedMemory(
5381  change_in_bytes);
5382 }
5383 
5384 
5386  i::Isolate* isolate = i::Isolate::Current();
5387  if (IsDeadCheck(isolate, "v8::V8::SetGlobalGCPrologueCallback()")) return;
5388  isolate->heap()->SetGlobalGCPrologueCallback(callback);
5389 }
5390 
5391 
5393  i::Isolate* isolate = i::Isolate::Current();
5394  if (IsDeadCheck(isolate, "v8::V8::SetGlobalGCEpilogueCallback()")) return;
5395  isolate->heap()->SetGlobalGCEpilogueCallback(callback);
5396 }
5397 
5398 
5400  i::Isolate* isolate = i::Isolate::Current();
5401  if (IsDeadCheck(isolate, "v8::V8::AddGCPrologueCallback()")) return;
5402  isolate->heap()->AddGCPrologueCallback(callback, gc_type);
5403 }
5404 
5405 
5407  i::Isolate* isolate = i::Isolate::Current();
5408  if (IsDeadCheck(isolate, "v8::V8::RemoveGCPrologueCallback()")) return;
5409  isolate->heap()->RemoveGCPrologueCallback(callback);
5410 }
5411 
5412 
5414  i::Isolate* isolate = i::Isolate::Current();
5415  if (IsDeadCheck(isolate, "v8::V8::AddGCEpilogueCallback()")) return;
5416  isolate->heap()->AddGCEpilogueCallback(callback, gc_type);
5417 }
5418 
5419 
5421  i::Isolate* isolate = i::Isolate::Current();
5422  if (IsDeadCheck(isolate, "v8::V8::RemoveGCEpilogueCallback()")) return;
5423  isolate->heap()->RemoveGCEpilogueCallback(callback);
5424 }
5425 
5426 
5428  ObjectSpace space,
5429  AllocationAction action) {
5430  i::Isolate* isolate = i::Isolate::Current();
5431  if (IsDeadCheck(isolate, "v8::V8::AddMemoryAllocationCallback()")) return;
5433  callback, space, action);
5434 }
5435 
5436 
5438  i::Isolate* isolate = i::Isolate::Current();
5439  if (IsDeadCheck(isolate, "v8::V8::RemoveMemoryAllocationCallback()")) return;
5441  callback);
5442 }
5443 
5444 
5446  if (callback == NULL) return;
5448  i::Isolate* isolate = i::Isolate::Current();
5449  if (IsDeadCheck(isolate, "v8::V8::AddLeaveScriptCallback()")) return;
5451 }
5452 
5453 
5456  i::Isolate* isolate = i::Isolate::Current();
5457  if (IsDeadCheck(isolate, "v8::V8::RemoveLeaveScriptCallback()")) return;
5459 }
5460 
5461 
5463  i::Isolate* isolate = i::Isolate::Current();
5464  isolate->logger()->PauseProfiler();
5465 }
5466 
5467 
5469  i::Isolate* isolate = i::Isolate::Current();
5470  isolate->logger()->ResumeProfiler();
5471 }
5472 
5473 
5475  i::Isolate* isolate = i::Isolate::Current();
5476  return isolate->logger()->IsProfilerPaused();
5477 }
5478 
5479 
5481  i::Isolate* isolate = i::Isolate::Current();
5482  EnsureInitializedForIsolate(isolate, "V8::GetCurrentThreadId()");
5483  return isolate->thread_id().ToInteger();
5484 }
5485 
5486 
5487 void V8::TerminateExecution(int thread_id) {
5488  i::Isolate* isolate = i::Isolate::Current();
5489  if (!isolate->IsInitialized()) return;
5490  API_ENTRY_CHECK(isolate, "V8::TerminateExecution()");
5491  // If the thread_id identifies the current thread just terminate
5492  // execution right away. Otherwise, ask the thread manager to
5493  // terminate the thread with the given id if any.
5494  i::ThreadId internal_tid = i::ThreadId::FromInteger(thread_id);
5495  if (isolate->thread_id().Equals(internal_tid)) {
5496  isolate->stack_guard()->TerminateExecution();
5497  } else {
5498  isolate->thread_manager()->TerminateExecution(internal_tid);
5499  }
5500 }
5501 
5502 
5504  // If no isolate is supplied, use the default isolate.
5505  if (isolate != NULL) {
5506  reinterpret_cast<i::Isolate*>(isolate)->stack_guard()->TerminateExecution();
5507  } else {
5509  }
5510 }
5511 
5512 
5514  i::Isolate* i_isolate = isolate != NULL ?
5515  reinterpret_cast<i::Isolate*>(isolate) : i::Isolate::Current();
5516  return IsExecutionTerminatingCheck(i_isolate);
5517 }
5518 
5519 
5521  i::Isolate* isolate = i::Isolate::UncheckedCurrent();
5522  return reinterpret_cast<Isolate*>(isolate);
5523 }
5524 
5525 
5527  i::Isolate* isolate = new i::Isolate();
5528  return reinterpret_cast<Isolate*>(isolate);
5529 }
5530 
5531 
5533  i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
5534  if (!ApiCheck(!isolate->IsInUse(),
5535  "v8::Isolate::Dispose()",
5536  "Disposing the isolate that is entered by a thread.")) {
5537  return;
5538  }
5539  isolate->TearDown();
5540 }
5541 
5542 
5544  i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
5545  isolate->Enter();
5546 }
5547 
5548 
5550  i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
5551  isolate->Exit();
5552 }
5553 
5554 
5556  : str_(NULL), length_(0) {
5557  i::Isolate* isolate = i::Isolate::Current();
5558  if (IsDeadCheck(isolate, "v8::String::Utf8Value::Utf8Value()")) return;
5559  if (obj.IsEmpty()) return;
5560  ENTER_V8(isolate);
5561  i::HandleScope scope(isolate);
5562  TryCatch try_catch;
5563  Handle<String> str = obj->ToString();
5564  if (str.IsEmpty()) return;
5565  i::Handle<i::String> i_str = Utils::OpenHandle(*str);
5566  length_ = i::Utf8Length(i_str);
5567  str_ = i::NewArray<char>(length_ + 1);
5568  str->WriteUtf8(str_);
5569 }
5570 
5571 
5573  i::DeleteArray(str_);
5574 }
5575 
5576 
5578  : str_(NULL), length_(0) {
5579  i::Isolate* isolate = i::Isolate::Current();
5580  if (IsDeadCheck(isolate, "v8::String::AsciiValue::AsciiValue()")) return;
5581  if (obj.IsEmpty()) return;
5582  ENTER_V8(isolate);
5583  i::HandleScope scope(isolate);
5584  TryCatch try_catch;
5585  Handle<String> str = obj->ToString();
5586  if (str.IsEmpty()) return;
5587  length_ = str->Length();
5588  str_ = i::NewArray<char>(length_ + 1);
5589  str->WriteAscii(str_);
5590 }
5591 
5592 
5594  i::DeleteArray(str_);
5595 }
5596 
5597 
5599  : str_(NULL), length_(0) {
5600  i::Isolate* isolate = i::Isolate::Current();
5601  if (IsDeadCheck(isolate, "v8::String::Value::Value()")) return;
5602  if (obj.IsEmpty()) return;
5603  ENTER_V8(isolate);
5604  i::HandleScope scope(isolate);
5605  TryCatch try_catch;
5606  Handle<String> str = obj->ToString();
5607  if (str.IsEmpty()) return;
5608  length_ = str->Length();
5609  str_ = i::NewArray<uint16_t>(length_ + 1);
5610  str->Write(str_);
5611 }
5612 
5613 
5615  i::DeleteArray(str_);
5616 }
5617 
5619  i::Isolate* isolate = i::Isolate::Current();
5620  LOG_API(isolate, "RangeError");
5621  ON_BAILOUT(isolate, "v8::Exception::RangeError()", return Local<Value>());
5622  ENTER_V8(isolate);
5623  i::Object* error;
5624  {
5625  i::HandleScope scope(isolate);
5626  i::Handle<i::String> message = Utils::OpenHandle(*raw_message);
5627  i::Handle<i::Object> result = isolate->factory()->NewRangeError(message);
5628  error = *result;
5629  }
5630  i::Handle<i::Object> result(error);
5631  return Utils::ToLocal(result);
5632 }
5633 
5635  i::Isolate* isolate = i::Isolate::Current();
5636  LOG_API(isolate, "ReferenceError");
5637  ON_BAILOUT(isolate, "v8::Exception::ReferenceError()", return Local<Value>());
5638  ENTER_V8(isolate);
5639  i::Object* error;
5640  {
5641  i::HandleScope scope(isolate);
5642  i::Handle<i::String> message = Utils::OpenHandle(*raw_message);
5643  i::Handle<i::Object> result =
5644  isolate->factory()->NewReferenceError(message);
5645  error = *result;
5646  }
5647  i::Handle<i::Object> result(error);
5648  return Utils::ToLocal(result);
5649 }
5650 
5652  i::Isolate* isolate = i::Isolate::Current();
5653  LOG_API(isolate, "SyntaxError");
5654  ON_BAILOUT(isolate, "v8::Exception::SyntaxError()", return Local<Value>());
5655  ENTER_V8(isolate);
5656  i::Object* error;
5657  {
5658  i::HandleScope scope(isolate);
5659  i::Handle<i::String> message = Utils::OpenHandle(*raw_message);
5660  i::Handle<i::Object> result = isolate->factory()->NewSyntaxError(message);
5661  error = *result;
5662  }
5663  i::Handle<i::Object> result(error);
5664  return Utils::ToLocal(result);
5665 }
5666 
5668  i::Isolate* isolate = i::Isolate::Current();
5669  LOG_API(isolate, "TypeError");
5670  ON_BAILOUT(isolate, "v8::Exception::TypeError()", return Local<Value>());
5671  ENTER_V8(isolate);
5672  i::Object* error;
5673  {
5674  i::HandleScope scope(isolate);
5675  i::Handle<i::String> message = Utils::OpenHandle(*raw_message);
5676  i::Handle<i::Object> result = isolate->factory()->NewTypeError(message);
5677  error = *result;
5678  }
5679  i::Handle<i::Object> result(error);
5680  return Utils::ToLocal(result);
5681 }
5682 
5684  i::Isolate* isolate = i::Isolate::Current();
5685  LOG_API(isolate, "Error");
5686  ON_BAILOUT(isolate, "v8::Exception::Error()", return Local<Value>());
5687  ENTER_V8(isolate);
5688  i::Object* error;
5689  {
5690  i::HandleScope scope(isolate);
5691  i::Handle<i::String> message = Utils::OpenHandle(*raw_message);
5692  i::Handle<i::Object> result = isolate->factory()->NewError(message);
5693  error = *result;
5694  }
5695  i::Handle<i::Object> result(error);
5696  return Utils::ToLocal(result);
5697 }
5698 
5699 
5700 // --- D e b u g S u p p o r t ---
5701 
5702 #ifdef ENABLE_DEBUGGER_SUPPORT
5703 
5704 static void EventCallbackWrapper(const v8::Debug::EventDetails& event_details) {
5705  i::Isolate* isolate = i::Isolate::Current();
5706  if (isolate->debug_event_callback() != NULL) {
5707  isolate->debug_event_callback()(event_details.GetEvent(),
5708  event_details.GetExecutionState(),
5709  event_details.GetEventData(),
5710  event_details.GetCallbackData());
5711  }
5712 }
5713 
5714 
5715 bool Debug::SetDebugEventListener(EventCallback that, Handle<Value> data) {
5716  i::Isolate* isolate = i::Isolate::Current();
5717  EnsureInitializedForIsolate(isolate, "v8::Debug::SetDebugEventListener()");
5718  ON_BAILOUT(isolate, "v8::Debug::SetDebugEventListener()", return false);
5719  ENTER_V8(isolate);
5720 
5721  isolate->set_debug_event_callback(that);
5722 
5723  i::HandleScope scope(isolate);
5724  i::Handle<i::Object> foreign = isolate->factory()->undefined_value();
5725  if (that != NULL) {
5726  foreign =
5727  isolate->factory()->NewForeign(FUNCTION_ADDR(EventCallbackWrapper));
5728  }
5729  isolate->debugger()->SetEventListener(foreign,
5730  Utils::OpenHandle(*data, true));
5731  return true;
5732 }
5733 
5734 
5735 bool Debug::SetDebugEventListener2(EventCallback2 that, Handle<Value> data) {
5736  i::Isolate* isolate = i::Isolate::Current();
5737  EnsureInitializedForIsolate(isolate, "v8::Debug::SetDebugEventListener2()");
5738  ON_BAILOUT(isolate, "v8::Debug::SetDebugEventListener2()", return false);
5739  ENTER_V8(isolate);
5740  i::HandleScope scope(isolate);
5741  i::Handle<i::Object> foreign = isolate->factory()->undefined_value();
5742  if (that != NULL) {
5743  foreign = isolate->factory()->NewForeign(FUNCTION_ADDR(that));
5744  }
5745  isolate->debugger()->SetEventListener(foreign,
5746  Utils::OpenHandle(*data, true));
5747  return true;
5748 }
5749 
5750 
5752  Handle<Value> data) {
5753  i::Isolate* isolate = i::Isolate::Current();
5754  ON_BAILOUT(isolate, "v8::Debug::SetDebugEventListener()", return false);
5755  ENTER_V8(isolate);
5756  isolate->debugger()->SetEventListener(Utils::OpenHandle(*that),
5757  Utils::OpenHandle(*data, true));
5758  return true;
5759 }
5760 
5761 
5762 void Debug::DebugBreak(Isolate* isolate) {
5763  // If no isolate is supplied, use the default isolate.
5764  if (isolate != NULL) {
5765  reinterpret_cast<i::Isolate*>(isolate)->stack_guard()->DebugBreak();
5766  } else {
5768  }
5769 }
5770 
5771 
5772 void Debug::CancelDebugBreak(Isolate* isolate) {
5773  // If no isolate is supplied, use the default isolate.
5774  if (isolate != NULL) {
5775  i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
5776  internal_isolate->stack_guard()->Continue(i::DEBUGBREAK);
5777  } else {
5779  }
5780 }
5781 
5782 
5783 void Debug::DebugBreakForCommand(ClientData* data, Isolate* isolate) {
5784  // If no isolate is supplied, use the default isolate.
5785  if (isolate != NULL) {
5786  i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
5787  internal_isolate->debugger()->EnqueueDebugCommand(data);
5788  } else {
5789  i::Isolate::GetDefaultIsolateDebugger()->EnqueueDebugCommand(data);
5790  }
5791 }
5792 
5793 
5794 static void MessageHandlerWrapper(const v8::Debug::Message& message) {
5795  i::Isolate* isolate = i::Isolate::Current();
5796  if (isolate->message_handler()) {
5797  v8::String::Value json(message.GetJSON());
5798  (isolate->message_handler())(*json, json.length(), message.GetClientData());
5799  }
5800 }
5801 
5802 
5804  bool message_handler_thread) {
5805  i::Isolate* isolate = i::Isolate::Current();
5806  EnsureInitializedForIsolate(isolate, "v8::Debug::SetMessageHandler");
5807  ENTER_V8(isolate);
5808 
5809  // Message handler thread not supported any more. Parameter temporally left in
5810  // the API for client compatibility reasons.
5811  CHECK(!message_handler_thread);
5812 
5813  // TODO(sgjesse) support the old message handler API through a simple wrapper.
5814  isolate->set_message_handler(handler);
5815  if (handler != NULL) {
5816  isolate->debugger()->SetMessageHandler(MessageHandlerWrapper);
5817  } else {
5818  isolate->debugger()->SetMessageHandler(NULL);
5819  }
5820 }
5821 
5822 
5824  i::Isolate* isolate = i::Isolate::Current();
5825  EnsureInitializedForIsolate(isolate, "v8::Debug::SetMessageHandler");
5826  ENTER_V8(isolate);
5827  isolate->debugger()->SetMessageHandler(handler);
5828 }
5829 
5830 
5831 void Debug::SendCommand(const uint16_t* command, int length,
5832  ClientData* client_data,
5833  Isolate* isolate) {
5834  // If no isolate is supplied, use the default isolate.
5835  if (isolate != NULL) {
5836  i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
5837  internal_isolate->debugger()->ProcessCommand(
5838  i::Vector<const uint16_t>(command, length), client_data);
5839  } else {
5840  i::Isolate::GetDefaultIsolateDebugger()->ProcessCommand(
5841  i::Vector<const uint16_t>(command, length), client_data);
5842  }
5843 }
5844 
5845 
5846 void Debug::SetHostDispatchHandler(HostDispatchHandler handler,
5847  int period) {
5848  i::Isolate* isolate = i::Isolate::Current();
5849  EnsureInitializedForIsolate(isolate, "v8::Debug::SetHostDispatchHandler");
5850  ENTER_V8(isolate);
5851  isolate->debugger()->SetHostDispatchHandler(handler, period);
5852 }
5853 
5854 
5856  DebugMessageDispatchHandler handler, bool provide_locker) {
5857  i::Isolate* isolate = i::Isolate::Current();
5858  EnsureInitializedForIsolate(isolate,
5859  "v8::Debug::SetDebugMessageDispatchHandler");
5860  ENTER_V8(isolate);
5861  isolate->debugger()->SetDebugMessageDispatchHandler(
5862  handler, provide_locker);
5863 }
5864 
5865 
5866 Local<Value> Debug::Call(v8::Handle<v8::Function> fun,
5867  v8::Handle<v8::Value> data) {
5868  i::Isolate* isolate = i::Isolate::Current();
5869  if (!isolate->IsInitialized()) return Local<Value>();
5870  ON_BAILOUT(isolate, "v8::Debug::Call()", return Local<Value>());
5871  ENTER_V8(isolate);
5872  i::Handle<i::Object> result;
5873  EXCEPTION_PREAMBLE(isolate);
5874  if (data.IsEmpty()) {
5875  result = isolate->debugger()->Call(Utils::OpenHandle(*fun),
5876  isolate->factory()->undefined_value(),
5877  &has_pending_exception);
5878  } else {
5879  result = isolate->debugger()->Call(Utils::OpenHandle(*fun),
5880  Utils::OpenHandle(*data),
5881  &has_pending_exception);
5882  }
5883  EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>());
5884  return Utils::ToLocal(result);
5885 }
5886 
5887 
5888 Local<Value> Debug::GetMirror(v8::Handle<v8::Value> obj) {
5889  i::Isolate* isolate = i::Isolate::Current();
5890  if (!isolate->IsInitialized()) return Local<Value>();
5891  ON_BAILOUT(isolate, "v8::Debug::GetMirror()", return Local<Value>());
5892  ENTER_V8(isolate);
5893  v8::HandleScope scope;
5894  i::Debug* isolate_debug = isolate->debug();
5895  isolate_debug->Load();
5896  i::Handle<i::JSObject> debug(isolate_debug->debug_context()->global_object());
5897  i::Handle<i::String> name =
5898  isolate->factory()->LookupAsciiSymbol("MakeMirror");
5899  i::Handle<i::Object> fun_obj = i::GetProperty(debug, name);
5902  const int kArgc = 1;
5903  v8::Handle<v8::Value> argv[kArgc] = { obj };
5904  EXCEPTION_PREAMBLE(isolate);
5905  v8::Handle<v8::Value> result = v8_fun->Call(Utils::ToLocal(debug),
5906  kArgc,
5907  argv);
5908  EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>());
5909  return scope.Close(result);
5910 }
5911 
5912 
5913 bool Debug::EnableAgent(const char* name, int port, bool wait_for_connection) {
5914  return i::Isolate::Current()->debugger()->StartAgent(name, port,
5915  wait_for_connection);
5916 }
5917 
5918 
5919 void Debug::DisableAgent() {
5920  return i::Isolate::Current()->debugger()->StopAgent();
5921 }
5922 
5923 
5925  i::Execution::ProcessDebugMessages(true);
5926 }
5927 
5928 
5929 Local<Context> Debug::GetDebugContext() {
5930  i::Isolate* isolate = i::Isolate::Current();
5931  EnsureInitializedForIsolate(isolate, "v8::Debug::GetDebugContext()");
5932  ENTER_V8(isolate);
5933  return Utils::ToLocal(i::Isolate::Current()->debugger()->GetDebugContext());
5934 }
5935 
5936 
5937 void Debug::SetLiveEditEnabled(bool enable, Isolate* isolate) {
5938  // If no isolate is supplied, use the default isolate.
5939  i::Debugger* debugger;
5940  if (isolate != NULL) {
5941  i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
5942  debugger = internal_isolate->debugger();
5943  } else {
5944  debugger = i::Isolate::GetDefaultIsolateDebugger();
5945  }
5946  debugger->set_live_edit_enabled(enable);
5947 }
5948 
5949 
5950 #endif // ENABLE_DEBUGGER_SUPPORT
5951 
5952 
5954  i::Isolate* isolate = i::Isolate::Current();
5955  IsDeadCheck(isolate, "v8::CpuProfileNode::GetFunctionName");
5956  const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this);
5957  const i::CodeEntry* entry = node->entry();
5958  if (!entry->has_name_prefix()) {
5959  return Handle<String>(ToApi<String>(
5960  isolate->factory()->LookupAsciiSymbol(entry->name())));
5961  } else {
5962  return Handle<String>(ToApi<String>(isolate->factory()->NewConsString(
5963  isolate->factory()->LookupAsciiSymbol(entry->name_prefix()),
5964  isolate->factory()->LookupAsciiSymbol(entry->name()))));
5965  }
5966 }
5967 
5968 
5970  i::Isolate* isolate = i::Isolate::Current();
5971  IsDeadCheck(isolate, "v8::CpuProfileNode::GetScriptResourceName");
5972  const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this);
5973  return Handle<String>(ToApi<String>(isolate->factory()->LookupAsciiSymbol(
5974  node->entry()->resource_name())));
5975 }
5976 
5977 
5979  i::Isolate* isolate = i::Isolate::Current();
5980  IsDeadCheck(isolate, "v8::CpuProfileNode::GetLineNumber");
5981  return reinterpret_cast<const i::ProfileNode*>(this)->entry()->line_number();
5982 }
5983 
5984 
5986  i::Isolate* isolate = i::Isolate::Current();
5987  IsDeadCheck(isolate, "v8::CpuProfileNode::GetTotalTime");
5988  return reinterpret_cast<const i::ProfileNode*>(this)->GetTotalMillis();
5989 }
5990 
5991 
5993  i::Isolate* isolate = i::Isolate::Current();
5994  IsDeadCheck(isolate, "v8::CpuProfileNode::GetSelfTime");
5995  return reinterpret_cast<const i::ProfileNode*>(this)->GetSelfMillis();
5996 }
5997 
5998 
6000  i::Isolate* isolate = i::Isolate::Current();
6001  IsDeadCheck(isolate, "v8::CpuProfileNode::GetTotalSamplesCount");
6002  return reinterpret_cast<const i::ProfileNode*>(this)->total_ticks();
6003 }
6004 
6005 
6007  i::Isolate* isolate = i::Isolate::Current();
6008  IsDeadCheck(isolate, "v8::CpuProfileNode::GetSelfSamplesCount");
6009  return reinterpret_cast<const i::ProfileNode*>(this)->self_ticks();
6010 }
6011 
6012 
6013 unsigned CpuProfileNode::GetCallUid() const {
6014  i::Isolate* isolate = i::Isolate::Current();
6015  IsDeadCheck(isolate, "v8::CpuProfileNode::GetCallUid");
6016  return reinterpret_cast<const i::ProfileNode*>(this)->entry()->GetCallUid();
6017 }
6018 
6019 
6021  i::Isolate* isolate = i::Isolate::Current();
6022  IsDeadCheck(isolate, "v8::CpuProfileNode::GetChildrenCount");
6023  return reinterpret_cast<const i::ProfileNode*>(this)->children()->length();
6024 }
6025 
6026 
6027 const CpuProfileNode* CpuProfileNode::GetChild(int index) const {
6028  i::Isolate* isolate = i::Isolate::Current();
6029  IsDeadCheck(isolate, "v8::CpuProfileNode::GetChild");
6030  const i::ProfileNode* child =
6031  reinterpret_cast<const i::ProfileNode*>(this)->children()->at(index);
6032  return reinterpret_cast<const CpuProfileNode*>(child);
6033 }
6034 
6035 
6037  i::Isolate* isolate = i::Isolate::Current();
6038  IsDeadCheck(isolate, "v8::CpuProfile::Delete");
6039  i::CpuProfiler::DeleteProfile(reinterpret_cast<i::CpuProfile*>(this));
6040  if (i::CpuProfiler::GetProfilesCount() == 0 &&
6042  // If this was the last profile, clean up all accessory data as well.
6044  }
6045 }
6046 
6047 
6048 unsigned CpuProfile::GetUid() const {
6049  i::Isolate* isolate = i::Isolate::Current();
6050  IsDeadCheck(isolate, "v8::CpuProfile::GetUid");
6051  return reinterpret_cast<const i::CpuProfile*>(this)->uid();
6052 }
6053 
6054 
6056  i::Isolate* isolate = i::Isolate::Current();
6057  IsDeadCheck(isolate, "v8::CpuProfile::GetTitle");
6058  const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this);
6059  return Handle<String>(ToApi<String>(isolate->factory()->LookupAsciiSymbol(
6060  profile->title())));
6061 }
6062 
6063 
6065  i::Isolate* isolate = i::Isolate::Current();
6066  IsDeadCheck(isolate, "v8::CpuProfile::GetBottomUpRoot");
6067  const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this);
6068  return reinterpret_cast<const CpuProfileNode*>(profile->bottom_up()->root());
6069 }
6070 
6071 
6073  i::Isolate* isolate = i::Isolate::Current();
6074  IsDeadCheck(isolate, "v8::CpuProfile::GetTopDownRoot");
6075  const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this);
6076  return reinterpret_cast<const CpuProfileNode*>(profile->top_down()->root());
6077 }
6078 
6079 
6081  i::Isolate* isolate = i::Isolate::Current();
6082  IsDeadCheck(isolate, "v8::CpuProfiler::GetProfilesCount");
6084 }
6085 
6086 
6088  Handle<Value> security_token) {
6089  i::Isolate* isolate = i::Isolate::Current();
6090  IsDeadCheck(isolate, "v8::CpuProfiler::GetProfile");
6091  return reinterpret_cast<const CpuProfile*>(
6093  security_token.IsEmpty() ? NULL : *Utils::OpenHandle(*security_token),
6094  index));
6095 }
6096 
6097 
6099  Handle<Value> security_token) {
6100  i::Isolate* isolate = i::Isolate::Current();
6101  IsDeadCheck(isolate, "v8::CpuProfiler::FindProfile");
6102  return reinterpret_cast<const CpuProfile*>(
6104  security_token.IsEmpty() ? NULL : *Utils::OpenHandle(*security_token),
6105  uid));
6106 }
6107 
6108 
6110  i::Isolate* isolate = i::Isolate::Current();
6111  IsDeadCheck(isolate, "v8::CpuProfiler::StartProfiling");
6112  i::CpuProfiler::StartProfiling(*Utils::OpenHandle(*title));
6113 }
6114 
6115 
6117  Handle<Value> security_token) {
6118  i::Isolate* isolate = i::Isolate::Current();
6119  IsDeadCheck(isolate, "v8::CpuProfiler::StopProfiling");
6120  return reinterpret_cast<const CpuProfile*>(
6122  security_token.IsEmpty() ? NULL : *Utils::OpenHandle(*security_token),
6123  *Utils::OpenHandle(*title)));
6124 }
6125 
6126 
6128  i::Isolate* isolate = i::Isolate::Current();
6129  IsDeadCheck(isolate, "v8::CpuProfiler::DeleteAllProfiles");
6131 }
6132 
6133 
6134 static i::HeapGraphEdge* ToInternal(const HeapGraphEdge* edge) {
6135  return const_cast<i::HeapGraphEdge*>(
6136  reinterpret_cast<const i::HeapGraphEdge*>(edge));
6137 }
6138 
6139 
6141  i::Isolate* isolate = i::Isolate::Current();
6142  IsDeadCheck(isolate, "v8::HeapGraphEdge::GetType");
6143  return static_cast<HeapGraphEdge::Type>(ToInternal(this)->type());
6144 }
6145 
6146 
6148  i::Isolate* isolate = i::Isolate::Current();
6149  IsDeadCheck(isolate, "v8::HeapGraphEdge::GetName");
6150  i::HeapGraphEdge* edge = ToInternal(this);
6151  switch (edge->type()) {
6152  case i::HeapGraphEdge::kContextVariable:
6153  case i::HeapGraphEdge::kInternal:
6154  case i::HeapGraphEdge::kProperty:
6155  case i::HeapGraphEdge::kShortcut:
6156  return Handle<String>(ToApi<String>(isolate->factory()->LookupAsciiSymbol(
6157  edge->name())));
6158  case i::HeapGraphEdge::kElement:
6159  case i::HeapGraphEdge::kHidden:
6160  return Handle<Number>(ToApi<Number>(isolate->factory()->NewNumberFromInt(
6161  edge->index())));
6162  default: UNREACHABLE();
6163  }
6164  return v8::Undefined();
6165 }
6166 
6167 
6169  i::Isolate* isolate = i::Isolate::Current();
6170  IsDeadCheck(isolate, "v8::HeapGraphEdge::GetFromNode");
6171  const i::HeapEntry* from = ToInternal(this)->from();
6172  return reinterpret_cast<const HeapGraphNode*>(from);
6173 }
6174 
6175 
6177  i::Isolate* isolate = i::Isolate::Current();
6178  IsDeadCheck(isolate, "v8::HeapGraphEdge::GetToNode");
6179  const i::HeapEntry* to = ToInternal(this)->to();
6180  return reinterpret_cast<const HeapGraphNode*>(to);
6181 }
6182 
6183 
6184 static i::HeapEntry* ToInternal(const HeapGraphNode* entry) {
6185  return const_cast<i::HeapEntry*>(
6186  reinterpret_cast<const i::HeapEntry*>(entry));
6187 }
6188 
6189 
6191  i::Isolate* isolate = i::Isolate::Current();
6192  IsDeadCheck(isolate, "v8::HeapGraphNode::GetType");
6193  return static_cast<HeapGraphNode::Type>(ToInternal(this)->type());
6194 }
6195 
6196 
6198  i::Isolate* isolate = i::Isolate::Current();
6199  IsDeadCheck(isolate, "v8::HeapGraphNode::GetName");
6200  return Handle<String>(ToApi<String>(isolate->factory()->LookupAsciiSymbol(
6201  ToInternal(this)->name())));
6202 }
6203 
6204 
6206  i::Isolate* isolate = i::Isolate::Current();
6207  IsDeadCheck(isolate, "v8::HeapGraphNode::GetId");
6208  return ToInternal(this)->id();
6209 }
6210 
6211 
6213  i::Isolate* isolate = i::Isolate::Current();
6214  IsDeadCheck(isolate, "v8::HeapGraphNode::GetSelfSize");
6215  return ToInternal(this)->self_size();
6216 }
6217 
6218 
6220  i::Isolate* isolate = i::Isolate::Current();
6221  IsDeadCheck(isolate, "v8::HeapSnapshot::GetChildrenCount");
6222  return ToInternal(this)->children().length();
6223 }
6224 
6225 
6226 const HeapGraphEdge* HeapGraphNode::GetChild(int index) const {
6227  i::Isolate* isolate = i::Isolate::Current();
6228  IsDeadCheck(isolate, "v8::HeapSnapshot::GetChild");
6229  return reinterpret_cast<const HeapGraphEdge*>(
6230  ToInternal(this)->children()[index]);
6231 }
6232 
6233 
6235  i::Isolate* isolate = i::Isolate::Current();
6236  IsDeadCheck(isolate, "v8::HeapGraphNode::GetHeapValue");
6237  i::Handle<i::HeapObject> object = ToInternal(this)->GetHeapObject();
6238  return v8::Handle<Value>(!object.is_null() ?
6239  ToApi<Value>(object) : ToApi<Value>(
6240  isolate->factory()->undefined_value()));
6241 }
6242 
6243 
6244 static i::HeapSnapshot* ToInternal(const HeapSnapshot* snapshot) {
6245  return const_cast<i::HeapSnapshot*>(
6246  reinterpret_cast<const i::HeapSnapshot*>(snapshot));
6247 }
6248 
6249 
6251  i::Isolate* isolate = i::Isolate::Current();
6252  IsDeadCheck(isolate, "v8::HeapSnapshot::Delete");
6254  ToInternal(this)->Delete();
6255  } else {
6256  // If this is the last snapshot, clean up all accessory data as well.
6258  }
6259 }
6260 
6261 
6263  i::Isolate* isolate = i::Isolate::Current();
6264  IsDeadCheck(isolate, "v8::HeapSnapshot::GetType");
6265  return static_cast<HeapSnapshot::Type>(ToInternal(this)->type());
6266 }
6267 
6268 
6269 unsigned HeapSnapshot::GetUid() const {
6270  i::Isolate* isolate = i::Isolate::Current();
6271  IsDeadCheck(isolate, "v8::HeapSnapshot::GetUid");
6272  return ToInternal(this)->uid();
6273 }
6274 
6275 
6277  i::Isolate* isolate = i::Isolate::Current();
6278  IsDeadCheck(isolate, "v8::HeapSnapshot::GetTitle");
6279  return Handle<String>(ToApi<String>(isolate->factory()->LookupAsciiSymbol(
6280  ToInternal(this)->title())));
6281 }
6282 
6283 
6285  i::Isolate* isolate = i::Isolate::Current();
6286  IsDeadCheck(isolate, "v8::HeapSnapshot::GetHead");
6287  return reinterpret_cast<const HeapGraphNode*>(ToInternal(this)->root());
6288 }
6289 
6290 
6292  i::Isolate* isolate = i::Isolate::Current();
6293  IsDeadCheck(isolate, "v8::HeapSnapshot::GetNodeById");
6294  return reinterpret_cast<const HeapGraphNode*>(
6295  ToInternal(this)->GetEntryById(id));
6296 }
6297 
6298 
6300  i::Isolate* isolate = i::Isolate::Current();
6301  IsDeadCheck(isolate, "v8::HeapSnapshot::GetNodesCount");
6302  return ToInternal(this)->entries().length();
6303 }
6304 
6305 
6306 const HeapGraphNode* HeapSnapshot::GetNode(int index) const {
6307  i::Isolate* isolate = i::Isolate::Current();
6308  IsDeadCheck(isolate, "v8::HeapSnapshot::GetNode");
6309  return reinterpret_cast<const HeapGraphNode*>(
6310  &ToInternal(this)->entries().at(index));
6311 }
6312 
6313 
6315  i::Isolate* isolate = i::Isolate::Current();
6316  IsDeadCheck(isolate, "v8::HeapSnapshot::GetMaxSnapshotJSObjectId");
6317  return ToInternal(this)->max_snapshot_js_object_id();
6318 }
6319 
6320 
6322  HeapSnapshot::SerializationFormat format) const {
6323  i::Isolate* isolate = i::Isolate::Current();
6324  IsDeadCheck(isolate, "v8::HeapSnapshot::Serialize");
6325  ApiCheck(format == kJSON,
6326  "v8::HeapSnapshot::Serialize",
6327  "Unknown serialization format");
6328  ApiCheck(stream->GetOutputEncoding() == OutputStream::kAscii,
6329  "v8::HeapSnapshot::Serialize",
6330  "Unsupported output encoding");
6331  ApiCheck(stream->GetChunkSize() > 0,
6332  "v8::HeapSnapshot::Serialize",
6333  "Invalid stream chunk size");
6334  i::HeapSnapshotJSONSerializer serializer(ToInternal(this));
6335  serializer.Serialize(stream);
6336 }
6337 
6338 
6340  i::Isolate* isolate = i::Isolate::Current();
6341  IsDeadCheck(isolate, "v8::HeapProfiler::GetSnapshotsCount");
6343 }
6344 
6345 
6347  i::Isolate* isolate = i::Isolate::Current();
6348  IsDeadCheck(isolate, "v8::HeapProfiler::GetSnapshot");
6349  return reinterpret_cast<const HeapSnapshot*>(
6351 }
6352 
6353 
6355  i::Isolate* isolate = i::Isolate::Current();
6356  IsDeadCheck(isolate, "v8::HeapProfiler::FindSnapshot");
6357  return reinterpret_cast<const HeapSnapshot*>(
6359 }
6360 
6361 
6363  i::Isolate* isolate = i::Isolate::Current();
6364  IsDeadCheck(isolate, "v8::HeapProfiler::GetSnapshotObjectId");
6365  i::Handle<i::Object> obj = Utils::OpenHandle(*value);
6367 }
6368 
6369 
6371  HeapSnapshot::Type type,
6372  ActivityControl* control) {
6373  i::Isolate* isolate = i::Isolate::Current();
6374  IsDeadCheck(isolate, "v8::HeapProfiler::TakeSnapshot");
6376  switch (type) {
6377  case HeapSnapshot::kFull:
6378  internal_type = i::HeapSnapshot::kFull;
6379  break;
6380  default:
6381  UNREACHABLE();
6382  }
6383  return reinterpret_cast<const HeapSnapshot*>(
6385  *Utils::OpenHandle(*title), internal_type, control));
6386 }
6387 
6388 
6390  i::Isolate* isolate = i::Isolate::Current();
6391  IsDeadCheck(isolate, "v8::HeapProfiler::StartHeapObjectsTracking");
6393 }
6394 
6395 
6397  i::Isolate* isolate = i::Isolate::Current();
6398  IsDeadCheck(isolate, "v8::HeapProfiler::StopHeapObjectsTracking");
6400 }
6401 
6402 
6404  i::Isolate* isolate = i::Isolate::Current();
6405  IsDeadCheck(isolate, "v8::HeapProfiler::PushHeapObjectsStats");
6407 }
6408 
6409 
6411  i::Isolate* isolate = i::Isolate::Current();
6412  IsDeadCheck(isolate, "v8::HeapProfiler::DeleteAllSnapshots");
6414 }
6415 
6416 
6418  WrapperInfoCallback callback) {
6419  i::Isolate::Current()->heap_profiler()->DefineWrapperClass(class_id,
6420  callback);
6421 }
6422 
6423 
6425  i::Isolate* isolate = i::Isolate::Current();
6426  return isolate->global_handles()->NumberOfGlobalHandles();
6427 }
6428 
6429 
6432 }
6433 
6434 
6435 v8::Testing::StressType internal::Testing::stress_type_ =
6437 
6438 
6441 }
6442 
6444  if (internal::FLAG_stress_runs != 0) return internal::FLAG_stress_runs;
6445 #ifdef DEBUG
6446  // In debug mode the code runs much slower so stressing will only make two
6447  // runs.
6448  return 2;
6449 #else
6450  return 5;
6451 #endif
6452 }
6453 
6454 
6455 static void SetFlagsFromString(const char* flags) {
6456  V8::SetFlagsFromString(flags, i::StrLength(flags));
6457 }
6458 
6459 
6461  static const char* kLazyOptimizations =
6462  "--prepare-always-opt "
6463  "--max-inlined-source-size=999999 "
6464  "--max-inlined-nodes=999999 "
6465  "--max-inlined-nodes-cumulative=999999 "
6466  "--noalways-opt";
6467  static const char* kForcedOptimizations = "--always-opt";
6468 
6469  // If deoptimization stressed turn on frequent deoptimization. If no value
6470  // is spefified through --deopt-every-n-times use a default default value.
6471  static const char* kDeoptEvery13Times = "--deopt-every-n-times=13";
6473  internal::FLAG_deopt_every_n_times == 0) {
6474  SetFlagsFromString(kDeoptEvery13Times);
6475  }
6476 
6477 #ifdef DEBUG
6478  // As stressing in debug mode only make two runs skip the deopt stressing
6479  // here.
6480  if (run == GetStressRuns() - 1) {
6481  SetFlagsFromString(kForcedOptimizations);
6482  } else {
6483  SetFlagsFromString(kLazyOptimizations);
6484  }
6485 #else
6486  if (run == GetStressRuns() - 1) {
6487  SetFlagsFromString(kForcedOptimizations);
6488  } else if (run != GetStressRuns() - 2) {
6489  SetFlagsFromString(kLazyOptimizations);
6490  }
6491 #endif
6492 }
6493 
6494 
6497 }
6498 
6499 
6500 namespace internal {
6501 
6502 
6503 void HandleScopeImplementer::FreeThreadResources() {
6504  Free();
6505 }
6506 
6507 
6508 char* HandleScopeImplementer::ArchiveThread(char* storage) {
6510  isolate_->handle_scope_data();
6511  handle_scope_data_ = *current;
6512  memcpy(storage, this, sizeof(*this));
6513 
6514  ResetAfterArchive();
6515  current->Initialize();
6516 
6517  return storage + ArchiveSpacePerThread();
6518 }
6519 
6520 
6521 int HandleScopeImplementer::ArchiveSpacePerThread() {
6522  return sizeof(HandleScopeImplementer);
6523 }
6524 
6525 
6526 char* HandleScopeImplementer::RestoreThread(char* storage) {
6527  memcpy(this, storage, sizeof(*this));
6528  *isolate_->handle_scope_data() = handle_scope_data_;
6529  return storage + ArchiveSpacePerThread();
6530 }
6531 
6532 
6533 void HandleScopeImplementer::IterateThis(ObjectVisitor* v) {
6534 #ifdef DEBUG
6535  bool found_block_before_deferred = false;
6536 #endif
6537  // Iterate over all handles in the blocks except for the last.
6538  for (int i = blocks()->length() - 2; i >= 0; --i) {
6539  Object** block = blocks()->at(i);
6540  if (last_handle_before_deferred_block_ != NULL &&
6541  (last_handle_before_deferred_block_ < &block[kHandleBlockSize]) &&
6542  (last_handle_before_deferred_block_ >= block)) {
6543  v->VisitPointers(block, last_handle_before_deferred_block_);
6544  ASSERT(!found_block_before_deferred);
6545 #ifdef DEBUG
6546  found_block_before_deferred = true;
6547 #endif
6548  } else {
6549  v->VisitPointers(block, &block[kHandleBlockSize]);
6550  }
6551  }
6552 
6553  ASSERT(last_handle_before_deferred_block_ == NULL ||
6554  found_block_before_deferred);
6555 
6556  // Iterate over live handles in the last block (if any).
6557  if (!blocks()->is_empty()) {
6558  v->VisitPointers(blocks()->last(), handle_scope_data_.next);
6559  }
6560 
6561  if (!saved_contexts_.is_empty()) {
6562  Object** start = reinterpret_cast<Object**>(&saved_contexts_.first());
6563  v->VisitPointers(start, start + saved_contexts_.length());
6564  }
6565 }
6566 
6567 
6568 void HandleScopeImplementer::Iterate(ObjectVisitor* v) {
6570  isolate_->handle_scope_data();
6571  handle_scope_data_ = *current;
6572  IterateThis(v);
6573 }
6574 
6575 
6576 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) {
6577  HandleScopeImplementer* scope_implementer =
6578  reinterpret_cast<HandleScopeImplementer*>(storage);
6579  scope_implementer->IterateThis(v);
6580  return storage + ArchiveSpacePerThread();
6581 }
6582 
6583 
6584 DeferredHandles* HandleScopeImplementer::Detach(Object** prev_limit) {
6585  DeferredHandles* deferred =
6586  new DeferredHandles(isolate()->handle_scope_data()->next, isolate());
6587 
6588  while (!blocks_.is_empty()) {
6589  Object** block_start = blocks_.last();
6590  Object** block_limit = &block_start[kHandleBlockSize];
6591  // We should not need to check for NoHandleAllocation here. Assert
6592  // this.
6593  ASSERT(prev_limit == block_limit ||
6594  !(block_start <= prev_limit && prev_limit <= block_limit));
6595  if (prev_limit == block_limit) break;
6596  deferred->blocks_.Add(blocks_.last());
6597  blocks_.RemoveLast();
6598  }
6599 
6600  // deferred->blocks_ now contains the blocks installed on the
6601  // HandleScope stack since BeginDeferredScope was called, but in
6602  // reverse order.
6603 
6604  ASSERT(prev_limit == NULL || !blocks_.is_empty());
6605 
6606  ASSERT(!blocks_.is_empty() && prev_limit != NULL);
6607  ASSERT(last_handle_before_deferred_block_ != NULL);
6608  last_handle_before_deferred_block_ = NULL;
6609  return deferred;
6610 }
6611 
6612 
6613 void HandleScopeImplementer::BeginDeferredScope() {
6614  ASSERT(last_handle_before_deferred_block_ == NULL);
6615  last_handle_before_deferred_block_ = isolate()->handle_scope_data()->next;
6616 }
6617 
6618 
6619 DeferredHandles::~DeferredHandles() {
6620  isolate_->UnlinkDeferredHandles(this);
6621 
6622  for (int i = 0; i < blocks_.length(); i++) {
6623 #ifdef DEBUG
6624  HandleScope::ZapRange(blocks_[i], &blocks_[i][kHandleBlockSize]);
6625 #endif
6626  isolate_->handle_scope_implementer()->ReturnBlock(blocks_[i]);
6627  }
6628 }
6629 
6630 
6631 void DeferredHandles::Iterate(ObjectVisitor* v) {
6632  ASSERT(!blocks_.is_empty());
6633 
6634  ASSERT((first_block_limit_ >= blocks_.first()) &&
6635  (first_block_limit_ <= &(blocks_.first())[kHandleBlockSize]));
6636 
6637  v->VisitPointers(blocks_.first(), first_block_limit_);
6638 
6639  for (int i = 1; i < blocks_.length(); i++) {
6640  v->VisitPointers(blocks_[i], &blocks_[i][kHandleBlockSize]);
6641  }
6642 }
6643 
6644 
6645 } } // namespace v8::internal
void API_Fatal(const char *location, const char *format,...)
Definition: checks.cc:92
void Enter()
Definition: api.cc:742
Object * GetPrototype()
Definition: objects.cc:725
byte * Address
Definition: globals.h:157
static Local< Context > GetCurrent()
Definition: api.cc:4545
static CpuProfile * FindProfile(Object *security_token, unsigned uid)
void SaveContext(Context *context)
Definition: api.h:513
int Utf8Length(Handle< String > str)
Definition: handles.cc:1010
static Isolate * GetCurrent()
Definition: api.cc:5520
void SetCallAsFunctionHandler(InvocationCallback callback, Handle< Value > data=Handle< Value >())
Definition: api.cc:1412
void PauseProfiler()
Definition: log.cc:1349
static void DeleteAllSnapshots()
Definition: api.cc:6410
static void set_stress_type(v8::Testing::StressType stress_type)
Definition: api.h:584
static Handle< Object > New(Handle< JSFunction > func, int argc, Handle< Object > argv[], bool *pending_exception)
Definition: execution.cc:183
Handle< Array >(* NamedPropertyEnumerator)(const AccessorInfo &info)
Definition: v8.h:2086
Handle< Value > GetScriptData() const
Definition: api.cc:1810
static void DeleteProfile(CpuProfile *profile)
static Handle< Object > DeleteElement(Handle< JSObject > obj, uint32_t index)
Definition: objects.cc:3875
RegisteredExtension * next()
Definition: api.h:151
double GetSelfTime() const
Definition: api.cc:5992
V8EXPORT int Length() const
Definition: api.cc:3741
static void SetLiveEditEnabled(bool enable, Isolate *isolate=NULL)
V8EXPORT double NumberValue() const
Definition: api.cc:2555
static bool Initialize(Deserializer *des)
Definition: v8.cc:64
void(* GCCallback)()
Definition: v8.h:2762
const HeapGraphEdge * GetChild(int index) const
Definition: api.cc:6226
static const byte * data()
Definition: snapshot.h:55
void Destroy(Object **location)
static Local< Script > Compile(Handle< String > source, ScriptOrigin *origin=NULL, ScriptData *pre_data=NULL, Handle< String > script_data=Handle< String >())
Definition: api.cc:1568
int GetLineNumber() const
Definition: api.cc:2021
void FlattenString(Handle< String > string)
Definition: handles.cc:211
bool IsEval() const
Definition: api.cc:2101
static void AddGCEpilogueCallback(GCEpilogueCallback callback, GCType gc_type_filter=kGCTypeAll)
Definition: api.cc:5413
V8EXPORT int WriteUtf8(char *buffer, int length=-1, int *nchars_ref=NULL, int options=NO_OPTIONS) const
Definition: api.cc:3852
static int NumberOfHandles()
Definition: handles.cc:48
static void SetAllowCodeGenerationFromStringsCallback(AllowCodeGenerationFromStringsCallback that)
Definition: api.cc:461
V8EXPORT bool HasRealIndexedProperty(uint32_t index)
Definition: api.cc:3144
static ScriptDataImpl * PreParse(Utf16CharacterStream *source, v8::Extension *extension, int flags)
Definition: parser.cc:5909
void(* MemoryAllocationCallback)(ObjectSpace space, AllocationAction action, int size)
Definition: v8.h:2719
static HeapSnapshot * GetSnapshot(int index)
Handle< JSObject > NewJSObject(Handle< JSFunction > constructor, PretenureFlag pretenure=NOT_TENURED)
Definition: factory.cc:904
DateCache * date_cache()
Definition: isolate.h:1050
Handle< String > NewExternalStringFromAscii(const ExternalAsciiString::Resource *resource)
Definition: factory.cc:270
V8EXPORT bool BooleanValue() const
Definition: api.cc:5001
#define CHECK_EQ(expected, value)
Definition: checks.h:219
V8EXPORT bool IsTrue() const
Definition: api.cc:2143
Local< Array > AsArray()
Definition: api.cc:1998
V8EXPORT uint8_t * GetIndexedPropertiesPixelData()
Definition: api.cc:3435
static bool IsExecutionTerminating(Isolate *isolate=NULL)
Definition: api.cc:5513
static const int kMaxLength
Definition: objects.h:3738
const char * data
Definition: v8.h:2899
Handle< JSFunction > NewFunctionFromSharedFunctionInfo(Handle< SharedFunctionInfo > function_info, Handle< Context > context, PretenureFlag pretenure=TENURED)
Definition: factory.cc:548
static Local< FunctionTemplate > New(InvocationCallback callback=0, Handle< Value > data=Handle< Value >(), Handle< Signature > signature=Handle< Signature >())
Definition: api.cc:951
static Handle< Object > TryCall(Handle< JSFunction > func, Handle< Object > receiver, int argc, Handle< Object > argv[], bool *caught_exception)
Definition: execution.cc:192
V8EXPORT bool DeleteHiddenValue(Handle< String > key)
Definition: api.cc:3336
void Dispose()
Definition: api.cc:5532
Handle< Boolean > V8EXPORT True()
Definition: api.cc:569
V8EXPORT Local< String > GetSource() const
Definition: api.cc:5125
V8EXPORT const ExternalAsciiStringResource * GetExternalAsciiStringResource() const
Definition: api.cc:4122
static SnapshotObjectId PushHeapObjectsStats(OutputStream *stream)
static int GetStressRuns()
Definition: api.cc:6443
void(* CallCompletedCallback)()
Definition: v8.h:2724
static const HeapSnapshot * TakeSnapshot(Handle< String > title, HeapSnapshot::Type type=HeapSnapshot::kFull, ActivityControl *control=NULL)
Definition: api.cc:6370
Handle< Value >(* NamedPropertySetter)(Local< String > property, Local< Value > value, const AccessorInfo &info)
Definition: v8.h:2061
void RecordWrite(Handle< String > string)
Definition: api.h:315
static Handle< Object > ToUint32(Handle< Object > obj, bool *exc)
Definition: execution.cc:660
intptr_t * old_pointer_space_size
Definition: heap.h:2179
void Exit()
Definition: api.cc:5549
intptr_t * cell_space_size
Definition: heap.h:2187
const HeapGraphNode * GetFromNode() const
Definition: api.cc:6168
void SetSecurityToken(Handle< Value > token)
Definition: api.cc:4485
Extension(const char *name, const char *source=0, int dep_count=0, const char **deps=0, int source_length=-1)
Definition: api.cc:532
Local< Value > Exception() const
Definition: api.cc:1720
static String * cast(Object *obj)
void ScheduleThrow(Object *exception)
Definition: isolate.cc:971
int * new_space_capacity
Definition: heap.h:2178
const int kPointerToSmiShift
Definition: v8.h:4064
HandleScopeImplementer * handle_scope_implementer()
Definition: isolate.h:864
Definition: v8.h:3044
v8::internal::Handle< v8::internal::JSObject > value()
Definition: api.h:77
Handle< Context > GetCallingNativeContext()
Definition: isolate.cc:1357
void set(int index, v8::internal::Object *value)
Definition: api.cc:888
V8EXPORT Local< Object > CloneElementAt(uint32_t index)
Definition: api.cc:5181
Definition: v8.h:869
static Local< Number > NumberToLocal(v8::internal::Handle< v8::internal::Object > obj)
V8EXPORT bool StrictEquals(Handle< Value > that) const
Definition: api.cc:2711
static void SetAddHistogramSampleFunction(AddHistogramSampleCallback)
Definition: api.cc:5328
bool HasOutOfMemoryException()
Definition: api.cc:4521
V8EXPORT Local< Value > Get(Handle< Value > key)
Definition: api.cc:2853
static Smi * FromInt(int value)
Definition: objects-inl.h:981
Handle< Integer > ResourceLineOffset() const
Definition: v8.h:4335
V8EXPORT bool IsNativeError() const
Definition: api.cc:2279
virtual Handle< Object > GetEventData() const =0
void V8EXPORT RegisterExtension(Extension *extension)
Definition: api.cc:526
Local< Object > NewInstance()
Definition: api.cc:4660
V8EXPORT PropertyAttribute GetPropertyAttributes(Handle< Value > key)
Definition: api.cc:2880
~HandleScope()
Definition: api.cc:698
bool HasCaught() const
Definition: api.cc:1703
double GetTotalTime() const
Definition: api.cc:5985
V8EXPORT Local< Array > GetOwnPropertyNames()
Definition: api.cc:2967
void SetCaptureMessage(bool value)
Definition: api.cc:1773
StackTraceOptions
Definition: v8.h:769
static ObjectTemplateInfo * cast(Object *obj)
intptr_t MaxReserved()
Definition: heap.h:471
Handle< Value > GetName() const
Definition: api.cc:6147
static Local< AccessorSignature > AccessorSignatureToLocal(v8::internal::Handle< v8::internal::FunctionTemplateInfo > obj)
StatsTable * stats_table()
Definition: isolate.cc:1952
Handle< JSArray > NewJSArray(int capacity, ElementsKind elements_kind=TERMINAL_FAST_ELEMENTS_KIND, PretenureFlag pretenure=NOT_TENURED)
Definition: factory.cc:937
Handle< String > GetName() const
Definition: api.cc:6197
static void SetFatalError()
Definition: v8.cc:97
SnapshotObjectId GetId() const
Definition: api.cc:6205
V8EXPORT bool IsBooleanObject() const
Definition: api.cc:2298
static Handle< T > cast(Handle< S > that)
Definition: handles.h:81
Local< String > Get() const
Definition: api.cc:1781
static void SetCaptureStackTraceForUncaughtExceptions(bool capture, int frame_limit=10, StackTrace::StackTraceOptions options=StackTrace::kOverview)
Definition: api.cc:5303
void AllowCodeGenerationFromStrings(bool allow)
Definition: api.cc:4606
void AddString(String *string)
Definition: heap-inl.h:580
ThreadId thread_id()
Definition: isolate.h:538
static V8EXPORT Local< String > New(const char *data, int length=-1)
Definition: api.cc:4779
void AddGCPrologueCallback(GCPrologueCallback callback, GCType gc_type_filter)
Definition: heap.cc:6356
void SetData(Handle< String > data)
Definition: api.cc:1660
void AddImplicitReferences(HeapObject **parent, Object ***children, size_t length)
int ToInteger() const
Definition: isolate.h:171
bool IsAsciiRepresentation()
Definition: objects-inl.h:290
const CpuProfileNode * GetChild(int index) const
Definition: api.cc:6027
static ExternalTwoByteString * cast(Object *obj)
#define API_ENTRY_CHECK(isolate, msg)
Definition: api.cc:116
void VisitExternalResources(v8::ExternalResourceVisitor *visitor)
Definition: heap.cc:1548
int32_t uc32
Definition: globals.h:260
V8EXPORT bool IsExternal() const
Definition: api.cc:2197
bool(* IndexedSecurityCallback)(Local< Object > host, uint32_t index, AccessType type, Local< Value > data)
Definition: v8.h:2154
static V8EXPORT Local< String > NewSymbol(const char *data, int length=-1)
Definition: api.cc:5203
V8EXPORT Local< String > GetConstructorName()
Definition: api.cc:3053
Local< ObjectTemplate > InstanceTemplate()
Definition: api.cc:1122
V8EXPORT Local< Int32 > ToInt32() const
Definition: api.cc:2597
static Handle< Object > ToInteger(Handle< Object > obj, bool *exc)
Definition: execution.cc:655
Handle< Primitive > V8EXPORT Null()
Definition: api.cc:559
Definition: v8.h:512
static Handle< Object > ToObject(Handle< Object > obj, bool *exc)
Definition: execution.cc:649
V8EXPORT Local< Context > CreationContext()
Definition: api.cc:3284
void SetGlobalGCPrologueCallback(GCCallback callback)
Definition: heap.h:1145
int int32_t
Definition: unicode.cc:47
static void AddMemoryAllocationCallback(MemoryAllocationCallback callback, ObjectSpace space, AllocationAction action)
Definition: api.cc:5427
void(* MessageCallback)(Handle< Message > message, Handle< Value > error)
Definition: v8.h:2663
static void SetReturnAddressLocationResolver(ReturnAddressLocationResolver return_address_resolver)
Definition: api.cc:4283
V8EXPORT bool HasRealNamedCallbackProperty(Handle< String > key)
Definition: api.cc:3152
virtual Handle< Value > GetCallbackData() const =0
V8EXPORT Local< Value > GetHiddenValue(Handle< String > key)
Definition: api.cc:3322
v8::HandleScope::Data HandleScopeData
Definition: apiutils.h:69
Bootstrapper * bootstrapper()
Definition: isolate.h:818
Handle< String > GetScriptResourceName() const
Definition: api.cc:5969
static bool IsNearDeath(Object **location)
const HeapGraphNode * GetNodeById(SnapshotObjectId id) const
Definition: api.cc:6291
static Local< Context > GetDebugContext()
static Foreign * cast(Object *obj)
int GetStartPosition() const
Definition: api.cc:1888
int length()
Definition: api.cc:857
Local< Value > GetData()
Definition: api.cc:788
AllocationAction
Definition: v8.h:2713
static CpuProfile * StopProfiling(const char *title)
static const int kNoColumnInfo
Definition: v8.h:754
int *(* CounterLookupCallback)(const char *name)
Definition: v8.h:2690
const HeapGraphNode * GetNode(int index) const
Definition: api.cc:6306
void ReattachGlobal(Handle< Object > global_object)
Definition: api.cc:4593
static Local< Value > Error(Handle< String > message)
Definition: api.cc:5683
intptr_t * code_space_size
Definition: heap.h:2183
void SetIndexedPropertyHandler(IndexedPropertyGetter getter, IndexedPropertySetter setter=0, IndexedPropertyQuery query=0, IndexedPropertyDeleter deleter=0, IndexedPropertyEnumerator enumerator=0, Handle< Value > data=Handle< Value >())
Definition: api.cc:1386
void AddGCEpilogueCallback(GCEpilogueCallback callback, GCType gc_type_filter)
Definition: heap.cc:6376
Handle< Object > SetAccessor(Handle< JSObject > obj, Handle< AccessorInfo > info)
Definition: handles.cc:342
static void set_context_raw_data(const byte *context_raw_data)
Definition: snapshot.h:64
V8EXPORT Local< Array > GetPropertyNames()
Definition: api.cc:2946
V8EXPORT ExternalArrayType GetIndexedPropertiesExternalArrayDataType()
Definition: api.cc:3505
virtual DebugEvent GetEvent() const =0
V8EXPORT Local< Value > Call(Handle< Object > recv, int argc, Handle< Value > argv[])
Definition: api.cc:3652
V8EXPORT bool IsRegExp() const
Definition: api.cc:2306
static V8EXPORT const int kLineOffsetNotFound
Definition: v8.h:1801
#define ENTER_V8(isolate)
Definition: api.cc:65
Utf8Value(Handle< v8::Value > obj)
Definition: api.cc:5555
static Handle< Object > ToInt32(Handle< Object > obj, bool *exc)
Definition: execution.cc:665
#define ASSERT(condition)
Definition: checks.h:270
static Vector< const byte > GetScriptsSource()
void(* GCPrologueCallback)(GCType type, GCCallbackFlags flags)
Definition: v8.h:2759
V8EXPORT bool MayContainNonAscii() const
Definition: api.cc:3843
void ClearWeakness(Object **location)
~TryCatch()
Definition: api.cc:1690
V8EXPORT Local< Number > ToNumber() const
Definition: api.cc:2390
void SetFailedAccessCheckCallback(v8::FailedAccessCheckCallback callback)
Definition: isolate.cc:767
void UseDefaultSecurityToken()
Definition: api.cc:4497
static int GetSnapshotsCount()
Definition: api.cc:6339
static int size()
Definition: snapshot.h:56
CompressionAlgorithm
Definition: v8.h:2894
void EnterContext(Handle< Object > context)
Definition: api.h:528
void ResumeProfiler()
Definition: log.cc:1368
static bool SetFunctionEntryHook(FunctionEntryHook entry_hook)
Definition: code-stubs.cc:494
static StackGuard * GetDefaultIsolateStackGuard()
Definition: isolate.cc:393
static bool AddMessageListener(MessageCallback that)
Definition: api.cc:5273
static Script * cast(Object *obj)
ExternalArrayType
Definition: v8.h:1431
void(* MessageHandler2)(const Message &message)
Definition: v8-debug.h:235
unsigned short uint16_t
Definition: unicode.cc:46
V8EXPORT void * GetIndexedPropertiesExternalArrayData()
Definition: api.cc:3492
TryCatch()
Definition: api.cc:1677
V8EXPORT bool IsCallable()
Definition: api.cc:3548
static void DeoptimizeAll()
Definition: deoptimizer.cc:250
static void SetDecompressedStartupData(StartupData *decompressed_data)
Definition: api.cc:426
int GetSelfSize() const
Definition: api.cc:6212
Handle< Value > ResourceName() const
Definition: v8.h:4330
static V8EXPORT Local< Value > Wrap(void *data)
Definition: api.cc:4707
#define EXCEPTION_BAILOUT_CHECK(isolate, value)
Definition: api.cc:112
ThreadManager * thread_manager()
Definition: isolate.h:882
kPropertyAccessorsOffset kNamedPropertyHandlerOffset instance_template
Definition: objects-inl.h:3860
static SharedFunctionInfo * cast(Object *obj)
virtual int DecompressData(char *raw_data, int *raw_data_size, const char *compressed_data, int compressed_data_size)=0
static bool IsDead()
Definition: api.cc:228
void(* FatalErrorCallback)(const char *location, const char *message)
Definition: v8.h:2660
V8EXPORT Local< String > ToString() const
Definition: api.cc:2313
static const int kNoLineNumberInfo
Definition: v8.h:753
static void DefineWrapperClass(uint16_t class_id, WrapperInfoCallback callback)
Definition: api.cc:6417
intptr_t CommittedMemoryExecutable()
Definition: heap.cc:215
static bool InContext()
Definition: api.cc:4527
Type GetType() const
Definition: api.cc:6140
Handle< Object > NewNumber(double value, PretenureFlag pretenure=NOT_TENURED)
Definition: factory.cc:597
#define CHECK(condition)
Definition: checks.h:56
static const int kShortSize
Definition: objects.h:7746
Handle< Value >(* IndexedPropertySetter)(uint32_t index, Local< Value > value, const AccessorInfo &info)
Definition: v8.h:2101
int GetScriptColumnNumber(Handle< Script > script, int code_pos)
Definition: handles.cc:504
static const CpuProfile * FindProfile(unsigned uid, Handle< Value > security_token=Handle< Value >())
Definition: api.cc:6098
static bool IsDead()
Definition: v8.h:89
void ResetDateCache()
Definition: date.cc:51
V8EXPORT Local< Value > CallAsConstructor(int argc, Handle< Value > argv[])
Definition: api.cc:3591
static Handle< Object > ToDetailString(Handle< Object > obj, bool *exc)
Definition: execution.cc:644
static intptr_t AdjustAmountOfExternalAllocatedMemory(intptr_t change_in_bytes)
Definition: api.cc:5374
void SetVerbose(bool value)
Definition: api.cc:1768
int isnan(double x)
static CpuProfile * GetProfile(Object *security_token, int index)
Handle< Object > GetProperty(Handle< JSReceiver > obj, const char *name)
Definition: handles.cc:282
activate correct semantics for inheriting readonliness enable harmony semantics for typeof enable harmony enable harmony proxies enable all harmony harmony_scoping harmony_proxies harmony_scoping tracks arrays with only smi values automatically unbox arrays of doubles use crankshaft use hydrogen range analysis use hydrogen global value numbering use function inlining maximum number of AST nodes considered for a single inlining loop invariant code motion print statistics for hydrogen trace generated IR for specified phases trace register allocator trace range analysis trace representation types environment for every instruction put a break point before deoptimizing polymorphic inlining perform array bounds checks elimination use dead code elimination trace on stack replacement optimize closures cache optimized code for closures functions with arguments object loop weight for representation inference allow uint32 values on optimize frames if they are used only in safe operations track parallel recompilation enable all profiler experiments number of stack frames inspected by the profiler call recompile stub directly when self optimizing trigger profiler ticks based on counting instead of timing weight back edges by jump distance for interrupt triggering percentage of ICs that must have type info to allow optimization watch_ic_patching retry_self_opt interrupt_at_exit extra verbose compilation tracing generate extra emit comments in code disassembly enable use of SSE3 instructions if available enable use of CMOV instruction if available enable use of SAHF instruction if enable use of VFP3 instructions if available this implies enabling ARMv7 and VFP2 enable use of VFP2 instructions if available enable use of SDIV and UDIV instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of MIPS FPU instructions if expose natives in global object expose gc extension number of stack frames to capture disable builtin natives files print a stack trace if an assertion failure occurs use random jit cookie to mask large constants trace lazy optimization use adaptive optimizations prepare for turning on always opt minimum length for automatic enable preparsing maximum number of optimization attempts before giving up cache prototype transitions automatically set the debug break flag when debugger commands are in the queue always cause a debug break before aborting maximum length of function source code printed in a stack trace max size of the new max size of the old max size of executable always perform global GCs print one trace line following each garbage collection do not print trace line after scavenger collection print more details following each garbage collection print amount of external allocated memory after each time it is adjusted flush code that we expect not to use again before full gc do incremental marking steps track object counts and memory usage use caching Perform compaction on every full GC Never perform compaction on full GC testing only Compact code space on full incremental collections Default seed for initializing random allows verbose printing trace parsing and preparsing Check icache flushes in ARM and MIPS simulator Stack alingment in bytes in print stack trace when throwing exceptions randomize hashes to avoid predictable hash Fixed seed to use to hash property activate a timer that switches between V8 threads testing_bool_flag float flag Seed used for threading test randomness A filename with extra code to be included in the Print usage including flags
virtual ClientData * GetClientData() const =0
V8EXPORT bool CanMakeExternal()
Definition: api.cc:4944
V8EXPORT bool IsDirty()
Definition: api.cc:3251
void Set(Handle< String > name, Handle< Data > value, PropertyAttribute attributes=None)
Definition: api.cc:902
Factory * factory()
Definition: isolate.h:992
static bool HasDetachedProfiles()
void AddObjectGroup(Object ***handles, size_t length, v8::RetainedObjectInfo *info)
PropertyAttributes
V8EXPORT Handle< Value > GetName() const
Definition: api.cc:3685
int * pending_global_handle_count
Definition: heap.h:2192
static bool Dispose()
Definition: api.cc:4303
static void SetFailedAccessCheckCallbackFunction(FailedAccessCheckCallback)
Definition: api.cc:5342
static V8EXPORT Local< String > NewUndetectable(const char *data, int length=-1)
Definition: api.cc:4806
Handle< String > LookupAsciiSymbol(Vector< const char > str)
Definition: factory.cc:174
V8EXPORT void SetIndexedPropertiesToExternalArrayData(void *data, ExternalArrayType array_type, int number_of_elements)
Definition: api.cc:3460
const CpuProfileNode * GetBottomUpRoot() const
Definition: api.cc:6064
static const unsigned kMaxEncodedSize
Definition: unicode.h:163
virtual const uint16_t * data() const =0
static Handle< Object > SetHiddenProperty(Handle< JSObject > obj, Handle< String > key, Handle< Object > value)
Definition: objects.cc:3601
V8EXPORT Local< Uint32 > ToUint32() const
Definition: api.cc:2615
V8EXPORT bool Equals(Handle< Value > that) const
Definition: api.cc:2684
Handle< Object > NewSyntaxError(const char *type, Handle< JSArray > args)
Definition: factory.cc:652
V8EXPORT Handle< Value > GetScriptId() const
Definition: api.cc:3733
static void VisitExternalResources(ExternalResourceVisitor *visitor)
Definition: api.cc:4340
#define SET_FIELD_WRAPPED(obj, setter, cdata)
Definition: api.cc:1045
REGEXP_FLAG_ASSERT_EQ(kNone, NONE)
bool IsDefaultIsolate() const
Definition: isolate.h:469
Handle< String > GetFunctionName() const
Definition: api.cc:5953
static void GetCompressedStartupData(StartupData *compressed_data)
Definition: api.cc:395
Handle< Object > LastEnteredContext()
Definition: api.h:540
void SetCounterFunction(CounterLookupCallback f)
Definition: counters.h:45
V8EXPORT Local< Value > GetConstructor()
Definition: api.cc:3042
Handle< Value > GetScriptResourceName() const
Definition: api.cc:1793
static void AddGCPrologueCallback(GCPrologueCallback callback, GCType gc_type_filter=kGCTypeAll)
Definition: api.cc:5399
static Smi * cast(Object *object)
void(* FailedAccessCheckCallback)(Local< Object > target, AccessType type, Local< Value > data)
Definition: v8.h:2727
Value(Handle< v8::Value > obj)
Definition: api.cc:5598
const size_t num_flags
Definition: flags.cc:178
Handle< Object > ForceDeleteProperty(Handle< JSObject > object, Handle< Object > key)
Definition: handles.cc:259
V8EXPORT bool IsExternal() const
Definition: api.cc:4064
v8::internal::Handle< v8::internal::JSObject > value()
Definition: api.h:64
V8EXPORT bool HasIndexedPropertiesInExternalArrayData()
Definition: api.cc:3483
static bool IdleNotification(int hint)
Definition: v8.cc:187
bool Equals(String *other)
Definition: objects-inl.h:2419
static void SetEntropySource(EntropySource source)
Definition: v8.cc:159
V8EXPORT void SetInternalField(int index, Handle< Value > value)
Definition: api.cc:4214
static Local< StackFrame > StackFrameToLocal(v8::internal::Handle< v8::internal::JSObject > obj)
V8EXPORT void SetPointerInInternalField(int index, void *value)
Definition: api.cc:4248
void SetClassName(Handle< String > name)
Definition: api.cc:1139
static V8EXPORT Local< Integer > NewFromUnsigned(uint32_t value)
Definition: api.cc:5235
StackGuard * stack_guard()
Definition: isolate.h:834
int GetEndColumn() const
Definition: api.cc:1928
void set_context_exit_happened(bool context_exit_happened)
Definition: isolate.h:1042
double GetSelfSamplesCount() const
Definition: api.cc:6006
Handle< Context > global_context()
Definition: isolate.cc:1351
Handle< Value >(* IndexedPropertyGetter)(uint32_t index, const AccessorInfo &info)
Definition: v8.h:2093
intptr_t * lo_space_size
Definition: heap.h:2189
static void DebugBreakForCommand(ClientData *data=NULL, Isolate *isolate=NULL)
Local< StackFrame > GetFrame(uint32_t index) const
Definition: api.cc:1976
static const char * GetVersion()
Definition: api.cc:4394
V8EXPORT Local< Value > GetRealNamedProperty(Handle< String > key)
Definition: api.cc:3217
int NotifyContextDisposed()
Definition: heap.h:1107
#define LEAVE_V8(isolate)
Definition: api.cc:68
Local< Value > Id()
Definition: api.cc:1643
V8EXPORT bool IsExternalAscii() const
Definition: api.cc:4074
void TerminateExecution(ThreadId thread_id)
Definition: v8threads.cc:416
const uint16_t * SeqTwoByteStringGetData(unsigned start)
Definition: objects.cc:6340
Handle< Map > GetElementsTransitionMap(Handle< JSObject > object, ElementsKind elements_kind)
Definition: factory.cc:513
V8EXPORT bool IsStringObject() const
Definition: api.cc:2247
V8EXPORT bool MakeExternal(ExternalStringResource *resource)
Definition: api.cc:4884
Handle< String > NewStringFromUtf8(Vector< const char > str, PretenureFlag pretenure=NOT_TENURED)
Definition: factory.cc:207
int * near_death_global_handle_count
Definition: heap.h:2193
V8EXPORT ScriptOrigin GetScriptOrigin() const
Definition: api.cc:3697
void(* FunctionEntryHook)(uintptr_t function, uintptr_t return_addr_location)
Definition: v8.h:2965
static Local< Script > New(Handle< String > source, ScriptOrigin *origin=NULL, ScriptData *pre_data=NULL, Handle< String > script_data=Handle< String >())
Definition: api.cc:1506
static int GetCompressedStartupDataCount()
Definition: api.cc:386
T ** location() const
Definition: handles.h:75
unsigned GetCallUid() const
Definition: api.cc:6013
Handle< Object > NewRangeError(const char *type, Vector< Handle< Object > > args)
Definition: factory.cc:641
void RemoveMemoryAllocationCallback(MemoryAllocationCallback callback)
Definition: spaces.cc:684
V8EXPORT bool IsUint32() const
Definition: api.cc:2222
static Local< StackTrace > StackTraceToLocal(v8::internal::Handle< v8::internal::JSArray > obj)
static bool SetDebugEventListener(EventCallback that, Handle< Value > data=Handle< Value >())
V8EXPORT int InternalFieldCount()
Definition: api.cc:4185
static bool HasSmiTag(internal::Object *value)
Definition: v8.h:4109
int GetChildrenCount() const
Definition: api.cc:6219
static void DeoptimizeGlobalObject(JSObject *object)
Definition: deoptimizer.cc:262
#define UNREACHABLE()
Definition: checks.h:50
Handle< Value >(* InvocationCallback)(const Arguments &args)
Definition: v8.h:2047
static ScriptData * PreCompile(const char *input, int length)
Definition: api.cc:1462
Handle< Value >(* NamedPropertyGetter)(Local< String > property, const AccessorInfo &info)
Definition: v8.h:2053
Object * GetElementNoExceptionThrown(uint32_t index)
Definition: objects-inl.h:850
bool HasInstance(Handle< Value > object)
Definition: api.cc:4690
static void SetFlagsFromString(const char *str, int length)
Definition: api.cc:476
static void AddObjectGroup(Persistent< Value > *objects, size_t length, RetainedObjectInfo *info=NULL)
Definition: api.cc:5351
Handle< Map > CopyMap(Handle< Map > map, int extra_inobject_props)
Definition: factory.cc:483
static Local< Message > MessageToLocal(v8::internal::Handle< v8::internal::Object > obj)
int max_old_space_size() const
Definition: v8.h:2639
static void EnsureDefaultIsolate()
Definition: isolate.cc:363
V8EXPORT void * Value() const
Definition: api.cc:4762
V8EXPORT Local< String > ObjectProtoToString()
Definition: api.cc:2988
T * start() const
Definition: utils.h:390
static V8EXPORT void DateTimeConfigurationChangeNotification()
Definition: api.cc:5062
static const CpuProfile * GetProfile(int index, Handle< Value > security_token=Handle< Value >())
Definition: api.cc:6087
static const HeapSnapshot * FindSnapshot(unsigned uid)
Definition: api.cc:6354
static Handle< Object > ToBoolean(Handle< Object > obj)
Definition: execution.cc:618
static void RemoveCallCompletedCallback(CallCompletedCallback callback)
Definition: api.cc:5454
void *(* CreateHistogramCallback)(const char *name, int min, int max, size_t buckets)
Definition: v8.h:2692
v8::internal::Object * get(int index)
Definition: api.cc:862
static Local< ObjectTemplate > New()
Definition: api.cc:1253
V8EXPORT bool HasIndexedPropertiesInPixelData()
Definition: api.cc:3427
static void SetJitCodeEventHandler(JitCodeEventOptions options, JitCodeEventHandler event_handler)
Definition: api.cc:4294
void DetachGlobal()
Definition: api.cc:4582
#define ON_BAILOUT(isolate, location, code)
Definition: api.cc:73
void SetCallHandler(InvocationCallback callback, Handle< Value > data=Handle< Value >())
Definition: api.cc:1051
Handle< JSObject > NewNeanderObject()
Definition: factory.cc:621
int max_young_space_size() const
Definition: v8.h:2637
Handle< Value > ReThrow()
Definition: api.cc:1713
static void StopHeapObjectsTracking()
Definition: api.cc:6396
void RemoveGCEpilogueCallback(GCEpilogueCallback callback)
Definition: heap.cc:6384
static size_t GetMemorySizeUsedByProfiler()
static SlicedString * cast(Object *obj)
static void MemCopy(void *dest, const void *src, size_t size)
Definition: platform.h:339
StringTracker * string_tracker()
Definition: isolate.h:890
RuntimeProfiler * runtime_profiler()
Definition: isolate.h:826
SnapshotObjectId GetMaxSnapshotJSObjectId() const
Definition: api.cc:6314
Handle< Integer >(* NamedPropertyQuery)(Local< String > property, const AccessorInfo &info)
Definition: v8.h:2070
virtual int GetChunkSize()
Definition: v8.h:3961
V8EXPORT Local< Value > GetPrototype()
Definition: api.cc:2900
static void StartProfiling(Handle< String > title)
Definition: api.cc:6109
static void GetHeapStatistics(HeapStatistics *heap_statistics)
Definition: api.cc:4321
Handle< Object > Create(Object *value)
static bool IsValid(intptr_t value)
Definition: objects-inl.h:1059
static Local< Uint32 > Uint32ToLocal(v8::internal::Handle< v8::internal::Object > obj)
void set_context(Context *context)
Definition: isolate.h:521
static int context_raw_size()
Definition: snapshot.h:63
static void SetHostDispatchHandler(HostDispatchHandler handler, int period=100)
void CollectAllAvailableGarbage(const char *gc_reason=NULL)
Definition: heap.cc:548
virtual Handle< Object > GetExecutionState() const =0
V8EXPORT bool ForceDelete(Handle< Value > key)
Definition: api.cc:2829
bool(* AllowCodeGenerationFromStringsCallback)(Local< Context > context)
Definition: v8.h:2737
static uint16_t GetWrapperClassId(Object **location)
JSObject * global_proxy()
Definition: contexts.cc:78
static void EnterDefaultIsolate()
Definition: isolate.cc:399
Handle< String > GetTitle() const
Definition: api.cc:6055
int compressed_size
Definition: v8.h:2900
MemoryAllocator * memory_allocator()
Definition: isolate.h:845
V8EXPORT int Utf8Length() const
Definition: api.cc:3748
MaybeObject * scheduled_exception()
Definition: isolate.h:602
T * NewArray(size_t size)
Definition: allocation.h:83
void SetAccessor(Handle< String > name, AccessorGetter getter, AccessorSetter setter=0, Handle< Value > data=Handle< Value >(), AccessControl settings=DEFAULT, PropertyAttribute attribute=None, Handle< AccessorSignature > signature=Handle< AccessorSignature >())
Definition: api.cc:1291
Handle< Object > SetProperty(Handle< Object > object, Handle< Object > key, Handle< Object > value, PropertyAttributes attributes, StrictModeFlag strict_mode)
Definition: handles.cc:232
static void ResumeProfiler()
Definition: api.cc:5468
int * global_handle_count
Definition: heap.h:2190
void SetInternalFieldCount(int value)
Definition: api.cc:1438
unsigned int FastD2UI(double x)
int GetColumn() const
Definition: api.cc:2037
#define LOG_API(isolate, expr)
Definition: api.cc:63
static Isolate * New()
Definition: api.cc:5526
static void SetFatalErrorHandler(FatalErrorCallback that)
Definition: api.cc:455
V8EXPORT bool HasIndexedLookupInterceptor()
Definition: api.cc:3171
intptr_t * cell_space_capacity
Definition: heap.h:2188
intptr_t * memory_allocator_size
Definition: heap.h:2195
Handle< Integer >(* IndexedPropertyQuery)(uint32_t index, const AccessorInfo &info)
Definition: v8.h:2110
uintptr_t(* ReturnAddressLocationResolver)(uintptr_t return_addr_location)
Definition: v8.h:2950
void PrintCurrentStackTrace(FILE *out)
Definition: isolate.cc:989
activate correct semantics for inheriting readonliness enable harmony semantics for typeof enable harmony enable harmony proxies enable all harmony harmony_scoping harmony_proxies harmony_scoping tracks arrays with only smi values automatically unbox arrays of doubles use crankshaft use hydrogen range analysis use hydrogen global value numbering use function inlining maximum number of AST nodes considered for a single inlining loop invariant code motion print statistics for hydrogen trace generated IR for specified phases trace register allocator trace range analysis trace representation types environment for every instruction put a break point before deoptimizing polymorphic inlining perform array bounds checks elimination use dead code elimination trace on stack replacement optimize closures cache optimized code for closures functions with arguments object loop weight for representation inference allow uint32 values on optimize frames if they are used only in safe operations track parallel recompilation enable all profiler experiments number of stack frames inspected by the profiler call recompile stub directly when self optimizing trigger profiler ticks based on counting instead of timing weight back edges by jump distance for interrupt triggering percentage of ICs that must have type info to allow optimization watch_ic_patching retry_self_opt interrupt_at_exit extra verbose compilation tracing generate extra emit comments in code disassembly enable use of SSE3 instructions if available enable use of CMOV instruction if available enable use of SAHF instruction if enable use of VFP3 instructions if available this implies enabling ARMv7 and VFP2 enable use of VFP2 instructions if available enable use of SDIV and UDIV instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of MIPS FPU instructions if expose natives in global object expose gc extension number of stack frames to capture disable builtin natives files print a stack trace if an assertion failure occurs use random jit cookie to mask large constants trace lazy optimization use adaptive optimizations prepare for turning on always opt minimum length for automatic enable preparsing maximum number of optimization attempts before giving up cache prototype transitions automatically set the debug break flag when debugger commands are in the queue always cause a debug break before aborting maximum length of function source code printed in a stack trace max size of the new max size of the old max size of executable always perform global GCs print one trace line following each garbage collection do not print trace line after scavenger collection print more details following each garbage collection print amount of external allocated memory after each time it is adjusted flush code that we expect not to use again before full gc do incremental marking steps track object counts and memory usage use caching Perform compaction on every full GC Never perform compaction on full GC testing only Compact code space on full incremental collections Default seed for initializing random allows verbose printing trace parsing and preparsing Check icache flushes in ARM and MIPS simulator Stack alingment in bytes in print stack trace when throwing exceptions randomize hashes to avoid predictable hash Fixed seed to use to hash property activate a timer that switches between V8 threads testing_bool_flag float flag Seed used for threading test randomness A filename with extra code to be included in the Print usage message
Handle< String > LookupSymbol(Vector< const char > str)
Definition: factory.cc:161
static SnapshotObjectId PushHeapObjectsStats(OutputStream *stream)
Definition: api.cc:6403
static int ContextDisposedNotification()
Definition: api.cc:4387
static bool SetFunctionEntryHook(FunctionEntryHook entry_hook)
Definition: api.cc:4289
Handle< JSArray > CaptureCurrentStackTrace(int frame_limit, StackTrace::StackTraceOptions options)
Definition: isolate.cc:568
static void TerminateExecution(int thread_id)
Definition: api.cc:5487
GlobalHandles * global_handles()
Definition: isolate.h:880
V8EXPORT int32_t Int32Value() const
Definition: api.cc:2662
static void RemoveCallCompletedCallback(CallCompletedCallback callback)
Definition: v8.cc:208
void(* AccessorSetter)(Local< String > property, Local< Value > value, const AccessorInfo &info)
Definition: v8.h:1452
V8EXPORT bool IsBoolean() const
Definition: api.cc:2189
V8EXPORT Local< Object > NewInstance() const
Definition: api.cc:3628
int InternalFieldCount()
Definition: api.cc:1429
static void TransformToFastProperties(Handle< JSObject > object, int unused_property_fields)
Definition: objects.cc:3392
intptr_t * code_space_capacity
Definition: heap.h:2184
bool IsConstructor() const
Definition: api.cc:2112
Local< Object > Global()
Definition: api.cc:4570
static bool IsIndependent(Object **location)
int raw_size
Definition: v8.h:2901
Handle< String > NewStringFromTwoByte(Vector< const uc16 > str, PretenureFlag pretenure=NOT_TENURED)
Definition: factory.cc:216
Handle< ExternalArray > NewExternalArray(int length, ExternalArrayType array_type, void *external_pointer, PretenureFlag pretenure=NOT_TENURED)
Definition: factory.cc:435
static FunctionTemplateInfo * cast(Object *obj)
V8EXPORT void SetIndexedPropertiesToPixelData(uint8_t *data, int length)
Definition: api.cc:3407
Handle< FixedArray > NewFixedArray(int size, PretenureFlag pretenure=NOT_TENURED)
Definition: factory.cc:44
V8EXPORT void TurnOnAccessCheck()
Definition: api.cc:3233
int length() const
Definition: utils.h:384
static void PrintCurrentStackTrace(FILE *out)
Definition: api.cc:1966
v8::ImplementationUtilities::HandleScopeData * handle_scope_data()
Definition: isolate.h:861
static void SetStressRunType(StressType type)
Definition: api.cc:6439
V8EXPORT int GetScriptColumnNumber() const
Definition: api.cc:3724
bool ConfigureHeap(int max_semispace_size, intptr_t max_old_gen_size, intptr_t max_executable_size)
Definition: heap.cc:5833
intptr_t * map_space_size
Definition: heap.h:2185
Handle< FixedArray > GetKeysInFixedArrayFor(Handle< JSReceiver > object, KeyCollectionType type, bool *threw)
Definition: handles.cc:606
void Enter()
Definition: api.cc:5543
static void RemoveMessageListeners(MessageCallback that)
Definition: api.cc:5285
GCType
Definition: v8.h:2748
static MUST_USE_RESULT Handle< Object > SetElement(Handle< JSObject > object, uint32_t index, Handle< Object > value, PropertyAttributes attr, StrictModeFlag strict_mode, SetPropertyMode set_mode=SET_PROPERTY)
Definition: objects.cc:9886
V8EXPORT bool Has(Handle< String > key)
Definition: api.cc:3075
static ExternalPixelArray * cast(Object *obj)
static bool IsProfilerPaused()
Definition: api.cc:5474
static const char * GetVersion()
Definition: version.h:49
void(* AddHistogramSampleCallback)(void *histogram, int sample)
Definition: v8.h:2697
static Handle< JSRegExp > NewJSRegExp(Handle< String > pattern, Handle< String > flags, bool *exc)
Definition: execution.cc:679
static Local< Integer > IntegerToLocal(v8::internal::Handle< v8::internal::Object > obj)
V8EXPORT bool SetHiddenValue(Handle< String > key, Handle< Value > value)
Definition: api.cc:3305
intptr_t AdjustAmountOfExternalAllocatedMemory(intptr_t change_in_bytes)
Definition: heap-inl.h:459
V8EXPORT Local< String > ToDetailString() const
Definition: api.cc:2333
virtual Handle< String > GetJSON() const =0
static Handle< String > GetMessage(Handle< Object > data)
Definition: messages.cc:151
int max_executable_size()
Definition: v8.h:2641
static void SetWrapperClassId(Object **location, uint16_t class_id)
static Local< T > New(Handle< T > that)
Definition: v8.h:4193
Local< String > GetScriptNameOrSourceURL() const
Definition: api.cc:2069
double FastUI2D(unsigned x)
Definition: conversions.h:84
static Handle< Object > NewDate(double time, bool *exc)
Definition: execution.cc:670
V8EXPORT bool HasNamedLookupInterceptor()
Definition: api.cc:3163
Handle< JSBuiltinsObject > js_builtins_object()
Definition: isolate.h:656
activate correct semantics for inheriting readonliness false
static int GetIdentityHash(Handle< JSObject > obj)
Definition: objects.cc:3531
Definition: v8.h:105
V8EXPORT bool BooleanValue() const
Definition: api.cc:2540
static void UnregisterAll()
Definition: api.cc:516
uint32_t * stack_limit() const
Definition: v8.h:2643
static bool EnableAgent(const char *name, int port, bool wait_for_connection=false)
Handle< Object > ToObject(Handle< Object > object)
Definition: factory.cc:1154
static Local< Context > GetCalling()
Definition: api.cc:4557
V8EXPORT bool SetPrototype(Handle< Value > prototype)
Definition: api.cc:2911
void EnableSlidingStateWindow()
Definition: log.cc:1801
NeanderObject(int size)
Definition: api.cc:837
void(* WeakReferenceCallback)(Persistent< Value > object, void *parameter)
Definition: v8.h:138
int GetLineNumber() const
Definition: api.cc:1873
V8EXPORT bool IsFunction() const
Definition: api.cc:2155
static Local< Value > RangeError(Handle< String > message)
Definition: api.cc:5618
int * free_global_handle_count
Definition: heap.h:2194
static void SetMessageHandler(MessageHandler handler, bool message_handler_thread=false)
void(* MessageHandler)(const uint16_t *message, int length, ClientData *client_data)
Definition: v8-debug.h:224
Handle< Boolean > V8EXPORT False()
Definition: api.cc:579
void SetHiddenPrototype(bool value)
Definition: api.cc:1147
Definition: v8.h:598
Handle< FixedArray > CopyFixedArray(Handle< FixedArray > array)
Definition: factory.cc:523
static Handle< Object > Call(Handle< Object > callable, Handle< Object > receiver, int argc, Handle< Object > argv[], bool *pending_exception, bool convert_receiver=false)
Definition: execution.cc:150
static void DeleteAllSnapshots()
static SnapshotObjectId GetSnapshotObjectId(Handle< Object > obj)
void IterateAllRootsWithClassIds(ObjectVisitor *v)
void RemoveGCPrologueCallback(GCPrologueCallback callback)
Definition: heap.cc:6364
Vector< const char > CStrVector(const char *data)
Definition: utils.h:526
static unsigned Encode(char *out, uchar c, int previous)
Definition: unicode-inl.h:82
int StrLength(const char *string)
Definition: utils.h:234
static Local< Context > ToLocal(v8::internal::Handle< v8::internal::Context > obj)
void SetNamedPropertyHandler(NamedPropertyGetter getter, NamedPropertySetter setter=0, NamedPropertyQuery query=0, NamedPropertyDeleter deleter=0, NamedPropertyEnumerator enumerator=0, Handle< Value > data=Handle< Value >())
Definition: api.cc:1316
intptr_t CommittedMemory()
Definition: heap.cc:203
intptr_t SizeOfObjects()
Definition: heap.cc:429
static void AddCallCompletedCallback(CallCompletedCallback callback)
Definition: api.cc:5445
RegisteredExtension(Extension *extension)
Definition: api.cc:506
Handle< Context > CreateEnvironment(Isolate *isolate, Handle< Object > global_object, v8::Handle< v8::ObjectTemplate > global_template, v8::ExtensionConfiguration *extensions)
Local< String > GetScriptName() const
Definition: api.cc:2053
V8EXPORT int64_t IntegerValue() const
Definition: api.cc:2575
Handle< JSArray > NewJSArrayWithElements(Handle< FixedArrayBase > elements, ElementsKind elements_kind=TERMINAL_FAST_ELEMENTS_KIND, PretenureFlag pretenure=NOT_TENURED)
Definition: factory.cc:951
Context * context()
Definition: isolate.h:520
bool CanContinue() const
Definition: api.cc:1708
static SeqTwoByteString * cast(Object *obj)
V8EXPORT bool IsObject() const
Definition: api.cc:2177
void(* GCEpilogueCallback)(GCType type, GCCallbackFlags flags)
Definition: v8.h:2760
V8EXPORT void SetName(Handle< String > name)
Definition: api.cc:3676
#define EXCEPTION_PREAMBLE(isolate)
Definition: api.cc:81
Handle< Object > NewNumberFromInt(int32_t value, PretenureFlag pretenure=NOT_TENURED)
Definition: factory.cc:605
activate correct semantics for inheriting readonliness enable harmony semantics for typeof enable harmony enable harmony proxies enable all harmony harmony_scoping harmony_proxies harmony_scoping tracks arrays with only smi values automatically unbox arrays of doubles use crankshaft use hydrogen range analysis use hydrogen global value numbering use function inlining maximum number of AST nodes considered for a single inlining loop invariant code motion print statistics for hydrogen trace generated IR for specified phases trace register allocator trace range analysis trace representation types environment for every instruction put a break point before deoptimizing polymorphic inlining perform array bounds checks elimination use dead code elimination trace on stack replacement optimize closures cache optimized code for closures functions with arguments object loop weight for representation inference allow uint32 values on optimize frames if they are used only in safe operations track parallel recompilation enable all profiler experiments number of stack frames inspected by the profiler call recompile stub directly when self optimizing trigger profiler ticks based on counting instead of timing weight back edges by jump distance for interrupt triggering percentage of ICs that must have type info to allow optimization watch_ic_patching retry_self_opt interrupt_at_exit extra verbose compilation tracing generate extra emit comments in code disassembly enable use of SSE3 instructions if available enable use of CMOV instruction if available enable use of SAHF instruction if enable use of VFP3 instructions if available this implies enabling ARMv7 and VFP2 enable use of VFP2 instructions if available enable use of SDIV and UDIV instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of MIPS FPU instructions if expose natives in global object expose gc extension number of stack frames to capture disable builtin natives files print a stack trace if an assertion failure occurs use random jit cookie to mask large constants trace lazy optimization use adaptive optimizations prepare for turning on always opt minimum length for automatic enable preparsing maximum number of optimization attempts before giving up cache prototype transitions automatically set the debug break flag when debugger commands are in the queue always cause a debug break before aborting maximum length of function source code printed in a stack trace max size of the new max size of the old max size of executable always perform global GCs print one trace line following each garbage collection do not print trace line after scavenger collection print more details following each garbage collection print amount of external allocated memory after each time it is adjusted flush code that we expect not to use again before full gc do incremental marking steps track object counts and memory usage use caching Perform compaction on every full GC Never perform compaction on full GC testing only Compact code space on full incremental collections Default seed for initializing random allows verbose printing trace parsing and preparsing Check icache flushes in ARM and MIPS simulator Stack alingment in bytes in print stack trace when throwing exceptions randomize hashes to avoid predictable hash Fixed seed to use to hash property activate a timer that switches between V8 threads testing_bool_flag float flag Seed used for threading test randomness A filename with extra code to be included in the snapshot(mksnapshot only)") DEFINE_bool(help
V8EXPORT double Value() const
Definition: api.cc:4138
bool IsCodeGenerationFromStringsAllowed()
Definition: api.cc:4620
static Local< Value > ReferenceError(Handle< String > message)
Definition: api.cc:5634
void(* JitCodeEventHandler)(const JitCodeEvent *event)
Definition: v8.h:3017
Local< Value > StackTrace() const
Definition: api.cc:1732
bool IsFreshUnusedString(Handle< String > string)
Definition: api.h:326
static void SetMessageHandler2(MessageHandler2 handler)
static V8EXPORT v8::Local< v8::String > Empty()
Definition: api.cc:4769
int GetScriptLineNumber(Handle< Script > script, int code_pos)
Definition: handles.cc:479
intptr_t * old_data_space_capacity
Definition: heap.h:2182
static void StopHeapObjectsTracking()
static Handle< JSFunction > InstantiateFunction(Handle< FunctionTemplateInfo > data, bool *exc)
Definition: execution.cc:722
V8EXPORT Local< Value > CallAsFunction(Handle< Object > recv, int argc, Handle< Value > argv[])
Definition: api.cc:3559
int GetEndPosition() const
Definition: api.cc:1899
const CpuProfileNode * GetTopDownRoot() const
Definition: api.cc:6072
V8EXPORT bool IsDate() const
Definition: api.cc:2239
static Local< Context > GetEntered()
Definition: api.cc:4532
void add(v8::internal::Handle< v8::internal::Object > value)
Definition: api.cc:874
Handle< Integer > ResourceColumnOffset() const
Definition: v8.h:4340
static int NumberOfHandles()
Definition: api.cc:723
static void WriteToFlat(String *source, sinkchar *sink, int from, int to)
Definition: objects.cc:6891
static Handle< SharedFunctionInfo > Compile(Handle< String > source, Handle< Object > script_name, int line_offset, int column_offset, Handle< Context > context, v8::Extension *extension, ScriptDataImpl *pre_data, Handle< Object > script_data, NativesFlag is_natives_code)
Definition: compiler.cc:542
V8EXPORT int GetIndexedPropertiesExternalArrayDataLength()
Definition: api.cc:3535
static internal::Object ** CreateHandle(internal::Object *value)
Definition: api.cc:730
static size_t GetMemorySizeUsedByProfiler()
Definition: api.cc:6430
Handle< String > NewExternalStringFromTwoByte(const ExternalTwoByteString::Resource *resource)
Definition: factory.cc:279
V8EXPORT uint32_t Uint32Value() const
Definition: api.cc:2743
static double nan_value()
static Local< AccessorSignature > New(Handle< FunctionTemplate > receiver=Handle< FunctionTemplate >())
Definition: api.cc:1001
static void * GetExternalPointerFromSmi(internal::Object *value)
Definition: v8.h:4128
static void SetDebugMessageDispatchHandler(DebugMessageDispatchHandler handler, bool provide_locker=false)
int * weak_global_handle_count
Definition: heap.h:2191
void Continue(InterruptFlag after_what)
Definition: execution.cc:513
void Exit()
Definition: api.cc:755
static void SetEntropySource(EntropySource source)
Definition: api.cc:4278
bool is_null() const
Definition: handles.h:87
Handle< Object > NewReferenceError(const char *type, Vector< Handle< Object > > args)
Definition: factory.cc:662
void SetGlobalGCEpilogueCallback(GCCallback callback)
Definition: heap.h:1149
V8EXPORT bool IsNumber() const
Definition: api.cc:2183
static void CancelDebugBreak(Isolate *isolate=NULL)
static int SetFlagsFromString(const char *str, int len)
Definition: flags.cc:475
void DetachGlobal(Handle< Context > env)
Type GetType() const
Definition: api.cc:6262
Handle< String > GetTitle() const
Definition: api.cc:6276
uint32_t SnapshotObjectId
Definition: v8-profiler.h:68
void FatalProcessOutOfMemory(const char *message)
ExternalStringTable * external_string_table()
Definition: heap.h:1568
static void DeleteAllProfiles()
Definition: api.cc:6127
V8EXPORT Local< String > StringValue() const
Definition: api.cc:5022
Local< Function > GetFunction()
Definition: api.cc:4675
static Handle< Object > DeleteProperty(Handle< JSObject > obj, Handle< String > name)
Definition: objects.cc:3926
V8EXPORT bool ForceSet(Handle< Value > key, Handle< Value > value, PropertyAttribute attribs=None)
Definition: api.cc:2807
V8EXPORT bool Delete(Handle< String > key)
Definition: api.cc:3064
static int GetCurrentThreadId()
Definition: api.cc:5480
static void set_raw_data(const byte *raw_data)
Definition: snapshot.h:58
int GetNodesCount() const
Definition: api.cc:6299
static Local< Value > SyntaxError(Handle< String > message)
Definition: api.cc:5651
Handle< Object > NewTypeError(const char *type, Vector< Handle< Object > > args)
Definition: factory.cc:630
static ThreadId FromInteger(int id)
Definition: isolate.h:175
static void AddCallCompletedCallback(CallCompletedCallback callback)
Definition: v8.cc:197
static Handle< Object > GetFunctionDelegate(Handle< Object > object)
Definition: execution.cc:229
int GetChildrenCount() const
Definition: api.cc:6020
V8EXPORT Local< Object > Clone()
Definition: api.cc:3256
virtual const char * data() const =0
static void DisableAgent()
#define EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, value)
Definition: api.cc:107
static int context_size()
Definition: snapshot.h:62
i::Handle< i::String > NewExternalStringHandle(i::Isolate *isolate, v8::String::ExternalStringResource *resource)
Definition: api.cc:4855
const HeapGraphNode * GetRoot() const
Definition: api.cc:6284
static bool SetDebugEventListener2(EventCallback2 that, Handle< Value > data=Handle< Value >())
V8EXPORT bool SetAccessor(Handle< String > name, AccessorGetter getter, AccessorSetter setter=0, Handle< Value > data=Handle< Value >(), AccessControl settings=DEFAULT, PropertyAttribute attribute=None)
Definition: api.cc:3104
V8EXPORT int GetIndexedPropertiesPixelDataLength()
Definition: api.cc:3448
bool(* NamedSecurityCallback)(Local< Object > host, Local< Value > key, AccessType type, Local< Value > data)
Definition: v8.h:2144
static void RemoveMemoryAllocationCallback(MemoryAllocationCallback callback)
Definition: api.cc:5437
Local< ObjectTemplate > PrototypeTemplate()
Definition: api.cc:928
Handle< Foreign > NewForeign(Address addr, PretenureFlag pretenure=NOT_TENURED)
Definition: factory.cc:414
V8EXPORT bool IsFalse() const
Definition: api.cc:2149
static void VisitHandlesWithClassIds(PersistentHandleVisitor *visitor)
Definition: api.cc:4347
const int kHandleBlockSize
Definition: api.h:510
V8EXPORT Flags GetFlags() const
Definition: api.cc:5145
void set(int index, v8::internal::Object *value)
Definition: api.h:113
MUST_USE_RESULT MaybeObject * GetProperty(String *key)
Definition: objects-inl.h:859
#define ASSERT_EQ(v1, v2)
Definition: checks.h:271
void MarkAsUndetectable()
Definition: api.cc:1341
static void SetReturnAddressLocationResolver(ReturnAddressLocationResolver resolver)
Definition: v8.cc:164
static Local< Value > TypeError(Handle< String > message)
Definition: api.cc:5667
static int GetProfilesCount()
Definition: api.cc:6080
static void TearDown()
Definition: v8.cc:103
bool(* EntropySource)(unsigned char *buffer, size_t length)
Definition: v8.h:2934
static Local< Signature > New(Handle< FunctionTemplate > receiver=Handle< FunctionTemplate >(), int argc=0, Handle< FunctionTemplate > argv[]=0)
Definition: api.cc:978
static void Register(RegisteredExtension *that)
Definition: api.cc:510
static void SetGlobalGCPrologueCallback(GCCallback)
Definition: api.cc:5385
static Handle< Object > ToNumber(Handle< Object > obj, bool *exc)
Definition: execution.cc:634
void USE(T)
Definition: globals.h:289
void set_ignore_out_of_memory(bool value)
Definition: isolate.h:701
Counters * counters()
Definition: isolate.h:819
static V8EXPORT Local< Integer > New(int32_t value)
Definition: api.cc:5228
V8EXPORT int GetScriptLineNumber() const
Definition: api.cc:3714
static Handle< JSObject > InstantiateObject(Handle< ObjectTemplateInfo > data, bool *exc)
Definition: execution.cc:744
static void StartProfiling(const char *title)
static void RemoveGCEpilogueCallback(GCEpilogueCallback callback)
Definition: api.cc:5420
activate correct semantics for inheriting readonliness enable harmony semantics for typeof enable harmony enable harmony proxies enable all harmony harmony_scoping harmony_proxies harmony_scoping tracks arrays with only smi values automatically unbox arrays of doubles use crankshaft use hydrogen range analysis use hydrogen global value numbering use function inlining maximum number of AST nodes considered for a single inlining loop invariant code motion print statistics for hydrogen trace generated IR for specified phases trace register allocator trace range analysis trace representation types environment for every instruction put a break point before deoptimizing polymorphic inlining perform array bounds checks elimination use dead code elimination trace on stack replacement optimize closures cache optimized code for closures functions with arguments object loop weight for representation inference allow uint32 values on optimize frames if they are used only in safe operations track parallel recompilation enable all profiler experiments number of stack frames inspected by the profiler call recompile stub directly when self optimizing trigger profiler ticks based on counting instead of timing weight back edges by jump distance for interrupt triggering percentage of ICs that must have type info to allow optimization watch_ic_patching retry_self_opt interrupt_at_exit extra verbose compilation tracing generate extra emit comments in code disassembly enable use of SSE3 instructions if available enable use of CMOV instruction if available enable use of SAHF instruction if enable use of VFP3 instructions if available this implies enabling ARMv7 and VFP2 enable use of VFP2 instructions if available enable use of SDIV and UDIV instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of MIPS FPU instructions if NULL
static void PrepareStressRun(int run)
Definition: api.cc:6460
Handle< StackTrace > GetStackTrace() const
Definition: api.cc:1827
V8EXPORT int64_t Value() const
Definition: api.cc:4152
static void SetCreateHistogramFunction(CreateHistogramCallback)
Definition: api.cc:5320
Local< T > Close(Handle< T > value)
Definition: v8.h:4324
V8EXPORT bool IsNumberObject() const
Definition: api.cc:2255
void MarkIndependent(Object **location)
static FixedArray * cast(Object *obj)
void InitializeLoggingAndCounters()
Definition: isolate.cc:1781
V8EXPORT int WriteAscii(char *buffer, int start=0, int length=-1, int options=NO_OPTIONS) const
Definition: api.cc:3984
static Local< Value > Call(v8::Handle< v8::Function > fun, Handle< Value > data=Handle< Value >())
static bool IsWeak(Object **location)
void Delete()
Definition: api.cc:6036
static void RemoveGCPrologueCallback(GCPrologueCallback callback)
Definition: api.cc:5406
Failure * TerminateExecution()
Definition: isolate.cc:939
static bool ReportApiFailure(const char *location, const char *message)
Definition: api.cc:220
Handle< Primitive > V8EXPORT Undefined()
Definition: api.cc:549
V8EXPORT Local< Value > GetRealNamedPropertyInPrototypeChain(Handle< String > key)
Definition: api.cc:3202
static void EnableSlidingStateWindow()
Definition: api.cc:5335
static V8EXPORT Local< Number > New(double value)
Definition: api.cc:5215
void SetCreateHistogramFunction(CreateHistogramCallback f)
Definition: counters.h:51
intptr_t * old_pointer_space_capacity
Definition: heap.h:2180
ObjectSpace
Definition: v8.h:2700
static Handle< Object > GetElement(Handle< Object > object, uint32_t index)
Definition: objects.cc:250
static HeapSnapshot * FindSnapshot(unsigned uid)
bool IsEmpty() const
Definition: v8.h:209
Local< Value > Run()
Definition: api.cc:1598
#define FACTORY
Definition: isolate.h:1434
static V8EXPORT Local< String > Concat(Handle< String > left, Handle< String > right)
Definition: api.cc:4793
V8EXPORT double NumberValue() const
Definition: api.cc:4979
Logger * logger()
Definition: isolate.h:828
double FastI2D(int x)
Definition: conversions.h:76
V8EXPORT bool HasOwnProperty(Handle< String > key)
Definition: api.cc:3126
void SetData(Handle< Value > data)
Definition: api.cc:776
i::Handle< i::String > NewExternalAsciiStringHandle(i::Isolate *isolate, v8::String::ExternalAsciiStringResource *resource)
Definition: api.cc:4863
static int GetPersistentHandleCount()
Definition: api.cc:6424
void Reset(Input input)
Definition: unicode-inl.h:233
Object * get(int index)
Definition: objects-inl.h:1737
static Handle< Object > ToString(Handle< Object > obj, bool *exc)
Definition: execution.cc:639
static void DeleteAllProfiles()
Handle< Value > GetHeapValue() const
Definition: api.cc:6234
void RecordStats(HeapStats *stats, bool take_snapshot=false)
Definition: heap.cc:5910
unsigned GetUid() const
Definition: api.cc:6048
static Persistent< Context > New(ExtensionConfiguration *extensions=NULL, Handle< ObjectTemplate > global_template=Handle< ObjectTemplate >(), Handle< Value > global_object=Handle< Value >())
Definition: api.cc:4411
void RegisterTryCatchHandler(v8::TryCatch *that)
Definition: isolate.cc:489
bool IsInstanceOf(FunctionTemplateInfo *type)
Definition: objects-inl.h:137
bool IsInGCPostProcessing()
Definition: heap.h:1328
Type GetType() const
Definition: api.cc:6190
static Local< StackTrace > CurrentStackTrace(int frame_limit, StackTraceOptions options=kOverview)
Definition: api.cc:2006
static Local< TypeSwitch > New(Handle< FunctionTemplate > type)
Definition: api.cc:1007
V8EXPORT Local< Object > ToObject() const
Definition: api.cc:2353
V8EXPORT bool IsArray() const
Definition: api.cc:2171
bool IsProfilerPaused()
Definition: log.cc:1344
const uintptr_t kEncodablePointerMask
Definition: v8.h:4062
Handle< Struct > NewStruct(InstanceType type)
Definition: factory.cc:358
bool has_scheduled_exception()
Definition: isolate.h:606
static bool IsLeadSurrogate(int code)
Definition: unicode.h:120
static void LowMemoryNotification()
Definition: api.cc:4380
V8EXPORT uint32_t Length() const
Definition: api.cc:5168
Handle< Object > ForceSetProperty(Handle< JSObject > object, Handle< Object > key, Handle< Object > value, PropertyAttributes attributes)
Definition: handles.cc:246
Handle< Context > native_context()
Definition: isolate.cc:1345
static ScriptData * New(const char *data, int length)
Definition: api.cc:1482
static const CpuProfile * StopProfiling(Handle< String > title, Handle< Value > security_token=Handle< Value >())
Definition: api.cc:6116
V8EXPORT Local< Boolean > ToBoolean() const
Definition: api.cc:2373
StringInputBuffer * write_input_buffer()
Definition: isolate.h:878
V8EXPORT Local< Integer > ToInteger() const
Definition: api.cc:2410
static void SendCommand(const uint16_t *command, int length, ClientData *client_data=NULL, Isolate *isolate=NULL)
intptr_t * map_space_capacity
Definition: heap.h:2186
static bool IsTrailSurrogate(int code)
Definition: unicode.h:124
static void SetFlagsFromCommandLine(int *argc, char **argv, bool remove_flags)
Definition: api.cc:481
void ReattachGlobal(Handle< Context > env, Handle< JSGlobalProxy > global_proxy)
static V8EXPORT Local< External > New(void *value)
Definition: api.cc:4752
static void DebugBreak(Isolate *isolate=NULL)
static const HeapSnapshot * GetSnapshot(int index)
Definition: api.cc:6346
void Delete()
Definition: api.cc:6250
AsciiValue(Handle< v8::Value > obj)
Definition: api.cc:5577
Handle< Boolean >(* IndexedPropertyDeleter)(uint32_t index, const AccessorInfo &info)
Definition: v8.h:2118
void MakeWeak(Object **location, void *parameter, WeakReferenceCallback callback)
V8EXPORT bool IsInt32() const
Definition: api.cc:2205
Handle< Object > SetPrototype(Handle< JSFunction > function, Handle< Object > prototype)
Definition: handles.cc:221
V8EXPORT bool HasRealNamedProperty(Handle< String > key)
Definition: api.cc:3135
#define STATIC_ASSERT(test)
Definition: checks.h:283
static void StartHeapObjectsTracking()
Definition: api.cc:6389
unsigned GetUid() const
Definition: api.cc:6269
static void StartHeapObjectsTracking()
static V8EXPORT Local< String > NewExternal(ExternalStringResource *resource)
Definition: api.cc:4871
static Local< Value > GetMirror(v8::Handle< v8::Value > obj)
void DeleteArray(T *array)
Definition: allocation.h:91
bool V8EXPORT SetResourceConstraints(ResourceConstraints *constraints)
Definition: api.cc:596
intptr_t * memory_allocator_capacity
Definition: heap.h:2196
int GetStartColumn() const
Definition: api.cc:1910
V8EXPORT Handle< Value > GetInferredName() const
Definition: api.cc:3691
static ConsString * cast(Object *obj)
static Handle< Object > TryGetConstructorDelegate(Handle< Object > object, bool *has_pending_exception)
Definition: execution.cc:313
#define FUNCTION_ADDR(f)
Definition: globals.h:293
V8EXPORT Local< Object > FindInstanceInPrototypeChain(Handle< FunctionTemplate > tmpl)
Definition: api.cc:2928
static bool Initialize(const char *snapshot_file=NULL)
void SetStackLimit(uintptr_t limit)
Definition: execution.cc:363
CompressedStartupDataItems
Definition: api.cc:378
static FixedArrayBase * cast(Object *object)
Definition: objects-inl.h:1731
Handle< Value > V8EXPORT ThrowException(Handle< Value > exception)
Definition: api.cc:486
static SnapshotObjectId GetSnapshotObjectId(Handle< Value > value)
Definition: api.cc:6362
Handle< String > NewConsString(Handle< String > first, Handle< String > second)
Definition: factory.cc:243
static const int kMaxValue
Definition: objects.h:1050
static StartupData::CompressionAlgorithm GetCompressedStartupDataAlgorithm()
Definition: api.cc:369
intptr_t * old_data_space_size
Definition: heap.h:2181
virtual ~StartupDataDecompressor()
Definition: api.cc:336
void Reset()
Definition: api.cc:1761
void ReadOnlyPrototype()
Definition: api.cc:1157
static void DeoptimizeAll()
Definition: api.cc:6495
const HeapGraphNode * GetToNode() const
Definition: api.cc:6176
Handle< Value > GetSecurityToken()
Definition: api.cc:4509
Handle< Array >(* IndexedPropertyEnumerator)(const AccessorInfo &info)
Definition: v8.h:2125
static void FatalProcessOutOfMemory(const char *location, bool take_snapshot=false)
V8EXPORT int32_t Value() const
Definition: api.cc:4163
Handle< Value >(* AccessorGetter)(Local< String > property, const AccessorInfo &info)
Definition: v8.h:1448
#define ARRAY_SIZE(a)
Definition: globals.h:281
static void ProcessDebugMessages()
static int raw_size()
Definition: snapshot.h:57
Definition: v8.h:106
void SetErrorMessageForCodeGenerationFromStrings(Handle< String > message)
Definition: api.cc:4634
const int kCharSize
Definition: globals.h:215
static const byte * context_data()
Definition: snapshot.h:61
int match(Handle< Value > value)
Definition: api.cc:1030
static void PauseProfiler()
Definition: api.cc:5462
void Serialize(OutputStream *stream, SerializationFormat format) const
Definition: api.cc:6321
Local< v8::Message > Message() const
Definition: api.cc:1750
V8EXPORT int Write(uint16_t *buffer, int start=0, int length=-1, int options=NO_OPTIONS) const
Definition: api.cc:4035
static int SetFlagsFromCommandLine(int *argc, char **argv, bool remove_flags)
Definition: flags.cc:343
static Handle< Object > TryGetFunctionDelegate(Handle< Object > object, bool *has_pending_exception)
Definition: execution.cc:256
AccessControl
Definition: v8.h:1470
void Inherit(Handle< FunctionTemplate > parent)
Definition: api.cc:943
static HeapSnapshot * TakeSnapshot(const char *name, int type, v8::ActivityControl *control)
PropertyAttribute
Definition: v8.h:1424
static void AddImplicitReferences(Persistent< Object > parent, Persistent< Value > *children, size_t length)
Definition: api.cc:5362
static JSObject * cast(Object *obj)
static bool Initialize()
Definition: api.cc:4269
static void SetRawScriptsSource(Vector< const char > raw_source)
Local< String > GetFunctionName() const
Definition: api.cc:2085
Local< String > GetSourceLine() const
Definition: api.cc:1948
static V8EXPORT Local< Object > New()
Definition: api.cc:4957
int FastD2I(double x)
Definition: conversions.h:69
static const int kNoPreviousCharacter
Definition: unicode.h:132
static void SetCounterFunction(CounterLookupCallback)
Definition: api.cc:5314
v8::internal::Object * get(int index)
Definition: api.h:107
V8EXPORT Local< Uint32 > ToArrayIndex() const
Definition: api.cc:2633
Handle< T > CloseAndEscape(Handle< T > handle_value)
Definition: handles-inl.h:113
void AddMemoryAllocationCallback(MemoryAllocationCallback callback, ObjectSpace space, AllocationAction action)
Definition: spaces.cc:673
Handle< Object > NewError(const char *maker, const char *type, Handle< JSArray > args)
Definition: factory.cc:735
int size()
Definition: api.cc:847
int GetLineNumber() const
Definition: api.cc:5978
static void SetGlobalGCEpilogueCallback(GCCallback)
Definition: api.cc:5392
static void DeleteExtensions(Isolate *isolate)
Definition: handles.cc:99
V8EXPORT uint32_t Value() const
Definition: api.cc:4174
V8EXPORT int GetIdentityHash()
Definition: api.cc:3295
static T ** CreateHandle(T *value, Isolate *isolate)
Definition: handles-inl.h:132
virtual OutputEncoding GetOutputEncoding()
Definition: v8.h:3963
JitCodeEventOptions
Definition: v8.h:3005
void SetAccessCheckCallbacks(NamedSecurityCallback named_handler, IndexedSecurityCallback indexed_handler, Handle< Value > data=Handle< Value >(), bool turned_on_by_default=true)
Definition: api.cc:1354
Handle< Boolean >(* NamedPropertyDeleter)(Local< String > property, const AccessorInfo &info)
Definition: v8.h:2079
V8EXPORT bool Value() const
Definition: api.cc:4145
V8EXPORT bool Set(Handle< Value > key, Handle< Value > value, PropertyAttribute attribs=None)
Definition: api.cc:2765
double GetTotalSamplesCount() const
Definition: api.cc:5999
void SetCodeEventHandler(uint32_t options, JitCodeEventHandler event_handler)
Definition: log.cc:1752
int GetFrameCount() const
Definition: api.cc:1990
Handle< JSObject > Copy(Handle< JSObject > obj)
Definition: handles.cc:335
static bool IdleNotification(int hint=1000)
Definition: api.cc:4371
V8EXPORT double NumberValue() const
Definition: api.cc:5052
static v8::Testing::StressType stress_type()
Definition: api.h:583
static void IgnoreOutOfMemoryException()
Definition: api.cc:5268
static JSFunction * cast(Object *obj)