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

Side by Side Diff: src/api.cc

Issue 6685088: Merge isolates to bleeding_edge. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/api.h ('k') | src/apiutils.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 26 matching lines...) Expand all
37 #include "execution.h" 37 #include "execution.h"
38 #include "global-handles.h" 38 #include "global-handles.h"
39 #include "heap-profiler.h" 39 #include "heap-profiler.h"
40 #include "messages.h" 40 #include "messages.h"
41 #include "parser.h" 41 #include "parser.h"
42 #include "platform.h" 42 #include "platform.h"
43 #include "profile-generator-inl.h" 43 #include "profile-generator-inl.h"
44 #include "runtime-profiler.h" 44 #include "runtime-profiler.h"
45 #include "serialize.h" 45 #include "serialize.h"
46 #include "snapshot.h" 46 #include "snapshot.h"
47 #include "top.h"
48 #include "v8threads.h" 47 #include "v8threads.h"
49 #include "version.h" 48 #include "version.h"
50 #include "vm-state-inl.h" 49 #include "vm-state-inl.h"
51 50
52 #include "../include/v8-profiler.h" 51 #include "../include/v8-profiler.h"
53 #include "../include/v8-testing.h" 52 #include "../include/v8-testing.h"
54 53
55 #define LOG_API(expr) LOG(ApiEntryCall(expr)) 54 #define LOG_API(isolate, expr) LOG(isolate, ApiEntryCall(expr))
56 55
56 // TODO(isolates): avoid repeated TLS reads in function prologues.
57 #ifdef ENABLE_VMSTATE_TRACKING 57 #ifdef ENABLE_VMSTATE_TRACKING
58 #define ENTER_V8 ASSERT(i::V8::IsRunning()); i::VMState __state__(i::OTHER) 58 #define ENTER_V8 \
59 #define LEAVE_V8 i::VMState __state__(i::EXTERNAL) 59 ASSERT(i::Isolate::Current()->IsInitialized()); \
60 i::VMState __state__(i::Isolate::Current(), i::OTHER)
61 #define LEAVE_V8 \
62 i::VMState __state__(i::Isolate::Current(), i::EXTERNAL)
60 #else 63 #else
61 #define ENTER_V8 ((void) 0) 64 #define ENTER_V8 ((void) 0)
62 #define LEAVE_V8 ((void) 0) 65 #define LEAVE_V8 ((void) 0)
63 #endif 66 #endif
64 67
65 namespace v8 { 68 namespace v8 {
66 69
67 #define ON_BAILOUT(location, code) \ 70 #define ON_BAILOUT(isolate, location, code) \
68 if (IsDeadCheck(location) || v8::V8::IsExecutionTerminating()) { \ 71 if (IsDeadCheck(isolate, location) || \
72 v8::V8::IsExecutionTerminating()) { \
69 code; \ 73 code; \
70 UNREACHABLE(); \ 74 UNREACHABLE(); \
71 } 75 }
72 76
73 77
74 #define EXCEPTION_PREAMBLE() \ 78 #define EXCEPTION_PREAMBLE() \
75 thread_local.IncrementCallDepth(); \ 79 i::Isolate::Current()->handle_scope_implementer()->IncrementCallDepth(); \
76 ASSERT(!i::Top::external_caught_exception()); \ 80 ASSERT(!i::Isolate::Current()->external_caught_exception()); \
77 bool has_pending_exception = false 81 bool has_pending_exception = false
78 82
79 83
80 #define EXCEPTION_BAILOUT_CHECK(value) \ 84 #define EXCEPTION_BAILOUT_CHECK(value) \
81 do { \ 85 do { \
82 thread_local.DecrementCallDepth(); \ 86 i::HandleScopeImplementer* handle_scope_implementer = \
87 isolate->handle_scope_implementer(); \
88 handle_scope_implementer->DecrementCallDepth(); \
83 if (has_pending_exception) { \ 89 if (has_pending_exception) { \
84 if (thread_local.CallDepthIsZero() && i::Top::is_out_of_memory()) { \ 90 if (handle_scope_implementer->CallDepthIsZero() && \
85 if (!thread_local.ignore_out_of_memory()) \ 91 i::Isolate::Current()->is_out_of_memory()) { \
92 if (!handle_scope_implementer->ignore_out_of_memory()) \
86 i::V8::FatalProcessOutOfMemory(NULL); \ 93 i::V8::FatalProcessOutOfMemory(NULL); \
87 } \ 94 } \
88 bool call_depth_is_zero = thread_local.CallDepthIsZero(); \ 95 bool call_depth_is_zero = handle_scope_implementer->CallDepthIsZero(); \
89 i::Top::OptionalRescheduleException(call_depth_is_zero); \ 96 i::Isolate::Current()->OptionalRescheduleException(call_depth_is_zero); \
90 return value; \ 97 return value; \
91 } \ 98 } \
92 } while (false) 99 } while (false)
93 100
101 // TODO(isolates): Add a parameter to this macro for an isolate.
94 102
95 #define API_ENTRY_CHECK(msg) \ 103 #define API_ENTRY_CHECK(msg) \
96 do { \ 104 do { \
97 if (v8::Locker::IsActive()) { \ 105 if (v8::Locker::IsActive()) { \
98 ApiCheck(i::ThreadManager::IsLockedByCurrentThread(), \ 106 ApiCheck(i::Isolate::Current()->thread_manager()-> \
107 IsLockedByCurrentThread(), \
99 msg, \ 108 msg, \
100 "Entering the V8 API without proper locking in place"); \ 109 "Entering the V8 API without proper locking in place"); \
101 } \ 110 } \
102 } while (false) 111 } while (false)
103 112
104 113
105 // --- D a t a t h a t i s s p e c i f i c t o a t h r e a d ---
106
107
108 static i::HandleScopeImplementer thread_local;
109
110
111 // --- E x c e p t i o n B e h a v i o r --- 114 // --- E x c e p t i o n B e h a v i o r ---
112 115
113 116
114 static FatalErrorCallback exception_behavior = NULL;
115
116 static void DefaultFatalErrorHandler(const char* location, 117 static void DefaultFatalErrorHandler(const char* location,
117 const char* message) { 118 const char* message) {
118 #ifdef ENABLE_VMSTATE_TRACKING 119 #ifdef ENABLE_VMSTATE_TRACKING
119 i::VMState __state__(i::OTHER); 120 i::VMState __state__(i::Isolate::Current(), i::OTHER);
120 #endif 121 #endif
121 API_Fatal(location, message); 122 API_Fatal(location, message);
122 } 123 }
123 124
124 125
125 static FatalErrorCallback& GetFatalErrorHandler() { 126 static FatalErrorCallback GetFatalErrorHandler() {
126 if (exception_behavior == NULL) { 127 i::Isolate* isolate = i::Isolate::Current();
127 exception_behavior = DefaultFatalErrorHandler; 128 if (isolate->exception_behavior() == NULL) {
129 isolate->set_exception_behavior(DefaultFatalErrorHandler);
128 } 130 }
129 return exception_behavior; 131 return isolate->exception_behavior();
130 } 132 }
131 133
132 134
133 void i::FatalProcessOutOfMemory(const char* location) { 135 void i::FatalProcessOutOfMemory(const char* location) {
134 i::V8::FatalProcessOutOfMemory(location, false); 136 i::V8::FatalProcessOutOfMemory(location, false);
135 } 137 }
136 138
137 139
138 // When V8 cannot allocated memory FatalProcessOutOfMemory is called. 140 // When V8 cannot allocated memory FatalProcessOutOfMemory is called.
139 // The default fatal error handler is called and execution is stopped. 141 // The default fatal error handler is called and execution is stopped.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 intptr_t memory_allocator_capacity; 184 intptr_t memory_allocator_capacity;
183 heap_stats.memory_allocator_capacity = &memory_allocator_capacity; 185 heap_stats.memory_allocator_capacity = &memory_allocator_capacity;
184 int objects_per_type[LAST_TYPE + 1] = {0}; 186 int objects_per_type[LAST_TYPE + 1] = {0};
185 heap_stats.objects_per_type = objects_per_type; 187 heap_stats.objects_per_type = objects_per_type;
186 int size_per_type[LAST_TYPE + 1] = {0}; 188 int size_per_type[LAST_TYPE + 1] = {0};
187 heap_stats.size_per_type = size_per_type; 189 heap_stats.size_per_type = size_per_type;
188 int os_error; 190 int os_error;
189 heap_stats.os_error = &os_error; 191 heap_stats.os_error = &os_error;
190 int end_marker; 192 int end_marker;
191 heap_stats.end_marker = &end_marker; 193 heap_stats.end_marker = &end_marker;
192 i::Heap::RecordStats(&heap_stats, take_snapshot); 194 HEAP->RecordStats(&heap_stats, take_snapshot);
193 i::V8::SetFatalError(); 195 i::V8::SetFatalError();
194 FatalErrorCallback callback = GetFatalErrorHandler(); 196 FatalErrorCallback callback = GetFatalErrorHandler();
195 { 197 {
196 LEAVE_V8; 198 LEAVE_V8;
197 callback(location, "Allocation failed - process out of memory"); 199 callback(location, "Allocation failed - process out of memory");
198 } 200 }
199 // If the callback returns, we stop execution. 201 // If the callback returns, we stop execution.
200 UNREACHABLE(); 202 UNREACHABLE();
201 } 203 }
202 204
203 205
204 void V8::SetFatalErrorHandler(FatalErrorCallback that) {
205 exception_behavior = that;
206 }
207
208
209 bool Utils::ReportApiFailure(const char* location, const char* message) { 206 bool Utils::ReportApiFailure(const char* location, const char* message) {
210 FatalErrorCallback callback = GetFatalErrorHandler(); 207 FatalErrorCallback callback = GetFatalErrorHandler();
211 callback(location, message); 208 callback(location, message);
212 i::V8::SetFatalError(); 209 i::V8::SetFatalError();
213 return false; 210 return false;
214 } 211 }
215 212
216 213
217 bool V8::IsDead() { 214 bool V8::IsDead() {
218 return i::V8::IsDead(); 215 return i::V8::IsDead();
(...skipping 26 matching lines...) Expand all
245 * out of memory at some point this check will fail. It should be called on 242 * out of memory at some point this check will fail. It should be called on
246 * entry to all methods that touch anything in the heap, except destructors 243 * entry to all methods that touch anything in the heap, except destructors
247 * which you sometimes can't avoid calling after the vm has crashed. Functions 244 * which you sometimes can't avoid calling after the vm has crashed. Functions
248 * that call EnsureInitialized or ON_BAILOUT don't have to also call 245 * that call EnsureInitialized or ON_BAILOUT don't have to also call
249 * IsDeadCheck. ON_BAILOUT has the advantage over EnsureInitialized that you 246 * IsDeadCheck. ON_BAILOUT has the advantage over EnsureInitialized that you
250 * can arrange to return if the VM is dead. This is needed to ensure that no VM 247 * can arrange to return if the VM is dead. This is needed to ensure that no VM
251 * heap allocations are attempted on a dead VM. EnsureInitialized has the 248 * heap allocations are attempted on a dead VM. EnsureInitialized has the
252 * advantage over ON_BAILOUT that it actually initializes the VM if this has not 249 * advantage over ON_BAILOUT that it actually initializes the VM if this has not
253 * yet been done. 250 * yet been done.
254 */ 251 */
255 static inline bool IsDeadCheck(const char* location) { 252 static inline bool IsDeadCheck(i::Isolate* isolate, const char* location) {
256 return !i::V8::IsRunning() 253 return !isolate->IsInitialized()
257 && i::V8::IsDead() ? ReportV8Dead(location) : false; 254 && i::V8::IsDead() ? ReportV8Dead(location) : false;
258 } 255 }
259 256
260 257
261 static inline bool EmptyCheck(const char* location, v8::Handle<v8::Data> obj) { 258 static inline bool EmptyCheck(const char* location, v8::Handle<v8::Data> obj) {
262 return obj.IsEmpty() ? ReportEmptyHandle(location) : false; 259 return obj.IsEmpty() ? ReportEmptyHandle(location) : false;
263 } 260 }
264 261
265 262
266 static inline bool EmptyCheck(const char* location, const v8::Data* obj) { 263 static inline bool EmptyCheck(const char* location, const v8::Data* obj) {
267 return (obj == 0) ? ReportEmptyHandle(location) : false; 264 return (obj == 0) ? ReportEmptyHandle(location) : false;
268 } 265 }
269 266
270 // --- S t a t i c s --- 267 // --- S t a t i c s ---
271 268
272 269
273 static i::StringInputBuffer write_input_buffer; 270 static bool InitializeHelper() {
274 271 if (i::Snapshot::Initialize()) return true;
275 272 return i::V8::Initialize(NULL);
276 static inline bool EnsureInitialized(const char* location) {
277 if (i::V8::IsRunning()) {
278 return true;
279 }
280 if (IsDeadCheck(location)) {
281 return false;
282 }
283 return ApiCheck(v8::V8::Initialize(), location, "Error initializing V8");
284 } 273 }
285 274
286 275
287 ImplementationUtilities::HandleScopeData* 276 static inline bool EnsureInitializedForIsolate(i::Isolate* isolate,
288 ImplementationUtilities::CurrentHandleScope() { 277 const char* location) {
289 return &i::HandleScope::current_; 278 if (IsDeadCheck(isolate, location)) return false;
279 if (isolate != NULL) {
280 if (isolate->IsInitialized()) return true;
281 }
282 return ApiCheck(InitializeHelper(), location, "Error initializing V8");
283 }
284
285 static inline bool EnsureInitialized(const char* location) {
286 i::Isolate* isolate = i::Isolate::UncheckedCurrent();
287 return EnsureInitializedForIsolate(isolate, location);
288 }
289
290 // Some initializing API functions are called early and may be
291 // called on a thread different from static initializer thread.
292 // If Isolate API is used, Isolate::Enter() will initialize TLS so
293 // Isolate::Current() works. If it's a legacy case, then the thread
294 // may not have TLS initialized yet. However, in initializing APIs it
295 // may be too early to call EnsureInitialized() - some pre-init
296 // parameters still have to be configured.
297 static inline i::Isolate* EnterIsolateIfNeeded() {
298 i::Isolate* isolate = i::Isolate::UncheckedCurrent();
299 if (isolate != NULL)
300 return isolate;
301
302 i::Isolate::EnterDefaultIsolate();
303 isolate = i::Isolate::Current();
304 return isolate;
305 }
306
307
308 void V8::SetFatalErrorHandler(FatalErrorCallback that) {
309 i::Isolate* isolate = EnterIsolateIfNeeded();
310 isolate->set_exception_behavior(that);
290 } 311 }
291 312
292 313
293 #ifdef DEBUG 314 #ifdef DEBUG
294 void ImplementationUtilities::ZapHandleRange(i::Object** begin, 315 void ImplementationUtilities::ZapHandleRange(i::Object** begin,
295 i::Object** end) { 316 i::Object** end) {
296 i::HandleScope::ZapRange(begin, end); 317 i::HandleScope::ZapRange(begin, end);
297 } 318 }
298 #endif 319 #endif
299 320
300 321
301 v8::Handle<v8::Primitive> ImplementationUtilities::Undefined() { 322 v8::Handle<v8::Primitive> ImplementationUtilities::Undefined() {
302 if (!EnsureInitialized("v8::Undefined()")) return v8::Handle<v8::Primitive>(); 323 if (!EnsureInitialized("v8::Undefined()")) return v8::Handle<v8::Primitive>();
303 return v8::Handle<Primitive>(ToApi<Primitive>(i::Factory::undefined_value())); 324 return v8::Handle<Primitive>(ToApi<Primitive>(FACTORY->undefined_value()));
304 } 325 }
305 326
306 327
307 v8::Handle<v8::Primitive> ImplementationUtilities::Null() { 328 v8::Handle<v8::Primitive> ImplementationUtilities::Null() {
308 if (!EnsureInitialized("v8::Null()")) return v8::Handle<v8::Primitive>(); 329 i::Isolate* isolate = i::Isolate::UncheckedCurrent();
309 return v8::Handle<Primitive>(ToApi<Primitive>(i::Factory::null_value())); 330 if (!EnsureInitializedForIsolate(isolate, "v8::Null()"))
331 return v8::Handle<v8::Primitive>();
332 return v8::Handle<Primitive>(
333 ToApi<Primitive>(isolate->factory()->null_value()));
310 } 334 }
311 335
312 336
313 v8::Handle<v8::Boolean> ImplementationUtilities::True() { 337 v8::Handle<v8::Boolean> ImplementationUtilities::True() {
314 if (!EnsureInitialized("v8::True()")) return v8::Handle<v8::Boolean>(); 338 if (!EnsureInitialized("v8::True()")) return v8::Handle<v8::Boolean>();
315 return v8::Handle<v8::Boolean>(ToApi<Boolean>(i::Factory::true_value())); 339 return v8::Handle<v8::Boolean>(ToApi<Boolean>(FACTORY->true_value()));
316 } 340 }
317 341
318 342
319 v8::Handle<v8::Boolean> ImplementationUtilities::False() { 343 v8::Handle<v8::Boolean> ImplementationUtilities::False() {
320 if (!EnsureInitialized("v8::False()")) return v8::Handle<v8::Boolean>(); 344 if (!EnsureInitialized("v8::False()")) return v8::Handle<v8::Boolean>();
321 return v8::Handle<v8::Boolean>(ToApi<Boolean>(i::Factory::false_value())); 345 return v8::Handle<v8::Boolean>(ToApi<Boolean>(FACTORY->false_value()));
322 } 346 }
323 347
324
325 void V8::SetFlagsFromString(const char* str, int length) { 348 void V8::SetFlagsFromString(const char* str, int length) {
326 i::FlagList::SetFlagsFromString(str, length); 349 i::FlagList::SetFlagsFromString(str, length);
327 } 350 }
328 351
329 352
330 void V8::SetFlagsFromCommandLine(int* argc, char** argv, bool remove_flags) { 353 void V8::SetFlagsFromCommandLine(int* argc, char** argv, bool remove_flags) {
331 i::FlagList::SetFlagsFromCommandLine(argc, argv, remove_flags); 354 i::FlagList::SetFlagsFromCommandLine(argc, argv, remove_flags);
332 } 355 }
333 356
334 357
335 v8::Handle<Value> ThrowException(v8::Handle<v8::Value> value) { 358 v8::Handle<Value> ThrowException(v8::Handle<v8::Value> value) {
336 if (IsDeadCheck("v8::ThrowException()")) return v8::Handle<Value>(); 359 i::Isolate* isolate = i::Isolate::Current();
360 if (IsDeadCheck(isolate, "v8::ThrowException()")) {
361 return v8::Handle<Value>();
362 }
337 ENTER_V8; 363 ENTER_V8;
338 // If we're passed an empty handle, we throw an undefined exception 364 // If we're passed an empty handle, we throw an undefined exception
339 // to deal more gracefully with out of memory situations. 365 // to deal more gracefully with out of memory situations.
340 if (value.IsEmpty()) { 366 if (value.IsEmpty()) {
341 i::Top::ScheduleThrow(i::Heap::undefined_value()); 367 isolate->ScheduleThrow(HEAP->undefined_value());
342 } else { 368 } else {
343 i::Top::ScheduleThrow(*Utils::OpenHandle(*value)); 369 isolate->ScheduleThrow(*Utils::OpenHandle(*value));
344 } 370 }
345 return v8::Undefined(); 371 return v8::Undefined();
346 } 372 }
347 373
348 374
349 RegisteredExtension* RegisteredExtension::first_extension_ = NULL; 375 RegisteredExtension* RegisteredExtension::first_extension_ = NULL;
350 376
351 377
352 RegisteredExtension::RegisteredExtension(Extension* extension) 378 RegisteredExtension::RegisteredExtension(Extension* extension)
353 : extension_(extension), state_(UNVISITED) { } 379 : extension_(extension), state_(UNVISITED) { }
354 380
355 381
356 void RegisteredExtension::Register(RegisteredExtension* that) { 382 void RegisteredExtension::Register(RegisteredExtension* that) {
357 that->next_ = RegisteredExtension::first_extension_; 383 that->next_ = first_extension_;
358 RegisteredExtension::first_extension_ = that; 384 first_extension_ = that;
359 } 385 }
360 386
361 387
362 void RegisterExtension(Extension* that) { 388 void RegisterExtension(Extension* that) {
363 RegisteredExtension* extension = new RegisteredExtension(that); 389 RegisteredExtension* extension = new RegisteredExtension(that);
364 RegisteredExtension::Register(extension); 390 RegisteredExtension::Register(extension);
365 } 391 }
366 392
367 393
368 Extension::Extension(const char* name, 394 Extension::Extension(const char* name,
369 const char* source, 395 const char* source,
370 int dep_count, 396 int dep_count,
371 const char** deps) 397 const char** deps)
372 : name_(name), 398 : name_(name),
373 source_(source), 399 source_(source),
374 dep_count_(dep_count), 400 dep_count_(dep_count),
375 deps_(deps), 401 deps_(deps),
376 auto_enable_(false) { } 402 auto_enable_(false) { }
377 403
378 404
379 v8::Handle<Primitive> Undefined() { 405 v8::Handle<Primitive> Undefined() {
380 LOG_API("Undefined"); 406 i::Isolate* isolate = i::Isolate::Current();
407 LOG_API(isolate, "Undefined");
381 return ImplementationUtilities::Undefined(); 408 return ImplementationUtilities::Undefined();
382 } 409 }
383 410
384 411
385 v8::Handle<Primitive> Null() { 412 v8::Handle<Primitive> Null() {
386 LOG_API("Null"); 413 i::Isolate* isolate = i::Isolate::Current();
414 LOG_API(isolate, "Null");
387 return ImplementationUtilities::Null(); 415 return ImplementationUtilities::Null();
388 } 416 }
389 417
390 418
391 v8::Handle<Boolean> True() { 419 v8::Handle<Boolean> True() {
392 LOG_API("True"); 420 i::Isolate* isolate = i::Isolate::Current();
421 LOG_API(isolate, "True");
393 return ImplementationUtilities::True(); 422 return ImplementationUtilities::True();
394 } 423 }
395 424
396 425
397 v8::Handle<Boolean> False() { 426 v8::Handle<Boolean> False() {
398 LOG_API("False"); 427 i::Isolate* isolate = i::Isolate::Current();
428 LOG_API(isolate, "False");
399 return ImplementationUtilities::False(); 429 return ImplementationUtilities::False();
400 } 430 }
401 431
402 432
403 ResourceConstraints::ResourceConstraints() 433 ResourceConstraints::ResourceConstraints()
404 : max_young_space_size_(0), 434 : max_young_space_size_(0),
405 max_old_space_size_(0), 435 max_old_space_size_(0),
406 max_executable_size_(0), 436 max_executable_size_(0),
407 stack_limit_(NULL) { } 437 stack_limit_(NULL) { }
408 438
409 439
410 bool SetResourceConstraints(ResourceConstraints* constraints) { 440 bool SetResourceConstraints(ResourceConstraints* constraints) {
441 i::Isolate* isolate = EnterIsolateIfNeeded();
442
411 int young_space_size = constraints->max_young_space_size(); 443 int young_space_size = constraints->max_young_space_size();
412 int old_gen_size = constraints->max_old_space_size(); 444 int old_gen_size = constraints->max_old_space_size();
413 int max_executable_size = constraints->max_executable_size(); 445 int max_executable_size = constraints->max_executable_size();
414 if (young_space_size != 0 || old_gen_size != 0 || max_executable_size != 0) { 446 if (young_space_size != 0 || old_gen_size != 0 || max_executable_size != 0) {
415 bool result = i::Heap::ConfigureHeap(young_space_size / 2, 447 // After initialization it's too late to change Heap constraints.
416 old_gen_size, 448 ASSERT(!isolate->IsInitialized());
417 max_executable_size); 449 bool result = isolate->heap()->ConfigureHeap(young_space_size / 2,
450 old_gen_size,
451 max_executable_size);
418 if (!result) return false; 452 if (!result) return false;
419 } 453 }
420 if (constraints->stack_limit() != NULL) { 454 if (constraints->stack_limit() != NULL) {
421 uintptr_t limit = reinterpret_cast<uintptr_t>(constraints->stack_limit()); 455 uintptr_t limit = reinterpret_cast<uintptr_t>(constraints->stack_limit());
422 i::StackGuard::SetStackLimit(limit); 456 isolate->stack_guard()->SetStackLimit(limit);
423 } 457 }
424 return true; 458 return true;
425 } 459 }
426 460
427 461
428 i::Object** V8::GlobalizeReference(i::Object** obj) { 462 i::Object** V8::GlobalizeReference(i::Object** obj) {
429 if (IsDeadCheck("V8::Persistent::New")) return NULL; 463 i::Isolate* isolate = i::Isolate::Current();
430 LOG_API("Persistent::New"); 464 if (IsDeadCheck(isolate, "V8::Persistent::New")) return NULL;
465 LOG_API(isolate, "Persistent::New");
431 i::Handle<i::Object> result = 466 i::Handle<i::Object> result =
432 i::GlobalHandles::Create(*obj); 467 isolate->global_handles()->Create(*obj);
433 return result.location(); 468 return result.location();
434 } 469 }
435 470
436 471
437 void V8::MakeWeak(i::Object** object, void* parameters, 472 void V8::MakeWeak(i::Object** object, void* parameters,
438 WeakReferenceCallback callback) { 473 WeakReferenceCallback callback) {
439 LOG_API("MakeWeak"); 474 i::Isolate* isolate = i::Isolate::Current();
440 i::GlobalHandles::MakeWeak(object, parameters, callback); 475 LOG_API(isolate, "MakeWeak");
476 isolate->global_handles()->MakeWeak(object, parameters,
477 callback);
441 } 478 }
442 479
443 480
444 void V8::ClearWeak(i::Object** obj) { 481 void V8::ClearWeak(i::Object** obj) {
445 LOG_API("ClearWeak"); 482 i::Isolate* isolate = i::Isolate::Current();
446 i::GlobalHandles::ClearWeakness(obj); 483 LOG_API(isolate, "ClearWeak");
484 isolate->global_handles()->ClearWeakness(obj);
447 } 485 }
448 486
449 487
450 bool V8::IsGlobalNearDeath(i::Object** obj) { 488 bool V8::IsGlobalNearDeath(i::Object** obj) {
451 LOG_API("IsGlobalNearDeath"); 489 i::Isolate* isolate = i::Isolate::Current();
452 if (!i::V8::IsRunning()) return false; 490 LOG_API(isolate, "IsGlobalNearDeath");
491 if (!isolate->IsInitialized()) return false;
453 return i::GlobalHandles::IsNearDeath(obj); 492 return i::GlobalHandles::IsNearDeath(obj);
454 } 493 }
455 494
456 495
457 bool V8::IsGlobalWeak(i::Object** obj) { 496 bool V8::IsGlobalWeak(i::Object** obj) {
458 LOG_API("IsGlobalWeak"); 497 i::Isolate* isolate = i::Isolate::Current();
459 if (!i::V8::IsRunning()) return false; 498 LOG_API(isolate, "IsGlobalWeak");
499 if (!isolate->IsInitialized()) return false;
460 return i::GlobalHandles::IsWeak(obj); 500 return i::GlobalHandles::IsWeak(obj);
461 } 501 }
462 502
463 503
464 void V8::DisposeGlobal(i::Object** obj) { 504 void V8::DisposeGlobal(i::Object** obj) {
465 LOG_API("DisposeGlobal"); 505 i::Isolate* isolate = i::Isolate::Current();
466 if (!i::V8::IsRunning()) return; 506 LOG_API(isolate, "DisposeGlobal");
467 i::GlobalHandles::Destroy(obj); 507 if (!isolate->IsInitialized()) return;
508 isolate->global_handles()->Destroy(obj);
468 } 509 }
469 510
470 // --- H a n d l e s --- 511 // --- H a n d l e s ---
471 512
472 513
473 HandleScope::HandleScope() 514 HandleScope::HandleScope() {
474 : prev_next_(i::HandleScope::current_.next),
475 prev_limit_(i::HandleScope::current_.limit),
476 is_closed_(false) {
477 API_ENTRY_CHECK("HandleScope::HandleScope"); 515 API_ENTRY_CHECK("HandleScope::HandleScope");
478 i::HandleScope::current_.level++; 516 i::Isolate* isolate = i::Isolate::Current();
517 v8::ImplementationUtilities::HandleScopeData* current =
518 isolate->handle_scope_data();
519 isolate_ = isolate;
520 prev_next_ = current->next;
521 prev_limit_ = current->limit;
522 is_closed_ = false;
523 current->level++;
479 } 524 }
480 525
481 526
482 HandleScope::~HandleScope() { 527 HandleScope::~HandleScope() {
483 if (!is_closed_) { 528 if (!is_closed_) {
484 Leave(); 529 Leave();
485 } 530 }
486 } 531 }
487 532
488 533
489 void HandleScope::Leave() { 534 void HandleScope::Leave() {
490 i::HandleScope::current_.level--; 535 ASSERT(isolate_ == i::Isolate::Current());
491 ASSERT(i::HandleScope::current_.level >= 0); 536 v8::ImplementationUtilities::HandleScopeData* current =
492 i::HandleScope::current_.next = prev_next_; 537 isolate_->handle_scope_data();
493 if (i::HandleScope::current_.limit != prev_limit_) { 538 current->level--;
494 i::HandleScope::current_.limit = prev_limit_; 539 ASSERT(current->level >= 0);
495 i::HandleScope::DeleteExtensions(); 540 current->next = prev_next_;
541 if (current->limit != prev_limit_) {
542 current->limit = prev_limit_;
543 i::HandleScope::DeleteExtensions(isolate_);
496 } 544 }
497 545
498 #ifdef DEBUG 546 #ifdef DEBUG
499 i::HandleScope::ZapRange(prev_next_, prev_limit_); 547 i::HandleScope::ZapRange(prev_next_, prev_limit_);
500 #endif 548 #endif
501 } 549 }
502 550
503 551
504 int HandleScope::NumberOfHandles() { 552 int HandleScope::NumberOfHandles() {
553 EnsureInitialized("HandleScope::NumberOfHandles");
505 return i::HandleScope::NumberOfHandles(); 554 return i::HandleScope::NumberOfHandles();
506 } 555 }
507 556
508 557
509 i::Object** v8::HandleScope::CreateHandle(i::Object* value) { 558 i::Object** HandleScope::CreateHandle(i::Object* value) {
510 return i::HandleScope::CreateHandle(value); 559 return i::HandleScope::CreateHandle(value, i::Isolate::Current());
560 }
561
562
563 i::Object** HandleScope::CreateHandle(i::HeapObject* value) {
564 ASSERT(value->IsHeapObject());
565 return reinterpret_cast<i::Object**>(
566 i::HandleScope::CreateHandle(value, value->GetIsolate()));
511 } 567 }
512 568
513 569
514 void Context::Enter() { 570 void Context::Enter() {
515 if (IsDeadCheck("v8::Context::Enter()")) return; 571 // TODO(isolates): Context should have a pointer to isolate.
572 i::Isolate* isolate = i::Isolate::Current();
573 if (IsDeadCheck(isolate, "v8::Context::Enter()")) return;
516 ENTER_V8; 574 ENTER_V8;
517 i::Handle<i::Context> env = Utils::OpenHandle(this); 575 i::Handle<i::Context> env = Utils::OpenHandle(this);
518 thread_local.EnterContext(env); 576 isolate->handle_scope_implementer()->EnterContext(env);
519 577
520 thread_local.SaveContext(i::Top::context()); 578 isolate->handle_scope_implementer()->SaveContext(isolate->context());
521 i::Top::set_context(*env); 579 isolate->set_context(*env);
522 } 580 }
523 581
524 582
525 void Context::Exit() { 583 void Context::Exit() {
526 if (!i::V8::IsRunning()) return; 584 // TODO(isolates): Context should have a pointer to isolate.
527 if (!ApiCheck(thread_local.LeaveLastContext(), 585 i::Isolate* isolate = i::Isolate::Current();
586 if (!isolate->IsInitialized()) return;
587
588 if (!ApiCheck(isolate->handle_scope_implementer()->LeaveLastContext(),
528 "v8::Context::Exit()", 589 "v8::Context::Exit()",
529 "Cannot exit non-entered context")) { 590 "Cannot exit non-entered context")) {
530 return; 591 return;
531 } 592 }
532 593
533 // Content of 'last_context' could be NULL. 594 // Content of 'last_context' could be NULL.
534 i::Context* last_context = thread_local.RestoreContext(); 595 i::Context* last_context =
535 i::Top::set_context(last_context); 596 isolate->handle_scope_implementer()->RestoreContext();
597 isolate->set_context(last_context);
536 } 598 }
537 599
538 600
539 void Context::SetData(v8::Handle<String> data) { 601 void Context::SetData(v8::Handle<String> data) {
540 if (IsDeadCheck("v8::Context::SetData()")) return; 602 // TODO(isolates): Context should have a pointer to isolate.
603 i::Isolate* isolate = i::Isolate::Current();
604 if (IsDeadCheck(isolate, "v8::Context::SetData()")) return;
541 ENTER_V8; 605 ENTER_V8;
542 { 606 {
543 HandleScope scope; 607 i::HandleScope scope(isolate);
544 i::Handle<i::Context> env = Utils::OpenHandle(this); 608 i::Handle<i::Context> env = Utils::OpenHandle(this);
545 i::Handle<i::Object> raw_data = Utils::OpenHandle(*data); 609 i::Handle<i::Object> raw_data = Utils::OpenHandle(*data);
546 ASSERT(env->IsGlobalContext()); 610 ASSERT(env->IsGlobalContext());
547 if (env->IsGlobalContext()) { 611 if (env->IsGlobalContext()) {
548 env->set_data(*raw_data); 612 env->set_data(*raw_data);
549 } 613 }
550 } 614 }
551 } 615 }
552 616
553 617
554 v8::Local<v8::Value> Context::GetData() { 618 v8::Local<v8::Value> Context::GetData() {
555 if (IsDeadCheck("v8::Context::GetData()")) return v8::Local<Value>(); 619 // TODO(isolates): Context should have a pointer to isolate.
620 i::Isolate* isolate = i::Isolate::Current();
621 if (IsDeadCheck(isolate, "v8::Context::GetData()")) {
622 return v8::Local<Value>();
623 }
556 ENTER_V8; 624 ENTER_V8;
557 i::Object* raw_result = NULL; 625 i::Object* raw_result = NULL;
558 { 626 {
559 HandleScope scope; 627 i::HandleScope scope(isolate);
560 i::Handle<i::Context> env = Utils::OpenHandle(this); 628 i::Handle<i::Context> env = Utils::OpenHandle(this);
561 ASSERT(env->IsGlobalContext()); 629 ASSERT(env->IsGlobalContext());
562 if (env->IsGlobalContext()) { 630 if (env->IsGlobalContext()) {
563 raw_result = env->data(); 631 raw_result = env->data();
564 } else { 632 } else {
565 return Local<Value>(); 633 return Local<Value>();
566 } 634 }
567 } 635 }
568 i::Handle<i::Object> result(raw_result); 636 i::Handle<i::Object> result(raw_result);
569 return Utils::ToLocal(result); 637 return Utils::ToLocal(result);
570 } 638 }
571 639
572 640
573 i::Object** v8::HandleScope::RawClose(i::Object** value) { 641 i::Object** v8::HandleScope::RawClose(i::Object** value) {
574 if (!ApiCheck(!is_closed_, 642 if (!ApiCheck(!is_closed_,
575 "v8::HandleScope::Close()", 643 "v8::HandleScope::Close()",
576 "Local scope has already been closed")) { 644 "Local scope has already been closed")) {
577 return 0; 645 return 0;
578 } 646 }
579 LOG_API("CloseHandleScope"); 647 LOG_API(isolate_, "CloseHandleScope");
580 648
581 // Read the result before popping the handle block. 649 // Read the result before popping the handle block.
582 i::Object* result = NULL; 650 i::Object* result = NULL;
583 if (value != NULL) { 651 if (value != NULL) {
584 result = *value; 652 result = *value;
585 } 653 }
586 is_closed_ = true; 654 is_closed_ = true;
587 Leave(); 655 Leave();
588 656
589 if (value == NULL) { 657 if (value == NULL) {
(...skipping 10 matching lines...) Expand all
600 668
601 669
602 // A constructor cannot easily return an error value, therefore it is necessary 670 // A constructor cannot easily return an error value, therefore it is necessary
603 // to check for a dead VM with ON_BAILOUT before constructing any Neander 671 // to check for a dead VM with ON_BAILOUT before constructing any Neander
604 // objects. To remind you about this there is no HandleScope in the 672 // objects. To remind you about this there is no HandleScope in the
605 // NeanderObject constructor. When you add one to the site calling the 673 // NeanderObject constructor. When you add one to the site calling the
606 // constructor you should check that you ensured the VM was not dead first. 674 // constructor you should check that you ensured the VM was not dead first.
607 NeanderObject::NeanderObject(int size) { 675 NeanderObject::NeanderObject(int size) {
608 EnsureInitialized("v8::Nowhere"); 676 EnsureInitialized("v8::Nowhere");
609 ENTER_V8; 677 ENTER_V8;
610 value_ = i::Factory::NewNeanderObject(); 678 value_ = FACTORY->NewNeanderObject();
611 i::Handle<i::FixedArray> elements = i::Factory::NewFixedArray(size); 679 i::Handle<i::FixedArray> elements = FACTORY->NewFixedArray(size);
612 value_->set_elements(*elements); 680 value_->set_elements(*elements);
613 } 681 }
614 682
615 683
616 int NeanderObject::size() { 684 int NeanderObject::size() {
617 return i::FixedArray::cast(value_->elements())->length(); 685 return i::FixedArray::cast(value_->elements())->length();
618 } 686 }
619 687
620 688
621 NeanderArray::NeanderArray() : obj_(2) { 689 NeanderArray::NeanderArray() : obj_(2) {
(...skipping 15 matching lines...) Expand all
637 705
638 // This method cannot easily return an error value, therefore it is necessary 706 // This method cannot easily return an error value, therefore it is necessary
639 // to check for a dead VM with ON_BAILOUT before calling it. To remind you 707 // to check for a dead VM with ON_BAILOUT before calling it. To remind you
640 // about this there is no HandleScope in this method. When you add one to the 708 // about this there is no HandleScope in this method. When you add one to the
641 // site calling this method you should check that you ensured the VM was not 709 // site calling this method you should check that you ensured the VM was not
642 // dead first. 710 // dead first.
643 void NeanderArray::add(i::Handle<i::Object> value) { 711 void NeanderArray::add(i::Handle<i::Object> value) {
644 int length = this->length(); 712 int length = this->length();
645 int size = obj_.size(); 713 int size = obj_.size();
646 if (length == size - 1) { 714 if (length == size - 1) {
647 i::Handle<i::FixedArray> new_elms = i::Factory::NewFixedArray(2 * size); 715 i::Handle<i::FixedArray> new_elms = FACTORY->NewFixedArray(2 * size);
648 for (int i = 0; i < length; i++) 716 for (int i = 0; i < length; i++)
649 new_elms->set(i + 1, get(i)); 717 new_elms->set(i + 1, get(i));
650 obj_.value()->set_elements(*new_elms); 718 obj_.value()->set_elements(*new_elms);
651 } 719 }
652 obj_.set(length + 1, *value); 720 obj_.set(length + 1, *value);
653 obj_.set(0, i::Smi::FromInt(length + 1)); 721 obj_.set(0, i::Smi::FromInt(length + 1));
654 } 722 }
655 723
656 724
657 void NeanderArray::set(int index, i::Object* value) { 725 void NeanderArray::set(int index, i::Object* value) {
658 if (index < 0 || index >= this->length()) return; 726 if (index < 0 || index >= this->length()) return;
659 obj_.set(index + 1, value); 727 obj_.set(index + 1, value);
660 } 728 }
661 729
662 730
663 // --- T e m p l a t e --- 731 // --- T e m p l a t e ---
664 732
665 733
666 static void InitializeTemplate(i::Handle<i::TemplateInfo> that, int type) { 734 static void InitializeTemplate(i::Handle<i::TemplateInfo> that, int type) {
667 that->set_tag(i::Smi::FromInt(type)); 735 that->set_tag(i::Smi::FromInt(type));
668 } 736 }
669 737
670 738
671 void Template::Set(v8::Handle<String> name, v8::Handle<Data> value, 739 void Template::Set(v8::Handle<String> name, v8::Handle<Data> value,
672 v8::PropertyAttribute attribute) { 740 v8::PropertyAttribute attribute) {
673 if (IsDeadCheck("v8::Template::Set()")) return; 741 i::Isolate* isolate = i::Isolate::Current();
742 if (IsDeadCheck(isolate, "v8::Template::Set()")) return;
674 ENTER_V8; 743 ENTER_V8;
675 HandleScope scope; 744 i::HandleScope scope(isolate);
676 i::Handle<i::Object> list(Utils::OpenHandle(this)->property_list()); 745 i::Handle<i::Object> list(Utils::OpenHandle(this)->property_list());
677 if (list->IsUndefined()) { 746 if (list->IsUndefined()) {
678 list = NeanderArray().value(); 747 list = NeanderArray().value();
679 Utils::OpenHandle(this)->set_property_list(*list); 748 Utils::OpenHandle(this)->set_property_list(*list);
680 } 749 }
681 NeanderArray array(list); 750 NeanderArray array(list);
682 array.add(Utils::OpenHandle(*name)); 751 array.add(Utils::OpenHandle(*name));
683 array.add(Utils::OpenHandle(*value)); 752 array.add(Utils::OpenHandle(*value));
684 array.add(Utils::OpenHandle(*v8::Integer::New(attribute))); 753 array.add(Utils::OpenHandle(*v8::Integer::New(attribute)));
685 } 754 }
686 755
687 756
688 // --- F u n c t i o n T e m p l a t e --- 757 // --- F u n c t i o n T e m p l a t e ---
689 static void InitializeFunctionTemplate( 758 static void InitializeFunctionTemplate(
690 i::Handle<i::FunctionTemplateInfo> info) { 759 i::Handle<i::FunctionTemplateInfo> info) {
691 info->set_tag(i::Smi::FromInt(Consts::FUNCTION_TEMPLATE)); 760 info->set_tag(i::Smi::FromInt(Consts::FUNCTION_TEMPLATE));
692 info->set_flag(0); 761 info->set_flag(0);
693 } 762 }
694 763
695 764
696 Local<ObjectTemplate> FunctionTemplate::PrototypeTemplate() { 765 Local<ObjectTemplate> FunctionTemplate::PrototypeTemplate() {
697 if (IsDeadCheck("v8::FunctionTemplate::PrototypeTemplate()")) { 766 i::Isolate* isolate = i::Isolate::Current();
767 if (IsDeadCheck(isolate, "v8::FunctionTemplate::PrototypeTemplate()")) {
698 return Local<ObjectTemplate>(); 768 return Local<ObjectTemplate>();
699 } 769 }
700 ENTER_V8; 770 ENTER_V8;
701 i::Handle<i::Object> result(Utils::OpenHandle(this)->prototype_template()); 771 i::Handle<i::Object> result(Utils::OpenHandle(this)->prototype_template());
702 if (result->IsUndefined()) { 772 if (result->IsUndefined()) {
703 result = Utils::OpenHandle(*ObjectTemplate::New()); 773 result = Utils::OpenHandle(*ObjectTemplate::New());
704 Utils::OpenHandle(this)->set_prototype_template(*result); 774 Utils::OpenHandle(this)->set_prototype_template(*result);
705 } 775 }
706 return Local<ObjectTemplate>(ToApi<ObjectTemplate>(result)); 776 return Local<ObjectTemplate>(ToApi<ObjectTemplate>(result));
707 } 777 }
708 778
709 779
710 void FunctionTemplate::Inherit(v8::Handle<FunctionTemplate> value) { 780 void FunctionTemplate::Inherit(v8::Handle<FunctionTemplate> value) {
711 if (IsDeadCheck("v8::FunctionTemplate::Inherit()")) return; 781 i::Isolate* isolate = i::Isolate::Current();
782 if (IsDeadCheck(isolate, "v8::FunctionTemplate::Inherit()")) return;
712 ENTER_V8; 783 ENTER_V8;
713 Utils::OpenHandle(this)->set_parent_template(*Utils::OpenHandle(*value)); 784 Utils::OpenHandle(this)->set_parent_template(*Utils::OpenHandle(*value));
714 } 785 }
715 786
716 787
717 // To distinguish the function templates, so that we can find them in the
718 // function cache of the global context.
719 static int next_serial_number = 0;
720
721
722 Local<FunctionTemplate> FunctionTemplate::New(InvocationCallback callback, 788 Local<FunctionTemplate> FunctionTemplate::New(InvocationCallback callback,
723 v8::Handle<Value> data, v8::Handle<Signature> signature) { 789 v8::Handle<Value> data, v8::Handle<Signature> signature) {
724 EnsureInitialized("v8::FunctionTemplate::New()"); 790 i::Isolate* isolate = i::Isolate::Current();
725 LOG_API("FunctionTemplate::New"); 791 EnsureInitializedForIsolate(isolate, "v8::FunctionTemplate::New()");
792 LOG_API(isolate, "FunctionTemplate::New");
726 ENTER_V8; 793 ENTER_V8;
727 i::Handle<i::Struct> struct_obj = 794 i::Handle<i::Struct> struct_obj =
728 i::Factory::NewStruct(i::FUNCTION_TEMPLATE_INFO_TYPE); 795 FACTORY->NewStruct(i::FUNCTION_TEMPLATE_INFO_TYPE);
729 i::Handle<i::FunctionTemplateInfo> obj = 796 i::Handle<i::FunctionTemplateInfo> obj =
730 i::Handle<i::FunctionTemplateInfo>::cast(struct_obj); 797 i::Handle<i::FunctionTemplateInfo>::cast(struct_obj);
731 InitializeFunctionTemplate(obj); 798 InitializeFunctionTemplate(obj);
732 obj->set_serial_number(i::Smi::FromInt(next_serial_number++)); 799 int next_serial_number = isolate->next_serial_number();
800 isolate->set_next_serial_number(next_serial_number + 1);
801 obj->set_serial_number(i::Smi::FromInt(next_serial_number));
733 if (callback != 0) { 802 if (callback != 0) {
734 if (data.IsEmpty()) data = v8::Undefined(); 803 if (data.IsEmpty()) data = v8::Undefined();
735 Utils::ToLocal(obj)->SetCallHandler(callback, data); 804 Utils::ToLocal(obj)->SetCallHandler(callback, data);
736 } 805 }
737 obj->set_undetectable(false); 806 obj->set_undetectable(false);
738 obj->set_needs_access_check(false); 807 obj->set_needs_access_check(false);
739 808
740 if (!signature.IsEmpty()) 809 if (!signature.IsEmpty())
741 obj->set_signature(*Utils::OpenHandle(*signature)); 810 obj->set_signature(*Utils::OpenHandle(*signature));
742 return Utils::ToLocal(obj); 811 return Utils::ToLocal(obj);
743 } 812 }
744 813
745 814
746 Local<Signature> Signature::New(Handle<FunctionTemplate> receiver, 815 Local<Signature> Signature::New(Handle<FunctionTemplate> receiver,
747 int argc, Handle<FunctionTemplate> argv[]) { 816 int argc, Handle<FunctionTemplate> argv[]) {
748 EnsureInitialized("v8::Signature::New()"); 817 i::Isolate* isolate = i::Isolate::Current();
749 LOG_API("Signature::New"); 818 EnsureInitializedForIsolate(isolate, "v8::Signature::New()");
819 LOG_API(isolate, "Signature::New");
750 ENTER_V8; 820 ENTER_V8;
751 i::Handle<i::Struct> struct_obj = 821 i::Handle<i::Struct> struct_obj =
752 i::Factory::NewStruct(i::SIGNATURE_INFO_TYPE); 822 FACTORY->NewStruct(i::SIGNATURE_INFO_TYPE);
753 i::Handle<i::SignatureInfo> obj = 823 i::Handle<i::SignatureInfo> obj =
754 i::Handle<i::SignatureInfo>::cast(struct_obj); 824 i::Handle<i::SignatureInfo>::cast(struct_obj);
755 if (!receiver.IsEmpty()) obj->set_receiver(*Utils::OpenHandle(*receiver)); 825 if (!receiver.IsEmpty()) obj->set_receiver(*Utils::OpenHandle(*receiver));
756 if (argc > 0) { 826 if (argc > 0) {
757 i::Handle<i::FixedArray> args = i::Factory::NewFixedArray(argc); 827 i::Handle<i::FixedArray> args = FACTORY->NewFixedArray(argc);
758 for (int i = 0; i < argc; i++) { 828 for (int i = 0; i < argc; i++) {
759 if (!argv[i].IsEmpty()) 829 if (!argv[i].IsEmpty())
760 args->set(i, *Utils::OpenHandle(*argv[i])); 830 args->set(i, *Utils::OpenHandle(*argv[i]));
761 } 831 }
762 obj->set_args(*args); 832 obj->set_args(*args);
763 } 833 }
764 return Utils::ToLocal(obj); 834 return Utils::ToLocal(obj);
765 } 835 }
766 836
767 837
768 Local<TypeSwitch> TypeSwitch::New(Handle<FunctionTemplate> type) { 838 Local<TypeSwitch> TypeSwitch::New(Handle<FunctionTemplate> type) {
769 Handle<FunctionTemplate> types[1] = { type }; 839 Handle<FunctionTemplate> types[1] = { type };
770 return TypeSwitch::New(1, types); 840 return TypeSwitch::New(1, types);
771 } 841 }
772 842
773 843
774 Local<TypeSwitch> TypeSwitch::New(int argc, Handle<FunctionTemplate> types[]) { 844 Local<TypeSwitch> TypeSwitch::New(int argc, Handle<FunctionTemplate> types[]) {
775 EnsureInitialized("v8::TypeSwitch::New()"); 845 i::Isolate* isolate = i::Isolate::Current();
776 LOG_API("TypeSwitch::New"); 846 EnsureInitializedForIsolate(isolate, "v8::TypeSwitch::New()");
847 LOG_API(isolate, "TypeSwitch::New");
777 ENTER_V8; 848 ENTER_V8;
778 i::Handle<i::FixedArray> vector = i::Factory::NewFixedArray(argc); 849 i::Handle<i::FixedArray> vector = isolate->factory()->NewFixedArray(argc);
779 for (int i = 0; i < argc; i++) 850 for (int i = 0; i < argc; i++)
780 vector->set(i, *Utils::OpenHandle(*types[i])); 851 vector->set(i, *Utils::OpenHandle(*types[i]));
781 i::Handle<i::Struct> struct_obj = 852 i::Handle<i::Struct> struct_obj =
782 i::Factory::NewStruct(i::TYPE_SWITCH_INFO_TYPE); 853 isolate->factory()->NewStruct(i::TYPE_SWITCH_INFO_TYPE);
783 i::Handle<i::TypeSwitchInfo> obj = 854 i::Handle<i::TypeSwitchInfo> obj =
784 i::Handle<i::TypeSwitchInfo>::cast(struct_obj); 855 i::Handle<i::TypeSwitchInfo>::cast(struct_obj);
785 obj->set_types(*vector); 856 obj->set_types(*vector);
786 return Utils::ToLocal(obj); 857 return Utils::ToLocal(obj);
787 } 858 }
788 859
789 860
790 int TypeSwitch::match(v8::Handle<Value> value) { 861 int TypeSwitch::match(v8::Handle<Value> value) {
791 LOG_API("TypeSwitch::match"); 862 i::Isolate* isolate = i::Isolate::Current();
863 LOG_API(isolate, "TypeSwitch::match");
792 i::Handle<i::Object> obj = Utils::OpenHandle(*value); 864 i::Handle<i::Object> obj = Utils::OpenHandle(*value);
793 i::Handle<i::TypeSwitchInfo> info = Utils::OpenHandle(this); 865 i::Handle<i::TypeSwitchInfo> info = Utils::OpenHandle(this);
794 i::FixedArray* types = i::FixedArray::cast(info->types()); 866 i::FixedArray* types = i::FixedArray::cast(info->types());
795 for (int i = 0; i < types->length(); i++) { 867 for (int i = 0; i < types->length(); i++) {
796 if (obj->IsInstanceOf(i::FunctionTemplateInfo::cast(types->get(i)))) 868 if (obj->IsInstanceOf(i::FunctionTemplateInfo::cast(types->get(i))))
797 return i + 1; 869 return i + 1;
798 } 870 }
799 return 0; 871 return 0;
800 } 872 }
801 873
802 874
803 #define SET_FIELD_WRAPPED(obj, setter, cdata) do { \ 875 #define SET_FIELD_WRAPPED(obj, setter, cdata) do { \
804 i::Handle<i::Object> proxy = FromCData(cdata); \ 876 i::Handle<i::Object> proxy = FromCData(cdata); \
805 (obj)->setter(*proxy); \ 877 (obj)->setter(*proxy); \
806 } while (false) 878 } while (false)
807 879
808 880
809 void FunctionTemplate::SetCallHandler(InvocationCallback callback, 881 void FunctionTemplate::SetCallHandler(InvocationCallback callback,
810 v8::Handle<Value> data) { 882 v8::Handle<Value> data) {
811 if (IsDeadCheck("v8::FunctionTemplate::SetCallHandler()")) return; 883 i::Isolate* isolate = i::Isolate::Current();
884 if (IsDeadCheck(isolate, "v8::FunctionTemplate::SetCallHandler()")) return;
812 ENTER_V8; 885 ENTER_V8;
813 HandleScope scope; 886 i::HandleScope scope(isolate);
814 i::Handle<i::Struct> struct_obj = 887 i::Handle<i::Struct> struct_obj =
815 i::Factory::NewStruct(i::CALL_HANDLER_INFO_TYPE); 888 FACTORY->NewStruct(i::CALL_HANDLER_INFO_TYPE);
816 i::Handle<i::CallHandlerInfo> obj = 889 i::Handle<i::CallHandlerInfo> obj =
817 i::Handle<i::CallHandlerInfo>::cast(struct_obj); 890 i::Handle<i::CallHandlerInfo>::cast(struct_obj);
818 SET_FIELD_WRAPPED(obj, set_callback, callback); 891 SET_FIELD_WRAPPED(obj, set_callback, callback);
819 if (data.IsEmpty()) data = v8::Undefined(); 892 if (data.IsEmpty()) data = v8::Undefined();
820 obj->set_data(*Utils::OpenHandle(*data)); 893 obj->set_data(*Utils::OpenHandle(*data));
821 Utils::OpenHandle(this)->set_call_code(*obj); 894 Utils::OpenHandle(this)->set_call_code(*obj);
822 } 895 }
823 896
824 897
825 static i::Handle<i::AccessorInfo> MakeAccessorInfo( 898 static i::Handle<i::AccessorInfo> MakeAccessorInfo(
826 v8::Handle<String> name, 899 v8::Handle<String> name,
827 AccessorGetter getter, 900 AccessorGetter getter,
828 AccessorSetter setter, 901 AccessorSetter setter,
829 v8::Handle<Value> data, 902 v8::Handle<Value> data,
830 v8::AccessControl settings, 903 v8::AccessControl settings,
831 v8::PropertyAttribute attributes) { 904 v8::PropertyAttribute attributes) {
832 i::Handle<i::AccessorInfo> obj = i::Factory::NewAccessorInfo(); 905 i::Handle<i::AccessorInfo> obj = FACTORY->NewAccessorInfo();
833 ASSERT(getter != NULL); 906 ASSERT(getter != NULL);
834 SET_FIELD_WRAPPED(obj, set_getter, getter); 907 SET_FIELD_WRAPPED(obj, set_getter, getter);
835 SET_FIELD_WRAPPED(obj, set_setter, setter); 908 SET_FIELD_WRAPPED(obj, set_setter, setter);
836 if (data.IsEmpty()) data = v8::Undefined(); 909 if (data.IsEmpty()) data = v8::Undefined();
837 obj->set_data(*Utils::OpenHandle(*data)); 910 obj->set_data(*Utils::OpenHandle(*data));
838 obj->set_name(*Utils::OpenHandle(*name)); 911 obj->set_name(*Utils::OpenHandle(*name));
839 if (settings & ALL_CAN_READ) obj->set_all_can_read(true); 912 if (settings & ALL_CAN_READ) obj->set_all_can_read(true);
840 if (settings & ALL_CAN_WRITE) obj->set_all_can_write(true); 913 if (settings & ALL_CAN_WRITE) obj->set_all_can_write(true);
841 if (settings & PROHIBITS_OVERWRITING) obj->set_prohibits_overwriting(true); 914 if (settings & PROHIBITS_OVERWRITING) obj->set_prohibits_overwriting(true);
842 obj->set_property_attributes(static_cast<PropertyAttributes>(attributes)); 915 obj->set_property_attributes(static_cast<PropertyAttributes>(attributes));
843 return obj; 916 return obj;
844 } 917 }
845 918
846 919
847 void FunctionTemplate::AddInstancePropertyAccessor( 920 void FunctionTemplate::AddInstancePropertyAccessor(
848 v8::Handle<String> name, 921 v8::Handle<String> name,
849 AccessorGetter getter, 922 AccessorGetter getter,
850 AccessorSetter setter, 923 AccessorSetter setter,
851 v8::Handle<Value> data, 924 v8::Handle<Value> data,
852 v8::AccessControl settings, 925 v8::AccessControl settings,
853 v8::PropertyAttribute attributes) { 926 v8::PropertyAttribute attributes) {
854 if (IsDeadCheck("v8::FunctionTemplate::AddInstancePropertyAccessor()")) { 927 i::Isolate* isolate = i::Isolate::Current();
928 if (IsDeadCheck(isolate,
929 "v8::FunctionTemplate::AddInstancePropertyAccessor()")) {
855 return; 930 return;
856 } 931 }
857 ENTER_V8; 932 ENTER_V8;
858 HandleScope scope; 933 i::HandleScope scope(isolate);
859 934
860 i::Handle<i::AccessorInfo> obj = MakeAccessorInfo(name, 935 i::Handle<i::AccessorInfo> obj = MakeAccessorInfo(name,
861 getter, setter, data, 936 getter, setter, data,
862 settings, attributes); 937 settings, attributes);
863 i::Handle<i::Object> list(Utils::OpenHandle(this)->property_accessors()); 938 i::Handle<i::Object> list(Utils::OpenHandle(this)->property_accessors());
864 if (list->IsUndefined()) { 939 if (list->IsUndefined()) {
865 list = NeanderArray().value(); 940 list = NeanderArray().value();
866 Utils::OpenHandle(this)->set_property_accessors(*list); 941 Utils::OpenHandle(this)->set_property_accessors(*list);
867 } 942 }
868 NeanderArray array(list); 943 NeanderArray array(list);
869 array.add(obj); 944 array.add(obj);
870 } 945 }
871 946
872 947
873 Local<ObjectTemplate> FunctionTemplate::InstanceTemplate() { 948 Local<ObjectTemplate> FunctionTemplate::InstanceTemplate() {
874 if (IsDeadCheck("v8::FunctionTemplate::InstanceTemplate()") 949 i::Isolate* isolate = i::Isolate::Current();
950 if (IsDeadCheck(isolate, "v8::FunctionTemplate::InstanceTemplate()")
875 || EmptyCheck("v8::FunctionTemplate::InstanceTemplate()", this)) 951 || EmptyCheck("v8::FunctionTemplate::InstanceTemplate()", this))
876 return Local<ObjectTemplate>(); 952 return Local<ObjectTemplate>();
877 ENTER_V8; 953 ENTER_V8;
878 if (Utils::OpenHandle(this)->instance_template()->IsUndefined()) { 954 if (Utils::OpenHandle(this)->instance_template()->IsUndefined()) {
879 Local<ObjectTemplate> templ = 955 Local<ObjectTemplate> templ =
880 ObjectTemplate::New(v8::Handle<FunctionTemplate>(this)); 956 ObjectTemplate::New(v8::Handle<FunctionTemplate>(this));
881 Utils::OpenHandle(this)->set_instance_template(*Utils::OpenHandle(*templ)); 957 Utils::OpenHandle(this)->set_instance_template(*Utils::OpenHandle(*templ));
882 } 958 }
883 i::Handle<i::ObjectTemplateInfo> result(i::ObjectTemplateInfo::cast( 959 i::Handle<i::ObjectTemplateInfo> result(i::ObjectTemplateInfo::cast(
884 Utils::OpenHandle(this)->instance_template())); 960 Utils::OpenHandle(this)->instance_template()));
885 return Utils::ToLocal(result); 961 return Utils::ToLocal(result);
886 } 962 }
887 963
888 964
889 void FunctionTemplate::SetClassName(Handle<String> name) { 965 void FunctionTemplate::SetClassName(Handle<String> name) {
890 if (IsDeadCheck("v8::FunctionTemplate::SetClassName()")) return; 966 i::Isolate* isolate = i::Isolate::Current();
967 if (IsDeadCheck(isolate, "v8::FunctionTemplate::SetClassName()")) return;
891 ENTER_V8; 968 ENTER_V8;
892 Utils::OpenHandle(this)->set_class_name(*Utils::OpenHandle(*name)); 969 Utils::OpenHandle(this)->set_class_name(*Utils::OpenHandle(*name));
893 } 970 }
894 971
895 972
896 void FunctionTemplate::SetHiddenPrototype(bool value) { 973 void FunctionTemplate::SetHiddenPrototype(bool value) {
897 if (IsDeadCheck("v8::FunctionTemplate::SetHiddenPrototype()")) return; 974 i::Isolate* isolate = i::Isolate::Current();
975 if (IsDeadCheck(isolate, "v8::FunctionTemplate::SetHiddenPrototype()")) {
976 return;
977 }
898 ENTER_V8; 978 ENTER_V8;
899 Utils::OpenHandle(this)->set_hidden_prototype(value); 979 Utils::OpenHandle(this)->set_hidden_prototype(value);
900 } 980 }
901 981
902 982
903 void FunctionTemplate::SetNamedInstancePropertyHandler( 983 void FunctionTemplate::SetNamedInstancePropertyHandler(
904 NamedPropertyGetter getter, 984 NamedPropertyGetter getter,
905 NamedPropertySetter setter, 985 NamedPropertySetter setter,
906 NamedPropertyQuery query, 986 NamedPropertyQuery query,
907 NamedPropertyDeleter remover, 987 NamedPropertyDeleter remover,
908 NamedPropertyEnumerator enumerator, 988 NamedPropertyEnumerator enumerator,
909 Handle<Value> data) { 989 Handle<Value> data) {
910 if (IsDeadCheck("v8::FunctionTemplate::SetNamedInstancePropertyHandler()")) { 990 i::Isolate* isolate = i::Isolate::Current();
991 if (IsDeadCheck(isolate,
992 "v8::FunctionTemplate::SetNamedInstancePropertyHandler()")) {
911 return; 993 return;
912 } 994 }
913 ENTER_V8; 995 ENTER_V8;
914 HandleScope scope; 996 i::HandleScope scope(isolate);
915 i::Handle<i::Struct> struct_obj = 997 i::Handle<i::Struct> struct_obj =
916 i::Factory::NewStruct(i::INTERCEPTOR_INFO_TYPE); 998 isolate->factory()->NewStruct(i::INTERCEPTOR_INFO_TYPE);
917 i::Handle<i::InterceptorInfo> obj = 999 i::Handle<i::InterceptorInfo> obj =
918 i::Handle<i::InterceptorInfo>::cast(struct_obj); 1000 i::Handle<i::InterceptorInfo>::cast(struct_obj);
919 1001
920 if (getter != 0) SET_FIELD_WRAPPED(obj, set_getter, getter); 1002 if (getter != 0) SET_FIELD_WRAPPED(obj, set_getter, getter);
921 if (setter != 0) SET_FIELD_WRAPPED(obj, set_setter, setter); 1003 if (setter != 0) SET_FIELD_WRAPPED(obj, set_setter, setter);
922 if (query != 0) SET_FIELD_WRAPPED(obj, set_query, query); 1004 if (query != 0) SET_FIELD_WRAPPED(obj, set_query, query);
923 if (remover != 0) SET_FIELD_WRAPPED(obj, set_deleter, remover); 1005 if (remover != 0) SET_FIELD_WRAPPED(obj, set_deleter, remover);
924 if (enumerator != 0) SET_FIELD_WRAPPED(obj, set_enumerator, enumerator); 1006 if (enumerator != 0) SET_FIELD_WRAPPED(obj, set_enumerator, enumerator);
925 1007
926 if (data.IsEmpty()) data = v8::Undefined(); 1008 if (data.IsEmpty()) data = v8::Undefined();
927 obj->set_data(*Utils::OpenHandle(*data)); 1009 obj->set_data(*Utils::OpenHandle(*data));
928 Utils::OpenHandle(this)->set_named_property_handler(*obj); 1010 Utils::OpenHandle(this)->set_named_property_handler(*obj);
929 } 1011 }
930 1012
931 1013
932 void FunctionTemplate::SetIndexedInstancePropertyHandler( 1014 void FunctionTemplate::SetIndexedInstancePropertyHandler(
933 IndexedPropertyGetter getter, 1015 IndexedPropertyGetter getter,
934 IndexedPropertySetter setter, 1016 IndexedPropertySetter setter,
935 IndexedPropertyQuery query, 1017 IndexedPropertyQuery query,
936 IndexedPropertyDeleter remover, 1018 IndexedPropertyDeleter remover,
937 IndexedPropertyEnumerator enumerator, 1019 IndexedPropertyEnumerator enumerator,
938 Handle<Value> data) { 1020 Handle<Value> data) {
939 if (IsDeadCheck( 1021 i::Isolate* isolate = i::Isolate::Current();
1022 if (IsDeadCheck(isolate,
940 "v8::FunctionTemplate::SetIndexedInstancePropertyHandler()")) { 1023 "v8::FunctionTemplate::SetIndexedInstancePropertyHandler()")) {
941 return; 1024 return;
942 } 1025 }
943 ENTER_V8; 1026 ENTER_V8;
944 HandleScope scope; 1027 i::HandleScope scope(isolate);
945 i::Handle<i::Struct> struct_obj = 1028 i::Handle<i::Struct> struct_obj =
946 i::Factory::NewStruct(i::INTERCEPTOR_INFO_TYPE); 1029 isolate->factory()->NewStruct(i::INTERCEPTOR_INFO_TYPE);
947 i::Handle<i::InterceptorInfo> obj = 1030 i::Handle<i::InterceptorInfo> obj =
948 i::Handle<i::InterceptorInfo>::cast(struct_obj); 1031 i::Handle<i::InterceptorInfo>::cast(struct_obj);
949 1032
950 if (getter != 0) SET_FIELD_WRAPPED(obj, set_getter, getter); 1033 if (getter != 0) SET_FIELD_WRAPPED(obj, set_getter, getter);
951 if (setter != 0) SET_FIELD_WRAPPED(obj, set_setter, setter); 1034 if (setter != 0) SET_FIELD_WRAPPED(obj, set_setter, setter);
952 if (query != 0) SET_FIELD_WRAPPED(obj, set_query, query); 1035 if (query != 0) SET_FIELD_WRAPPED(obj, set_query, query);
953 if (remover != 0) SET_FIELD_WRAPPED(obj, set_deleter, remover); 1036 if (remover != 0) SET_FIELD_WRAPPED(obj, set_deleter, remover);
954 if (enumerator != 0) SET_FIELD_WRAPPED(obj, set_enumerator, enumerator); 1037 if (enumerator != 0) SET_FIELD_WRAPPED(obj, set_enumerator, enumerator);
955 1038
956 if (data.IsEmpty()) data = v8::Undefined(); 1039 if (data.IsEmpty()) data = v8::Undefined();
957 obj->set_data(*Utils::OpenHandle(*data)); 1040 obj->set_data(*Utils::OpenHandle(*data));
958 Utils::OpenHandle(this)->set_indexed_property_handler(*obj); 1041 Utils::OpenHandle(this)->set_indexed_property_handler(*obj);
959 } 1042 }
960 1043
961 1044
962 void FunctionTemplate::SetInstanceCallAsFunctionHandler( 1045 void FunctionTemplate::SetInstanceCallAsFunctionHandler(
963 InvocationCallback callback, 1046 InvocationCallback callback,
964 Handle<Value> data) { 1047 Handle<Value> data) {
965 if (IsDeadCheck("v8::FunctionTemplate::SetInstanceCallAsFunctionHandler()")) { 1048 i::Isolate* isolate = i::Isolate::Current();
1049 if (IsDeadCheck(isolate,
1050 "v8::FunctionTemplate::SetInstanceCallAsFunctionHandler()")) {
966 return; 1051 return;
967 } 1052 }
968 ENTER_V8; 1053 ENTER_V8;
969 HandleScope scope; 1054 i::HandleScope scope(isolate);
970 i::Handle<i::Struct> struct_obj = 1055 i::Handle<i::Struct> struct_obj =
971 i::Factory::NewStruct(i::CALL_HANDLER_INFO_TYPE); 1056 isolate->factory()->NewStruct(i::CALL_HANDLER_INFO_TYPE);
972 i::Handle<i::CallHandlerInfo> obj = 1057 i::Handle<i::CallHandlerInfo> obj =
973 i::Handle<i::CallHandlerInfo>::cast(struct_obj); 1058 i::Handle<i::CallHandlerInfo>::cast(struct_obj);
974 SET_FIELD_WRAPPED(obj, set_callback, callback); 1059 SET_FIELD_WRAPPED(obj, set_callback, callback);
975 if (data.IsEmpty()) data = v8::Undefined(); 1060 if (data.IsEmpty()) data = v8::Undefined();
976 obj->set_data(*Utils::OpenHandle(*data)); 1061 obj->set_data(*Utils::OpenHandle(*data));
977 Utils::OpenHandle(this)->set_instance_call_handler(*obj); 1062 Utils::OpenHandle(this)->set_instance_call_handler(*obj);
978 } 1063 }
979 1064
980 1065
981 // --- O b j e c t T e m p l a t e --- 1066 // --- O b j e c t T e m p l a t e ---
982 1067
983 1068
984 Local<ObjectTemplate> ObjectTemplate::New() { 1069 Local<ObjectTemplate> ObjectTemplate::New() {
985 return New(Local<FunctionTemplate>()); 1070 return New(Local<FunctionTemplate>());
986 } 1071 }
987 1072
988 1073
989 Local<ObjectTemplate> ObjectTemplate::New( 1074 Local<ObjectTemplate> ObjectTemplate::New(
990 v8::Handle<FunctionTemplate> constructor) { 1075 v8::Handle<FunctionTemplate> constructor) {
991 if (IsDeadCheck("v8::ObjectTemplate::New()")) return Local<ObjectTemplate>(); 1076 i::Isolate* isolate = i::Isolate::Current();
992 EnsureInitialized("v8::ObjectTemplate::New()"); 1077 if (IsDeadCheck(isolate, "v8::ObjectTemplate::New()")) {
993 LOG_API("ObjectTemplate::New"); 1078 return Local<ObjectTemplate>();
1079 }
1080 EnsureInitializedForIsolate(isolate, "v8::ObjectTemplate::New()");
1081 LOG_API(isolate, "ObjectTemplate::New");
994 ENTER_V8; 1082 ENTER_V8;
995 i::Handle<i::Struct> struct_obj = 1083 i::Handle<i::Struct> struct_obj =
996 i::Factory::NewStruct(i::OBJECT_TEMPLATE_INFO_TYPE); 1084 FACTORY->NewStruct(i::OBJECT_TEMPLATE_INFO_TYPE);
997 i::Handle<i::ObjectTemplateInfo> obj = 1085 i::Handle<i::ObjectTemplateInfo> obj =
998 i::Handle<i::ObjectTemplateInfo>::cast(struct_obj); 1086 i::Handle<i::ObjectTemplateInfo>::cast(struct_obj);
999 InitializeTemplate(obj, Consts::OBJECT_TEMPLATE); 1087 InitializeTemplate(obj, Consts::OBJECT_TEMPLATE);
1000 if (!constructor.IsEmpty()) 1088 if (!constructor.IsEmpty())
1001 obj->set_constructor(*Utils::OpenHandle(*constructor)); 1089 obj->set_constructor(*Utils::OpenHandle(*constructor));
1002 obj->set_internal_field_count(i::Smi::FromInt(0)); 1090 obj->set_internal_field_count(i::Smi::FromInt(0));
1003 return Utils::ToLocal(obj); 1091 return Utils::ToLocal(obj);
1004 } 1092 }
1005 1093
1006 1094
1007 // Ensure that the object template has a constructor. If no 1095 // Ensure that the object template has a constructor. If no
1008 // constructor is available we create one. 1096 // constructor is available we create one.
1009 static void EnsureConstructor(ObjectTemplate* object_template) { 1097 static void EnsureConstructor(ObjectTemplate* object_template) {
1010 if (Utils::OpenHandle(object_template)->constructor()->IsUndefined()) { 1098 if (Utils::OpenHandle(object_template)->constructor()->IsUndefined()) {
1011 Local<FunctionTemplate> templ = FunctionTemplate::New(); 1099 Local<FunctionTemplate> templ = FunctionTemplate::New();
1012 i::Handle<i::FunctionTemplateInfo> constructor = Utils::OpenHandle(*templ); 1100 i::Handle<i::FunctionTemplateInfo> constructor = Utils::OpenHandle(*templ);
1013 constructor->set_instance_template(*Utils::OpenHandle(object_template)); 1101 constructor->set_instance_template(*Utils::OpenHandle(object_template));
1014 Utils::OpenHandle(object_template)->set_constructor(*constructor); 1102 Utils::OpenHandle(object_template)->set_constructor(*constructor);
1015 } 1103 }
1016 } 1104 }
1017 1105
1018 1106
1019 void ObjectTemplate::SetAccessor(v8::Handle<String> name, 1107 void ObjectTemplate::SetAccessor(v8::Handle<String> name,
1020 AccessorGetter getter, 1108 AccessorGetter getter,
1021 AccessorSetter setter, 1109 AccessorSetter setter,
1022 v8::Handle<Value> data, 1110 v8::Handle<Value> data,
1023 AccessControl settings, 1111 AccessControl settings,
1024 PropertyAttribute attribute) { 1112 PropertyAttribute attribute) {
1025 if (IsDeadCheck("v8::ObjectTemplate::SetAccessor()")) return; 1113 i::Isolate* isolate = i::Isolate::Current();
1114 if (IsDeadCheck(isolate, "v8::ObjectTemplate::SetAccessor()")) return;
1026 ENTER_V8; 1115 ENTER_V8;
1027 HandleScope scope; 1116 i::HandleScope scope(isolate);
1028 EnsureConstructor(this); 1117 EnsureConstructor(this);
1029 i::FunctionTemplateInfo* constructor = 1118 i::FunctionTemplateInfo* constructor =
1030 i::FunctionTemplateInfo::cast(Utils::OpenHandle(this)->constructor()); 1119 i::FunctionTemplateInfo::cast(Utils::OpenHandle(this)->constructor());
1031 i::Handle<i::FunctionTemplateInfo> cons(constructor); 1120 i::Handle<i::FunctionTemplateInfo> cons(constructor);
1032 Utils::ToLocal(cons)->AddInstancePropertyAccessor(name, 1121 Utils::ToLocal(cons)->AddInstancePropertyAccessor(name,
1033 getter, 1122 getter,
1034 setter, 1123 setter,
1035 data, 1124 data,
1036 settings, 1125 settings,
1037 attribute); 1126 attribute);
1038 } 1127 }
1039 1128
1040 1129
1041 void ObjectTemplate::SetNamedPropertyHandler(NamedPropertyGetter getter, 1130 void ObjectTemplate::SetNamedPropertyHandler(NamedPropertyGetter getter,
1042 NamedPropertySetter setter, 1131 NamedPropertySetter setter,
1043 NamedPropertyQuery query, 1132 NamedPropertyQuery query,
1044 NamedPropertyDeleter remover, 1133 NamedPropertyDeleter remover,
1045 NamedPropertyEnumerator enumerator, 1134 NamedPropertyEnumerator enumerator,
1046 Handle<Value> data) { 1135 Handle<Value> data) {
1047 if (IsDeadCheck("v8::ObjectTemplate::SetNamedPropertyHandler()")) return; 1136 i::Isolate* isolate = i::Isolate::Current();
1137 if (IsDeadCheck(isolate, "v8::ObjectTemplate::SetNamedPropertyHandler()")) {
1138 return;
1139 }
1048 ENTER_V8; 1140 ENTER_V8;
1049 HandleScope scope; 1141 HandleScope scope;
1050 EnsureConstructor(this); 1142 EnsureConstructor(this);
1051 i::FunctionTemplateInfo* constructor = 1143 i::FunctionTemplateInfo* constructor =
1052 i::FunctionTemplateInfo::cast(Utils::OpenHandle(this)->constructor()); 1144 i::FunctionTemplateInfo::cast(Utils::OpenHandle(this)->constructor());
1053 i::Handle<i::FunctionTemplateInfo> cons(constructor); 1145 i::Handle<i::FunctionTemplateInfo> cons(constructor);
1054 Utils::ToLocal(cons)->SetNamedInstancePropertyHandler(getter, 1146 Utils::ToLocal(cons)->SetNamedInstancePropertyHandler(getter,
1055 setter, 1147 setter,
1056 query, 1148 query,
1057 remover, 1149 remover,
1058 enumerator, 1150 enumerator,
1059 data); 1151 data);
1060 } 1152 }
1061 1153
1062 1154
1063 void ObjectTemplate::MarkAsUndetectable() { 1155 void ObjectTemplate::MarkAsUndetectable() {
1064 if (IsDeadCheck("v8::ObjectTemplate::MarkAsUndetectable()")) return; 1156 i::Isolate* isolate = i::Isolate::Current();
1157 if (IsDeadCheck(isolate, "v8::ObjectTemplate::MarkAsUndetectable()")) return;
1065 ENTER_V8; 1158 ENTER_V8;
1066 HandleScope scope; 1159 i::HandleScope scope(isolate);
1067 EnsureConstructor(this); 1160 EnsureConstructor(this);
1068 i::FunctionTemplateInfo* constructor = 1161 i::FunctionTemplateInfo* constructor =
1069 i::FunctionTemplateInfo::cast(Utils::OpenHandle(this)->constructor()); 1162 i::FunctionTemplateInfo::cast(Utils::OpenHandle(this)->constructor());
1070 i::Handle<i::FunctionTemplateInfo> cons(constructor); 1163 i::Handle<i::FunctionTemplateInfo> cons(constructor);
1071 cons->set_undetectable(true); 1164 cons->set_undetectable(true);
1072 } 1165 }
1073 1166
1074 1167
1075 void ObjectTemplate::SetAccessCheckCallbacks( 1168 void ObjectTemplate::SetAccessCheckCallbacks(
1076 NamedSecurityCallback named_callback, 1169 NamedSecurityCallback named_callback,
1077 IndexedSecurityCallback indexed_callback, 1170 IndexedSecurityCallback indexed_callback,
1078 Handle<Value> data, 1171 Handle<Value> data,
1079 bool turned_on_by_default) { 1172 bool turned_on_by_default) {
1080 if (IsDeadCheck("v8::ObjectTemplate::SetAccessCheckCallbacks()")) return; 1173 i::Isolate* isolate = i::Isolate::Current();
1174 if (IsDeadCheck(isolate, "v8::ObjectTemplate::SetAccessCheckCallbacks()")) {
1175 return;
1176 }
1081 ENTER_V8; 1177 ENTER_V8;
1082 HandleScope scope; 1178 i::HandleScope scope(isolate);
1083 EnsureConstructor(this); 1179 EnsureConstructor(this);
1084 1180
1085 i::Handle<i::Struct> struct_info = 1181 i::Handle<i::Struct> struct_info =
1086 i::Factory::NewStruct(i::ACCESS_CHECK_INFO_TYPE); 1182 FACTORY->NewStruct(i::ACCESS_CHECK_INFO_TYPE);
1087 i::Handle<i::AccessCheckInfo> info = 1183 i::Handle<i::AccessCheckInfo> info =
1088 i::Handle<i::AccessCheckInfo>::cast(struct_info); 1184 i::Handle<i::AccessCheckInfo>::cast(struct_info);
1089 1185
1090 SET_FIELD_WRAPPED(info, set_named_callback, named_callback); 1186 SET_FIELD_WRAPPED(info, set_named_callback, named_callback);
1091 SET_FIELD_WRAPPED(info, set_indexed_callback, indexed_callback); 1187 SET_FIELD_WRAPPED(info, set_indexed_callback, indexed_callback);
1092 1188
1093 if (data.IsEmpty()) data = v8::Undefined(); 1189 if (data.IsEmpty()) data = v8::Undefined();
1094 info->set_data(*Utils::OpenHandle(*data)); 1190 info->set_data(*Utils::OpenHandle(*data));
1095 1191
1096 i::FunctionTemplateInfo* constructor = 1192 i::FunctionTemplateInfo* constructor =
1097 i::FunctionTemplateInfo::cast(Utils::OpenHandle(this)->constructor()); 1193 i::FunctionTemplateInfo::cast(Utils::OpenHandle(this)->constructor());
1098 i::Handle<i::FunctionTemplateInfo> cons(constructor); 1194 i::Handle<i::FunctionTemplateInfo> cons(constructor);
1099 cons->set_access_check_info(*info); 1195 cons->set_access_check_info(*info);
1100 cons->set_needs_access_check(turned_on_by_default); 1196 cons->set_needs_access_check(turned_on_by_default);
1101 } 1197 }
1102 1198
1103 1199
1104 void ObjectTemplate::SetIndexedPropertyHandler( 1200 void ObjectTemplate::SetIndexedPropertyHandler(
1105 IndexedPropertyGetter getter, 1201 IndexedPropertyGetter getter,
1106 IndexedPropertySetter setter, 1202 IndexedPropertySetter setter,
1107 IndexedPropertyQuery query, 1203 IndexedPropertyQuery query,
1108 IndexedPropertyDeleter remover, 1204 IndexedPropertyDeleter remover,
1109 IndexedPropertyEnumerator enumerator, 1205 IndexedPropertyEnumerator enumerator,
1110 Handle<Value> data) { 1206 Handle<Value> data) {
1111 if (IsDeadCheck("v8::ObjectTemplate::SetIndexedPropertyHandler()")) return; 1207 i::Isolate* isolate = i::Isolate::Current();
1208 if (IsDeadCheck(isolate, "v8::ObjectTemplate::SetIndexedPropertyHandler()")) {
1209 return;
1210 }
1112 ENTER_V8; 1211 ENTER_V8;
1113 HandleScope scope; 1212 i::HandleScope scope(isolate);
1114 EnsureConstructor(this); 1213 EnsureConstructor(this);
1115 i::FunctionTemplateInfo* constructor = 1214 i::FunctionTemplateInfo* constructor =
1116 i::FunctionTemplateInfo::cast(Utils::OpenHandle(this)->constructor()); 1215 i::FunctionTemplateInfo::cast(Utils::OpenHandle(this)->constructor());
1117 i::Handle<i::FunctionTemplateInfo> cons(constructor); 1216 i::Handle<i::FunctionTemplateInfo> cons(constructor);
1118 Utils::ToLocal(cons)->SetIndexedInstancePropertyHandler(getter, 1217 Utils::ToLocal(cons)->SetIndexedInstancePropertyHandler(getter,
1119 setter, 1218 setter,
1120 query, 1219 query,
1121 remover, 1220 remover,
1122 enumerator, 1221 enumerator,
1123 data); 1222 data);
1124 } 1223 }
1125 1224
1126 1225
1127 void ObjectTemplate::SetCallAsFunctionHandler(InvocationCallback callback, 1226 void ObjectTemplate::SetCallAsFunctionHandler(InvocationCallback callback,
1128 Handle<Value> data) { 1227 Handle<Value> data) {
1129 if (IsDeadCheck("v8::ObjectTemplate::SetCallAsFunctionHandler()")) return; 1228 i::Isolate* isolate = i::Isolate::Current();
1229 if (IsDeadCheck(isolate,
1230 "v8::ObjectTemplate::SetCallAsFunctionHandler()")) {
1231 return;
1232 }
1130 ENTER_V8; 1233 ENTER_V8;
1131 HandleScope scope; 1234 i::HandleScope scope(isolate);
1132 EnsureConstructor(this); 1235 EnsureConstructor(this);
1133 i::FunctionTemplateInfo* constructor = 1236 i::FunctionTemplateInfo* constructor =
1134 i::FunctionTemplateInfo::cast(Utils::OpenHandle(this)->constructor()); 1237 i::FunctionTemplateInfo::cast(Utils::OpenHandle(this)->constructor());
1135 i::Handle<i::FunctionTemplateInfo> cons(constructor); 1238 i::Handle<i::FunctionTemplateInfo> cons(constructor);
1136 Utils::ToLocal(cons)->SetInstanceCallAsFunctionHandler(callback, data); 1239 Utils::ToLocal(cons)->SetInstanceCallAsFunctionHandler(callback, data);
1137 } 1240 }
1138 1241
1139 1242
1140 int ObjectTemplate::InternalFieldCount() { 1243 int ObjectTemplate::InternalFieldCount() {
1141 if (IsDeadCheck("v8::ObjectTemplate::InternalFieldCount()")) { 1244 if (IsDeadCheck(i::Isolate::Current(),
1245 "v8::ObjectTemplate::InternalFieldCount()")) {
1142 return 0; 1246 return 0;
1143 } 1247 }
1144 return i::Smi::cast(Utils::OpenHandle(this)->internal_field_count())->value(); 1248 return i::Smi::cast(Utils::OpenHandle(this)->internal_field_count())->value();
1145 } 1249 }
1146 1250
1147 1251
1148 void ObjectTemplate::SetInternalFieldCount(int value) { 1252 void ObjectTemplate::SetInternalFieldCount(int value) {
1149 if (IsDeadCheck("v8::ObjectTemplate::SetInternalFieldCount()")) return; 1253 i::Isolate* isolate = i::Isolate::Current();
1254 if (IsDeadCheck(isolate, "v8::ObjectTemplate::SetInternalFieldCount()")) {
1255 return;
1256 }
1150 if (!ApiCheck(i::Smi::IsValid(value), 1257 if (!ApiCheck(i::Smi::IsValid(value),
1151 "v8::ObjectTemplate::SetInternalFieldCount()", 1258 "v8::ObjectTemplate::SetInternalFieldCount()",
1152 "Invalid internal field count")) { 1259 "Invalid internal field count")) {
1153 return; 1260 return;
1154 } 1261 }
1155 ENTER_V8; 1262 ENTER_V8;
1156 if (value > 0) { 1263 if (value > 0) {
1157 // The internal field count is set by the constructor function's 1264 // The internal field count is set by the constructor function's
1158 // construct code, so we ensure that there is a constructor 1265 // construct code, so we ensure that there is a constructor
1159 // function to do the setting. 1266 // function to do the setting.
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1207 } 1314 }
1208 1315
1209 1316
1210 // --- S c r i p t --- 1317 // --- S c r i p t ---
1211 1318
1212 1319
1213 Local<Script> Script::New(v8::Handle<String> source, 1320 Local<Script> Script::New(v8::Handle<String> source,
1214 v8::ScriptOrigin* origin, 1321 v8::ScriptOrigin* origin,
1215 v8::ScriptData* pre_data, 1322 v8::ScriptData* pre_data,
1216 v8::Handle<String> script_data) { 1323 v8::Handle<String> script_data) {
1217 ON_BAILOUT("v8::Script::New()", return Local<Script>()); 1324 i::Isolate* isolate = i::Isolate::Current();
1218 LOG_API("Script::New"); 1325 ON_BAILOUT(isolate, "v8::Script::New()", return Local<Script>());
1326 LOG_API(isolate, "Script::New");
1219 ENTER_V8; 1327 ENTER_V8;
1220 i::Handle<i::String> str = Utils::OpenHandle(*source); 1328 i::Handle<i::String> str = Utils::OpenHandle(*source);
1221 i::Handle<i::Object> name_obj; 1329 i::Handle<i::Object> name_obj;
1222 int line_offset = 0; 1330 int line_offset = 0;
1223 int column_offset = 0; 1331 int column_offset = 0;
1224 if (origin != NULL) { 1332 if (origin != NULL) {
1225 if (!origin->ResourceName().IsEmpty()) { 1333 if (!origin->ResourceName().IsEmpty()) {
1226 name_obj = Utils::OpenHandle(*origin->ResourceName()); 1334 name_obj = Utils::OpenHandle(*origin->ResourceName());
1227 } 1335 }
1228 if (!origin->ResourceLineOffset().IsEmpty()) { 1336 if (!origin->ResourceLineOffset().IsEmpty()) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1260 v8::Handle<Value> file_name) { 1368 v8::Handle<Value> file_name) {
1261 ScriptOrigin origin(file_name); 1369 ScriptOrigin origin(file_name);
1262 return New(source, &origin); 1370 return New(source, &origin);
1263 } 1371 }
1264 1372
1265 1373
1266 Local<Script> Script::Compile(v8::Handle<String> source, 1374 Local<Script> Script::Compile(v8::Handle<String> source,
1267 v8::ScriptOrigin* origin, 1375 v8::ScriptOrigin* origin,
1268 v8::ScriptData* pre_data, 1376 v8::ScriptData* pre_data,
1269 v8::Handle<String> script_data) { 1377 v8::Handle<String> script_data) {
1270 ON_BAILOUT("v8::Script::Compile()", return Local<Script>()); 1378 i::Isolate* isolate = i::Isolate::Current();
1271 LOG_API("Script::Compile"); 1379 ON_BAILOUT(isolate, "v8::Script::Compile()", return Local<Script>());
1380 LOG_API(isolate, "Script::Compile");
1272 ENTER_V8; 1381 ENTER_V8;
1273 Local<Script> generic = New(source, origin, pre_data, script_data); 1382 Local<Script> generic = New(source, origin, pre_data, script_data);
1274 if (generic.IsEmpty()) 1383 if (generic.IsEmpty())
1275 return generic; 1384 return generic;
1276 i::Handle<i::Object> obj = Utils::OpenHandle(*generic); 1385 i::Handle<i::Object> obj = Utils::OpenHandle(*generic);
1277 i::Handle<i::SharedFunctionInfo> function = 1386 i::Handle<i::SharedFunctionInfo> function =
1278 i::Handle<i::SharedFunctionInfo>(i::SharedFunctionInfo::cast(*obj)); 1387 i::Handle<i::SharedFunctionInfo>(i::SharedFunctionInfo::cast(*obj));
1279 i::Handle<i::JSFunction> result = 1388 i::Handle<i::JSFunction> result =
1280 i::Factory::NewFunctionFromSharedFunctionInfo(function, 1389 FACTORY->NewFunctionFromSharedFunctionInfo(
1281 i::Top::global_context()); 1390 function,
1391 i::Isolate::Current()->global_context());
1282 return Local<Script>(ToApi<Script>(result)); 1392 return Local<Script>(ToApi<Script>(result));
1283 } 1393 }
1284 1394
1285 1395
1286 Local<Script> Script::Compile(v8::Handle<String> source, 1396 Local<Script> Script::Compile(v8::Handle<String> source,
1287 v8::Handle<Value> file_name, 1397 v8::Handle<Value> file_name,
1288 v8::Handle<String> script_data) { 1398 v8::Handle<String> script_data) {
1289 ScriptOrigin origin(file_name); 1399 ScriptOrigin origin(file_name);
1290 return Compile(source, &origin, 0, script_data); 1400 return Compile(source, &origin, 0, script_data);
1291 } 1401 }
1292 1402
1293 1403
1294 Local<Value> Script::Run() { 1404 Local<Value> Script::Run() {
1295 ON_BAILOUT("v8::Script::Run()", return Local<Value>()); 1405 i::Isolate* isolate = i::Isolate::Current();
1296 LOG_API("Script::Run"); 1406 ON_BAILOUT(isolate, "v8::Script::Run()", return Local<Value>());
1407 LOG_API(isolate, "Script::Run");
1297 ENTER_V8; 1408 ENTER_V8;
1298 i::Object* raw_result = NULL; 1409 i::Object* raw_result = NULL;
1299 { 1410 {
1300 HandleScope scope; 1411 HandleScope scope;
1301 i::Handle<i::Object> obj = Utils::OpenHandle(this); 1412 i::Handle<i::Object> obj = Utils::OpenHandle(this);
1302 i::Handle<i::JSFunction> fun; 1413 i::Handle<i::JSFunction> fun;
1303 if (obj->IsSharedFunctionInfo()) { 1414 if (obj->IsSharedFunctionInfo()) {
1304 i::Handle<i::SharedFunctionInfo> 1415 i::Handle<i::SharedFunctionInfo>
1305 function_info(i::SharedFunctionInfo::cast(*obj)); 1416 function_info(i::SharedFunctionInfo::cast(*obj));
1306 fun = i::Factory::NewFunctionFromSharedFunctionInfo( 1417 fun = FACTORY->NewFunctionFromSharedFunctionInfo(
1307 function_info, i::Top::global_context()); 1418 function_info, i::Isolate::Current()->global_context());
1308 } else { 1419 } else {
1309 fun = i::Handle<i::JSFunction>(i::JSFunction::cast(*obj)); 1420 fun = i::Handle<i::JSFunction>(i::JSFunction::cast(*obj));
1310 } 1421 }
1311 EXCEPTION_PREAMBLE(); 1422 EXCEPTION_PREAMBLE();
1312 i::Handle<i::Object> receiver(i::Top::context()->global_proxy()); 1423 i::Handle<i::Object> receiver(
1424 i::Isolate::Current()->context()->global_proxy());
1313 i::Handle<i::Object> result = 1425 i::Handle<i::Object> result =
1314 i::Execution::Call(fun, receiver, 0, NULL, &has_pending_exception); 1426 i::Execution::Call(fun, receiver, 0, NULL, &has_pending_exception);
1315 EXCEPTION_BAILOUT_CHECK(Local<Value>()); 1427 EXCEPTION_BAILOUT_CHECK(Local<Value>());
1316 raw_result = *result; 1428 raw_result = *result;
1317 } 1429 }
1318 i::Handle<i::Object> result(raw_result); 1430 i::Handle<i::Object> result(raw_result);
1319 return Utils::ToLocal(result); 1431 return Utils::ToLocal(result);
1320 } 1432 }
1321 1433
1322 1434
1323 static i::Handle<i::SharedFunctionInfo> OpenScript(Script* script) { 1435 static i::Handle<i::SharedFunctionInfo> OpenScript(Script* script) {
1324 i::Handle<i::Object> obj = Utils::OpenHandle(script); 1436 i::Handle<i::Object> obj = Utils::OpenHandle(script);
1325 i::Handle<i::SharedFunctionInfo> result; 1437 i::Handle<i::SharedFunctionInfo> result;
1326 if (obj->IsSharedFunctionInfo()) { 1438 if (obj->IsSharedFunctionInfo()) {
1327 result = 1439 result =
1328 i::Handle<i::SharedFunctionInfo>(i::SharedFunctionInfo::cast(*obj)); 1440 i::Handle<i::SharedFunctionInfo>(i::SharedFunctionInfo::cast(*obj));
1329 } else { 1441 } else {
1330 result = 1442 result =
1331 i::Handle<i::SharedFunctionInfo>(i::JSFunction::cast(*obj)->shared()); 1443 i::Handle<i::SharedFunctionInfo>(i::JSFunction::cast(*obj)->shared());
1332 } 1444 }
1333 return result; 1445 return result;
1334 } 1446 }
1335 1447
1336 1448
1337 Local<Value> Script::Id() { 1449 Local<Value> Script::Id() {
1338 ON_BAILOUT("v8::Script::Id()", return Local<Value>()); 1450 i::Isolate* isolate = i::Isolate::Current();
1339 LOG_API("Script::Id"); 1451 ON_BAILOUT(isolate, "v8::Script::Id()", return Local<Value>());
1452 LOG_API(isolate, "Script::Id");
1340 i::Object* raw_id = NULL; 1453 i::Object* raw_id = NULL;
1341 { 1454 {
1342 HandleScope scope; 1455 i::HandleScope scope(isolate);
1343 i::Handle<i::SharedFunctionInfo> function_info = OpenScript(this); 1456 i::Handle<i::SharedFunctionInfo> function_info = OpenScript(this);
1344 i::Handle<i::Script> script(i::Script::cast(function_info->script())); 1457 i::Handle<i::Script> script(i::Script::cast(function_info->script()));
1345 i::Handle<i::Object> id(script->id()); 1458 i::Handle<i::Object> id(script->id());
1346 raw_id = *id; 1459 raw_id = *id;
1347 } 1460 }
1348 i::Handle<i::Object> id(raw_id); 1461 i::Handle<i::Object> id(raw_id);
1349 return Utils::ToLocal(id); 1462 return Utils::ToLocal(id);
1350 } 1463 }
1351 1464
1352 1465
1353 void Script::SetData(v8::Handle<String> data) { 1466 void Script::SetData(v8::Handle<String> data) {
1354 ON_BAILOUT("v8::Script::SetData()", return); 1467 i::Isolate* isolate = i::Isolate::Current();
1355 LOG_API("Script::SetData"); 1468 ON_BAILOUT(isolate, "v8::Script::SetData()", return);
1469 LOG_API(isolate, "Script::SetData");
1356 { 1470 {
1357 HandleScope scope; 1471 i::HandleScope scope(isolate);
1358 i::Handle<i::SharedFunctionInfo> function_info = OpenScript(this); 1472 i::Handle<i::SharedFunctionInfo> function_info = OpenScript(this);
1359 i::Handle<i::Object> raw_data = Utils::OpenHandle(*data); 1473 i::Handle<i::Object> raw_data = Utils::OpenHandle(*data);
1360 i::Handle<i::Script> script(i::Script::cast(function_info->script())); 1474 i::Handle<i::Script> script(i::Script::cast(function_info->script()));
1361 script->set_data(*raw_data); 1475 script->set_data(*raw_data);
1362 } 1476 }
1363 } 1477 }
1364 1478
1365 1479
1366 // --- E x c e p t i o n s --- 1480 // --- E x c e p t i o n s ---
1367 1481
1368 1482
1369 v8::TryCatch::TryCatch() 1483 v8::TryCatch::TryCatch()
1370 : next_(i::Top::try_catch_handler_address()), 1484 : next_(i::Isolate::Current()->try_catch_handler_address()),
1371 exception_(i::Heap::the_hole_value()), 1485 exception_(HEAP->the_hole_value()),
1372 message_(i::Smi::FromInt(0)), 1486 message_(i::Smi::FromInt(0)),
1373 is_verbose_(false), 1487 is_verbose_(false),
1374 can_continue_(true), 1488 can_continue_(true),
1375 capture_message_(true), 1489 capture_message_(true),
1376 rethrow_(false) { 1490 rethrow_(false) {
1377 i::Top::RegisterTryCatchHandler(this); 1491 i::Isolate::Current()->RegisterTryCatchHandler(this);
1378 } 1492 }
1379 1493
1380 1494
1381 v8::TryCatch::~TryCatch() { 1495 v8::TryCatch::~TryCatch() {
1382 if (rethrow_) { 1496 if (rethrow_) {
1383 v8::HandleScope scope; 1497 v8::HandleScope scope;
1384 v8::Local<v8::Value> exc = v8::Local<v8::Value>::New(Exception()); 1498 v8::Local<v8::Value> exc = v8::Local<v8::Value>::New(Exception());
1385 i::Top::UnregisterTryCatchHandler(this); 1499 i::Isolate::Current()->UnregisterTryCatchHandler(this);
1386 v8::ThrowException(exc); 1500 v8::ThrowException(exc);
1387 } else { 1501 } else {
1388 i::Top::UnregisterTryCatchHandler(this); 1502 i::Isolate::Current()->UnregisterTryCatchHandler(this);
1389 } 1503 }
1390 } 1504 }
1391 1505
1392 1506
1393 bool v8::TryCatch::HasCaught() const { 1507 bool v8::TryCatch::HasCaught() const {
1394 return !reinterpret_cast<i::Object*>(exception_)->IsTheHole(); 1508 return !reinterpret_cast<i::Object*>(exception_)->IsTheHole();
1395 } 1509 }
1396 1510
1397 1511
1398 bool v8::TryCatch::CanContinue() const { 1512 bool v8::TryCatch::CanContinue() const {
(...skipping 18 matching lines...) Expand all
1417 } 1531 }
1418 } 1532 }
1419 1533
1420 1534
1421 v8::Local<Value> v8::TryCatch::StackTrace() const { 1535 v8::Local<Value> v8::TryCatch::StackTrace() const {
1422 if (HasCaught()) { 1536 if (HasCaught()) {
1423 i::Object* raw_obj = reinterpret_cast<i::Object*>(exception_); 1537 i::Object* raw_obj = reinterpret_cast<i::Object*>(exception_);
1424 if (!raw_obj->IsJSObject()) return v8::Local<Value>(); 1538 if (!raw_obj->IsJSObject()) return v8::Local<Value>();
1425 v8::HandleScope scope; 1539 v8::HandleScope scope;
1426 i::Handle<i::JSObject> obj(i::JSObject::cast(raw_obj)); 1540 i::Handle<i::JSObject> obj(i::JSObject::cast(raw_obj));
1427 i::Handle<i::String> name = i::Factory::LookupAsciiSymbol("stack"); 1541 i::Handle<i::String> name = FACTORY->LookupAsciiSymbol("stack");
1428 if (!obj->HasProperty(*name)) 1542 if (!obj->HasProperty(*name))
1429 return v8::Local<Value>(); 1543 return v8::Local<Value>();
1430 return scope.Close(v8::Utils::ToLocal(i::GetProperty(obj, name))); 1544 return scope.Close(v8::Utils::ToLocal(i::GetProperty(obj, name)));
1431 } else { 1545 } else {
1432 return v8::Local<Value>(); 1546 return v8::Local<Value>();
1433 } 1547 }
1434 } 1548 }
1435 1549
1436 1550
1437 v8::Local<v8::Message> v8::TryCatch::Message() const { 1551 v8::Local<v8::Message> v8::TryCatch::Message() const {
1438 if (HasCaught() && message_ != i::Smi::FromInt(0)) { 1552 if (HasCaught() && message_ != i::Smi::FromInt(0)) {
1439 i::Object* message = reinterpret_cast<i::Object*>(message_); 1553 i::Object* message = reinterpret_cast<i::Object*>(message_);
1440 return v8::Utils::MessageToLocal(i::Handle<i::Object>(message)); 1554 return v8::Utils::MessageToLocal(i::Handle<i::Object>(message));
1441 } else { 1555 } else {
1442 return v8::Local<v8::Message>(); 1556 return v8::Local<v8::Message>();
1443 } 1557 }
1444 } 1558 }
1445 1559
1446 1560
1447 void v8::TryCatch::Reset() { 1561 void v8::TryCatch::Reset() {
1448 exception_ = i::Heap::the_hole_value(); 1562 exception_ = HEAP->the_hole_value();
1449 message_ = i::Smi::FromInt(0); 1563 message_ = i::Smi::FromInt(0);
1450 } 1564 }
1451 1565
1452 1566
1453 void v8::TryCatch::SetVerbose(bool value) { 1567 void v8::TryCatch::SetVerbose(bool value) {
1454 is_verbose_ = value; 1568 is_verbose_ = value;
1455 } 1569 }
1456 1570
1457 1571
1458 void v8::TryCatch::SetCaptureMessage(bool value) { 1572 void v8::TryCatch::SetCaptureMessage(bool value) {
1459 capture_message_ = value; 1573 capture_message_ = value;
1460 } 1574 }
1461 1575
1462 1576
1463 // --- M e s s a g e --- 1577 // --- M e s s a g e ---
1464 1578
1465 1579
1466 Local<String> Message::Get() const { 1580 Local<String> Message::Get() const {
1467 ON_BAILOUT("v8::Message::Get()", return Local<String>()); 1581 i::Isolate* isolate = i::Isolate::Current();
1582 ON_BAILOUT(isolate, "v8::Message::Get()", return Local<String>());
1468 ENTER_V8; 1583 ENTER_V8;
1469 HandleScope scope; 1584 HandleScope scope;
1470 i::Handle<i::Object> obj = Utils::OpenHandle(this); 1585 i::Handle<i::Object> obj = Utils::OpenHandle(this);
1471 i::Handle<i::String> raw_result = i::MessageHandler::GetMessage(obj); 1586 i::Handle<i::String> raw_result = i::MessageHandler::GetMessage(obj);
1472 Local<String> result = Utils::ToLocal(raw_result); 1587 Local<String> result = Utils::ToLocal(raw_result);
1473 return scope.Close(result); 1588 return scope.Close(result);
1474 } 1589 }
1475 1590
1476 1591
1477 v8::Handle<Value> Message::GetScriptResourceName() const { 1592 v8::Handle<Value> Message::GetScriptResourceName() const {
1478 if (IsDeadCheck("v8::Message::GetScriptResourceName()")) { 1593 i::Isolate* isolate = i::Isolate::Current();
1594 if (IsDeadCheck(isolate, "v8::Message::GetScriptResourceName()")) {
1479 return Local<String>(); 1595 return Local<String>();
1480 } 1596 }
1481 ENTER_V8; 1597 ENTER_V8;
1482 HandleScope scope; 1598 HandleScope scope;
1483 i::Handle<i::JSMessageObject> message = 1599 i::Handle<i::JSMessageObject> message =
1484 i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this)); 1600 i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this));
1485 // Return this.script.name. 1601 // Return this.script.name.
1486 i::Handle<i::JSValue> script = 1602 i::Handle<i::JSValue> script =
1487 i::Handle<i::JSValue>::cast(i::Handle<i::Object>(message->script())); 1603 i::Handle<i::JSValue>::cast(i::Handle<i::Object>(message->script()));
1488 i::Handle<i::Object> resource_name(i::Script::cast(script->value())->name()); 1604 i::Handle<i::Object> resource_name(i::Script::cast(script->value())->name());
1489 return scope.Close(Utils::ToLocal(resource_name)); 1605 return scope.Close(Utils::ToLocal(resource_name));
1490 } 1606 }
1491 1607
1492 1608
1493 v8::Handle<Value> Message::GetScriptData() const { 1609 v8::Handle<Value> Message::GetScriptData() const {
1494 if (IsDeadCheck("v8::Message::GetScriptResourceData()")) { 1610 i::Isolate* isolate = i::Isolate::Current();
1611 if (IsDeadCheck(isolate, "v8::Message::GetScriptResourceData()")) {
1495 return Local<Value>(); 1612 return Local<Value>();
1496 } 1613 }
1497 ENTER_V8; 1614 ENTER_V8;
1498 HandleScope scope; 1615 HandleScope scope;
1499 i::Handle<i::JSMessageObject> message = 1616 i::Handle<i::JSMessageObject> message =
1500 i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this)); 1617 i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this));
1501 // Return this.script.data. 1618 // Return this.script.data.
1502 i::Handle<i::JSValue> script = 1619 i::Handle<i::JSValue> script =
1503 i::Handle<i::JSValue>::cast(i::Handle<i::Object>(message->script())); 1620 i::Handle<i::JSValue>::cast(i::Handle<i::Object>(message->script()));
1504 i::Handle<i::Object> data(i::Script::cast(script->value())->data()); 1621 i::Handle<i::Object> data(i::Script::cast(script->value())->data());
1505 return scope.Close(Utils::ToLocal(data)); 1622 return scope.Close(Utils::ToLocal(data));
1506 } 1623 }
1507 1624
1508 1625
1509 v8::Handle<v8::StackTrace> Message::GetStackTrace() const { 1626 v8::Handle<v8::StackTrace> Message::GetStackTrace() const {
1510 if (IsDeadCheck("v8::Message::GetStackTrace()")) { 1627 i::Isolate* isolate = i::Isolate::Current();
1628 if (IsDeadCheck(isolate, "v8::Message::GetStackTrace()")) {
1511 return Local<v8::StackTrace>(); 1629 return Local<v8::StackTrace>();
1512 } 1630 }
1513 ENTER_V8; 1631 ENTER_V8;
1514 HandleScope scope; 1632 HandleScope scope;
1515 i::Handle<i::JSMessageObject> message = 1633 i::Handle<i::JSMessageObject> message =
1516 i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this)); 1634 i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this));
1517 i::Handle<i::Object> stackFramesObj(message->stack_frames()); 1635 i::Handle<i::Object> stackFramesObj(message->stack_frames());
1518 if (!stackFramesObj->IsJSArray()) return v8::Handle<v8::StackTrace>(); 1636 if (!stackFramesObj->IsJSArray()) return v8::Handle<v8::StackTrace>();
1519 i::Handle<i::JSArray> stackTrace = 1637 i::Handle<i::JSArray> stackTrace =
1520 i::Handle<i::JSArray>::cast(stackFramesObj); 1638 i::Handle<i::JSArray>::cast(stackFramesObj);
1521 return scope.Close(Utils::StackTraceToLocal(stackTrace)); 1639 return scope.Close(Utils::StackTraceToLocal(stackTrace));
1522 } 1640 }
1523 1641
1524 1642
1525 static i::Handle<i::Object> CallV8HeapFunction(const char* name, 1643 static i::Handle<i::Object> CallV8HeapFunction(const char* name,
1526 i::Handle<i::Object> recv, 1644 i::Handle<i::Object> recv,
1527 int argc, 1645 int argc,
1528 i::Object** argv[], 1646 i::Object** argv[],
1529 bool* has_pending_exception) { 1647 bool* has_pending_exception) {
1530 i::Handle<i::String> fmt_str = i::Factory::LookupAsciiSymbol(name); 1648 i::Isolate* isolate = i::Isolate::Current();
1649 i::Handle<i::String> fmt_str = isolate->factory()->LookupAsciiSymbol(name);
1531 i::Object* object_fun = 1650 i::Object* object_fun =
1532 i::Top::builtins()->GetPropertyNoExceptionThrown(*fmt_str); 1651 isolate->js_builtins_object()->GetPropertyNoExceptionThrown(*fmt_str);
1533 i::Handle<i::JSFunction> fun = 1652 i::Handle<i::JSFunction> fun =
1534 i::Handle<i::JSFunction>(i::JSFunction::cast(object_fun)); 1653 i::Handle<i::JSFunction>(i::JSFunction::cast(object_fun));
1535 i::Handle<i::Object> value = 1654 i::Handle<i::Object> value =
1536 i::Execution::Call(fun, recv, argc, argv, has_pending_exception); 1655 i::Execution::Call(fun, recv, argc, argv, has_pending_exception);
1537 return value; 1656 return value;
1538 } 1657 }
1539 1658
1540 1659
1541 static i::Handle<i::Object> CallV8HeapFunction(const char* name, 1660 static i::Handle<i::Object> CallV8HeapFunction(const char* name,
1542 i::Handle<i::Object> data, 1661 i::Handle<i::Object> data,
1543 bool* has_pending_exception) { 1662 bool* has_pending_exception) {
1544 i::Object** argv[1] = { data.location() }; 1663 i::Object** argv[1] = { data.location() };
1545 return CallV8HeapFunction(name, 1664 return CallV8HeapFunction(name,
1546 i::Top::builtins(), 1665 i::Isolate::Current()->js_builtins_object(),
1547 1, 1666 1,
1548 argv, 1667 argv,
1549 has_pending_exception); 1668 has_pending_exception);
1550 } 1669 }
1551 1670
1552 1671
1553 int Message::GetLineNumber() const { 1672 int Message::GetLineNumber() const {
1554 ON_BAILOUT("v8::Message::GetLineNumber()", return kNoLineNumberInfo); 1673 i::Isolate* isolate = i::Isolate::Current();
1674 ON_BAILOUT(isolate, "v8::Message::GetLineNumber()", return kNoLineNumberInfo);
1555 ENTER_V8; 1675 ENTER_V8;
1556 HandleScope scope; 1676 i::HandleScope scope(isolate);
1557 1677
1558 EXCEPTION_PREAMBLE(); 1678 EXCEPTION_PREAMBLE();
1559 i::Handle<i::Object> result = CallV8HeapFunction("GetLineNumber", 1679 i::Handle<i::Object> result = CallV8HeapFunction("GetLineNumber",
1560 Utils::OpenHandle(this), 1680 Utils::OpenHandle(this),
1561 &has_pending_exception); 1681 &has_pending_exception);
1562 EXCEPTION_BAILOUT_CHECK(0); 1682 EXCEPTION_BAILOUT_CHECK(0);
1563 return static_cast<int>(result->Number()); 1683 return static_cast<int>(result->Number());
1564 } 1684 }
1565 1685
1566 1686
1567 int Message::GetStartPosition() const { 1687 int Message::GetStartPosition() const {
1568 if (IsDeadCheck("v8::Message::GetStartPosition()")) return 0; 1688 i::Isolate* isolate = i::Isolate::Current();
1689 if (IsDeadCheck(isolate, "v8::Message::GetStartPosition()")) return 0;
1569 ENTER_V8; 1690 ENTER_V8;
1570 HandleScope scope; 1691 i::HandleScope scope(isolate);
1571 i::Handle<i::JSMessageObject> message = 1692 i::Handle<i::JSMessageObject> message =
1572 i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this)); 1693 i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this));
1573 return message->start_position(); 1694 return message->start_position();
1574 } 1695 }
1575 1696
1576 1697
1577 int Message::GetEndPosition() const { 1698 int Message::GetEndPosition() const {
1578 if (IsDeadCheck("v8::Message::GetEndPosition()")) return 0; 1699 i::Isolate* isolate = i::Isolate::Current();
1700 if (IsDeadCheck(isolate, "v8::Message::GetEndPosition()")) return 0;
1579 ENTER_V8; 1701 ENTER_V8;
1580 HandleScope scope; 1702 i::HandleScope scope(isolate);
1581 i::Handle<i::JSMessageObject> message = 1703 i::Handle<i::JSMessageObject> message =
1582 i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this)); 1704 i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this));
1583 return message->end_position(); 1705 return message->end_position();
1584 } 1706 }
1585 1707
1586 1708
1587 int Message::GetStartColumn() const { 1709 int Message::GetStartColumn() const {
1588 if (IsDeadCheck("v8::Message::GetStartColumn()")) return kNoColumnInfo; 1710 i::Isolate* isolate = i::Isolate::Current();
1711 if (IsDeadCheck(isolate, "v8::Message::GetStartColumn()")) {
1712 return kNoColumnInfo;
1713 }
1589 ENTER_V8; 1714 ENTER_V8;
1590 HandleScope scope; 1715 i::HandleScope scope(isolate);
1591 i::Handle<i::JSObject> data_obj = Utils::OpenHandle(this); 1716 i::Handle<i::JSObject> data_obj = Utils::OpenHandle(this);
1592 EXCEPTION_PREAMBLE(); 1717 EXCEPTION_PREAMBLE();
1593 i::Handle<i::Object> start_col_obj = CallV8HeapFunction( 1718 i::Handle<i::Object> start_col_obj = CallV8HeapFunction(
1594 "GetPositionInLine", 1719 "GetPositionInLine",
1595 data_obj, 1720 data_obj,
1596 &has_pending_exception); 1721 &has_pending_exception);
1597 EXCEPTION_BAILOUT_CHECK(0); 1722 EXCEPTION_BAILOUT_CHECK(0);
1598 return static_cast<int>(start_col_obj->Number()); 1723 return static_cast<int>(start_col_obj->Number());
1599 } 1724 }
1600 1725
1601 1726
1602 int Message::GetEndColumn() const { 1727 int Message::GetEndColumn() const {
1603 if (IsDeadCheck("v8::Message::GetEndColumn()")) return kNoColumnInfo; 1728 i::Isolate* isolate = i::Isolate::Current();
1729 if (IsDeadCheck(isolate, "v8::Message::GetEndColumn()")) return kNoColumnInfo;
1604 ENTER_V8; 1730 ENTER_V8;
1605 HandleScope scope; 1731 i::HandleScope scope(isolate);
1606 i::Handle<i::JSObject> data_obj = Utils::OpenHandle(this); 1732 i::Handle<i::JSObject> data_obj = Utils::OpenHandle(this);
1607 EXCEPTION_PREAMBLE(); 1733 EXCEPTION_PREAMBLE();
1608 i::Handle<i::Object> start_col_obj = CallV8HeapFunction( 1734 i::Handle<i::Object> start_col_obj = CallV8HeapFunction(
1609 "GetPositionInLine", 1735 "GetPositionInLine",
1610 data_obj, 1736 data_obj,
1611 &has_pending_exception); 1737 &has_pending_exception);
1612 EXCEPTION_BAILOUT_CHECK(0); 1738 EXCEPTION_BAILOUT_CHECK(0);
1613 i::Handle<i::JSMessageObject> message = 1739 i::Handle<i::JSMessageObject> message =
1614 i::Handle<i::JSMessageObject>::cast(data_obj); 1740 i::Handle<i::JSMessageObject>::cast(data_obj);
1615 int start = message->start_position(); 1741 int start = message->start_position();
1616 int end = message->end_position(); 1742 int end = message->end_position();
1617 return static_cast<int>(start_col_obj->Number()) + (end - start); 1743 return static_cast<int>(start_col_obj->Number()) + (end - start);
1618 } 1744 }
1619 1745
1620 1746
1621 Local<String> Message::GetSourceLine() const { 1747 Local<String> Message::GetSourceLine() const {
1622 ON_BAILOUT("v8::Message::GetSourceLine()", return Local<String>()); 1748 i::Isolate* isolate = i::Isolate::Current();
1749 ON_BAILOUT(isolate, "v8::Message::GetSourceLine()", return Local<String>());
1623 ENTER_V8; 1750 ENTER_V8;
1624 HandleScope scope; 1751 HandleScope scope;
1625 EXCEPTION_PREAMBLE(); 1752 EXCEPTION_PREAMBLE();
1626 i::Handle<i::Object> result = CallV8HeapFunction("GetSourceLine", 1753 i::Handle<i::Object> result = CallV8HeapFunction("GetSourceLine",
1627 Utils::OpenHandle(this), 1754 Utils::OpenHandle(this),
1628 &has_pending_exception); 1755 &has_pending_exception);
1629 EXCEPTION_BAILOUT_CHECK(Local<v8::String>()); 1756 EXCEPTION_BAILOUT_CHECK(Local<v8::String>());
1630 if (result->IsString()) { 1757 if (result->IsString()) {
1631 return scope.Close(Utils::ToLocal(i::Handle<i::String>::cast(result))); 1758 return scope.Close(Utils::ToLocal(i::Handle<i::String>::cast(result)));
1632 } else { 1759 } else {
1633 return Local<String>(); 1760 return Local<String>();
1634 } 1761 }
1635 } 1762 }
1636 1763
1637 1764
1638 void Message::PrintCurrentStackTrace(FILE* out) { 1765 void Message::PrintCurrentStackTrace(FILE* out) {
1639 if (IsDeadCheck("v8::Message::PrintCurrentStackTrace()")) return; 1766 i::Isolate* isolate = i::Isolate::Current();
1767 if (IsDeadCheck(isolate, "v8::Message::PrintCurrentStackTrace()")) return;
1640 ENTER_V8; 1768 ENTER_V8;
1641 i::Top::PrintCurrentStackTrace(out); 1769 isolate->PrintCurrentStackTrace(out);
1642 } 1770 }
1643 1771
1644 1772
1645 // --- S t a c k T r a c e --- 1773 // --- S t a c k T r a c e ---
1646 1774
1647 Local<StackFrame> StackTrace::GetFrame(uint32_t index) const { 1775 Local<StackFrame> StackTrace::GetFrame(uint32_t index) const {
1648 if (IsDeadCheck("v8::StackTrace::GetFrame()")) return Local<StackFrame>(); 1776 i::Isolate* isolate = i::Isolate::Current();
1777 if (IsDeadCheck(isolate, "v8::StackTrace::GetFrame()")) {
1778 return Local<StackFrame>();
1779 }
1649 ENTER_V8; 1780 ENTER_V8;
1650 HandleScope scope; 1781 HandleScope scope;
1651 i::Handle<i::JSArray> self = Utils::OpenHandle(this); 1782 i::Handle<i::JSArray> self = Utils::OpenHandle(this);
1652 i::Object* raw_object = self->GetElementNoExceptionThrown(index); 1783 i::Object* raw_object = self->GetElementNoExceptionThrown(index);
1653 i::Handle<i::JSObject> obj(i::JSObject::cast(raw_object)); 1784 i::Handle<i::JSObject> obj(i::JSObject::cast(raw_object));
1654 return scope.Close(Utils::StackFrameToLocal(obj)); 1785 return scope.Close(Utils::StackFrameToLocal(obj));
1655 } 1786 }
1656 1787
1657 1788
1658 int StackTrace::GetFrameCount() const { 1789 int StackTrace::GetFrameCount() const {
1659 if (IsDeadCheck("v8::StackTrace::GetFrameCount()")) return -1; 1790 i::Isolate* isolate = i::Isolate::Current();
1791 if (IsDeadCheck(isolate, "v8::StackTrace::GetFrameCount()")) return -1;
1660 ENTER_V8; 1792 ENTER_V8;
1661 return i::Smi::cast(Utils::OpenHandle(this)->length())->value(); 1793 return i::Smi::cast(Utils::OpenHandle(this)->length())->value();
1662 } 1794 }
1663 1795
1664 1796
1665 Local<Array> StackTrace::AsArray() { 1797 Local<Array> StackTrace::AsArray() {
1666 if (IsDeadCheck("v8::StackTrace::AsArray()")) Local<Array>(); 1798 i::Isolate* isolate = i::Isolate::Current();
1799 if (IsDeadCheck(isolate, "v8::StackTrace::AsArray()")) Local<Array>();
1667 ENTER_V8; 1800 ENTER_V8;
1668 return Utils::ToLocal(Utils::OpenHandle(this)); 1801 return Utils::ToLocal(Utils::OpenHandle(this));
1669 } 1802 }
1670 1803
1671 1804
1672 Local<StackTrace> StackTrace::CurrentStackTrace(int frame_limit, 1805 Local<StackTrace> StackTrace::CurrentStackTrace(int frame_limit,
1673 StackTraceOptions options) { 1806 StackTraceOptions options) {
1674 if (IsDeadCheck("v8::StackTrace::CurrentStackTrace()")) Local<StackTrace>(); 1807 i::Isolate* isolate = i::Isolate::Current();
1808 if (IsDeadCheck(isolate, "v8::StackTrace::CurrentStackTrace()")) {
1809 Local<StackTrace>();
1810 }
1675 ENTER_V8; 1811 ENTER_V8;
1676 i::Handle<i::JSArray> stackTrace = 1812 i::Handle<i::JSArray> stackTrace =
1677 i::Top::CaptureCurrentStackTrace(frame_limit, options); 1813 isolate->CaptureCurrentStackTrace(frame_limit, options);
1678 return Utils::StackTraceToLocal(stackTrace); 1814 return Utils::StackTraceToLocal(stackTrace);
1679 } 1815 }
1680 1816
1681 1817
1682 // --- S t a c k F r a m e --- 1818 // --- S t a c k F r a m e ---
1683 1819
1684 int StackFrame::GetLineNumber() const { 1820 int StackFrame::GetLineNumber() const {
1685 if (IsDeadCheck("v8::StackFrame::GetLineNumber()")) { 1821 i::Isolate* isolate = i::Isolate::Current();
1822 if (IsDeadCheck(isolate, "v8::StackFrame::GetLineNumber()")) {
1686 return Message::kNoLineNumberInfo; 1823 return Message::kNoLineNumberInfo;
1687 } 1824 }
1688 ENTER_V8; 1825 ENTER_V8;
1689 i::HandleScope scope; 1826 i::HandleScope scope(isolate);
1690 i::Handle<i::JSObject> self = Utils::OpenHandle(this); 1827 i::Handle<i::JSObject> self = Utils::OpenHandle(this);
1691 i::Handle<i::Object> line = GetProperty(self, "lineNumber"); 1828 i::Handle<i::Object> line = GetProperty(self, "lineNumber");
1692 if (!line->IsSmi()) { 1829 if (!line->IsSmi()) {
1693 return Message::kNoLineNumberInfo; 1830 return Message::kNoLineNumberInfo;
1694 } 1831 }
1695 return i::Smi::cast(*line)->value(); 1832 return i::Smi::cast(*line)->value();
1696 } 1833 }
1697 1834
1698 1835
1699 int StackFrame::GetColumn() const { 1836 int StackFrame::GetColumn() const {
1700 if (IsDeadCheck("v8::StackFrame::GetColumn()")) { 1837 i::Isolate* isolate = i::Isolate::Current();
1838 if (IsDeadCheck(isolate, "v8::StackFrame::GetColumn()")) {
1701 return Message::kNoColumnInfo; 1839 return Message::kNoColumnInfo;
1702 } 1840 }
1703 ENTER_V8; 1841 ENTER_V8;
1704 i::HandleScope scope; 1842 i::HandleScope scope(isolate);
1705 i::Handle<i::JSObject> self = Utils::OpenHandle(this); 1843 i::Handle<i::JSObject> self = Utils::OpenHandle(this);
1706 i::Handle<i::Object> column = GetProperty(self, "column"); 1844 i::Handle<i::Object> column = GetProperty(self, "column");
1707 if (!column->IsSmi()) { 1845 if (!column->IsSmi()) {
1708 return Message::kNoColumnInfo; 1846 return Message::kNoColumnInfo;
1709 } 1847 }
1710 return i::Smi::cast(*column)->value(); 1848 return i::Smi::cast(*column)->value();
1711 } 1849 }
1712 1850
1713 1851
1714 Local<String> StackFrame::GetScriptName() const { 1852 Local<String> StackFrame::GetScriptName() const {
1715 if (IsDeadCheck("v8::StackFrame::GetScriptName()")) return Local<String>(); 1853 i::Isolate* isolate = i::Isolate::Current();
1854 if (IsDeadCheck(isolate, "v8::StackFrame::GetScriptName()")) {
1855 return Local<String>();
1856 }
1716 ENTER_V8; 1857 ENTER_V8;
1717 HandleScope scope; 1858 HandleScope scope;
1718 i::Handle<i::JSObject> self = Utils::OpenHandle(this); 1859 i::Handle<i::JSObject> self = Utils::OpenHandle(this);
1719 i::Handle<i::Object> name = GetProperty(self, "scriptName"); 1860 i::Handle<i::Object> name = GetProperty(self, "scriptName");
1720 if (!name->IsString()) { 1861 if (!name->IsString()) {
1721 return Local<String>(); 1862 return Local<String>();
1722 } 1863 }
1723 return scope.Close(Local<String>::Cast(Utils::ToLocal(name))); 1864 return scope.Close(Local<String>::Cast(Utils::ToLocal(name)));
1724 } 1865 }
1725 1866
1726 1867
1727 Local<String> StackFrame::GetScriptNameOrSourceURL() const { 1868 Local<String> StackFrame::GetScriptNameOrSourceURL() const {
1728 if (IsDeadCheck("v8::StackFrame::GetScriptNameOrSourceURL()")) { 1869 i::Isolate* isolate = i::Isolate::Current();
1870 if (IsDeadCheck(isolate, "v8::StackFrame::GetScriptNameOrSourceURL()")) {
1729 return Local<String>(); 1871 return Local<String>();
1730 } 1872 }
1731 ENTER_V8; 1873 ENTER_V8;
1732 HandleScope scope; 1874 HandleScope scope;
1733 i::Handle<i::JSObject> self = Utils::OpenHandle(this); 1875 i::Handle<i::JSObject> self = Utils::OpenHandle(this);
1734 i::Handle<i::Object> name = GetProperty(self, "scriptNameOrSourceURL"); 1876 i::Handle<i::Object> name = GetProperty(self, "scriptNameOrSourceURL");
1735 if (!name->IsString()) { 1877 if (!name->IsString()) {
1736 return Local<String>(); 1878 return Local<String>();
1737 } 1879 }
1738 return scope.Close(Local<String>::Cast(Utils::ToLocal(name))); 1880 return scope.Close(Local<String>::Cast(Utils::ToLocal(name)));
1739 } 1881 }
1740 1882
1741 1883
1742 Local<String> StackFrame::GetFunctionName() const { 1884 Local<String> StackFrame::GetFunctionName() const {
1743 if (IsDeadCheck("v8::StackFrame::GetFunctionName()")) return Local<String>(); 1885 i::Isolate* isolate = i::Isolate::Current();
1886 if (IsDeadCheck(isolate, "v8::StackFrame::GetFunctionName()")) {
1887 return Local<String>();
1888 }
1744 ENTER_V8; 1889 ENTER_V8;
1745 HandleScope scope; 1890 HandleScope scope;
1746 i::Handle<i::JSObject> self = Utils::OpenHandle(this); 1891 i::Handle<i::JSObject> self = Utils::OpenHandle(this);
1747 i::Handle<i::Object> name = GetProperty(self, "functionName"); 1892 i::Handle<i::Object> name = GetProperty(self, "functionName");
1748 if (!name->IsString()) { 1893 if (!name->IsString()) {
1749 return Local<String>(); 1894 return Local<String>();
1750 } 1895 }
1751 return scope.Close(Local<String>::Cast(Utils::ToLocal(name))); 1896 return scope.Close(Local<String>::Cast(Utils::ToLocal(name)));
1752 } 1897 }
1753 1898
1754 1899
1755 bool StackFrame::IsEval() const { 1900 bool StackFrame::IsEval() const {
1756 if (IsDeadCheck("v8::StackFrame::IsEval()")) return false; 1901 i::Isolate* isolate = i::Isolate::Current();
1902 if (IsDeadCheck(isolate, "v8::StackFrame::IsEval()")) return false;
1757 ENTER_V8; 1903 ENTER_V8;
1758 i::HandleScope scope; 1904 i::HandleScope scope(isolate);
1759 i::Handle<i::JSObject> self = Utils::OpenHandle(this); 1905 i::Handle<i::JSObject> self = Utils::OpenHandle(this);
1760 i::Handle<i::Object> is_eval = GetProperty(self, "isEval"); 1906 i::Handle<i::Object> is_eval = GetProperty(self, "isEval");
1761 return is_eval->IsTrue(); 1907 return is_eval->IsTrue();
1762 } 1908 }
1763 1909
1764 1910
1765 bool StackFrame::IsConstructor() const { 1911 bool StackFrame::IsConstructor() const {
1766 if (IsDeadCheck("v8::StackFrame::IsConstructor()")) return false; 1912 i::Isolate* isolate = i::Isolate::Current();
1913 if (IsDeadCheck(isolate, "v8::StackFrame::IsConstructor()")) return false;
1767 ENTER_V8; 1914 ENTER_V8;
1768 i::HandleScope scope; 1915 i::HandleScope scope(isolate);
1769 i::Handle<i::JSObject> self = Utils::OpenHandle(this); 1916 i::Handle<i::JSObject> self = Utils::OpenHandle(this);
1770 i::Handle<i::Object> is_constructor = GetProperty(self, "isConstructor"); 1917 i::Handle<i::Object> is_constructor = GetProperty(self, "isConstructor");
1771 return is_constructor->IsTrue(); 1918 return is_constructor->IsTrue();
1772 } 1919 }
1773 1920
1774 1921
1775 // --- D a t a --- 1922 // --- D a t a ---
1776 1923
1777 bool Value::IsUndefined() const { 1924 bool Value::IsUndefined() const {
1778 if (IsDeadCheck("v8::Value::IsUndefined()")) return false; 1925 if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsUndefined()")) {
1926 return false;
1927 }
1779 return Utils::OpenHandle(this)->IsUndefined(); 1928 return Utils::OpenHandle(this)->IsUndefined();
1780 } 1929 }
1781 1930
1782 1931
1783 bool Value::IsNull() const { 1932 bool Value::IsNull() const {
1784 if (IsDeadCheck("v8::Value::IsNull()")) return false; 1933 if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsNull()")) return false;
1785 return Utils::OpenHandle(this)->IsNull(); 1934 return Utils::OpenHandle(this)->IsNull();
1786 } 1935 }
1787 1936
1788 1937
1789 bool Value::IsTrue() const { 1938 bool Value::IsTrue() const {
1790 if (IsDeadCheck("v8::Value::IsTrue()")) return false; 1939 if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsTrue()")) return false;
1791 return Utils::OpenHandle(this)->IsTrue(); 1940 return Utils::OpenHandle(this)->IsTrue();
1792 } 1941 }
1793 1942
1794 1943
1795 bool Value::IsFalse() const { 1944 bool Value::IsFalse() const {
1796 if (IsDeadCheck("v8::Value::IsFalse()")) return false; 1945 if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsFalse()")) return false;
1797 return Utils::OpenHandle(this)->IsFalse(); 1946 return Utils::OpenHandle(this)->IsFalse();
1798 } 1947 }
1799 1948
1800 1949
1801 bool Value::IsFunction() const { 1950 bool Value::IsFunction() const {
1802 if (IsDeadCheck("v8::Value::IsFunction()")) return false; 1951 if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsFunction()")) {
1952 return false;
1953 }
1803 return Utils::OpenHandle(this)->IsJSFunction(); 1954 return Utils::OpenHandle(this)->IsJSFunction();
1804 } 1955 }
1805 1956
1806 1957
1807 bool Value::FullIsString() const { 1958 bool Value::FullIsString() const {
1808 if (IsDeadCheck("v8::Value::IsString()")) return false; 1959 if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsString()")) return false;
1809 bool result = Utils::OpenHandle(this)->IsString(); 1960 bool result = Utils::OpenHandle(this)->IsString();
1810 ASSERT_EQ(result, QuickIsString()); 1961 ASSERT_EQ(result, QuickIsString());
1811 return result; 1962 return result;
1812 } 1963 }
1813 1964
1814 1965
1815 bool Value::IsArray() const { 1966 bool Value::IsArray() const {
1816 if (IsDeadCheck("v8::Value::IsArray()")) return false; 1967 if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsArray()")) return false;
1817 return Utils::OpenHandle(this)->IsJSArray(); 1968 return Utils::OpenHandle(this)->IsJSArray();
1818 } 1969 }
1819 1970
1820 1971
1821 bool Value::IsObject() const { 1972 bool Value::IsObject() const {
1822 if (IsDeadCheck("v8::Value::IsObject()")) return false; 1973 if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsObject()")) return false;
1823 return Utils::OpenHandle(this)->IsJSObject(); 1974 return Utils::OpenHandle(this)->IsJSObject();
1824 } 1975 }
1825 1976
1826 1977
1827 bool Value::IsNumber() const { 1978 bool Value::IsNumber() const {
1828 if (IsDeadCheck("v8::Value::IsNumber()")) return false; 1979 if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsNumber()")) return false;
1829 return Utils::OpenHandle(this)->IsNumber(); 1980 return Utils::OpenHandle(this)->IsNumber();
1830 } 1981 }
1831 1982
1832 1983
1833 bool Value::IsBoolean() const { 1984 bool Value::IsBoolean() const {
1834 if (IsDeadCheck("v8::Value::IsBoolean()")) return false; 1985 if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsBoolean()")) {
1986 return false;
1987 }
1835 return Utils::OpenHandle(this)->IsBoolean(); 1988 return Utils::OpenHandle(this)->IsBoolean();
1836 } 1989 }
1837 1990
1838 1991
1839 bool Value::IsExternal() const { 1992 bool Value::IsExternal() const {
1840 if (IsDeadCheck("v8::Value::IsExternal()")) return false; 1993 if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsExternal()")) {
1994 return false;
1995 }
1841 return Utils::OpenHandle(this)->IsProxy(); 1996 return Utils::OpenHandle(this)->IsProxy();
1842 } 1997 }
1843 1998
1844 1999
1845 bool Value::IsInt32() const { 2000 bool Value::IsInt32() const {
1846 if (IsDeadCheck("v8::Value::IsInt32()")) return false; 2001 if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsInt32()")) return false;
1847 i::Handle<i::Object> obj = Utils::OpenHandle(this); 2002 i::Handle<i::Object> obj = Utils::OpenHandle(this);
1848 if (obj->IsSmi()) return true; 2003 if (obj->IsSmi()) return true;
1849 if (obj->IsNumber()) { 2004 if (obj->IsNumber()) {
1850 double value = obj->Number(); 2005 double value = obj->Number();
1851 return i::FastI2D(i::FastD2I(value)) == value; 2006 return i::FastI2D(i::FastD2I(value)) == value;
1852 } 2007 }
1853 return false; 2008 return false;
1854 } 2009 }
1855 2010
1856 2011
1857 bool Value::IsUint32() const { 2012 bool Value::IsUint32() const {
1858 if (IsDeadCheck("v8::Value::IsUint32()")) return false; 2013 if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsUint32()")) return false;
1859 i::Handle<i::Object> obj = Utils::OpenHandle(this); 2014 i::Handle<i::Object> obj = Utils::OpenHandle(this);
1860 if (obj->IsSmi()) return i::Smi::cast(*obj)->value() >= 0; 2015 if (obj->IsSmi()) return i::Smi::cast(*obj)->value() >= 0;
1861 if (obj->IsNumber()) { 2016 if (obj->IsNumber()) {
1862 double value = obj->Number(); 2017 double value = obj->Number();
1863 return i::FastUI2D(i::FastD2UI(value)) == value; 2018 return i::FastUI2D(i::FastD2UI(value)) == value;
1864 } 2019 }
1865 return false; 2020 return false;
1866 } 2021 }
1867 2022
1868 2023
1869 bool Value::IsDate() const { 2024 bool Value::IsDate() const {
1870 if (IsDeadCheck("v8::Value::IsDate()")) return false; 2025 if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsDate()")) return false;
1871 i::Handle<i::Object> obj = Utils::OpenHandle(this); 2026 i::Handle<i::Object> obj = Utils::OpenHandle(this);
1872 return obj->HasSpecificClassOf(i::Heap::Date_symbol()); 2027 return obj->HasSpecificClassOf(HEAP->Date_symbol());
1873 } 2028 }
1874 2029
1875 2030
1876 bool Value::IsRegExp() const { 2031 bool Value::IsRegExp() const {
1877 if (IsDeadCheck("v8::Value::IsRegExp()")) return false; 2032 if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsRegExp()")) return false;
1878 i::Handle<i::Object> obj = Utils::OpenHandle(this); 2033 i::Handle<i::Object> obj = Utils::OpenHandle(this);
1879 return obj->IsJSRegExp(); 2034 return obj->IsJSRegExp();
1880 } 2035 }
1881 2036
1882 2037
1883 Local<String> Value::ToString() const { 2038 Local<String> Value::ToString() const {
1884 if (IsDeadCheck("v8::Value::ToString()")) return Local<String>(); 2039 i::Isolate* isolate = i::Isolate::Current();
1885 LOG_API("ToString"); 2040 if (IsDeadCheck(i::Isolate::Current(), "v8::Value::ToString()")) {
2041 return Local<String>();
2042 }
2043 LOG_API(isolate, "ToString");
1886 i::Handle<i::Object> obj = Utils::OpenHandle(this); 2044 i::Handle<i::Object> obj = Utils::OpenHandle(this);
1887 i::Handle<i::Object> str; 2045 i::Handle<i::Object> str;
1888 if (obj->IsString()) { 2046 if (obj->IsString()) {
1889 str = obj; 2047 str = obj;
1890 } else { 2048 } else {
1891 ENTER_V8; 2049 ENTER_V8;
1892 EXCEPTION_PREAMBLE(); 2050 EXCEPTION_PREAMBLE();
1893 str = i::Execution::ToString(obj, &has_pending_exception); 2051 str = i::Execution::ToString(obj, &has_pending_exception);
1894 EXCEPTION_BAILOUT_CHECK(Local<String>()); 2052 EXCEPTION_BAILOUT_CHECK(Local<String>());
1895 } 2053 }
1896 return Local<String>(ToApi<String>(str)); 2054 return Local<String>(ToApi<String>(str));
1897 } 2055 }
1898 2056
1899 2057
1900 Local<String> Value::ToDetailString() const { 2058 Local<String> Value::ToDetailString() const {
1901 if (IsDeadCheck("v8::Value::ToDetailString()")) return Local<String>(); 2059 i::Isolate* isolate = i::Isolate::Current();
1902 LOG_API("ToDetailString"); 2060 if (IsDeadCheck(isolate, "v8::Value::ToDetailString()")) {
2061 return Local<String>();
2062 }
2063 LOG_API(isolate, "ToDetailString");
1903 i::Handle<i::Object> obj = Utils::OpenHandle(this); 2064 i::Handle<i::Object> obj = Utils::OpenHandle(this);
1904 i::Handle<i::Object> str; 2065 i::Handle<i::Object> str;
1905 if (obj->IsString()) { 2066 if (obj->IsString()) {
1906 str = obj; 2067 str = obj;
1907 } else { 2068 } else {
1908 ENTER_V8; 2069 ENTER_V8;
1909 EXCEPTION_PREAMBLE(); 2070 EXCEPTION_PREAMBLE();
1910 str = i::Execution::ToDetailString(obj, &has_pending_exception); 2071 str = i::Execution::ToDetailString(obj, &has_pending_exception);
1911 EXCEPTION_BAILOUT_CHECK(Local<String>()); 2072 EXCEPTION_BAILOUT_CHECK(Local<String>());
1912 } 2073 }
1913 return Local<String>(ToApi<String>(str)); 2074 return Local<String>(ToApi<String>(str));
1914 } 2075 }
1915 2076
1916 2077
1917 Local<v8::Object> Value::ToObject() const { 2078 Local<v8::Object> Value::ToObject() const {
1918 if (IsDeadCheck("v8::Value::ToObject()")) return Local<v8::Object>(); 2079 i::Isolate* isolate = i::Isolate::Current();
1919 LOG_API("ToObject"); 2080 if (IsDeadCheck(isolate, "v8::Value::ToObject()")) return Local<v8::Object>();
2081 LOG_API(isolate, "ToObject");
1920 i::Handle<i::Object> obj = Utils::OpenHandle(this); 2082 i::Handle<i::Object> obj = Utils::OpenHandle(this);
1921 i::Handle<i::Object> val; 2083 i::Handle<i::Object> val;
1922 if (obj->IsJSObject()) { 2084 if (obj->IsJSObject()) {
1923 val = obj; 2085 val = obj;
1924 } else { 2086 } else {
1925 ENTER_V8; 2087 ENTER_V8;
1926 EXCEPTION_PREAMBLE(); 2088 EXCEPTION_PREAMBLE();
1927 val = i::Execution::ToObject(obj, &has_pending_exception); 2089 val = i::Execution::ToObject(obj, &has_pending_exception);
1928 EXCEPTION_BAILOUT_CHECK(Local<v8::Object>()); 2090 EXCEPTION_BAILOUT_CHECK(Local<v8::Object>());
1929 } 2091 }
1930 return Local<v8::Object>(ToApi<Object>(val)); 2092 return Local<v8::Object>(ToApi<Object>(val));
1931 } 2093 }
1932 2094
1933 2095
1934 Local<Boolean> Value::ToBoolean() const { 2096 Local<Boolean> Value::ToBoolean() const {
1935 if (IsDeadCheck("v8::Value::ToBoolean()")) return Local<Boolean>(); 2097 i::Isolate* isolate = i::Isolate::Current();
1936 LOG_API("ToBoolean"); 2098 if (IsDeadCheck(i::Isolate::Current(), "v8::Value::ToBoolean()")) {
2099 return Local<Boolean>();
2100 }
2101 LOG_API(isolate, "ToBoolean");
1937 i::Handle<i::Object> obj = Utils::OpenHandle(this); 2102 i::Handle<i::Object> obj = Utils::OpenHandle(this);
1938 if (obj->IsBoolean()) { 2103 if (obj->IsBoolean()) {
1939 return Local<Boolean>(ToApi<Boolean>(obj)); 2104 return Local<Boolean>(ToApi<Boolean>(obj));
1940 } else { 2105 } else {
1941 ENTER_V8; 2106 ENTER_V8;
1942 i::Handle<i::Object> val = i::Execution::ToBoolean(obj); 2107 i::Handle<i::Object> val = i::Execution::ToBoolean(obj);
1943 return Local<Boolean>(ToApi<Boolean>(val)); 2108 return Local<Boolean>(ToApi<Boolean>(val));
1944 } 2109 }
1945 } 2110 }
1946 2111
1947 2112
1948 Local<Number> Value::ToNumber() const { 2113 Local<Number> Value::ToNumber() const {
1949 if (IsDeadCheck("v8::Value::ToNumber()")) return Local<Number>(); 2114 i::Isolate* isolate = i::Isolate::Current();
1950 LOG_API("ToNumber"); 2115 if (IsDeadCheck(isolate, "v8::Value::ToNumber()")) return Local<Number>();
2116 LOG_API(isolate, "ToNumber");
1951 i::Handle<i::Object> obj = Utils::OpenHandle(this); 2117 i::Handle<i::Object> obj = Utils::OpenHandle(this);
1952 i::Handle<i::Object> num; 2118 i::Handle<i::Object> num;
1953 if (obj->IsNumber()) { 2119 if (obj->IsNumber()) {
1954 num = obj; 2120 num = obj;
1955 } else { 2121 } else {
1956 ENTER_V8; 2122 ENTER_V8;
1957 EXCEPTION_PREAMBLE(); 2123 EXCEPTION_PREAMBLE();
1958 num = i::Execution::ToNumber(obj, &has_pending_exception); 2124 num = i::Execution::ToNumber(obj, &has_pending_exception);
1959 EXCEPTION_BAILOUT_CHECK(Local<Number>()); 2125 EXCEPTION_BAILOUT_CHECK(Local<Number>());
1960 } 2126 }
1961 return Local<Number>(ToApi<Number>(num)); 2127 return Local<Number>(ToApi<Number>(num));
1962 } 2128 }
1963 2129
1964 2130
1965 Local<Integer> Value::ToInteger() const { 2131 Local<Integer> Value::ToInteger() const {
1966 if (IsDeadCheck("v8::Value::ToInteger()")) return Local<Integer>(); 2132 i::Isolate* isolate = i::Isolate::Current();
1967 LOG_API("ToInteger"); 2133 if (IsDeadCheck(isolate, "v8::Value::ToInteger()")) return Local<Integer>();
2134 LOG_API(isolate, "ToInteger");
1968 i::Handle<i::Object> obj = Utils::OpenHandle(this); 2135 i::Handle<i::Object> obj = Utils::OpenHandle(this);
1969 i::Handle<i::Object> num; 2136 i::Handle<i::Object> num;
1970 if (obj->IsSmi()) { 2137 if (obj->IsSmi()) {
1971 num = obj; 2138 num = obj;
1972 } else { 2139 } else {
1973 ENTER_V8; 2140 ENTER_V8;
1974 EXCEPTION_PREAMBLE(); 2141 EXCEPTION_PREAMBLE();
1975 num = i::Execution::ToInteger(obj, &has_pending_exception); 2142 num = i::Execution::ToInteger(obj, &has_pending_exception);
1976 EXCEPTION_BAILOUT_CHECK(Local<Integer>()); 2143 EXCEPTION_BAILOUT_CHECK(Local<Integer>());
1977 } 2144 }
1978 return Local<Integer>(ToApi<Integer>(num)); 2145 return Local<Integer>(ToApi<Integer>(num));
1979 } 2146 }
1980 2147
1981 2148
1982 void External::CheckCast(v8::Value* that) { 2149 void External::CheckCast(v8::Value* that) {
1983 if (IsDeadCheck("v8::External::Cast()")) return; 2150 if (IsDeadCheck(i::Isolate::Current(), "v8::External::Cast()")) return;
1984 i::Handle<i::Object> obj = Utils::OpenHandle(that); 2151 i::Handle<i::Object> obj = Utils::OpenHandle(that);
1985 ApiCheck(obj->IsProxy(), 2152 ApiCheck(obj->IsProxy(),
1986 "v8::External::Cast()", 2153 "v8::External::Cast()",
1987 "Could not convert to external"); 2154 "Could not convert to external");
1988 } 2155 }
1989 2156
1990 2157
1991 void v8::Object::CheckCast(Value* that) { 2158 void v8::Object::CheckCast(Value* that) {
1992 if (IsDeadCheck("v8::Object::Cast()")) return; 2159 if (IsDeadCheck(i::Isolate::Current(), "v8::Object::Cast()")) return;
1993 i::Handle<i::Object> obj = Utils::OpenHandle(that); 2160 i::Handle<i::Object> obj = Utils::OpenHandle(that);
1994 ApiCheck(obj->IsJSObject(), 2161 ApiCheck(obj->IsJSObject(),
1995 "v8::Object::Cast()", 2162 "v8::Object::Cast()",
1996 "Could not convert to object"); 2163 "Could not convert to object");
1997 } 2164 }
1998 2165
1999 2166
2000 void v8::Function::CheckCast(Value* that) { 2167 void v8::Function::CheckCast(Value* that) {
2001 if (IsDeadCheck("v8::Function::Cast()")) return; 2168 if (IsDeadCheck(i::Isolate::Current(), "v8::Function::Cast()")) return;
2002 i::Handle<i::Object> obj = Utils::OpenHandle(that); 2169 i::Handle<i::Object> obj = Utils::OpenHandle(that);
2003 ApiCheck(obj->IsJSFunction(), 2170 ApiCheck(obj->IsJSFunction(),
2004 "v8::Function::Cast()", 2171 "v8::Function::Cast()",
2005 "Could not convert to function"); 2172 "Could not convert to function");
2006 } 2173 }
2007 2174
2008 2175
2009 void v8::String::CheckCast(v8::Value* that) { 2176 void v8::String::CheckCast(v8::Value* that) {
2010 if (IsDeadCheck("v8::String::Cast()")) return; 2177 if (IsDeadCheck(i::Isolate::Current(), "v8::String::Cast()")) return;
2011 i::Handle<i::Object> obj = Utils::OpenHandle(that); 2178 i::Handle<i::Object> obj = Utils::OpenHandle(that);
2012 ApiCheck(obj->IsString(), 2179 ApiCheck(obj->IsString(),
2013 "v8::String::Cast()", 2180 "v8::String::Cast()",
2014 "Could not convert to string"); 2181 "Could not convert to string");
2015 } 2182 }
2016 2183
2017 2184
2018 void v8::Number::CheckCast(v8::Value* that) { 2185 void v8::Number::CheckCast(v8::Value* that) {
2019 if (IsDeadCheck("v8::Number::Cast()")) return; 2186 if (IsDeadCheck(i::Isolate::Current(), "v8::Number::Cast()")) return;
2020 i::Handle<i::Object> obj = Utils::OpenHandle(that); 2187 i::Handle<i::Object> obj = Utils::OpenHandle(that);
2021 ApiCheck(obj->IsNumber(), 2188 ApiCheck(obj->IsNumber(),
2022 "v8::Number::Cast()", 2189 "v8::Number::Cast()",
2023 "Could not convert to number"); 2190 "Could not convert to number");
2024 } 2191 }
2025 2192
2026 2193
2027 void v8::Integer::CheckCast(v8::Value* that) { 2194 void v8::Integer::CheckCast(v8::Value* that) {
2028 if (IsDeadCheck("v8::Integer::Cast()")) return; 2195 if (IsDeadCheck(i::Isolate::Current(), "v8::Integer::Cast()")) return;
2029 i::Handle<i::Object> obj = Utils::OpenHandle(that); 2196 i::Handle<i::Object> obj = Utils::OpenHandle(that);
2030 ApiCheck(obj->IsNumber(), 2197 ApiCheck(obj->IsNumber(),
2031 "v8::Integer::Cast()", 2198 "v8::Integer::Cast()",
2032 "Could not convert to number"); 2199 "Could not convert to number");
2033 } 2200 }
2034 2201
2035 2202
2036 void v8::Array::CheckCast(Value* that) { 2203 void v8::Array::CheckCast(Value* that) {
2037 if (IsDeadCheck("v8::Array::Cast()")) return; 2204 if (IsDeadCheck(i::Isolate::Current(), "v8::Array::Cast()")) return;
2038 i::Handle<i::Object> obj = Utils::OpenHandle(that); 2205 i::Handle<i::Object> obj = Utils::OpenHandle(that);
2039 ApiCheck(obj->IsJSArray(), 2206 ApiCheck(obj->IsJSArray(),
2040 "v8::Array::Cast()", 2207 "v8::Array::Cast()",
2041 "Could not convert to array"); 2208 "Could not convert to array");
2042 } 2209 }
2043 2210
2044 2211
2045 void v8::Date::CheckCast(v8::Value* that) { 2212 void v8::Date::CheckCast(v8::Value* that) {
2046 if (IsDeadCheck("v8::Date::Cast()")) return; 2213 if (IsDeadCheck(i::Isolate::Current(), "v8::Date::Cast()")) return;
2047 i::Handle<i::Object> obj = Utils::OpenHandle(that); 2214 i::Handle<i::Object> obj = Utils::OpenHandle(that);
2048 ApiCheck(obj->HasSpecificClassOf(i::Heap::Date_symbol()), 2215 ApiCheck(obj->HasSpecificClassOf(HEAP->Date_symbol()),
2049 "v8::Date::Cast()", 2216 "v8::Date::Cast()",
2050 "Could not convert to date"); 2217 "Could not convert to date");
2051 } 2218 }
2052 2219
2053 2220
2054 void v8::RegExp::CheckCast(v8::Value* that) { 2221 void v8::RegExp::CheckCast(v8::Value* that) {
2055 if (IsDeadCheck("v8::RegExp::Cast()")) return; 2222 if (IsDeadCheck(i::Isolate::Current(), "v8::RegExp::Cast()")) return;
2056 i::Handle<i::Object> obj = Utils::OpenHandle(that); 2223 i::Handle<i::Object> obj = Utils::OpenHandle(that);
2057 ApiCheck(obj->IsJSRegExp(), 2224 ApiCheck(obj->IsJSRegExp(),
2058 "v8::RegExp::Cast()", 2225 "v8::RegExp::Cast()",
2059 "Could not convert to regular expression"); 2226 "Could not convert to regular expression");
2060 } 2227 }
2061 2228
2062 2229
2063 bool Value::BooleanValue() const { 2230 bool Value::BooleanValue() const {
2064 if (IsDeadCheck("v8::Value::BooleanValue()")) return false; 2231 i::Isolate* isolate = i::Isolate::Current();
2065 LOG_API("BooleanValue"); 2232 if (IsDeadCheck(isolate, "v8::Value::BooleanValue()")) return false;
2233 LOG_API(isolate, "BooleanValue");
2066 i::Handle<i::Object> obj = Utils::OpenHandle(this); 2234 i::Handle<i::Object> obj = Utils::OpenHandle(this);
2067 if (obj->IsBoolean()) { 2235 if (obj->IsBoolean()) {
2068 return obj->IsTrue(); 2236 return obj->IsTrue();
2069 } else { 2237 } else {
2070 ENTER_V8; 2238 ENTER_V8;
2071 i::Handle<i::Object> value = i::Execution::ToBoolean(obj); 2239 i::Handle<i::Object> value = i::Execution::ToBoolean(obj);
2072 return value->IsTrue(); 2240 return value->IsTrue();
2073 } 2241 }
2074 } 2242 }
2075 2243
2076 2244
2077 double Value::NumberValue() const { 2245 double Value::NumberValue() const {
2078 if (IsDeadCheck("v8::Value::NumberValue()")) return i::OS::nan_value(); 2246 i::Isolate* isolate = i::Isolate::Current();
2079 LOG_API("NumberValue"); 2247 if (IsDeadCheck(isolate, "v8::Value::NumberValue()")) {
2248 return i::OS::nan_value();
2249 }
2250 LOG_API(isolate, "NumberValue");
2080 i::Handle<i::Object> obj = Utils::OpenHandle(this); 2251 i::Handle<i::Object> obj = Utils::OpenHandle(this);
2081 i::Handle<i::Object> num; 2252 i::Handle<i::Object> num;
2082 if (obj->IsNumber()) { 2253 if (obj->IsNumber()) {
2083 num = obj; 2254 num = obj;
2084 } else { 2255 } else {
2085 ENTER_V8; 2256 ENTER_V8;
2086 EXCEPTION_PREAMBLE(); 2257 EXCEPTION_PREAMBLE();
2087 num = i::Execution::ToNumber(obj, &has_pending_exception); 2258 num = i::Execution::ToNumber(obj, &has_pending_exception);
2088 EXCEPTION_BAILOUT_CHECK(i::OS::nan_value()); 2259 EXCEPTION_BAILOUT_CHECK(i::OS::nan_value());
2089 } 2260 }
2090 return num->Number(); 2261 return num->Number();
2091 } 2262 }
2092 2263
2093 2264
2094 int64_t Value::IntegerValue() const { 2265 int64_t Value::IntegerValue() const {
2095 if (IsDeadCheck("v8::Value::IntegerValue()")) return 0; 2266 i::Isolate* isolate = i::Isolate::Current();
2096 LOG_API("IntegerValue"); 2267 if (IsDeadCheck(isolate, "v8::Value::IntegerValue()")) return 0;
2268 LOG_API(isolate, "IntegerValue");
2097 i::Handle<i::Object> obj = Utils::OpenHandle(this); 2269 i::Handle<i::Object> obj = Utils::OpenHandle(this);
2098 i::Handle<i::Object> num; 2270 i::Handle<i::Object> num;
2099 if (obj->IsNumber()) { 2271 if (obj->IsNumber()) {
2100 num = obj; 2272 num = obj;
2101 } else { 2273 } else {
2102 ENTER_V8; 2274 ENTER_V8;
2103 EXCEPTION_PREAMBLE(); 2275 EXCEPTION_PREAMBLE();
2104 num = i::Execution::ToInteger(obj, &has_pending_exception); 2276 num = i::Execution::ToInteger(obj, &has_pending_exception);
2105 EXCEPTION_BAILOUT_CHECK(0); 2277 EXCEPTION_BAILOUT_CHECK(0);
2106 } 2278 }
2107 if (num->IsSmi()) { 2279 if (num->IsSmi()) {
2108 return i::Smi::cast(*num)->value(); 2280 return i::Smi::cast(*num)->value();
2109 } else { 2281 } else {
2110 return static_cast<int64_t>(num->Number()); 2282 return static_cast<int64_t>(num->Number());
2111 } 2283 }
2112 } 2284 }
2113 2285
2114 2286
2115 Local<Int32> Value::ToInt32() const { 2287 Local<Int32> Value::ToInt32() const {
2116 if (IsDeadCheck("v8::Value::ToInt32()")) return Local<Int32>(); 2288 i::Isolate* isolate = i::Isolate::Current();
2117 LOG_API("ToInt32"); 2289 if (IsDeadCheck(isolate, "v8::Value::ToInt32()")) return Local<Int32>();
2290 LOG_API(isolate, "ToInt32");
2118 i::Handle<i::Object> obj = Utils::OpenHandle(this); 2291 i::Handle<i::Object> obj = Utils::OpenHandle(this);
2119 i::Handle<i::Object> num; 2292 i::Handle<i::Object> num;
2120 if (obj->IsSmi()) { 2293 if (obj->IsSmi()) {
2121 num = obj; 2294 num = obj;
2122 } else { 2295 } else {
2123 ENTER_V8; 2296 ENTER_V8;
2124 EXCEPTION_PREAMBLE(); 2297 EXCEPTION_PREAMBLE();
2125 num = i::Execution::ToInt32(obj, &has_pending_exception); 2298 num = i::Execution::ToInt32(obj, &has_pending_exception);
2126 EXCEPTION_BAILOUT_CHECK(Local<Int32>()); 2299 EXCEPTION_BAILOUT_CHECK(Local<Int32>());
2127 } 2300 }
2128 return Local<Int32>(ToApi<Int32>(num)); 2301 return Local<Int32>(ToApi<Int32>(num));
2129 } 2302 }
2130 2303
2131 2304
2132 Local<Uint32> Value::ToUint32() const { 2305 Local<Uint32> Value::ToUint32() const {
2133 if (IsDeadCheck("v8::Value::ToUint32()")) return Local<Uint32>(); 2306 i::Isolate* isolate = i::Isolate::Current();
2134 LOG_API("ToUInt32"); 2307 if (IsDeadCheck(isolate, "v8::Value::ToUint32()")) return Local<Uint32>();
2308 LOG_API(isolate, "ToUInt32");
2135 i::Handle<i::Object> obj = Utils::OpenHandle(this); 2309 i::Handle<i::Object> obj = Utils::OpenHandle(this);
2136 i::Handle<i::Object> num; 2310 i::Handle<i::Object> num;
2137 if (obj->IsSmi()) { 2311 if (obj->IsSmi()) {
2138 num = obj; 2312 num = obj;
2139 } else { 2313 } else {
2140 ENTER_V8; 2314 ENTER_V8;
2141 EXCEPTION_PREAMBLE(); 2315 EXCEPTION_PREAMBLE();
2142 num = i::Execution::ToUint32(obj, &has_pending_exception); 2316 num = i::Execution::ToUint32(obj, &has_pending_exception);
2143 EXCEPTION_BAILOUT_CHECK(Local<Uint32>()); 2317 EXCEPTION_BAILOUT_CHECK(Local<Uint32>());
2144 } 2318 }
2145 return Local<Uint32>(ToApi<Uint32>(num)); 2319 return Local<Uint32>(ToApi<Uint32>(num));
2146 } 2320 }
2147 2321
2148 2322
2149 Local<Uint32> Value::ToArrayIndex() const { 2323 Local<Uint32> Value::ToArrayIndex() const {
2150 if (IsDeadCheck("v8::Value::ToArrayIndex()")) return Local<Uint32>(); 2324 i::Isolate* isolate = i::Isolate::Current();
2151 LOG_API("ToArrayIndex"); 2325 if (IsDeadCheck(isolate, "v8::Value::ToArrayIndex()")) return Local<Uint32>();
2326 LOG_API(isolate, "ToArrayIndex");
2152 i::Handle<i::Object> obj = Utils::OpenHandle(this); 2327 i::Handle<i::Object> obj = Utils::OpenHandle(this);
2153 if (obj->IsSmi()) { 2328 if (obj->IsSmi()) {
2154 if (i::Smi::cast(*obj)->value() >= 0) return Utils::Uint32ToLocal(obj); 2329 if (i::Smi::cast(*obj)->value() >= 0) return Utils::Uint32ToLocal(obj);
2155 return Local<Uint32>(); 2330 return Local<Uint32>();
2156 } 2331 }
2157 ENTER_V8; 2332 ENTER_V8;
2158 EXCEPTION_PREAMBLE(); 2333 EXCEPTION_PREAMBLE();
2159 i::Handle<i::Object> string_obj = 2334 i::Handle<i::Object> string_obj =
2160 i::Execution::ToString(obj, &has_pending_exception); 2335 i::Execution::ToString(obj, &has_pending_exception);
2161 EXCEPTION_BAILOUT_CHECK(Local<Uint32>()); 2336 EXCEPTION_BAILOUT_CHECK(Local<Uint32>());
2162 i::Handle<i::String> str = i::Handle<i::String>::cast(string_obj); 2337 i::Handle<i::String> str = i::Handle<i::String>::cast(string_obj);
2163 uint32_t index; 2338 uint32_t index;
2164 if (str->AsArrayIndex(&index)) { 2339 if (str->AsArrayIndex(&index)) {
2165 i::Handle<i::Object> value; 2340 i::Handle<i::Object> value;
2166 if (index <= static_cast<uint32_t>(i::Smi::kMaxValue)) { 2341 if (index <= static_cast<uint32_t>(i::Smi::kMaxValue)) {
2167 value = i::Handle<i::Object>(i::Smi::FromInt(index)); 2342 value = i::Handle<i::Object>(i::Smi::FromInt(index));
2168 } else { 2343 } else {
2169 value = i::Factory::NewNumber(index); 2344 value = FACTORY->NewNumber(index);
2170 } 2345 }
2171 return Utils::Uint32ToLocal(value); 2346 return Utils::Uint32ToLocal(value);
2172 } 2347 }
2173 return Local<Uint32>(); 2348 return Local<Uint32>();
2174 } 2349 }
2175 2350
2176 2351
2177 int32_t Value::Int32Value() const { 2352 int32_t Value::Int32Value() const {
2178 if (IsDeadCheck("v8::Value::Int32Value()")) return 0; 2353 i::Isolate* isolate = i::Isolate::Current();
2179 LOG_API("Int32Value"); 2354 if (IsDeadCheck(isolate, "v8::Value::Int32Value()")) return 0;
2355 LOG_API(isolate, "Int32Value");
2180 i::Handle<i::Object> obj = Utils::OpenHandle(this); 2356 i::Handle<i::Object> obj = Utils::OpenHandle(this);
2181 if (obj->IsSmi()) { 2357 if (obj->IsSmi()) {
2182 return i::Smi::cast(*obj)->value(); 2358 return i::Smi::cast(*obj)->value();
2183 } else { 2359 } else {
2184 LOG_API("Int32Value (slow)"); 2360 LOG_API(isolate, "Int32Value (slow)");
2185 ENTER_V8; 2361 ENTER_V8;
2186 EXCEPTION_PREAMBLE(); 2362 EXCEPTION_PREAMBLE();
2187 i::Handle<i::Object> num = 2363 i::Handle<i::Object> num =
2188 i::Execution::ToInt32(obj, &has_pending_exception); 2364 i::Execution::ToInt32(obj, &has_pending_exception);
2189 EXCEPTION_BAILOUT_CHECK(0); 2365 EXCEPTION_BAILOUT_CHECK(0);
2190 if (num->IsSmi()) { 2366 if (num->IsSmi()) {
2191 return i::Smi::cast(*num)->value(); 2367 return i::Smi::cast(*num)->value();
2192 } else { 2368 } else {
2193 return static_cast<int32_t>(num->Number()); 2369 return static_cast<int32_t>(num->Number());
2194 } 2370 }
2195 } 2371 }
2196 } 2372 }
2197 2373
2198 2374
2199 bool Value::Equals(Handle<Value> that) const { 2375 bool Value::Equals(Handle<Value> that) const {
2200 if (IsDeadCheck("v8::Value::Equals()") 2376 i::Isolate* isolate = i::Isolate::Current();
2377 if (IsDeadCheck(isolate, "v8::Value::Equals()")
2201 || EmptyCheck("v8::Value::Equals()", this) 2378 || EmptyCheck("v8::Value::Equals()", this)
2202 || EmptyCheck("v8::Value::Equals()", that)) { 2379 || EmptyCheck("v8::Value::Equals()", that)) {
2203 return false; 2380 return false;
2204 } 2381 }
2205 LOG_API("Equals"); 2382 LOG_API(isolate, "Equals");
2206 ENTER_V8; 2383 ENTER_V8;
2207 i::Handle<i::Object> obj = Utils::OpenHandle(this); 2384 i::Handle<i::Object> obj = Utils::OpenHandle(this);
2208 i::Handle<i::Object> other = Utils::OpenHandle(*that); 2385 i::Handle<i::Object> other = Utils::OpenHandle(*that);
2209 // If both obj and other are JSObjects, we'd better compare by identity 2386 // If both obj and other are JSObjects, we'd better compare by identity
2210 // immediately when going into JS builtin. The reason is Invoke 2387 // immediately when going into JS builtin. The reason is Invoke
2211 // would overwrite global object receiver with global proxy. 2388 // would overwrite global object receiver with global proxy.
2212 if (obj->IsJSObject() && other->IsJSObject()) { 2389 if (obj->IsJSObject() && other->IsJSObject()) {
2213 return *obj == *other; 2390 return *obj == *other;
2214 } 2391 }
2215 i::Object** args[1] = { other.location() }; 2392 i::Object** args[1] = { other.location() };
2216 EXCEPTION_PREAMBLE(); 2393 EXCEPTION_PREAMBLE();
2217 i::Handle<i::Object> result = 2394 i::Handle<i::Object> result =
2218 CallV8HeapFunction("EQUALS", obj, 1, args, &has_pending_exception); 2395 CallV8HeapFunction("EQUALS", obj, 1, args, &has_pending_exception);
2219 EXCEPTION_BAILOUT_CHECK(false); 2396 EXCEPTION_BAILOUT_CHECK(false);
2220 return *result == i::Smi::FromInt(i::EQUAL); 2397 return *result == i::Smi::FromInt(i::EQUAL);
2221 } 2398 }
2222 2399
2223 2400
2224 bool Value::StrictEquals(Handle<Value> that) const { 2401 bool Value::StrictEquals(Handle<Value> that) const {
2225 if (IsDeadCheck("v8::Value::StrictEquals()") 2402 i::Isolate* isolate = i::Isolate::Current();
2403 if (IsDeadCheck(isolate, "v8::Value::StrictEquals()")
2226 || EmptyCheck("v8::Value::StrictEquals()", this) 2404 || EmptyCheck("v8::Value::StrictEquals()", this)
2227 || EmptyCheck("v8::Value::StrictEquals()", that)) { 2405 || EmptyCheck("v8::Value::StrictEquals()", that)) {
2228 return false; 2406 return false;
2229 } 2407 }
2230 LOG_API("StrictEquals"); 2408 LOG_API(isolate, "StrictEquals");
2231 i::Handle<i::Object> obj = Utils::OpenHandle(this); 2409 i::Handle<i::Object> obj = Utils::OpenHandle(this);
2232 i::Handle<i::Object> other = Utils::OpenHandle(*that); 2410 i::Handle<i::Object> other = Utils::OpenHandle(*that);
2233 // Must check HeapNumber first, since NaN !== NaN. 2411 // Must check HeapNumber first, since NaN !== NaN.
2234 if (obj->IsHeapNumber()) { 2412 if (obj->IsHeapNumber()) {
2235 if (!other->IsNumber()) return false; 2413 if (!other->IsNumber()) return false;
2236 double x = obj->Number(); 2414 double x = obj->Number();
2237 double y = other->Number(); 2415 double y = other->Number();
2238 // Must check explicitly for NaN:s on Windows, but -0 works fine. 2416 // Must check explicitly for NaN:s on Windows, but -0 works fine.
2239 return x == y && !isnan(x) && !isnan(y); 2417 return x == y && !isnan(x) && !isnan(y);
2240 } else if (*obj == *other) { // Also covers Booleans. 2418 } else if (*obj == *other) { // Also covers Booleans.
2241 return true; 2419 return true;
2242 } else if (obj->IsSmi()) { 2420 } else if (obj->IsSmi()) {
2243 return other->IsNumber() && obj->Number() == other->Number(); 2421 return other->IsNumber() && obj->Number() == other->Number();
2244 } else if (obj->IsString()) { 2422 } else if (obj->IsString()) {
2245 return other->IsString() && 2423 return other->IsString() &&
2246 i::String::cast(*obj)->Equals(i::String::cast(*other)); 2424 i::String::cast(*obj)->Equals(i::String::cast(*other));
2247 } else if (obj->IsUndefined() || obj->IsUndetectableObject()) { 2425 } else if (obj->IsUndefined() || obj->IsUndetectableObject()) {
2248 return other->IsUndefined() || other->IsUndetectableObject(); 2426 return other->IsUndefined() || other->IsUndetectableObject();
2249 } else { 2427 } else {
2250 return false; 2428 return false;
2251 } 2429 }
2252 } 2430 }
2253 2431
2254 2432
2255 uint32_t Value::Uint32Value() const { 2433 uint32_t Value::Uint32Value() const {
2256 if (IsDeadCheck("v8::Value::Uint32Value()")) return 0; 2434 i::Isolate* isolate = i::Isolate::Current();
2257 LOG_API("Uint32Value"); 2435 if (IsDeadCheck(isolate, "v8::Value::Uint32Value()")) return 0;
2436 LOG_API(isolate, "Uint32Value");
2258 i::Handle<i::Object> obj = Utils::OpenHandle(this); 2437 i::Handle<i::Object> obj = Utils::OpenHandle(this);
2259 if (obj->IsSmi()) { 2438 if (obj->IsSmi()) {
2260 return i::Smi::cast(*obj)->value(); 2439 return i::Smi::cast(*obj)->value();
2261 } else { 2440 } else {
2262 ENTER_V8; 2441 ENTER_V8;
2263 EXCEPTION_PREAMBLE(); 2442 EXCEPTION_PREAMBLE();
2264 i::Handle<i::Object> num = 2443 i::Handle<i::Object> num =
2265 i::Execution::ToUint32(obj, &has_pending_exception); 2444 i::Execution::ToUint32(obj, &has_pending_exception);
2266 EXCEPTION_BAILOUT_CHECK(0); 2445 EXCEPTION_BAILOUT_CHECK(0);
2267 if (num->IsSmi()) { 2446 if (num->IsSmi()) {
2268 return i::Smi::cast(*num)->value(); 2447 return i::Smi::cast(*num)->value();
2269 } else { 2448 } else {
2270 return static_cast<uint32_t>(num->Number()); 2449 return static_cast<uint32_t>(num->Number());
2271 } 2450 }
2272 } 2451 }
2273 } 2452 }
2274 2453
2275 2454
2276 bool v8::Object::Set(v8::Handle<Value> key, v8::Handle<Value> value, 2455 bool v8::Object::Set(v8::Handle<Value> key, v8::Handle<Value> value,
2277 v8::PropertyAttribute attribs) { 2456 v8::PropertyAttribute attribs) {
2278 ON_BAILOUT("v8::Object::Set()", return false); 2457 i::Isolate* isolate = i::Isolate::Current();
2458 ON_BAILOUT(isolate, "v8::Object::Set()", return false);
2279 ENTER_V8; 2459 ENTER_V8;
2280 HandleScope scope; 2460 i::HandleScope scope(isolate);
2281 i::Handle<i::Object> self = Utils::OpenHandle(this); 2461 i::Handle<i::Object> self = Utils::OpenHandle(this);
2282 i::Handle<i::Object> key_obj = Utils::OpenHandle(*key); 2462 i::Handle<i::Object> key_obj = Utils::OpenHandle(*key);
2283 i::Handle<i::Object> value_obj = Utils::OpenHandle(*value); 2463 i::Handle<i::Object> value_obj = Utils::OpenHandle(*value);
2284 EXCEPTION_PREAMBLE(); 2464 EXCEPTION_PREAMBLE();
2285 i::Handle<i::Object> obj = i::SetProperty( 2465 i::Handle<i::Object> obj = i::SetProperty(
2286 self, 2466 self,
2287 key_obj, 2467 key_obj,
2288 value_obj, 2468 value_obj,
2289 static_cast<PropertyAttributes>(attribs), 2469 static_cast<PropertyAttributes>(attribs),
2290 i::kNonStrictMode); 2470 i::kNonStrictMode);
2291 has_pending_exception = obj.is_null(); 2471 has_pending_exception = obj.is_null();
2292 EXCEPTION_BAILOUT_CHECK(false); 2472 EXCEPTION_BAILOUT_CHECK(false);
2293 return true; 2473 return true;
2294 } 2474 }
2295 2475
2296 2476
2297 bool v8::Object::Set(uint32_t index, v8::Handle<Value> value) { 2477 bool v8::Object::Set(uint32_t index, v8::Handle<Value> value) {
2298 ON_BAILOUT("v8::Object::Set()", return false); 2478 i::Isolate* isolate = i::Isolate::Current();
2479 ON_BAILOUT(isolate, "v8::Object::Set()", return false);
2299 ENTER_V8; 2480 ENTER_V8;
2300 HandleScope scope; 2481 i::HandleScope scope(isolate);
2301 i::Handle<i::JSObject> self = Utils::OpenHandle(this); 2482 i::Handle<i::JSObject> self = Utils::OpenHandle(this);
2302 i::Handle<i::Object> value_obj = Utils::OpenHandle(*value); 2483 i::Handle<i::Object> value_obj = Utils::OpenHandle(*value);
2303 EXCEPTION_PREAMBLE(); 2484 EXCEPTION_PREAMBLE();
2304 i::Handle<i::Object> obj = i::SetElement( 2485 i::Handle<i::Object> obj = i::SetElement(
2305 self, 2486 self,
2306 index, 2487 index,
2307 value_obj, 2488 value_obj,
2308 i::kNonStrictMode); 2489 i::kNonStrictMode);
2309 has_pending_exception = obj.is_null(); 2490 has_pending_exception = obj.is_null();
2310 EXCEPTION_BAILOUT_CHECK(false); 2491 EXCEPTION_BAILOUT_CHECK(false);
2311 return true; 2492 return true;
2312 } 2493 }
2313 2494
2314 2495
2315 bool v8::Object::ForceSet(v8::Handle<Value> key, 2496 bool v8::Object::ForceSet(v8::Handle<Value> key,
2316 v8::Handle<Value> value, 2497 v8::Handle<Value> value,
2317 v8::PropertyAttribute attribs) { 2498 v8::PropertyAttribute attribs) {
2318 ON_BAILOUT("v8::Object::ForceSet()", return false); 2499 i::Isolate* isolate = i::Isolate::Current();
2500 ON_BAILOUT(isolate, "v8::Object::ForceSet()", return false);
2319 ENTER_V8; 2501 ENTER_V8;
2320 HandleScope scope; 2502 i::HandleScope scope(isolate);
2321 i::Handle<i::JSObject> self = Utils::OpenHandle(this); 2503 i::Handle<i::JSObject> self = Utils::OpenHandle(this);
2322 i::Handle<i::Object> key_obj = Utils::OpenHandle(*key); 2504 i::Handle<i::Object> key_obj = Utils::OpenHandle(*key);
2323 i::Handle<i::Object> value_obj = Utils::OpenHandle(*value); 2505 i::Handle<i::Object> value_obj = Utils::OpenHandle(*value);
2324 EXCEPTION_PREAMBLE(); 2506 EXCEPTION_PREAMBLE();
2325 i::Handle<i::Object> obj = i::ForceSetProperty( 2507 i::Handle<i::Object> obj = i::ForceSetProperty(
2326 self, 2508 self,
2327 key_obj, 2509 key_obj,
2328 value_obj, 2510 value_obj,
2329 static_cast<PropertyAttributes>(attribs)); 2511 static_cast<PropertyAttributes>(attribs));
2330 has_pending_exception = obj.is_null(); 2512 has_pending_exception = obj.is_null();
2331 EXCEPTION_BAILOUT_CHECK(false); 2513 EXCEPTION_BAILOUT_CHECK(false);
2332 return true; 2514 return true;
2333 } 2515 }
2334 2516
2335 2517
2336 bool v8::Object::ForceDelete(v8::Handle<Value> key) { 2518 bool v8::Object::ForceDelete(v8::Handle<Value> key) {
2337 ON_BAILOUT("v8::Object::ForceDelete()", return false); 2519 i::Isolate* isolate = i::Isolate::Current();
2520 ON_BAILOUT(isolate, "v8::Object::ForceDelete()", return false);
2338 ENTER_V8; 2521 ENTER_V8;
2339 HandleScope scope; 2522 i::HandleScope scope(isolate);
2340 i::Handle<i::JSObject> self = Utils::OpenHandle(this); 2523 i::Handle<i::JSObject> self = Utils::OpenHandle(this);
2341 i::Handle<i::Object> key_obj = Utils::OpenHandle(*key); 2524 i::Handle<i::Object> key_obj = Utils::OpenHandle(*key);
2342 2525
2343 // When turning on access checks for a global object deoptimize all functions 2526 // When turning on access checks for a global object deoptimize all functions
2344 // as optimized code does not always handle access checks. 2527 // as optimized code does not always handle access checks.
2345 i::Deoptimizer::DeoptimizeGlobalObject(*self); 2528 i::Deoptimizer::DeoptimizeGlobalObject(*self);
2346 2529
2347 EXCEPTION_PREAMBLE(); 2530 EXCEPTION_PREAMBLE();
2348 i::Handle<i::Object> obj = i::ForceDeleteProperty(self, key_obj); 2531 i::Handle<i::Object> obj = i::ForceDeleteProperty(self, key_obj);
2349 has_pending_exception = obj.is_null(); 2532 has_pending_exception = obj.is_null();
2350 EXCEPTION_BAILOUT_CHECK(false); 2533 EXCEPTION_BAILOUT_CHECK(false);
2351 return obj->IsTrue(); 2534 return obj->IsTrue();
2352 } 2535 }
2353 2536
2354 2537
2355 Local<Value> v8::Object::Get(v8::Handle<Value> key) { 2538 Local<Value> v8::Object::Get(v8::Handle<Value> key) {
2356 ON_BAILOUT("v8::Object::Get()", return Local<v8::Value>()); 2539 i::Isolate* isolate = i::Isolate::Current();
2540 ON_BAILOUT(isolate, "v8::Object::Get()", return Local<v8::Value>());
2357 ENTER_V8; 2541 ENTER_V8;
2358 i::Handle<i::Object> self = Utils::OpenHandle(this); 2542 i::Handle<i::Object> self = Utils::OpenHandle(this);
2359 i::Handle<i::Object> key_obj = Utils::OpenHandle(*key); 2543 i::Handle<i::Object> key_obj = Utils::OpenHandle(*key);
2360 EXCEPTION_PREAMBLE(); 2544 EXCEPTION_PREAMBLE();
2361 i::Handle<i::Object> result = i::GetProperty(self, key_obj); 2545 i::Handle<i::Object> result = i::GetProperty(self, key_obj);
2362 has_pending_exception = result.is_null(); 2546 has_pending_exception = result.is_null();
2363 EXCEPTION_BAILOUT_CHECK(Local<Value>()); 2547 EXCEPTION_BAILOUT_CHECK(Local<Value>());
2364 return Utils::ToLocal(result); 2548 return Utils::ToLocal(result);
2365 } 2549 }
2366 2550
2367 2551
2368 Local<Value> v8::Object::Get(uint32_t index) { 2552 Local<Value> v8::Object::Get(uint32_t index) {
2369 ON_BAILOUT("v8::Object::Get()", return Local<v8::Value>()); 2553 i::Isolate* isolate = i::Isolate::Current();
2554 ON_BAILOUT(isolate, "v8::Object::Get()", return Local<v8::Value>());
2370 ENTER_V8; 2555 ENTER_V8;
2371 i::Handle<i::JSObject> self = Utils::OpenHandle(this); 2556 i::Handle<i::JSObject> self = Utils::OpenHandle(this);
2372 EXCEPTION_PREAMBLE(); 2557 EXCEPTION_PREAMBLE();
2373 i::Handle<i::Object> result = i::GetElement(self, index); 2558 i::Handle<i::Object> result = i::GetElement(self, index);
2374 has_pending_exception = result.is_null(); 2559 has_pending_exception = result.is_null();
2375 EXCEPTION_BAILOUT_CHECK(Local<Value>()); 2560 EXCEPTION_BAILOUT_CHECK(Local<Value>());
2376 return Utils::ToLocal(result); 2561 return Utils::ToLocal(result);
2377 } 2562 }
2378 2563
2379 2564
2380 Local<Value> v8::Object::GetPrototype() { 2565 Local<Value> v8::Object::GetPrototype() {
2381 ON_BAILOUT("v8::Object::GetPrototype()", return Local<v8::Value>()); 2566 ON_BAILOUT(i::Isolate::Current(), "v8::Object::GetPrototype()",
2567 return Local<v8::Value>());
2382 ENTER_V8; 2568 ENTER_V8;
2383 i::Handle<i::Object> self = Utils::OpenHandle(this); 2569 i::Handle<i::Object> self = Utils::OpenHandle(this);
2384 i::Handle<i::Object> result = i::GetPrototype(self); 2570 i::Handle<i::Object> result = i::GetPrototype(self);
2385 return Utils::ToLocal(result); 2571 return Utils::ToLocal(result);
2386 } 2572 }
2387 2573
2388 2574
2389 bool v8::Object::SetPrototype(Handle<Value> value) { 2575 bool v8::Object::SetPrototype(Handle<Value> value) {
2390 ON_BAILOUT("v8::Object::SetPrototype()", return false); 2576 i::Isolate* isolate = i::Isolate::Current();
2577 ON_BAILOUT(isolate, "v8::Object::SetPrototype()", return false);
2391 ENTER_V8; 2578 ENTER_V8;
2392 i::Handle<i::JSObject> self = Utils::OpenHandle(this); 2579 i::Handle<i::JSObject> self = Utils::OpenHandle(this);
2393 i::Handle<i::Object> value_obj = Utils::OpenHandle(*value); 2580 i::Handle<i::Object> value_obj = Utils::OpenHandle(*value);
2394 EXCEPTION_PREAMBLE(); 2581 EXCEPTION_PREAMBLE();
2395 i::Handle<i::Object> result = i::SetPrototype(self, value_obj); 2582 i::Handle<i::Object> result = i::SetPrototype(self, value_obj);
2396 has_pending_exception = result.is_null(); 2583 has_pending_exception = result.is_null();
2397 EXCEPTION_BAILOUT_CHECK(false); 2584 EXCEPTION_BAILOUT_CHECK(false);
2398 return true; 2585 return true;
2399 } 2586 }
2400 2587
2401 2588
2402 Local<Object> v8::Object::FindInstanceInPrototypeChain( 2589 Local<Object> v8::Object::FindInstanceInPrototypeChain(
2403 v8::Handle<FunctionTemplate> tmpl) { 2590 v8::Handle<FunctionTemplate> tmpl) {
2404 ON_BAILOUT("v8::Object::FindInstanceInPrototypeChain()", 2591 ON_BAILOUT(i::Isolate::Current(),
2592 "v8::Object::FindInstanceInPrototypeChain()",
2405 return Local<v8::Object>()); 2593 return Local<v8::Object>());
2406 ENTER_V8; 2594 ENTER_V8;
2407 i::JSObject* object = *Utils::OpenHandle(this); 2595 i::JSObject* object = *Utils::OpenHandle(this);
2408 i::FunctionTemplateInfo* tmpl_info = *Utils::OpenHandle(*tmpl); 2596 i::FunctionTemplateInfo* tmpl_info = *Utils::OpenHandle(*tmpl);
2409 while (!object->IsInstanceOf(tmpl_info)) { 2597 while (!object->IsInstanceOf(tmpl_info)) {
2410 i::Object* prototype = object->GetPrototype(); 2598 i::Object* prototype = object->GetPrototype();
2411 if (!prototype->IsJSObject()) return Local<Object>(); 2599 if (!prototype->IsJSObject()) return Local<Object>();
2412 object = i::JSObject::cast(prototype); 2600 object = i::JSObject::cast(prototype);
2413 } 2601 }
2414 return Utils::ToLocal(i::Handle<i::JSObject>(object)); 2602 return Utils::ToLocal(i::Handle<i::JSObject>(object));
2415 } 2603 }
2416 2604
2417 2605
2418 Local<Array> v8::Object::GetPropertyNames() { 2606 Local<Array> v8::Object::GetPropertyNames() {
2419 ON_BAILOUT("v8::Object::GetPropertyNames()", return Local<v8::Array>()); 2607 ON_BAILOUT(i::Isolate::Current(), "v8::Object::GetPropertyNames()",
2608 return Local<v8::Array>());
2420 ENTER_V8; 2609 ENTER_V8;
2421 v8::HandleScope scope; 2610 v8::HandleScope scope;
2422 i::Handle<i::JSObject> self = Utils::OpenHandle(this); 2611 i::Handle<i::JSObject> self = Utils::OpenHandle(this);
2423 i::Handle<i::FixedArray> value = 2612 i::Handle<i::FixedArray> value =
2424 i::GetKeysInFixedArrayFor(self, i::INCLUDE_PROTOS); 2613 i::GetKeysInFixedArrayFor(self, i::INCLUDE_PROTOS);
2425 // Because we use caching to speed up enumeration it is important 2614 // Because we use caching to speed up enumeration it is important
2426 // to never change the result of the basic enumeration function so 2615 // to never change the result of the basic enumeration function so
2427 // we clone the result. 2616 // we clone the result.
2428 i::Handle<i::FixedArray> elms = i::Factory::CopyFixedArray(value); 2617 i::Handle<i::FixedArray> elms = FACTORY->CopyFixedArray(value);
2429 i::Handle<i::JSArray> result = i::Factory::NewJSArrayWithElements(elms); 2618 i::Handle<i::JSArray> result = FACTORY->NewJSArrayWithElements(elms);
2430 return scope.Close(Utils::ToLocal(result)); 2619 return scope.Close(Utils::ToLocal(result));
2431 } 2620 }
2432 2621
2433 2622
2434 Local<String> v8::Object::ObjectProtoToString() { 2623 Local<String> v8::Object::ObjectProtoToString() {
2435 ON_BAILOUT("v8::Object::ObjectProtoToString()", return Local<v8::String>()); 2624 ON_BAILOUT(i::Isolate::Current(), "v8::Object::ObjectProtoToString()",
2625 return Local<v8::String>());
2436 ENTER_V8; 2626 ENTER_V8;
2437 i::Handle<i::JSObject> self = Utils::OpenHandle(this); 2627 i::Handle<i::JSObject> self = Utils::OpenHandle(this);
2438 2628
2439 i::Handle<i::Object> name(self->class_name()); 2629 i::Handle<i::Object> name(self->class_name());
2440 2630
2441 // Native implementation of Object.prototype.toString (v8natives.js): 2631 // Native implementation of Object.prototype.toString (v8natives.js):
2442 // var c = %ClassOf(this); 2632 // var c = %ClassOf(this);
2443 // if (c === 'Arguments') c = 'Object'; 2633 // if (c === 'Arguments') c = 'Object';
2444 // return "[object " + c + "]"; 2634 // return "[object " + c + "]";
2445 2635
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
2477 2667
2478 // Copy the buffer into a heap-allocated string and return it. 2668 // Copy the buffer into a heap-allocated string and return it.
2479 Local<String> result = v8::String::New(buf.start(), buf_len); 2669 Local<String> result = v8::String::New(buf.start(), buf_len);
2480 return result; 2670 return result;
2481 } 2671 }
2482 } 2672 }
2483 } 2673 }
2484 2674
2485 2675
2486 Local<String> v8::Object::GetConstructorName() { 2676 Local<String> v8::Object::GetConstructorName() {
2487 ON_BAILOUT("v8::Object::GetConstructorName()", return Local<v8::String>()); 2677 i::Isolate* isolate = i::Isolate::Current();
2678 ON_BAILOUT(isolate, "v8::Object::GetConstructorName()",
2679 return Local<v8::String>());
2488 ENTER_V8; 2680 ENTER_V8;
2489 i::Handle<i::JSObject> self = Utils::OpenHandle(this); 2681 i::Handle<i::JSObject> self = Utils::OpenHandle(this);
2490 i::Handle<i::String> name(self->constructor_name()); 2682 i::Handle<i::String> name(self->constructor_name());
2491 return Utils::ToLocal(name); 2683 return Utils::ToLocal(name);
2492 } 2684 }
2493 2685
2494 2686
2495 bool v8::Object::Delete(v8::Handle<String> key) { 2687 bool v8::Object::Delete(v8::Handle<String> key) {
2496 ON_BAILOUT("v8::Object::Delete()", return false); 2688 i::Isolate* isolate = i::Isolate::Current();
2689 ON_BAILOUT(isolate, "v8::Object::Delete()", return false);
2497 ENTER_V8; 2690 ENTER_V8;
2498 HandleScope scope; 2691 i::HandleScope scope(isolate);
2499 i::Handle<i::JSObject> self = Utils::OpenHandle(this); 2692 i::Handle<i::JSObject> self = Utils::OpenHandle(this);
2500 i::Handle<i::String> key_obj = Utils::OpenHandle(*key); 2693 i::Handle<i::String> key_obj = Utils::OpenHandle(*key);
2501 return i::DeleteProperty(self, key_obj)->IsTrue(); 2694 return i::DeleteProperty(self, key_obj)->IsTrue();
2502 } 2695 }
2503 2696
2504 2697
2505 bool v8::Object::Has(v8::Handle<String> key) { 2698 bool v8::Object::Has(v8::Handle<String> key) {
2506 ON_BAILOUT("v8::Object::Has()", return false); 2699 ON_BAILOUT(i::Isolate::Current(), "v8::Object::Has()", return false);
2507 ENTER_V8; 2700 ENTER_V8;
2508 i::Handle<i::JSObject> self = Utils::OpenHandle(this); 2701 i::Handle<i::JSObject> self = Utils::OpenHandle(this);
2509 i::Handle<i::String> key_obj = Utils::OpenHandle(*key); 2702 i::Handle<i::String> key_obj = Utils::OpenHandle(*key);
2510 return self->HasProperty(*key_obj); 2703 return self->HasProperty(*key_obj);
2511 } 2704 }
2512 2705
2513 2706
2514 bool v8::Object::Delete(uint32_t index) { 2707 bool v8::Object::Delete(uint32_t index) {
2515 ON_BAILOUT("v8::Object::DeleteProperty()", return false); 2708 ON_BAILOUT(i::Isolate::Current(), "v8::Object::DeleteProperty()",
2709 return false);
2516 ENTER_V8; 2710 ENTER_V8;
2517 HandleScope scope; 2711 HandleScope scope;
2518 i::Handle<i::JSObject> self = Utils::OpenHandle(this); 2712 i::Handle<i::JSObject> self = Utils::OpenHandle(this);
2519 return i::DeleteElement(self, index)->IsTrue(); 2713 return i::DeleteElement(self, index)->IsTrue();
2520 } 2714 }
2521 2715
2522 2716
2523 bool v8::Object::Has(uint32_t index) { 2717 bool v8::Object::Has(uint32_t index) {
2524 ON_BAILOUT("v8::Object::HasProperty()", return false); 2718 ON_BAILOUT(i::Isolate::Current(), "v8::Object::HasProperty()", return false);
2525 i::Handle<i::JSObject> self = Utils::OpenHandle(this); 2719 i::Handle<i::JSObject> self = Utils::OpenHandle(this);
2526 return self->HasElement(index); 2720 return self->HasElement(index);
2527 } 2721 }
2528 2722
2529 2723
2530 bool Object::SetAccessor(Handle<String> name, 2724 bool Object::SetAccessor(Handle<String> name,
2531 AccessorGetter getter, 2725 AccessorGetter getter,
2532 AccessorSetter setter, 2726 AccessorSetter setter,
2533 v8::Handle<Value> data, 2727 v8::Handle<Value> data,
2534 AccessControl settings, 2728 AccessControl settings,
2535 PropertyAttribute attributes) { 2729 PropertyAttribute attributes) {
2536 ON_BAILOUT("v8::Object::SetAccessor()", return false); 2730 i::Isolate* isolate = i::Isolate::Current();
2731 ON_BAILOUT(isolate, "v8::Object::SetAccessor()", return false);
2537 ENTER_V8; 2732 ENTER_V8;
2538 HandleScope scope; 2733 i::HandleScope scope(isolate);
2539 i::Handle<i::AccessorInfo> info = MakeAccessorInfo(name, 2734 i::Handle<i::AccessorInfo> info = MakeAccessorInfo(name,
2540 getter, setter, data, 2735 getter, setter, data,
2541 settings, attributes); 2736 settings, attributes);
2542 i::Handle<i::Object> result = i::SetAccessor(Utils::OpenHandle(this), info); 2737 i::Handle<i::Object> result = i::SetAccessor(Utils::OpenHandle(this), info);
2543 return !result.is_null() && !result->IsUndefined(); 2738 return !result.is_null() && !result->IsUndefined();
2544 } 2739 }
2545 2740
2546 2741
2547 bool v8::Object::HasRealNamedProperty(Handle<String> key) { 2742 bool v8::Object::HasRealNamedProperty(Handle<String> key) {
2548 ON_BAILOUT("v8::Object::HasRealNamedProperty()", return false); 2743 ON_BAILOUT(i::Isolate::Current(), "v8::Object::HasRealNamedProperty()",
2744 return false);
2549 return Utils::OpenHandle(this)->HasRealNamedProperty( 2745 return Utils::OpenHandle(this)->HasRealNamedProperty(
2550 *Utils::OpenHandle(*key)); 2746 *Utils::OpenHandle(*key));
2551 } 2747 }
2552 2748
2553 2749
2554 bool v8::Object::HasRealIndexedProperty(uint32_t index) { 2750 bool v8::Object::HasRealIndexedProperty(uint32_t index) {
2555 ON_BAILOUT("v8::Object::HasRealIndexedProperty()", return false); 2751 ON_BAILOUT(i::Isolate::Current(), "v8::Object::HasRealIndexedProperty()",
2752 return false);
2556 return Utils::OpenHandle(this)->HasRealElementProperty(index); 2753 return Utils::OpenHandle(this)->HasRealElementProperty(index);
2557 } 2754 }
2558 2755
2559 2756
2560 bool v8::Object::HasRealNamedCallbackProperty(Handle<String> key) { 2757 bool v8::Object::HasRealNamedCallbackProperty(Handle<String> key) {
2561 ON_BAILOUT("v8::Object::HasRealNamedCallbackProperty()", return false); 2758 ON_BAILOUT(i::Isolate::Current(),
2759 "v8::Object::HasRealNamedCallbackProperty()",
2760 return false);
2562 ENTER_V8; 2761 ENTER_V8;
2563 return Utils::OpenHandle(this)->HasRealNamedCallbackProperty( 2762 return Utils::OpenHandle(this)->HasRealNamedCallbackProperty(
2564 *Utils::OpenHandle(*key)); 2763 *Utils::OpenHandle(*key));
2565 } 2764 }
2566 2765
2567 2766
2568 bool v8::Object::HasNamedLookupInterceptor() { 2767 bool v8::Object::HasNamedLookupInterceptor() {
2569 ON_BAILOUT("v8::Object::HasNamedLookupInterceptor()", return false); 2768 ON_BAILOUT(i::Isolate::Current(), "v8::Object::HasNamedLookupInterceptor()",
2769 return false);
2570 return Utils::OpenHandle(this)->HasNamedInterceptor(); 2770 return Utils::OpenHandle(this)->HasNamedInterceptor();
2571 } 2771 }
2572 2772
2573 2773
2574 bool v8::Object::HasIndexedLookupInterceptor() { 2774 bool v8::Object::HasIndexedLookupInterceptor() {
2575 ON_BAILOUT("v8::Object::HasIndexedLookupInterceptor()", return false); 2775 ON_BAILOUT(i::Isolate::Current(), "v8::Object::HasIndexedLookupInterceptor()",
2776 return false);
2576 return Utils::OpenHandle(this)->HasIndexedInterceptor(); 2777 return Utils::OpenHandle(this)->HasIndexedInterceptor();
2577 } 2778 }
2578 2779
2579 2780
2580 Local<Value> v8::Object::GetRealNamedPropertyInPrototypeChain( 2781 Local<Value> v8::Object::GetRealNamedPropertyInPrototypeChain(
2581 Handle<String> key) { 2782 Handle<String> key) {
2582 ON_BAILOUT("v8::Object::GetRealNamedPropertyInPrototypeChain()", 2783 ON_BAILOUT(i::Isolate::Current(),
2784 "v8::Object::GetRealNamedPropertyInPrototypeChain()",
2583 return Local<Value>()); 2785 return Local<Value>());
2584 ENTER_V8; 2786 ENTER_V8;
2585 i::Handle<i::JSObject> self_obj = Utils::OpenHandle(this); 2787 i::Handle<i::JSObject> self_obj = Utils::OpenHandle(this);
2586 i::Handle<i::String> key_obj = Utils::OpenHandle(*key); 2788 i::Handle<i::String> key_obj = Utils::OpenHandle(*key);
2587 i::LookupResult lookup; 2789 i::LookupResult lookup;
2588 self_obj->LookupRealNamedPropertyInPrototypes(*key_obj, &lookup); 2790 self_obj->LookupRealNamedPropertyInPrototypes(*key_obj, &lookup);
2589 if (lookup.IsProperty()) { 2791 if (lookup.IsProperty()) {
2590 PropertyAttributes attributes; 2792 PropertyAttributes attributes;
2591 i::Object* property = 2793 i::Object* property =
2592 self_obj->GetProperty(*self_obj, 2794 self_obj->GetProperty(*self_obj,
2593 &lookup, 2795 &lookup,
2594 *key_obj, 2796 *key_obj,
2595 &attributes)->ToObjectUnchecked(); 2797 &attributes)->ToObjectUnchecked();
2596 i::Handle<i::Object> result(property); 2798 i::Handle<i::Object> result(property);
2597 return Utils::ToLocal(result); 2799 return Utils::ToLocal(result);
2598 } 2800 }
2599 return Local<Value>(); // No real property was found in prototype chain. 2801 return Local<Value>(); // No real property was found in prototype chain.
2600 } 2802 }
2601 2803
2602 2804
2603 Local<Value> v8::Object::GetRealNamedProperty(Handle<String> key) { 2805 Local<Value> v8::Object::GetRealNamedProperty(Handle<String> key) {
2604 ON_BAILOUT("v8::Object::GetRealNamedProperty()", return Local<Value>()); 2806 ON_BAILOUT(i::Isolate::Current(), "v8::Object::GetRealNamedProperty()",
2807 return Local<Value>());
2605 ENTER_V8; 2808 ENTER_V8;
2606 i::Handle<i::JSObject> self_obj = Utils::OpenHandle(this); 2809 i::Handle<i::JSObject> self_obj = Utils::OpenHandle(this);
2607 i::Handle<i::String> key_obj = Utils::OpenHandle(*key); 2810 i::Handle<i::String> key_obj = Utils::OpenHandle(*key);
2608 i::LookupResult lookup; 2811 i::LookupResult lookup;
2609 self_obj->LookupRealNamedProperty(*key_obj, &lookup); 2812 self_obj->LookupRealNamedProperty(*key_obj, &lookup);
2610 if (lookup.IsProperty()) { 2813 if (lookup.IsProperty()) {
2611 PropertyAttributes attributes; 2814 PropertyAttributes attributes;
2612 i::Object* property = 2815 i::Object* property =
2613 self_obj->GetProperty(*self_obj, 2816 self_obj->GetProperty(*self_obj,
2614 &lookup, 2817 &lookup,
2615 *key_obj, 2818 *key_obj,
2616 &attributes)->ToObjectUnchecked(); 2819 &attributes)->ToObjectUnchecked();
2617 i::Handle<i::Object> result(property); 2820 i::Handle<i::Object> result(property);
2618 return Utils::ToLocal(result); 2821 return Utils::ToLocal(result);
2619 } 2822 }
2620 return Local<Value>(); // No real property was found in prototype chain. 2823 return Local<Value>(); // No real property was found in prototype chain.
2621 } 2824 }
2622 2825
2623 2826
2624 // Turns on access checks by copying the map and setting the check flag. 2827 // Turns on access checks by copying the map and setting the check flag.
2625 // Because the object gets a new map, existing inline cache caching 2828 // Because the object gets a new map, existing inline cache caching
2626 // the old map of this object will fail. 2829 // the old map of this object will fail.
2627 void v8::Object::TurnOnAccessCheck() { 2830 void v8::Object::TurnOnAccessCheck() {
2628 ON_BAILOUT("v8::Object::TurnOnAccessCheck()", return); 2831 i::Isolate* isolate = i::Isolate::Current();
2832 ON_BAILOUT(isolate, "v8::Object::TurnOnAccessCheck()", return);
2629 ENTER_V8; 2833 ENTER_V8;
2630 HandleScope scope; 2834 i::HandleScope scope(isolate);
2631 i::Handle<i::JSObject> obj = Utils::OpenHandle(this); 2835 i::Handle<i::JSObject> obj = Utils::OpenHandle(this);
2632 2836
2633 // When turning on access checks for a global object deoptimize all functions 2837 // When turning on access checks for a global object deoptimize all functions
2634 // as optimized code does not always handle access checks. 2838 // as optimized code does not always handle access checks.
2635 i::Deoptimizer::DeoptimizeGlobalObject(*obj); 2839 i::Deoptimizer::DeoptimizeGlobalObject(*obj);
2636 2840
2637 i::Handle<i::Map> new_map = 2841 i::Handle<i::Map> new_map =
2638 i::Factory::CopyMapDropTransitions(i::Handle<i::Map>(obj->map())); 2842 FACTORY->CopyMapDropTransitions(i::Handle<i::Map>(obj->map()));
2639 new_map->set_is_access_check_needed(true); 2843 new_map->set_is_access_check_needed(true);
2640 obj->set_map(*new_map); 2844 obj->set_map(*new_map);
2641 } 2845 }
2642 2846
2643 2847
2644 bool v8::Object::IsDirty() { 2848 bool v8::Object::IsDirty() {
2645 return Utils::OpenHandle(this)->IsDirty(); 2849 return Utils::OpenHandle(this)->IsDirty();
2646 } 2850 }
2647 2851
2648 2852
2649 Local<v8::Object> v8::Object::Clone() { 2853 Local<v8::Object> v8::Object::Clone() {
2650 ON_BAILOUT("v8::Object::Clone()", return Local<Object>()); 2854 i::Isolate* isolate = i::Isolate::Current();
2855 ON_BAILOUT(isolate, "v8::Object::Clone()", return Local<Object>());
2651 ENTER_V8; 2856 ENTER_V8;
2652 i::Handle<i::JSObject> self = Utils::OpenHandle(this); 2857 i::Handle<i::JSObject> self = Utils::OpenHandle(this);
2653 EXCEPTION_PREAMBLE(); 2858 EXCEPTION_PREAMBLE();
2654 i::Handle<i::JSObject> result = i::Copy(self); 2859 i::Handle<i::JSObject> result = i::Copy(self);
2655 has_pending_exception = result.is_null(); 2860 has_pending_exception = result.is_null();
2656 EXCEPTION_BAILOUT_CHECK(Local<Object>()); 2861 EXCEPTION_BAILOUT_CHECK(Local<Object>());
2657 return Utils::ToLocal(result); 2862 return Utils::ToLocal(result);
2658 } 2863 }
2659 2864
2660 2865
2661 int v8::Object::GetIdentityHash() { 2866 int v8::Object::GetIdentityHash() {
2662 ON_BAILOUT("v8::Object::GetIdentityHash()", return 0); 2867 i::Isolate* isolate = i::Isolate::Current();
2868 ON_BAILOUT(isolate, "v8::Object::GetIdentityHash()", return 0);
2663 ENTER_V8; 2869 ENTER_V8;
2664 HandleScope scope; 2870 i::HandleScope scope(isolate);
2665 i::Handle<i::JSObject> self = Utils::OpenHandle(this); 2871 i::Handle<i::JSObject> self = Utils::OpenHandle(this);
2666 i::Handle<i::Object> hidden_props_obj(i::GetHiddenProperties(self, true)); 2872 i::Handle<i::Object> hidden_props_obj(i::GetHiddenProperties(self, true));
2667 if (!hidden_props_obj->IsJSObject()) { 2873 if (!hidden_props_obj->IsJSObject()) {
2668 // We failed to create hidden properties. That's a detached 2874 // We failed to create hidden properties. That's a detached
2669 // global proxy. 2875 // global proxy.
2670 ASSERT(hidden_props_obj->IsUndefined()); 2876 ASSERT(hidden_props_obj->IsUndefined());
2671 return 0; 2877 return 0;
2672 } 2878 }
2673 i::Handle<i::JSObject> hidden_props = 2879 i::Handle<i::JSObject> hidden_props =
2674 i::Handle<i::JSObject>::cast(hidden_props_obj); 2880 i::Handle<i::JSObject>::cast(hidden_props_obj);
2675 i::Handle<i::String> hash_symbol = i::Factory::identity_hash_symbol(); 2881 i::Handle<i::String> hash_symbol = FACTORY->identity_hash_symbol();
2676 if (hidden_props->HasLocalProperty(*hash_symbol)) { 2882 if (hidden_props->HasLocalProperty(*hash_symbol)) {
2677 i::Handle<i::Object> hash = i::GetProperty(hidden_props, hash_symbol); 2883 i::Handle<i::Object> hash = i::GetProperty(hidden_props, hash_symbol);
2678 CHECK(!hash.is_null()); 2884 CHECK(!hash.is_null());
2679 CHECK(hash->IsSmi()); 2885 CHECK(hash->IsSmi());
2680 return i::Smi::cast(*hash)->value(); 2886 return i::Smi::cast(*hash)->value();
2681 } 2887 }
2682 2888
2683 int hash_value; 2889 int hash_value;
2684 int attempts = 0; 2890 int attempts = 0;
2685 do { 2891 do {
2686 // Generate a random 32-bit hash value but limit range to fit 2892 // Generate a random 32-bit hash value but limit range to fit
2687 // within a smi. 2893 // within a smi.
2688 hash_value = i::V8::Random() & i::Smi::kMaxValue; 2894 hash_value = i::V8::Random(self->GetIsolate()) & i::Smi::kMaxValue;
2689 attempts++; 2895 attempts++;
2690 } while (hash_value == 0 && attempts < 30); 2896 } while (hash_value == 0 && attempts < 30);
2691 hash_value = hash_value != 0 ? hash_value : 1; // never return 0 2897 hash_value = hash_value != 0 ? hash_value : 1; // never return 0
2692 CHECK(!i::SetLocalPropertyIgnoreAttributes( 2898 CHECK(!i::SetLocalPropertyIgnoreAttributes(
2693 hidden_props, 2899 hidden_props,
2694 hash_symbol, 2900 hash_symbol,
2695 i::Handle<i::Object>(i::Smi::FromInt(hash_value)), 2901 i::Handle<i::Object>(i::Smi::FromInt(hash_value)),
2696 static_cast<PropertyAttributes>(None)).is_null()); 2902 static_cast<PropertyAttributes>(None)).is_null());
2697 2903
2698 return hash_value; 2904 return hash_value;
2699 } 2905 }
2700 2906
2701 2907
2702 bool v8::Object::SetHiddenValue(v8::Handle<v8::String> key, 2908 bool v8::Object::SetHiddenValue(v8::Handle<v8::String> key,
2703 v8::Handle<v8::Value> value) { 2909 v8::Handle<v8::Value> value) {
2704 ON_BAILOUT("v8::Object::SetHiddenValue()", return false); 2910 i::Isolate* isolate = i::Isolate::Current();
2911 ON_BAILOUT(isolate, "v8::Object::SetHiddenValue()", return false);
2705 ENTER_V8; 2912 ENTER_V8;
2706 HandleScope scope; 2913 i::HandleScope scope(isolate);
2707 i::Handle<i::JSObject> self = Utils::OpenHandle(this); 2914 i::Handle<i::JSObject> self = Utils::OpenHandle(this);
2708 i::Handle<i::Object> hidden_props(i::GetHiddenProperties(self, true)); 2915 i::Handle<i::Object> hidden_props(i::GetHiddenProperties(self, true));
2709 i::Handle<i::Object> key_obj = Utils::OpenHandle(*key); 2916 i::Handle<i::Object> key_obj = Utils::OpenHandle(*key);
2710 i::Handle<i::Object> value_obj = Utils::OpenHandle(*value); 2917 i::Handle<i::Object> value_obj = Utils::OpenHandle(*value);
2711 EXCEPTION_PREAMBLE(); 2918 EXCEPTION_PREAMBLE();
2712 i::Handle<i::Object> obj = i::SetProperty( 2919 i::Handle<i::Object> obj = i::SetProperty(
2713 hidden_props, 2920 hidden_props,
2714 key_obj, 2921 key_obj,
2715 value_obj, 2922 value_obj,
2716 static_cast<PropertyAttributes>(None), 2923 static_cast<PropertyAttributes>(None),
2717 i::kNonStrictMode); 2924 i::kNonStrictMode);
2718 has_pending_exception = obj.is_null(); 2925 has_pending_exception = obj.is_null();
2719 EXCEPTION_BAILOUT_CHECK(false); 2926 EXCEPTION_BAILOUT_CHECK(false);
2720 return true; 2927 return true;
2721 } 2928 }
2722 2929
2723 2930
2724 v8::Local<v8::Value> v8::Object::GetHiddenValue(v8::Handle<v8::String> key) { 2931 v8::Local<v8::Value> v8::Object::GetHiddenValue(v8::Handle<v8::String> key) {
2725 ON_BAILOUT("v8::Object::GetHiddenValue()", return Local<v8::Value>()); 2932 i::Isolate* isolate = i::Isolate::Current();
2933 ON_BAILOUT(isolate, "v8::Object::GetHiddenValue()",
2934 return Local<v8::Value>());
2726 ENTER_V8; 2935 ENTER_V8;
2727 i::Handle<i::JSObject> self = Utils::OpenHandle(this); 2936 i::Handle<i::JSObject> self = Utils::OpenHandle(this);
2728 i::Handle<i::Object> hidden_props(i::GetHiddenProperties(self, false)); 2937 i::Handle<i::Object> hidden_props(i::GetHiddenProperties(self, false));
2729 if (hidden_props->IsUndefined()) { 2938 if (hidden_props->IsUndefined()) {
2730 return v8::Local<v8::Value>(); 2939 return v8::Local<v8::Value>();
2731 } 2940 }
2732 i::Handle<i::String> key_obj = Utils::OpenHandle(*key); 2941 i::Handle<i::String> key_obj = Utils::OpenHandle(*key);
2733 EXCEPTION_PREAMBLE(); 2942 EXCEPTION_PREAMBLE();
2734 i::Handle<i::Object> result = i::GetProperty(hidden_props, key_obj); 2943 i::Handle<i::Object> result = i::GetProperty(hidden_props, key_obj);
2735 has_pending_exception = result.is_null(); 2944 has_pending_exception = result.is_null();
2736 EXCEPTION_BAILOUT_CHECK(v8::Local<v8::Value>()); 2945 EXCEPTION_BAILOUT_CHECK(v8::Local<v8::Value>());
2737 if (result->IsUndefined()) { 2946 if (result->IsUndefined()) {
2738 return v8::Local<v8::Value>(); 2947 return v8::Local<v8::Value>();
2739 } 2948 }
2740 return Utils::ToLocal(result); 2949 return Utils::ToLocal(result);
2741 } 2950 }
2742 2951
2743 2952
2744 bool v8::Object::DeleteHiddenValue(v8::Handle<v8::String> key) { 2953 bool v8::Object::DeleteHiddenValue(v8::Handle<v8::String> key) {
2745 ON_BAILOUT("v8::DeleteHiddenValue()", return false); 2954 i::Isolate* isolate = i::Isolate::Current();
2955 ON_BAILOUT(isolate, "v8::DeleteHiddenValue()", return false);
2746 ENTER_V8; 2956 ENTER_V8;
2747 HandleScope scope; 2957 i::HandleScope scope(isolate);
2748 i::Handle<i::JSObject> self = Utils::OpenHandle(this); 2958 i::Handle<i::JSObject> self = Utils::OpenHandle(this);
2749 i::Handle<i::Object> hidden_props(i::GetHiddenProperties(self, false)); 2959 i::Handle<i::Object> hidden_props(i::GetHiddenProperties(self, false));
2750 if (hidden_props->IsUndefined()) { 2960 if (hidden_props->IsUndefined()) {
2751 return true; 2961 return true;
2752 } 2962 }
2753 i::Handle<i::JSObject> js_obj(i::JSObject::cast(*hidden_props)); 2963 i::Handle<i::JSObject> js_obj(i::JSObject::cast(*hidden_props));
2754 i::Handle<i::String> key_obj = Utils::OpenHandle(*key); 2964 i::Handle<i::String> key_obj = Utils::OpenHandle(*key);
2755 return i::DeleteProperty(js_obj, key_obj)->IsTrue(); 2965 return i::DeleteProperty(js_obj, key_obj)->IsTrue();
2756 } 2966 }
2757 2967
2758 2968
2759 namespace { 2969 namespace {
2760 2970
2761 void PrepareExternalArrayElements(i::Handle<i::JSObject> object, 2971 void PrepareExternalArrayElements(i::Handle<i::JSObject> object,
2762 void* data, 2972 void* data,
2763 ExternalArrayType array_type, 2973 ExternalArrayType array_type,
2764 int length) { 2974 int length) {
2765 i::Handle<i::ExternalArray> array = 2975 i::Handle<i::ExternalArray> array =
2766 i::Factory::NewExternalArray(length, array_type, data); 2976 FACTORY->NewExternalArray(length, array_type, data);
2767 2977
2768 // If the object already has external elements, create a new, unique 2978 // If the object already has external elements, create a new, unique
2769 // map if the element type is now changing, because assumptions about 2979 // map if the element type is now changing, because assumptions about
2770 // generated code based on the receiver's map will be invalid. 2980 // generated code based on the receiver's map will be invalid.
2771 i::Handle<i::HeapObject> elements(object->elements()); 2981 i::Handle<i::HeapObject> elements(object->elements());
2772 bool force_unique_map = 2982 bool force_unique_map =
2773 elements->map()->IsUndefined() || 2983 elements->map()->IsUndefined() ||
2774 !elements->map()->has_external_array_elements() || 2984 !elements->map()->has_external_array_elements() ||
2775 elements->map() != i::Heap::MapForExternalArrayType(array_type); 2985 elements->map() != HEAP->MapForExternalArrayType(array_type);
2776 if (force_unique_map) { 2986 if (force_unique_map) {
2777 i::Handle<i::Map> external_array_map = 2987 i::Handle<i::Map> external_array_map =
2778 i::Factory::NewExternalArrayElementsMap( 2988 FACTORY->NewExternalArrayElementsMap(
2779 i::Handle<i::Map>(object->map())); 2989 i::Handle<i::Map>(object->map()));
2780 object->set_map(*external_array_map); 2990 object->set_map(*external_array_map);
2781 } 2991 }
2782 object->set_elements(*array); 2992 object->set_elements(*array);
2783 } 2993 }
2784 2994
2785 } // namespace 2995 } // namespace
2786 2996
2787 2997
2788 void v8::Object::SetIndexedPropertiesToPixelData(uint8_t* data, int length) { 2998 void v8::Object::SetIndexedPropertiesToPixelData(uint8_t* data, int length) {
2789 ON_BAILOUT("v8::SetElementsToPixelData()", return); 2999 i::Isolate* isolate = i::Isolate::Current();
3000 ON_BAILOUT(isolate, "v8::SetElementsToPixelData()", return);
2790 ENTER_V8; 3001 ENTER_V8;
2791 HandleScope scope; 3002 i::HandleScope scope(isolate);
2792 if (!ApiCheck(length <= i::ExternalPixelArray::kMaxLength, 3003 if (!ApiCheck(length <= i::ExternalPixelArray::kMaxLength,
2793 "v8::Object::SetIndexedPropertiesToPixelData()", 3004 "v8::Object::SetIndexedPropertiesToPixelData()",
2794 "length exceeds max acceptable value")) { 3005 "length exceeds max acceptable value")) {
2795 return; 3006 return;
2796 } 3007 }
2797 i::Handle<i::JSObject> self = Utils::OpenHandle(this); 3008 i::Handle<i::JSObject> self = Utils::OpenHandle(this);
2798 if (!ApiCheck(!self->IsJSArray(), 3009 if (!ApiCheck(!self->IsJSArray(),
2799 "v8::Object::SetIndexedPropertiesToPixelData()", 3010 "v8::Object::SetIndexedPropertiesToPixelData()",
2800 "JSArray is not supported")) { 3011 "JSArray is not supported")) {
2801 return; 3012 return;
2802 } 3013 }
2803 PrepareExternalArrayElements(self, data, kExternalPixelArray, length); 3014 PrepareExternalArrayElements(self, data, kExternalPixelArray, length);
2804 } 3015 }
2805 3016
2806 3017
2807 bool v8::Object::HasIndexedPropertiesInPixelData() { 3018 bool v8::Object::HasIndexedPropertiesInPixelData() {
2808 ON_BAILOUT("v8::HasIndexedPropertiesInPixelData()", return false); 3019 ON_BAILOUT(i::Isolate::Current(), "v8::HasIndexedPropertiesInPixelData()",
3020 return false);
2809 i::Handle<i::JSObject> self = Utils::OpenHandle(this); 3021 i::Handle<i::JSObject> self = Utils::OpenHandle(this);
2810 return self->HasExternalPixelElements(); 3022 return self->HasExternalPixelElements();
2811 } 3023 }
2812 3024
2813 3025
2814 uint8_t* v8::Object::GetIndexedPropertiesPixelData() { 3026 uint8_t* v8::Object::GetIndexedPropertiesPixelData() {
2815 ON_BAILOUT("v8::GetIndexedPropertiesPixelData()", return NULL); 3027 ON_BAILOUT(i::Isolate::Current(), "v8::GetIndexedPropertiesPixelData()",
3028 return NULL);
2816 i::Handle<i::JSObject> self = Utils::OpenHandle(this); 3029 i::Handle<i::JSObject> self = Utils::OpenHandle(this);
2817 if (self->HasExternalPixelElements()) { 3030 if (self->HasExternalPixelElements()) {
2818 return i::ExternalPixelArray::cast(self->elements())-> 3031 return i::ExternalPixelArray::cast(self->elements())->
2819 external_pixel_pointer(); 3032 external_pixel_pointer();
2820 } else { 3033 } else {
2821 return NULL; 3034 return NULL;
2822 } 3035 }
2823 } 3036 }
2824 3037
2825 3038
2826 int v8::Object::GetIndexedPropertiesPixelDataLength() { 3039 int v8::Object::GetIndexedPropertiesPixelDataLength() {
2827 ON_BAILOUT("v8::GetIndexedPropertiesPixelDataLength()", return -1); 3040 ON_BAILOUT(i::Isolate::Current(), "v8::GetIndexedPropertiesPixelDataLength()",
3041 return -1);
2828 i::Handle<i::JSObject> self = Utils::OpenHandle(this); 3042 i::Handle<i::JSObject> self = Utils::OpenHandle(this);
2829 if (self->HasExternalPixelElements()) { 3043 if (self->HasExternalPixelElements()) {
2830 return i::ExternalPixelArray::cast(self->elements())->length(); 3044 return i::ExternalPixelArray::cast(self->elements())->length();
2831 } else { 3045 } else {
2832 return -1; 3046 return -1;
2833 } 3047 }
2834 } 3048 }
2835 3049
2836 void v8::Object::SetIndexedPropertiesToExternalArrayData( 3050 void v8::Object::SetIndexedPropertiesToExternalArrayData(
2837 void* data, 3051 void* data,
2838 ExternalArrayType array_type, 3052 ExternalArrayType array_type,
2839 int length) { 3053 int length) {
2840 ON_BAILOUT("v8::SetIndexedPropertiesToExternalArrayData()", return); 3054 i::Isolate* isolate = i::Isolate::Current();
3055 ON_BAILOUT(isolate, "v8::SetIndexedPropertiesToExternalArrayData()", return);
2841 ENTER_V8; 3056 ENTER_V8;
2842 HandleScope scope; 3057 i::HandleScope scope(isolate);
2843 if (!ApiCheck(length <= i::ExternalArray::kMaxLength, 3058 if (!ApiCheck(length <= i::ExternalArray::kMaxLength,
2844 "v8::Object::SetIndexedPropertiesToExternalArrayData()", 3059 "v8::Object::SetIndexedPropertiesToExternalArrayData()",
2845 "length exceeds max acceptable value")) { 3060 "length exceeds max acceptable value")) {
2846 return; 3061 return;
2847 } 3062 }
2848 i::Handle<i::JSObject> self = Utils::OpenHandle(this); 3063 i::Handle<i::JSObject> self = Utils::OpenHandle(this);
2849 if (!ApiCheck(!self->IsJSArray(), 3064 if (!ApiCheck(!self->IsJSArray(),
2850 "v8::Object::SetIndexedPropertiesToExternalArrayData()", 3065 "v8::Object::SetIndexedPropertiesToExternalArrayData()",
2851 "JSArray is not supported")) { 3066 "JSArray is not supported")) {
2852 return; 3067 return;
2853 } 3068 }
2854 PrepareExternalArrayElements(self, data, array_type, length); 3069 PrepareExternalArrayElements(self, data, array_type, length);
2855 } 3070 }
2856 3071
2857 3072
2858 bool v8::Object::HasIndexedPropertiesInExternalArrayData() { 3073 bool v8::Object::HasIndexedPropertiesInExternalArrayData() {
2859 ON_BAILOUT("v8::HasIndexedPropertiesInExternalArrayData()", return false); 3074 ON_BAILOUT(i::Isolate::Current(),
3075 "v8::HasIndexedPropertiesInExternalArrayData()",
3076 return false);
2860 i::Handle<i::JSObject> self = Utils::OpenHandle(this); 3077 i::Handle<i::JSObject> self = Utils::OpenHandle(this);
2861 return self->HasExternalArrayElements(); 3078 return self->HasExternalArrayElements();
2862 } 3079 }
2863 3080
2864 3081
2865 void* v8::Object::GetIndexedPropertiesExternalArrayData() { 3082 void* v8::Object::GetIndexedPropertiesExternalArrayData() {
2866 ON_BAILOUT("v8::GetIndexedPropertiesExternalArrayData()", return NULL); 3083 ON_BAILOUT(i::Isolate::Current(),
3084 "v8::GetIndexedPropertiesExternalArrayData()",
3085 return NULL);
2867 i::Handle<i::JSObject> self = Utils::OpenHandle(this); 3086 i::Handle<i::JSObject> self = Utils::OpenHandle(this);
2868 if (self->HasExternalArrayElements()) { 3087 if (self->HasExternalArrayElements()) {
2869 return i::ExternalArray::cast(self->elements())->external_pointer(); 3088 return i::ExternalArray::cast(self->elements())->external_pointer();
2870 } else { 3089 } else {
2871 return NULL; 3090 return NULL;
2872 } 3091 }
2873 } 3092 }
2874 3093
2875 3094
2876 ExternalArrayType v8::Object::GetIndexedPropertiesExternalArrayDataType() { 3095 ExternalArrayType v8::Object::GetIndexedPropertiesExternalArrayDataType() {
2877 ON_BAILOUT("v8::GetIndexedPropertiesExternalArrayDataType()", 3096 ON_BAILOUT(i::Isolate::Current(),
3097 "v8::GetIndexedPropertiesExternalArrayDataType()",
2878 return static_cast<ExternalArrayType>(-1)); 3098 return static_cast<ExternalArrayType>(-1));
2879 i::Handle<i::JSObject> self = Utils::OpenHandle(this); 3099 i::Handle<i::JSObject> self = Utils::OpenHandle(this);
2880 switch (self->elements()->map()->instance_type()) { 3100 switch (self->elements()->map()->instance_type()) {
2881 case i::EXTERNAL_BYTE_ARRAY_TYPE: 3101 case i::EXTERNAL_BYTE_ARRAY_TYPE:
2882 return kExternalByteArray; 3102 return kExternalByteArray;
2883 case i::EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE: 3103 case i::EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE:
2884 return kExternalUnsignedByteArray; 3104 return kExternalUnsignedByteArray;
2885 case i::EXTERNAL_SHORT_ARRAY_TYPE: 3105 case i::EXTERNAL_SHORT_ARRAY_TYPE:
2886 return kExternalShortArray; 3106 return kExternalShortArray;
2887 case i::EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE: 3107 case i::EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE:
2888 return kExternalUnsignedShortArray; 3108 return kExternalUnsignedShortArray;
2889 case i::EXTERNAL_INT_ARRAY_TYPE: 3109 case i::EXTERNAL_INT_ARRAY_TYPE:
2890 return kExternalIntArray; 3110 return kExternalIntArray;
2891 case i::EXTERNAL_UNSIGNED_INT_ARRAY_TYPE: 3111 case i::EXTERNAL_UNSIGNED_INT_ARRAY_TYPE:
2892 return kExternalUnsignedIntArray; 3112 return kExternalUnsignedIntArray;
2893 case i::EXTERNAL_FLOAT_ARRAY_TYPE: 3113 case i::EXTERNAL_FLOAT_ARRAY_TYPE:
2894 return kExternalFloatArray; 3114 return kExternalFloatArray;
2895 case i::EXTERNAL_PIXEL_ARRAY_TYPE: 3115 case i::EXTERNAL_PIXEL_ARRAY_TYPE:
2896 return kExternalPixelArray; 3116 return kExternalPixelArray;
2897 default: 3117 default:
2898 return static_cast<ExternalArrayType>(-1); 3118 return static_cast<ExternalArrayType>(-1);
2899 } 3119 }
2900 } 3120 }
2901 3121
2902 3122
2903 int v8::Object::GetIndexedPropertiesExternalArrayDataLength() { 3123 int v8::Object::GetIndexedPropertiesExternalArrayDataLength() {
2904 ON_BAILOUT("v8::GetIndexedPropertiesExternalArrayDataLength()", return 0); 3124 ON_BAILOUT(i::Isolate::Current(),
3125 "v8::GetIndexedPropertiesExternalArrayDataLength()",
3126 return 0);
2905 i::Handle<i::JSObject> self = Utils::OpenHandle(this); 3127 i::Handle<i::JSObject> self = Utils::OpenHandle(this);
2906 if (self->HasExternalArrayElements()) { 3128 if (self->HasExternalArrayElements()) {
2907 return i::ExternalArray::cast(self->elements())->length(); 3129 return i::ExternalArray::cast(self->elements())->length();
2908 } else { 3130 } else {
2909 return -1; 3131 return -1;
2910 } 3132 }
2911 } 3133 }
2912 3134
2913 3135
2914 Local<v8::Object> Function::NewInstance() const { 3136 Local<v8::Object> Function::NewInstance() const {
2915 return NewInstance(0, NULL); 3137 return NewInstance(0, NULL);
2916 } 3138 }
2917 3139
2918 3140
2919 Local<v8::Object> Function::NewInstance(int argc, 3141 Local<v8::Object> Function::NewInstance(int argc,
2920 v8::Handle<v8::Value> argv[]) const { 3142 v8::Handle<v8::Value> argv[]) const {
2921 ON_BAILOUT("v8::Function::NewInstance()", return Local<v8::Object>()); 3143 i::Isolate* isolate = i::Isolate::Current();
2922 LOG_API("Function::NewInstance"); 3144 ON_BAILOUT(isolate, "v8::Function::NewInstance()",
3145 return Local<v8::Object>());
3146 LOG_API(isolate, "Function::NewInstance");
2923 ENTER_V8; 3147 ENTER_V8;
2924 HandleScope scope; 3148 HandleScope scope;
2925 i::Handle<i::JSFunction> function = Utils::OpenHandle(this); 3149 i::Handle<i::JSFunction> function = Utils::OpenHandle(this);
2926 STATIC_ASSERT(sizeof(v8::Handle<v8::Value>) == sizeof(i::Object**)); 3150 STATIC_ASSERT(sizeof(v8::Handle<v8::Value>) == sizeof(i::Object**));
2927 i::Object*** args = reinterpret_cast<i::Object***>(argv); 3151 i::Object*** args = reinterpret_cast<i::Object***>(argv);
2928 EXCEPTION_PREAMBLE(); 3152 EXCEPTION_PREAMBLE();
2929 i::Handle<i::Object> returned = 3153 i::Handle<i::Object> returned =
2930 i::Execution::New(function, argc, args, &has_pending_exception); 3154 i::Execution::New(function, argc, args, &has_pending_exception);
2931 EXCEPTION_BAILOUT_CHECK(Local<v8::Object>()); 3155 EXCEPTION_BAILOUT_CHECK(Local<v8::Object>());
2932 return scope.Close(Utils::ToLocal(i::Handle<i::JSObject>::cast(returned))); 3156 return scope.Close(Utils::ToLocal(i::Handle<i::JSObject>::cast(returned)));
2933 } 3157 }
2934 3158
2935 3159
2936 Local<v8::Value> Function::Call(v8::Handle<v8::Object> recv, int argc, 3160 Local<v8::Value> Function::Call(v8::Handle<v8::Object> recv, int argc,
2937 v8::Handle<v8::Value> argv[]) { 3161 v8::Handle<v8::Value> argv[]) {
2938 ON_BAILOUT("v8::Function::Call()", return Local<v8::Value>()); 3162 i::Isolate* isolate = i::Isolate::Current();
2939 LOG_API("Function::Call"); 3163 ON_BAILOUT(isolate, "v8::Function::Call()", return Local<v8::Value>());
3164 LOG_API(isolate, "Function::Call");
2940 ENTER_V8; 3165 ENTER_V8;
2941 i::Object* raw_result = NULL; 3166 i::Object* raw_result = NULL;
2942 { 3167 {
2943 HandleScope scope; 3168 i::HandleScope scope(isolate);
2944 i::Handle<i::JSFunction> fun = Utils::OpenHandle(this); 3169 i::Handle<i::JSFunction> fun = Utils::OpenHandle(this);
2945 i::Handle<i::Object> recv_obj = Utils::OpenHandle(*recv); 3170 i::Handle<i::Object> recv_obj = Utils::OpenHandle(*recv);
2946 STATIC_ASSERT(sizeof(v8::Handle<v8::Value>) == sizeof(i::Object**)); 3171 STATIC_ASSERT(sizeof(v8::Handle<v8::Value>) == sizeof(i::Object**));
2947 i::Object*** args = reinterpret_cast<i::Object***>(argv); 3172 i::Object*** args = reinterpret_cast<i::Object***>(argv);
2948 EXCEPTION_PREAMBLE(); 3173 EXCEPTION_PREAMBLE();
2949 i::Handle<i::Object> returned = 3174 i::Handle<i::Object> returned =
2950 i::Execution::Call(fun, recv_obj, argc, args, &has_pending_exception); 3175 i::Execution::Call(fun, recv_obj, argc, args, &has_pending_exception);
2951 EXCEPTION_BAILOUT_CHECK(Local<Object>()); 3176 EXCEPTION_BAILOUT_CHECK(Local<Object>());
2952 raw_result = *returned; 3177 raw_result = *returned;
2953 } 3178 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2989 int Function::GetScriptLineNumber() const { 3214 int Function::GetScriptLineNumber() const {
2990 i::Handle<i::JSFunction> func = Utils::OpenHandle(this); 3215 i::Handle<i::JSFunction> func = Utils::OpenHandle(this);
2991 if (func->shared()->script()->IsScript()) { 3216 if (func->shared()->script()->IsScript()) {
2992 i::Handle<i::Script> script(i::Script::cast(func->shared()->script())); 3217 i::Handle<i::Script> script(i::Script::cast(func->shared()->script()));
2993 return i::GetScriptLineNumber(script, func->shared()->start_position()); 3218 return i::GetScriptLineNumber(script, func->shared()->start_position());
2994 } 3219 }
2995 return kLineOffsetNotFound; 3220 return kLineOffsetNotFound;
2996 } 3221 }
2997 3222
2998 3223
2999 namespace {
3000
3001 // Tracks string usage to help make better decisions when
3002 // externalizing strings.
3003 //
3004 // Implementation note: internally this class only tracks fresh
3005 // strings and keeps a single use counter for them.
3006 class StringTracker {
3007 public:
3008 // Records that the given string's characters were copied to some
3009 // external buffer. If this happens often we should honor
3010 // externalization requests for the string.
3011 static void RecordWrite(i::Handle<i::String> string) {
3012 i::Address address = reinterpret_cast<i::Address>(*string);
3013 i::Address top = i::Heap::NewSpaceTop();
3014 if (IsFreshString(address, top)) {
3015 IncrementUseCount(top);
3016 }
3017 }
3018
3019 // Estimates freshness and use frequency of the given string based
3020 // on how close it is to the new space top and the recorded usage
3021 // history.
3022 static inline bool IsFreshUnusedString(i::Handle<i::String> string) {
3023 i::Address address = reinterpret_cast<i::Address>(*string);
3024 i::Address top = i::Heap::NewSpaceTop();
3025 return IsFreshString(address, top) && IsUseCountLow(top);
3026 }
3027
3028 private:
3029 static inline bool IsFreshString(i::Address string, i::Address top) {
3030 return top - kFreshnessLimit <= string && string <= top;
3031 }
3032
3033 static inline bool IsUseCountLow(i::Address top) {
3034 if (last_top_ != top) return true;
3035 return use_count_ < kUseLimit;
3036 }
3037
3038 static inline void IncrementUseCount(i::Address top) {
3039 if (last_top_ != top) {
3040 use_count_ = 0;
3041 last_top_ = top;
3042 }
3043 ++use_count_;
3044 }
3045
3046 // How close to the new space top a fresh string has to be.
3047 static const int kFreshnessLimit = 1024;
3048
3049 // The number of uses required to consider a string useful.
3050 static const int kUseLimit = 32;
3051
3052 // Single use counter shared by all fresh strings.
3053 static int use_count_;
3054
3055 // Last new space top when the use count above was valid.
3056 static i::Address last_top_;
3057 };
3058
3059 int StringTracker::use_count_ = 0;
3060 i::Address StringTracker::last_top_ = NULL;
3061
3062 } // namespace
3063
3064
3065 int String::Length() const { 3224 int String::Length() const {
3066 if (IsDeadCheck("v8::String::Length()")) return 0; 3225 if (IsDeadCheck(i::Isolate::Current(), "v8::String::Length()")) return 0;
3067 return Utils::OpenHandle(this)->length(); 3226 return Utils::OpenHandle(this)->length();
3068 } 3227 }
3069 3228
3070 3229
3071 int String::Utf8Length() const { 3230 int String::Utf8Length() const {
3072 if (IsDeadCheck("v8::String::Utf8Length()")) return 0; 3231 if (IsDeadCheck(i::Isolate::Current(), "v8::String::Utf8Length()")) return 0;
3073 return Utils::OpenHandle(this)->Utf8Length(); 3232 return Utils::OpenHandle(this)->Utf8Length();
3074 } 3233 }
3075 3234
3076 3235
3077 int String::WriteUtf8(char* buffer, 3236 int String::WriteUtf8(char* buffer,
3078 int capacity, 3237 int capacity,
3079 int* nchars_ref, 3238 int* nchars_ref,
3080 WriteHints hints) const { 3239 WriteHints hints) const {
3081 if (IsDeadCheck("v8::String::WriteUtf8()")) return 0; 3240 i::Isolate* isolate = i::Isolate::Current();
3082 LOG_API("String::WriteUtf8"); 3241 if (IsDeadCheck(isolate, "v8::String::WriteUtf8()")) return 0;
3242 LOG_API(isolate, "String::WriteUtf8");
3083 ENTER_V8; 3243 ENTER_V8;
3244 i::StringInputBuffer& write_input_buffer = *isolate->write_input_buffer();
3084 i::Handle<i::String> str = Utils::OpenHandle(this); 3245 i::Handle<i::String> str = Utils::OpenHandle(this);
3085 StringTracker::RecordWrite(str); 3246 isolate->string_tracker()->RecordWrite(str);
3086 if (hints & HINT_MANY_WRITES_EXPECTED) { 3247 if (hints & HINT_MANY_WRITES_EXPECTED) {
3087 // Flatten the string for efficiency. This applies whether we are 3248 // Flatten the string for efficiency. This applies whether we are
3088 // using StringInputBuffer or Get(i) to access the characters. 3249 // using StringInputBuffer or Get(i) to access the characters.
3089 str->TryFlatten(); 3250 str->TryFlatten();
3090 } 3251 }
3091 write_input_buffer.Reset(0, *str); 3252 write_input_buffer.Reset(0, *str);
3092 int len = str->length(); 3253 int len = str->length();
3093 // Encode the first K - 3 bytes directly into the buffer since we 3254 // Encode the first K - 3 bytes directly into the buffer since we
3094 // know there's room for them. If no capacity is given we copy all 3255 // know there's room for them. If no capacity is given we copy all
3095 // of them here. 3256 // of them here.
(...skipping 30 matching lines...) Expand all
3126 if (i == len && (capacity == -1 || pos < capacity)) 3287 if (i == len && (capacity == -1 || pos < capacity))
3127 buffer[pos++] = '\0'; 3288 buffer[pos++] = '\0';
3128 return pos; 3289 return pos;
3129 } 3290 }
3130 3291
3131 3292
3132 int String::WriteAscii(char* buffer, 3293 int String::WriteAscii(char* buffer,
3133 int start, 3294 int start,
3134 int length, 3295 int length,
3135 WriteHints hints) const { 3296 WriteHints hints) const {
3136 if (IsDeadCheck("v8::String::WriteAscii()")) return 0; 3297 i::Isolate* isolate = i::Isolate::Current();
3137 LOG_API("String::WriteAscii"); 3298 if (IsDeadCheck(isolate, "v8::String::WriteAscii()")) return 0;
3299 LOG_API(isolate, "String::WriteAscii");
3138 ENTER_V8; 3300 ENTER_V8;
3301 i::StringInputBuffer& write_input_buffer = *isolate->write_input_buffer();
3139 ASSERT(start >= 0 && length >= -1); 3302 ASSERT(start >= 0 && length >= -1);
3140 i::Handle<i::String> str = Utils::OpenHandle(this); 3303 i::Handle<i::String> str = Utils::OpenHandle(this);
3141 StringTracker::RecordWrite(str); 3304 isolate->string_tracker()->RecordWrite(str);
3142 if (hints & HINT_MANY_WRITES_EXPECTED) { 3305 if (hints & HINT_MANY_WRITES_EXPECTED) {
3143 // Flatten the string for efficiency. This applies whether we are 3306 // Flatten the string for efficiency. This applies whether we are
3144 // using StringInputBuffer or Get(i) to access the characters. 3307 // using StringInputBuffer or Get(i) to access the characters.
3145 str->TryFlatten(); 3308 str->TryFlatten();
3146 } 3309 }
3147 int end = length; 3310 int end = length;
3148 if ( (length == -1) || (length > str->length() - start) ) 3311 if ( (length == -1) || (length > str->length() - start) )
3149 end = str->length() - start; 3312 end = str->length() - start;
3150 if (end < 0) return 0; 3313 if (end < 0) return 0;
3151 write_input_buffer.Reset(start, *str); 3314 write_input_buffer.Reset(start, *str);
3152 int i; 3315 int i;
3153 for (i = 0; i < end; i++) { 3316 for (i = 0; i < end; i++) {
3154 char c = static_cast<char>(write_input_buffer.GetNext()); 3317 char c = static_cast<char>(write_input_buffer.GetNext());
3155 if (c == '\0') c = ' '; 3318 if (c == '\0') c = ' ';
3156 buffer[i] = c; 3319 buffer[i] = c;
3157 } 3320 }
3158 if (length == -1 || i < length) 3321 if (length == -1 || i < length)
3159 buffer[i] = '\0'; 3322 buffer[i] = '\0';
3160 return i; 3323 return i;
3161 } 3324 }
3162 3325
3163 3326
3164 int String::Write(uint16_t* buffer, 3327 int String::Write(uint16_t* buffer,
3165 int start, 3328 int start,
3166 int length, 3329 int length,
3167 WriteHints hints) const { 3330 WriteHints hints) const {
3168 if (IsDeadCheck("v8::String::Write()")) return 0; 3331 i::Isolate* isolate = i::Isolate::Current();
3169 LOG_API("String::Write"); 3332 if (IsDeadCheck(isolate, "v8::String::Write()")) return 0;
3333 LOG_API(isolate, "String::Write");
3170 ENTER_V8; 3334 ENTER_V8;
3171 ASSERT(start >= 0 && length >= -1); 3335 ASSERT(start >= 0 && length >= -1);
3172 i::Handle<i::String> str = Utils::OpenHandle(this); 3336 i::Handle<i::String> str = Utils::OpenHandle(this);
3173 StringTracker::RecordWrite(str); 3337 isolate->string_tracker()->RecordWrite(str);
3174 if (hints & HINT_MANY_WRITES_EXPECTED) { 3338 if (hints & HINT_MANY_WRITES_EXPECTED) {
3175 // Flatten the string for efficiency. This applies whether we are 3339 // Flatten the string for efficiency. This applies whether we are
3176 // using StringInputBuffer or Get(i) to access the characters. 3340 // using StringInputBuffer or Get(i) to access the characters.
3177 str->TryFlatten(); 3341 str->TryFlatten();
3178 } 3342 }
3179 int end = start + length; 3343 int end = start + length;
3180 if ((length == -1) || (length > str->length() - start) ) 3344 if ((length == -1) || (length > str->length() - start) )
3181 end = str->length(); 3345 end = str->length();
3182 if (end < 0) return 0; 3346 if (end < 0) return 0;
3183 i::String::WriteToFlat(*str, buffer, start, end); 3347 i::String::WriteToFlat(*str, buffer, start, end);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
3223 if (i::StringShape(*str).IsExternalAscii()) { 3387 if (i::StringShape(*str).IsExternalAscii()) {
3224 void* resource = i::Handle<i::ExternalAsciiString>::cast(str)->resource(); 3388 void* resource = i::Handle<i::ExternalAsciiString>::cast(str)->resource();
3225 return reinterpret_cast<ExternalAsciiStringResource*>(resource); 3389 return reinterpret_cast<ExternalAsciiStringResource*>(resource);
3226 } else { 3390 } else {
3227 return NULL; 3391 return NULL;
3228 } 3392 }
3229 } 3393 }
3230 3394
3231 3395
3232 double Number::Value() const { 3396 double Number::Value() const {
3233 if (IsDeadCheck("v8::Number::Value()")) return 0; 3397 if (IsDeadCheck(i::Isolate::Current(), "v8::Number::Value()")) return 0;
3234 i::Handle<i::Object> obj = Utils::OpenHandle(this); 3398 i::Handle<i::Object> obj = Utils::OpenHandle(this);
3235 return obj->Number(); 3399 return obj->Number();
3236 } 3400 }
3237 3401
3238 3402
3239 bool Boolean::Value() const { 3403 bool Boolean::Value() const {
3240 if (IsDeadCheck("v8::Boolean::Value()")) return false; 3404 if (IsDeadCheck(i::Isolate::Current(), "v8::Boolean::Value()")) return false;
3241 i::Handle<i::Object> obj = Utils::OpenHandle(this); 3405 i::Handle<i::Object> obj = Utils::OpenHandle(this);
3242 return obj->IsTrue(); 3406 return obj->IsTrue();
3243 } 3407 }
3244 3408
3245 3409
3246 int64_t Integer::Value() const { 3410 int64_t Integer::Value() const {
3247 if (IsDeadCheck("v8::Integer::Value()")) return 0; 3411 if (IsDeadCheck(i::Isolate::Current(), "v8::Integer::Value()")) return 0;
3248 i::Handle<i::Object> obj = Utils::OpenHandle(this); 3412 i::Handle<i::Object> obj = Utils::OpenHandle(this);
3249 if (obj->IsSmi()) { 3413 if (obj->IsSmi()) {
3250 return i::Smi::cast(*obj)->value(); 3414 return i::Smi::cast(*obj)->value();
3251 } else { 3415 } else {
3252 return static_cast<int64_t>(obj->Number()); 3416 return static_cast<int64_t>(obj->Number());
3253 } 3417 }
3254 } 3418 }
3255 3419
3256 3420
3257 int32_t Int32::Value() const { 3421 int32_t Int32::Value() const {
3258 if (IsDeadCheck("v8::Int32::Value()")) return 0; 3422 if (IsDeadCheck(i::Isolate::Current(), "v8::Int32::Value()")) return 0;
3259 i::Handle<i::Object> obj = Utils::OpenHandle(this); 3423 i::Handle<i::Object> obj = Utils::OpenHandle(this);
3260 if (obj->IsSmi()) { 3424 if (obj->IsSmi()) {
3261 return i::Smi::cast(*obj)->value(); 3425 return i::Smi::cast(*obj)->value();
3262 } else { 3426 } else {
3263 return static_cast<int32_t>(obj->Number()); 3427 return static_cast<int32_t>(obj->Number());
3264 } 3428 }
3265 } 3429 }
3266 3430
3267 3431
3268 uint32_t Uint32::Value() const { 3432 uint32_t Uint32::Value() const {
3269 if (IsDeadCheck("v8::Uint32::Value()")) return 0; 3433 if (IsDeadCheck(i::Isolate::Current(), "v8::Uint32::Value()")) return 0;
3270 i::Handle<i::Object> obj = Utils::OpenHandle(this); 3434 i::Handle<i::Object> obj = Utils::OpenHandle(this);
3271 if (obj->IsSmi()) { 3435 if (obj->IsSmi()) {
3272 return i::Smi::cast(*obj)->value(); 3436 return i::Smi::cast(*obj)->value();
3273 } else { 3437 } else {
3274 return static_cast<uint32_t>(obj->Number()); 3438 return static_cast<uint32_t>(obj->Number());
3275 } 3439 }
3276 } 3440 }
3277 3441
3278 3442
3279 int v8::Object::InternalFieldCount() { 3443 int v8::Object::InternalFieldCount() {
3280 if (IsDeadCheck("v8::Object::InternalFieldCount()")) return 0; 3444 if (IsDeadCheck(i::Isolate::Current(), "v8::Object::InternalFieldCount()")) {
3445 return 0;
3446 }
3281 i::Handle<i::JSObject> obj = Utils::OpenHandle(this); 3447 i::Handle<i::JSObject> obj = Utils::OpenHandle(this);
3282 return obj->GetInternalFieldCount(); 3448 return obj->GetInternalFieldCount();
3283 } 3449 }
3284 3450
3285 3451
3286 Local<Value> v8::Object::CheckedGetInternalField(int index) { 3452 Local<Value> v8::Object::CheckedGetInternalField(int index) {
3287 if (IsDeadCheck("v8::Object::GetInternalField()")) return Local<Value>(); 3453 if (IsDeadCheck(i::Isolate::Current(), "v8::Object::GetInternalField()")) {
3454 return Local<Value>();
3455 }
3288 i::Handle<i::JSObject> obj = Utils::OpenHandle(this); 3456 i::Handle<i::JSObject> obj = Utils::OpenHandle(this);
3289 if (!ApiCheck(index < obj->GetInternalFieldCount(), 3457 if (!ApiCheck(index < obj->GetInternalFieldCount(),
3290 "v8::Object::GetInternalField()", 3458 "v8::Object::GetInternalField()",
3291 "Reading internal field out of bounds")) { 3459 "Reading internal field out of bounds")) {
3292 return Local<Value>(); 3460 return Local<Value>();
3293 } 3461 }
3294 i::Handle<i::Object> value(obj->GetInternalField(index)); 3462 i::Handle<i::Object> value(obj->GetInternalField(index));
3295 Local<Value> result = Utils::ToLocal(value); 3463 Local<Value> result = Utils::ToLocal(value);
3296 #ifdef DEBUG 3464 #ifdef DEBUG
3297 Local<Value> unchecked = UncheckedGetInternalField(index); 3465 Local<Value> unchecked = UncheckedGetInternalField(index);
3298 ASSERT(unchecked.IsEmpty() || (unchecked == result)); 3466 ASSERT(unchecked.IsEmpty() || (unchecked == result));
3299 #endif 3467 #endif
3300 return result; 3468 return result;
3301 } 3469 }
3302 3470
3303 3471
3304 void v8::Object::SetInternalField(int index, v8::Handle<Value> value) { 3472 void v8::Object::SetInternalField(int index, v8::Handle<Value> value) {
3305 if (IsDeadCheck("v8::Object::SetInternalField()")) return; 3473 if (IsDeadCheck(i::Isolate::Current(), "v8::Object::SetInternalField()")) {
3474 return;
3475 }
3306 i::Handle<i::JSObject> obj = Utils::OpenHandle(this); 3476 i::Handle<i::JSObject> obj = Utils::OpenHandle(this);
3307 if (!ApiCheck(index < obj->GetInternalFieldCount(), 3477 if (!ApiCheck(index < obj->GetInternalFieldCount(),
3308 "v8::Object::SetInternalField()", 3478 "v8::Object::SetInternalField()",
3309 "Writing internal field out of bounds")) { 3479 "Writing internal field out of bounds")) {
3310 return; 3480 return;
3311 } 3481 }
3312 ENTER_V8; 3482 ENTER_V8;
3313 i::Handle<i::Object> val = Utils::OpenHandle(*value); 3483 i::Handle<i::Object> val = Utils::OpenHandle(*value);
3314 obj->SetInternalField(index, *val); 3484 obj->SetInternalField(index, *val);
3315 } 3485 }
(...skipping 16 matching lines...) Expand all
3332 } 3502 }
3333 3503
3334 3504
3335 void v8::Object::SetPointerInInternalField(int index, void* value) { 3505 void v8::Object::SetPointerInInternalField(int index, void* value) {
3336 ENTER_V8; 3506 ENTER_V8;
3337 if (CanBeEncodedAsSmi(value)) { 3507 if (CanBeEncodedAsSmi(value)) {
3338 Utils::OpenHandle(this)->SetInternalField(index, EncodeAsSmi(value)); 3508 Utils::OpenHandle(this)->SetInternalField(index, EncodeAsSmi(value));
3339 } else { 3509 } else {
3340 HandleScope scope; 3510 HandleScope scope;
3341 i::Handle<i::Proxy> proxy = 3511 i::Handle<i::Proxy> proxy =
3342 i::Factory::NewProxy(reinterpret_cast<i::Address>(value), i::TENURED); 3512 FACTORY->NewProxy(reinterpret_cast<i::Address>(value), i::TENURED);
3343 if (!proxy.is_null()) 3513 if (!proxy.is_null())
3344 Utils::OpenHandle(this)->SetInternalField(index, *proxy); 3514 Utils::OpenHandle(this)->SetInternalField(index, *proxy);
3345 } 3515 }
3346 ASSERT_EQ(value, GetPointerFromInternalField(index)); 3516 ASSERT_EQ(value, GetPointerFromInternalField(index));
3347 } 3517 }
3348 3518
3349 3519
3350 // --- E n v i r o n m e n t --- 3520 // --- E n v i r o n m e n t ---
3351 3521
3522
3352 bool v8::V8::Initialize() { 3523 bool v8::V8::Initialize() {
3353 if (i::V8::IsRunning()) return true; 3524 i::Isolate* isolate = i::Isolate::UncheckedCurrent();
3354 HandleScope scope; 3525 if (isolate != NULL && isolate->IsInitialized()) {
3355 if (i::Snapshot::Initialize()) return true; 3526 return true;
3356 return i::V8::Initialize(NULL); 3527 }
3528 return InitializeHelper();
3357 } 3529 }
3358 3530
3359 3531
3360 bool v8::V8::Dispose() { 3532 bool v8::V8::Dispose() {
3533 i::Isolate* isolate = i::Isolate::Current();
3534 if (!ApiCheck(isolate != NULL && isolate->IsDefaultIsolate(),
3535 "v8::V8::Dispose()",
3536 "Use v8::Isolate::Dispose() for a non-default isolate.")) {
3537 return false;
3538 }
3361 i::V8::TearDown(); 3539 i::V8::TearDown();
3362 return true; 3540 return true;
3363 } 3541 }
3364 3542
3365 3543
3366 HeapStatistics::HeapStatistics(): total_heap_size_(0), 3544 HeapStatistics::HeapStatistics(): total_heap_size_(0),
3367 total_heap_size_executable_(0), 3545 total_heap_size_executable_(0),
3368 used_heap_size_(0), 3546 used_heap_size_(0),
3369 heap_size_limit_(0) { } 3547 heap_size_limit_(0) { }
3370 3548
3371 3549
3372 void v8::V8::GetHeapStatistics(HeapStatistics* heap_statistics) { 3550 void v8::V8::GetHeapStatistics(HeapStatistics* heap_statistics) {
3373 heap_statistics->set_total_heap_size(i::Heap::CommittedMemory()); 3551 heap_statistics->set_total_heap_size(HEAP->CommittedMemory());
3374 heap_statistics->set_total_heap_size_executable( 3552 heap_statistics->set_total_heap_size_executable(
3375 i::Heap::CommittedMemoryExecutable()); 3553 HEAP->CommittedMemoryExecutable());
3376 heap_statistics->set_used_heap_size(i::Heap::SizeOfObjects()); 3554 heap_statistics->set_used_heap_size(HEAP->SizeOfObjects());
3377 heap_statistics->set_heap_size_limit(i::Heap::MaxReserved()); 3555 heap_statistics->set_heap_size_limit(HEAP->MaxReserved());
3378 } 3556 }
3379 3557
3380 3558
3381 bool v8::V8::IdleNotification() { 3559 bool v8::V8::IdleNotification() {
3382 // Returning true tells the caller that it need not 3560 // Returning true tells the caller that it need not
3383 // continue to call IdleNotification. 3561 // continue to call IdleNotification.
3384 if (!i::V8::IsRunning()) return true; 3562 if (!i::Isolate::Current()->IsInitialized()) return true;
3385 return i::V8::IdleNotification(); 3563 return i::V8::IdleNotification();
3386 } 3564 }
3387 3565
3388 3566
3389 void v8::V8::LowMemoryNotification() { 3567 void v8::V8::LowMemoryNotification() {
3390 if (!i::V8::IsRunning()) return; 3568 if (!i::Isolate::Current()->IsInitialized()) return;
3391 i::Heap::CollectAllGarbage(true); 3569 HEAP->CollectAllGarbage(true);
3392 } 3570 }
3393 3571
3394 3572
3395 int v8::V8::ContextDisposedNotification() { 3573 int v8::V8::ContextDisposedNotification() {
3396 if (!i::V8::IsRunning()) return 0; 3574 if (!i::Isolate::Current()->IsInitialized()) return 0;
3397 return i::Heap::NotifyContextDisposed(); 3575 return HEAP->NotifyContextDisposed();
3398 } 3576 }
3399 3577
3400 3578
3401 const char* v8::V8::GetVersion() { 3579 const char* v8::V8::GetVersion() {
3402 static v8::internal::EmbeddedVector<char, 128> buffer; 3580 return i::Version::GetVersion();
3403 v8::internal::Version::GetString(buffer);
3404 return buffer.start();
3405 } 3581 }
3406 3582
3407 3583
3408 static i::Handle<i::FunctionTemplateInfo> 3584 static i::Handle<i::FunctionTemplateInfo>
3409 EnsureConstructor(i::Handle<i::ObjectTemplateInfo> templ) { 3585 EnsureConstructor(i::Handle<i::ObjectTemplateInfo> templ) {
3410 if (templ->constructor()->IsUndefined()) { 3586 if (templ->constructor()->IsUndefined()) {
3411 Local<FunctionTemplate> constructor = FunctionTemplate::New(); 3587 Local<FunctionTemplate> constructor = FunctionTemplate::New();
3412 Utils::OpenHandle(*constructor)->set_instance_template(*templ); 3588 Utils::OpenHandle(*constructor)->set_instance_template(*templ);
3413 templ->set_constructor(*Utils::OpenHandle(*constructor)); 3589 templ->set_constructor(*Utils::OpenHandle(*constructor));
3414 } 3590 }
3415 return i::Handle<i::FunctionTemplateInfo>( 3591 return i::Handle<i::FunctionTemplateInfo>(
3416 i::FunctionTemplateInfo::cast(templ->constructor())); 3592 i::FunctionTemplateInfo::cast(templ->constructor()));
3417 } 3593 }
3418 3594
3419 3595
3420 Persistent<Context> v8::Context::New( 3596 Persistent<Context> v8::Context::New(
3421 v8::ExtensionConfiguration* extensions, 3597 v8::ExtensionConfiguration* extensions,
3422 v8::Handle<ObjectTemplate> global_template, 3598 v8::Handle<ObjectTemplate> global_template,
3423 v8::Handle<Value> global_object) { 3599 v8::Handle<Value> global_object) {
3424 EnsureInitialized("v8::Context::New()"); 3600 i::Isolate* isolate = i::Isolate::Current();
3425 LOG_API("Context::New"); 3601 EnsureInitializedForIsolate(isolate, "v8::Context::New()");
3426 ON_BAILOUT("v8::Context::New()", return Persistent<Context>()); 3602 LOG_API(isolate, "Context::New");
3603 ON_BAILOUT(isolate, "v8::Context::New()", return Persistent<Context>());
3427 3604
3428 // Enter V8 via an ENTER_V8 scope. 3605 // Enter V8 via an ENTER_V8 scope.
3429 i::Handle<i::Context> env; 3606 i::Handle<i::Context> env;
3430 { 3607 {
3431 ENTER_V8; 3608 ENTER_V8;
3432 v8::Handle<ObjectTemplate> proxy_template = global_template; 3609 v8::Handle<ObjectTemplate> proxy_template = global_template;
3433 i::Handle<i::FunctionTemplateInfo> proxy_constructor; 3610 i::Handle<i::FunctionTemplateInfo> proxy_constructor;
3434 i::Handle<i::FunctionTemplateInfo> global_constructor; 3611 i::Handle<i::FunctionTemplateInfo> global_constructor;
3435 3612
3436 if (!global_template.IsEmpty()) { 3613 if (!global_template.IsEmpty()) {
(...skipping 13 matching lines...) Expand all
3450 3627
3451 // Migrate security handlers from global_template to 3628 // Migrate security handlers from global_template to
3452 // proxy_template. Temporarily removing access check 3629 // proxy_template. Temporarily removing access check
3453 // information from the global template. 3630 // information from the global template.
3454 if (!global_constructor->access_check_info()->IsUndefined()) { 3631 if (!global_constructor->access_check_info()->IsUndefined()) {
3455 proxy_constructor->set_access_check_info( 3632 proxy_constructor->set_access_check_info(
3456 global_constructor->access_check_info()); 3633 global_constructor->access_check_info());
3457 proxy_constructor->set_needs_access_check( 3634 proxy_constructor->set_needs_access_check(
3458 global_constructor->needs_access_check()); 3635 global_constructor->needs_access_check());
3459 global_constructor->set_needs_access_check(false); 3636 global_constructor->set_needs_access_check(false);
3460 global_constructor->set_access_check_info(i::Heap::undefined_value()); 3637 global_constructor->set_access_check_info(HEAP->undefined_value());
3461 } 3638 }
3462 } 3639 }
3463 3640
3464 // Create the environment. 3641 // Create the environment.
3465 env = i::Bootstrapper::CreateEnvironment( 3642 env = isolate->bootstrapper()->CreateEnvironment(
3466 Utils::OpenHandle(*global_object), 3643 Utils::OpenHandle(*global_object),
3467 proxy_template, 3644 proxy_template,
3468 extensions); 3645 extensions);
3469 3646
3470 // Restore the access check info on the global template. 3647 // Restore the access check info on the global template.
3471 if (!global_template.IsEmpty()) { 3648 if (!global_template.IsEmpty()) {
3472 ASSERT(!global_constructor.is_null()); 3649 ASSERT(!global_constructor.is_null());
3473 ASSERT(!proxy_constructor.is_null()); 3650 ASSERT(!proxy_constructor.is_null());
3474 global_constructor->set_access_check_info( 3651 global_constructor->set_access_check_info(
3475 proxy_constructor->access_check_info()); 3652 proxy_constructor->access_check_info());
3476 global_constructor->set_needs_access_check( 3653 global_constructor->set_needs_access_check(
3477 proxy_constructor->needs_access_check()); 3654 proxy_constructor->needs_access_check());
3478 } 3655 }
3479 i::RuntimeProfiler::Reset(); 3656 i::Isolate::Current()->runtime_profiler()->Reset();
3480 } 3657 }
3481 // Leave V8. 3658 // Leave V8.
3482 3659
3483 if (env.is_null()) 3660 if (env.is_null())
3484 return Persistent<Context>(); 3661 return Persistent<Context>();
3485 return Persistent<Context>(Utils::ToLocal(env)); 3662 return Persistent<Context>(Utils::ToLocal(env));
3486 } 3663 }
3487 3664
3488 3665
3489 void v8::Context::SetSecurityToken(Handle<Value> token) { 3666 void v8::Context::SetSecurityToken(Handle<Value> token) {
3490 if (IsDeadCheck("v8::Context::SetSecurityToken()")) return; 3667 if (IsDeadCheck(i::Isolate::Current(), "v8::Context::SetSecurityToken()")) {
3668 return;
3669 }
3491 ENTER_V8; 3670 ENTER_V8;
3492 i::Handle<i::Context> env = Utils::OpenHandle(this); 3671 i::Handle<i::Context> env = Utils::OpenHandle(this);
3493 i::Handle<i::Object> token_handle = Utils::OpenHandle(*token); 3672 i::Handle<i::Object> token_handle = Utils::OpenHandle(*token);
3494 env->set_security_token(*token_handle); 3673 env->set_security_token(*token_handle);
3495 } 3674 }
3496 3675
3497 3676
3498 void v8::Context::UseDefaultSecurityToken() { 3677 void v8::Context::UseDefaultSecurityToken() {
3499 if (IsDeadCheck("v8::Context::UseDefaultSecurityToken()")) return; 3678 if (IsDeadCheck(i::Isolate::Current(),
3679 "v8::Context::UseDefaultSecurityToken()")) {
3680 return;
3681 }
3500 ENTER_V8; 3682 ENTER_V8;
3501 i::Handle<i::Context> env = Utils::OpenHandle(this); 3683 i::Handle<i::Context> env = Utils::OpenHandle(this);
3502 env->set_security_token(env->global()); 3684 env->set_security_token(env->global());
3503 } 3685 }
3504 3686
3505 3687
3506 Handle<Value> v8::Context::GetSecurityToken() { 3688 Handle<Value> v8::Context::GetSecurityToken() {
3507 if (IsDeadCheck("v8::Context::GetSecurityToken()")) return Handle<Value>(); 3689 if (IsDeadCheck(i::Isolate::Current(), "v8::Context::GetSecurityToken()")) {
3690 return Handle<Value>();
3691 }
3508 i::Handle<i::Context> env = Utils::OpenHandle(this); 3692 i::Handle<i::Context> env = Utils::OpenHandle(this);
3509 i::Object* security_token = env->security_token(); 3693 i::Object* security_token = env->security_token();
3510 i::Handle<i::Object> token_handle(security_token); 3694 i::Handle<i::Object> token_handle(security_token);
3511 return Utils::ToLocal(token_handle); 3695 return Utils::ToLocal(token_handle);
3512 } 3696 }
3513 3697
3514 3698
3515 bool Context::HasOutOfMemoryException() { 3699 bool Context::HasOutOfMemoryException() {
3516 i::Handle<i::Context> env = Utils::OpenHandle(this); 3700 i::Handle<i::Context> env = Utils::OpenHandle(this);
3517 return env->has_out_of_memory(); 3701 return env->has_out_of_memory();
3518 } 3702 }
3519 3703
3520 3704
3521 bool Context::InContext() { 3705 bool Context::InContext() {
3522 return i::Top::context() != NULL; 3706 return i::Isolate::Current()->context() != NULL;
3523 } 3707 }
3524 3708
3525 3709
3526 v8::Local<v8::Context> Context::GetEntered() { 3710 v8::Local<v8::Context> Context::GetEntered() {
3527 if (IsDeadCheck("v8::Context::GetEntered()")) return Local<Context>(); 3711 if (IsDeadCheck(i::Isolate::Current(), "v8::Context::GetEntered()")) {
3528 i::Handle<i::Object> last = thread_local.LastEnteredContext(); 3712 return Local<Context>();
3713 }
3714 i::Handle<i::Object> last =
3715 i::Isolate::Current()->handle_scope_implementer()->LastEnteredContext();
3529 if (last.is_null()) return Local<Context>(); 3716 if (last.is_null()) return Local<Context>();
3530 i::Handle<i::Context> context = i::Handle<i::Context>::cast(last); 3717 i::Handle<i::Context> context = i::Handle<i::Context>::cast(last);
3531 return Utils::ToLocal(context); 3718 return Utils::ToLocal(context);
3532 } 3719 }
3533 3720
3534 3721
3535 v8::Local<v8::Context> Context::GetCurrent() { 3722 v8::Local<v8::Context> Context::GetCurrent() {
3536 if (IsDeadCheck("v8::Context::GetCurrent()")) return Local<Context>(); 3723 if (IsDeadCheck(i::Isolate::Current(), "v8::Context::GetCurrent()")) {
3537 i::Handle<i::Object> current = i::Top::global_context(); 3724 return Local<Context>();
3725 }
3726 i::Handle<i::Object> current = i::Isolate::Current()->global_context();
3538 if (current.is_null()) return Local<Context>(); 3727 if (current.is_null()) return Local<Context>();
3539 i::Handle<i::Context> context = i::Handle<i::Context>::cast(current); 3728 i::Handle<i::Context> context = i::Handle<i::Context>::cast(current);
3540 return Utils::ToLocal(context); 3729 return Utils::ToLocal(context);
3541 } 3730 }
3542 3731
3543 3732
3544 v8::Local<v8::Context> Context::GetCalling() { 3733 v8::Local<v8::Context> Context::GetCalling() {
3545 if (IsDeadCheck("v8::Context::GetCalling()")) return Local<Context>(); 3734 if (IsDeadCheck(i::Isolate::Current(), "v8::Context::GetCalling()")) {
3546 i::Handle<i::Object> calling = i::Top::GetCallingGlobalContext(); 3735 return Local<Context>();
3736 }
3737 i::Handle<i::Object> calling =
3738 i::Isolate::Current()->GetCallingGlobalContext();
3547 if (calling.is_null()) return Local<Context>(); 3739 if (calling.is_null()) return Local<Context>();
3548 i::Handle<i::Context> context = i::Handle<i::Context>::cast(calling); 3740 i::Handle<i::Context> context = i::Handle<i::Context>::cast(calling);
3549 return Utils::ToLocal(context); 3741 return Utils::ToLocal(context);
3550 } 3742 }
3551 3743
3552 3744
3553 v8::Local<v8::Object> Context::Global() { 3745 v8::Local<v8::Object> Context::Global() {
3554 if (IsDeadCheck("v8::Context::Global()")) return Local<v8::Object>(); 3746 if (IsDeadCheck(i::Isolate::Current(), "v8::Context::Global()")) {
3747 return Local<v8::Object>();
3748 }
3555 i::Object** ctx = reinterpret_cast<i::Object**>(this); 3749 i::Object** ctx = reinterpret_cast<i::Object**>(this);
3556 i::Handle<i::Context> context = 3750 i::Handle<i::Context> context =
3557 i::Handle<i::Context>::cast(i::Handle<i::Object>(ctx)); 3751 i::Handle<i::Context>::cast(i::Handle<i::Object>(ctx));
3558 i::Handle<i::Object> global(context->global_proxy()); 3752 i::Handle<i::Object> global(context->global_proxy());
3559 return Utils::ToLocal(i::Handle<i::JSObject>::cast(global)); 3753 return Utils::ToLocal(i::Handle<i::JSObject>::cast(global));
3560 } 3754 }
3561 3755
3562 3756
3563 void Context::DetachGlobal() { 3757 void Context::DetachGlobal() {
3564 if (IsDeadCheck("v8::Context::DetachGlobal()")) return; 3758 if (IsDeadCheck(i::Isolate::Current(), "v8::Context::DetachGlobal()")) return;
3565 ENTER_V8; 3759 ENTER_V8;
3566 i::Object** ctx = reinterpret_cast<i::Object**>(this); 3760 i::Object** ctx = reinterpret_cast<i::Object**>(this);
3567 i::Handle<i::Context> context = 3761 i::Handle<i::Context> context =
3568 i::Handle<i::Context>::cast(i::Handle<i::Object>(ctx)); 3762 i::Handle<i::Context>::cast(i::Handle<i::Object>(ctx));
3569 i::Bootstrapper::DetachGlobal(context); 3763 i::Isolate::Current()->bootstrapper()->DetachGlobal(context);
3570 } 3764 }
3571 3765
3572 3766
3573 void Context::ReattachGlobal(Handle<Object> global_object) { 3767 void Context::ReattachGlobal(Handle<Object> global_object) {
3574 if (IsDeadCheck("v8::Context::ReattachGlobal()")) return; 3768 i::Isolate* isolate = i::Isolate::Current();
3769 if (IsDeadCheck(isolate, "v8::Context::ReattachGlobal()")) return;
3575 ENTER_V8; 3770 ENTER_V8;
3576 i::Object** ctx = reinterpret_cast<i::Object**>(this); 3771 i::Object** ctx = reinterpret_cast<i::Object**>(this);
3577 i::Handle<i::Context> context = 3772 i::Handle<i::Context> context =
3578 i::Handle<i::Context>::cast(i::Handle<i::Object>(ctx)); 3773 i::Handle<i::Context>::cast(i::Handle<i::Object>(ctx));
3579 i::Bootstrapper::ReattachGlobal(context, Utils::OpenHandle(*global_object)); 3774 isolate->bootstrapper()->ReattachGlobal(
3775 context,
3776 Utils::OpenHandle(*global_object));
3580 } 3777 }
3581 3778
3582 3779
3583 void V8::SetWrapperClassId(i::Object** global_handle, uint16_t class_id) { 3780 void V8::SetWrapperClassId(i::Object** global_handle, uint16_t class_id) {
3584 i::GlobalHandles::SetWrapperClassId(global_handle, class_id); 3781 i::GlobalHandles::SetWrapperClassId(global_handle, class_id);
3585 } 3782 }
3586 3783
3587 3784
3588 Local<v8::Object> ObjectTemplate::NewInstance() { 3785 Local<v8::Object> ObjectTemplate::NewInstance() {
3589 ON_BAILOUT("v8::ObjectTemplate::NewInstance()", return Local<v8::Object>()); 3786 i::Isolate* isolate = i::Isolate::Current();
3590 LOG_API("ObjectTemplate::NewInstance"); 3787 ON_BAILOUT(isolate, "v8::ObjectTemplate::NewInstance()",
3788 return Local<v8::Object>());
3789 LOG_API(isolate, "ObjectTemplate::NewInstance");
3591 ENTER_V8; 3790 ENTER_V8;
3592 EXCEPTION_PREAMBLE(); 3791 EXCEPTION_PREAMBLE();
3593 i::Handle<i::Object> obj = 3792 i::Handle<i::Object> obj =
3594 i::Execution::InstantiateObject(Utils::OpenHandle(this), 3793 i::Execution::InstantiateObject(Utils::OpenHandle(this),
3595 &has_pending_exception); 3794 &has_pending_exception);
3596 EXCEPTION_BAILOUT_CHECK(Local<v8::Object>()); 3795 EXCEPTION_BAILOUT_CHECK(Local<v8::Object>());
3597 return Utils::ToLocal(i::Handle<i::JSObject>::cast(obj)); 3796 return Utils::ToLocal(i::Handle<i::JSObject>::cast(obj));
3598 } 3797 }
3599 3798
3600 3799
3601 Local<v8::Function> FunctionTemplate::GetFunction() { 3800 Local<v8::Function> FunctionTemplate::GetFunction() {
3602 ON_BAILOUT("v8::FunctionTemplate::GetFunction()", 3801 i::Isolate* isolate = i::Isolate::Current();
3802 ON_BAILOUT(isolate, "v8::FunctionTemplate::GetFunction()",
3603 return Local<v8::Function>()); 3803 return Local<v8::Function>());
3604 LOG_API("FunctionTemplate::GetFunction"); 3804 LOG_API(isolate, "FunctionTemplate::GetFunction");
3605 ENTER_V8; 3805 ENTER_V8;
3606 EXCEPTION_PREAMBLE(); 3806 EXCEPTION_PREAMBLE();
3607 i::Handle<i::Object> obj = 3807 i::Handle<i::Object> obj =
3608 i::Execution::InstantiateFunction(Utils::OpenHandle(this), 3808 i::Execution::InstantiateFunction(Utils::OpenHandle(this),
3609 &has_pending_exception); 3809 &has_pending_exception);
3610 EXCEPTION_BAILOUT_CHECK(Local<v8::Function>()); 3810 EXCEPTION_BAILOUT_CHECK(Local<v8::Function>());
3611 return Utils::ToLocal(i::Handle<i::JSFunction>::cast(obj)); 3811 return Utils::ToLocal(i::Handle<i::JSFunction>::cast(obj));
3612 } 3812 }
3613 3813
3614 3814
3615 bool FunctionTemplate::HasInstance(v8::Handle<v8::Value> value) { 3815 bool FunctionTemplate::HasInstance(v8::Handle<v8::Value> value) {
3616 ON_BAILOUT("v8::FunctionTemplate::HasInstanceOf()", return false); 3816 ON_BAILOUT(i::Isolate::Current(), "v8::FunctionTemplate::HasInstanceOf()",
3817 return false);
3617 i::Object* obj = *Utils::OpenHandle(*value); 3818 i::Object* obj = *Utils::OpenHandle(*value);
3618 return obj->IsInstanceOf(*Utils::OpenHandle(this)); 3819 return obj->IsInstanceOf(*Utils::OpenHandle(this));
3619 } 3820 }
3620 3821
3621 3822
3622 static Local<External> ExternalNewImpl(void* data) { 3823 static Local<External> ExternalNewImpl(void* data) {
3623 return Utils::ToLocal(i::Factory::NewProxy(static_cast<i::Address>(data))); 3824 return Utils::ToLocal(FACTORY->NewProxy(static_cast<i::Address>(data)));
3624 } 3825 }
3625 3826
3626 static void* ExternalValueImpl(i::Handle<i::Object> obj) { 3827 static void* ExternalValueImpl(i::Handle<i::Object> obj) {
3627 return reinterpret_cast<void*>(i::Proxy::cast(*obj)->proxy()); 3828 return reinterpret_cast<void*>(i::Proxy::cast(*obj)->proxy());
3628 } 3829 }
3629 3830
3630 3831
3631 Local<Value> v8::External::Wrap(void* data) { 3832 Local<Value> v8::External::Wrap(void* data) {
3833 i::Isolate* isolate = i::Isolate::Current();
3632 STATIC_ASSERT(sizeof(data) == sizeof(i::Address)); 3834 STATIC_ASSERT(sizeof(data) == sizeof(i::Address));
3633 LOG_API("External::Wrap"); 3835 LOG_API(isolate, "External::Wrap");
3634 EnsureInitialized("v8::External::Wrap()"); 3836 EnsureInitializedForIsolate(isolate, "v8::External::Wrap()");
3635 ENTER_V8; 3837 ENTER_V8;
3636 3838
3637 v8::Local<v8::Value> result = CanBeEncodedAsSmi(data) 3839 v8::Local<v8::Value> result = CanBeEncodedAsSmi(data)
3638 ? Utils::ToLocal(i::Handle<i::Object>(EncodeAsSmi(data))) 3840 ? Utils::ToLocal(i::Handle<i::Object>(EncodeAsSmi(data)))
3639 : v8::Local<v8::Value>(ExternalNewImpl(data)); 3841 : v8::Local<v8::Value>(ExternalNewImpl(data));
3640 3842
3641 ASSERT_EQ(data, Unwrap(result)); 3843 ASSERT_EQ(data, Unwrap(result));
3642 return result; 3844 return result;
3643 } 3845 }
3644 3846
3645 3847
3646 void* v8::Object::SlowGetPointerFromInternalField(int index) { 3848 void* v8::Object::SlowGetPointerFromInternalField(int index) {
3647 i::Handle<i::JSObject> obj = Utils::OpenHandle(this); 3849 i::Handle<i::JSObject> obj = Utils::OpenHandle(this);
3648 i::Object* value = obj->GetInternalField(index); 3850 i::Object* value = obj->GetInternalField(index);
3649 if (value->IsSmi()) { 3851 if (value->IsSmi()) {
3650 return i::Internals::GetExternalPointerFromSmi(value); 3852 return i::Internals::GetExternalPointerFromSmi(value);
3651 } else if (value->IsProxy()) { 3853 } else if (value->IsProxy()) {
3652 return reinterpret_cast<void*>(i::Proxy::cast(value)->proxy()); 3854 return reinterpret_cast<void*>(i::Proxy::cast(value)->proxy());
3653 } else { 3855 } else {
3654 return NULL; 3856 return NULL;
3655 } 3857 }
3656 } 3858 }
3657 3859
3658 3860
3659 void* v8::External::FullUnwrap(v8::Handle<v8::Value> wrapper) { 3861 void* v8::External::FullUnwrap(v8::Handle<v8::Value> wrapper) {
3660 if (IsDeadCheck("v8::External::Unwrap()")) return 0; 3862 if (IsDeadCheck(i::Isolate::Current(), "v8::External::Unwrap()")) return 0;
3661 i::Handle<i::Object> obj = Utils::OpenHandle(*wrapper); 3863 i::Handle<i::Object> obj = Utils::OpenHandle(*wrapper);
3662 void* result; 3864 void* result;
3663 if (obj->IsSmi()) { 3865 if (obj->IsSmi()) {
3664 result = i::Internals::GetExternalPointerFromSmi(*obj); 3866 result = i::Internals::GetExternalPointerFromSmi(*obj);
3665 } else if (obj->IsProxy()) { 3867 } else if (obj->IsProxy()) {
3666 result = ExternalValueImpl(obj); 3868 result = ExternalValueImpl(obj);
3667 } else { 3869 } else {
3668 result = NULL; 3870 result = NULL;
3669 } 3871 }
3670 ASSERT_EQ(result, QuickUnwrap(wrapper)); 3872 ASSERT_EQ(result, QuickUnwrap(wrapper));
3671 return result; 3873 return result;
3672 } 3874 }
3673 3875
3674 3876
3675 Local<External> v8::External::New(void* data) { 3877 Local<External> v8::External::New(void* data) {
3676 STATIC_ASSERT(sizeof(data) == sizeof(i::Address)); 3878 STATIC_ASSERT(sizeof(data) == sizeof(i::Address));
3677 LOG_API("External::New"); 3879 i::Isolate* isolate = i::Isolate::Current();
3678 EnsureInitialized("v8::External::New()"); 3880 LOG_API(isolate, "External::New");
3881 EnsureInitializedForIsolate(isolate, "v8::External::New()");
3679 ENTER_V8; 3882 ENTER_V8;
3680 return ExternalNewImpl(data); 3883 return ExternalNewImpl(data);
3681 } 3884 }
3682 3885
3683 3886
3684 void* External::Value() const { 3887 void* External::Value() const {
3685 if (IsDeadCheck("v8::External::Value()")) return 0; 3888 if (IsDeadCheck(i::Isolate::Current(), "v8::External::Value()")) return 0;
3686 i::Handle<i::Object> obj = Utils::OpenHandle(this); 3889 i::Handle<i::Object> obj = Utils::OpenHandle(this);
3687 return ExternalValueImpl(obj); 3890 return ExternalValueImpl(obj);
3688 } 3891 }
3689 3892
3690 3893
3691 Local<String> v8::String::Empty() { 3894 Local<String> v8::String::Empty() {
3692 EnsureInitialized("v8::String::Empty()"); 3895 i::Isolate* isolate = i::Isolate::Current();
3693 LOG_API("String::Empty()"); 3896 EnsureInitializedForIsolate(isolate, "v8::String::Empty()");
3694 return Utils::ToLocal(i::Factory::empty_symbol()); 3897 LOG_API(isolate, "String::Empty()");
3898 return Utils::ToLocal(isolate->factory()->empty_symbol());
3695 } 3899 }
3696 3900
3697 3901
3698 Local<String> v8::String::New(const char* data, int length) { 3902 Local<String> v8::String::New(const char* data, int length) {
3699 EnsureInitialized("v8::String::New()"); 3903 i::Isolate* isolate = i::Isolate::Current();
3700 LOG_API("String::New(char)"); 3904 EnsureInitializedForIsolate(isolate, "v8::String::New()");
3905 LOG_API(isolate, "String::New(char)");
3701 if (length == 0) return Empty(); 3906 if (length == 0) return Empty();
3702 ENTER_V8; 3907 ENTER_V8;
3703 if (length == -1) length = i::StrLength(data); 3908 if (length == -1) length = i::StrLength(data);
3704 i::Handle<i::String> result = 3909 i::Handle<i::String> result =
3705 i::Factory::NewStringFromUtf8(i::Vector<const char>(data, length)); 3910 isolate->factory()->NewStringFromUtf8(
3911 i::Vector<const char>(data, length));
3706 return Utils::ToLocal(result); 3912 return Utils::ToLocal(result);
3707 } 3913 }
3708 3914
3709 3915
3710 Local<String> v8::String::Concat(Handle<String> left, Handle<String> right) { 3916 Local<String> v8::String::Concat(Handle<String> left, Handle<String> right) {
3711 EnsureInitialized("v8::String::New()"); 3917 i::Isolate* isolate = i::Isolate::Current();
3712 LOG_API("String::New(char)"); 3918 EnsureInitializedForIsolate(isolate, "v8::String::New()");
3919 LOG_API(isolate, "String::New(char)");
3713 ENTER_V8; 3920 ENTER_V8;
3714 i::Handle<i::String> left_string = Utils::OpenHandle(*left); 3921 i::Handle<i::String> left_string = Utils::OpenHandle(*left);
3715 i::Handle<i::String> right_string = Utils::OpenHandle(*right); 3922 i::Handle<i::String> right_string = Utils::OpenHandle(*right);
3716 i::Handle<i::String> result = i::Factory::NewConsString(left_string, 3923 i::Handle<i::String> result = FACTORY->NewConsString(left_string,
3717 right_string); 3924 right_string);
3718 return Utils::ToLocal(result); 3925 return Utils::ToLocal(result);
3719 } 3926 }
3720 3927
3721 3928
3722 Local<String> v8::String::NewUndetectable(const char* data, int length) { 3929 Local<String> v8::String::NewUndetectable(const char* data, int length) {
3723 EnsureInitialized("v8::String::NewUndetectable()"); 3930 i::Isolate* isolate = i::Isolate::Current();
3724 LOG_API("String::NewUndetectable(char)"); 3931 EnsureInitializedForIsolate(isolate, "v8::String::NewUndetectable()");
3932 LOG_API(isolate, "String::NewUndetectable(char)");
3725 ENTER_V8; 3933 ENTER_V8;
3726 if (length == -1) length = i::StrLength(data); 3934 if (length == -1) length = i::StrLength(data);
3727 i::Handle<i::String> result = 3935 i::Handle<i::String> result =
3728 i::Factory::NewStringFromUtf8(i::Vector<const char>(data, length)); 3936 FACTORY->NewStringFromUtf8(i::Vector<const char>(data, length));
3729 result->MarkAsUndetectable(); 3937 result->MarkAsUndetectable();
3730 return Utils::ToLocal(result); 3938 return Utils::ToLocal(result);
3731 } 3939 }
3732 3940
3733 3941
3734 static int TwoByteStringLength(const uint16_t* data) { 3942 static int TwoByteStringLength(const uint16_t* data) {
3735 int length = 0; 3943 int length = 0;
3736 while (data[length] != '\0') length++; 3944 while (data[length] != '\0') length++;
3737 return length; 3945 return length;
3738 } 3946 }
3739 3947
3740 3948
3741 Local<String> v8::String::New(const uint16_t* data, int length) { 3949 Local<String> v8::String::New(const uint16_t* data, int length) {
3742 EnsureInitialized("v8::String::New()"); 3950 i::Isolate* isolate = i::Isolate::Current();
3743 LOG_API("String::New(uint16_)"); 3951 EnsureInitializedForIsolate(isolate, "v8::String::New()");
3952 LOG_API(isolate, "String::New(uint16_)");
3744 if (length == 0) return Empty(); 3953 if (length == 0) return Empty();
3745 ENTER_V8; 3954 ENTER_V8;
3746 if (length == -1) length = TwoByteStringLength(data); 3955 if (length == -1) length = TwoByteStringLength(data);
3747 i::Handle<i::String> result = 3956 i::Handle<i::String> result =
3748 i::Factory::NewStringFromTwoByte(i::Vector<const uint16_t>(data, length)); 3957 isolate->factory()->NewStringFromTwoByte(
3958 i::Vector<const uint16_t>(data, length));
3749 return Utils::ToLocal(result); 3959 return Utils::ToLocal(result);
3750 } 3960 }
3751 3961
3752 3962
3753 Local<String> v8::String::NewUndetectable(const uint16_t* data, int length) { 3963 Local<String> v8::String::NewUndetectable(const uint16_t* data, int length) {
3754 EnsureInitialized("v8::String::NewUndetectable()"); 3964 i::Isolate* isolate = i::Isolate::Current();
3755 LOG_API("String::NewUndetectable(uint16_)"); 3965 EnsureInitializedForIsolate(isolate, "v8::String::NewUndetectable()");
3966 LOG_API(isolate, "String::NewUndetectable(uint16_)");
3756 ENTER_V8; 3967 ENTER_V8;
3757 if (length == -1) length = TwoByteStringLength(data); 3968 if (length == -1) length = TwoByteStringLength(data);
3758 i::Handle<i::String> result = 3969 i::Handle<i::String> result =
3759 i::Factory::NewStringFromTwoByte(i::Vector<const uint16_t>(data, length)); 3970 isolate->factory()->NewStringFromTwoByte(
3971 i::Vector<const uint16_t>(data, length));
3760 result->MarkAsUndetectable(); 3972 result->MarkAsUndetectable();
3761 return Utils::ToLocal(result); 3973 return Utils::ToLocal(result);
3762 } 3974 }
3763 3975
3764 3976
3765 i::Handle<i::String> NewExternalStringHandle( 3977 i::Handle<i::String> NewExternalStringHandle(i::Isolate* isolate,
3766 v8::String::ExternalStringResource* resource) { 3978 v8::String::ExternalStringResource* resource) {
3767 i::Handle<i::String> result = 3979 i::Handle<i::String> result =
3768 i::Factory::NewExternalStringFromTwoByte(resource); 3980 isolate->factory()->NewExternalStringFromTwoByte(resource);
3769 return result; 3981 return result;
3770 } 3982 }
3771 3983
3772 3984
3773 i::Handle<i::String> NewExternalAsciiStringHandle( 3985 i::Handle<i::String> NewExternalAsciiStringHandle(i::Isolate* isolate,
3774 v8::String::ExternalAsciiStringResource* resource) { 3986 v8::String::ExternalAsciiStringResource* resource) {
3775 i::Handle<i::String> result = 3987 i::Handle<i::String> result =
3776 i::Factory::NewExternalStringFromAscii(resource); 3988 isolate->factory()->NewExternalStringFromAscii(resource);
3777 return result; 3989 return result;
3778 } 3990 }
3779 3991
3780 3992
3781 Local<String> v8::String::NewExternal( 3993 Local<String> v8::String::NewExternal(
3782 v8::String::ExternalStringResource* resource) { 3994 v8::String::ExternalStringResource* resource) {
3783 EnsureInitialized("v8::String::NewExternal()"); 3995 i::Isolate* isolate = i::Isolate::Current();
3784 LOG_API("String::NewExternal"); 3996 EnsureInitializedForIsolate(isolate, "v8::String::NewExternal()");
3997 LOG_API(isolate, "String::NewExternal");
3785 ENTER_V8; 3998 ENTER_V8;
3786 i::Handle<i::String> result = NewExternalStringHandle(resource); 3999 i::Handle<i::String> result = NewExternalStringHandle(isolate, resource);
3787 i::ExternalStringTable::AddString(*result); 4000 isolate->heap()->external_string_table()->AddString(*result);
3788 return Utils::ToLocal(result); 4001 return Utils::ToLocal(result);
3789 } 4002 }
3790 4003
3791 4004
3792 bool v8::String::MakeExternal(v8::String::ExternalStringResource* resource) { 4005 bool v8::String::MakeExternal(v8::String::ExternalStringResource* resource) {
3793 if (IsDeadCheck("v8::String::MakeExternal()")) return false; 4006 i::Isolate* isolate = i::Isolate::Current();
4007 if (IsDeadCheck(isolate, "v8::String::MakeExternal()")) return false;
3794 if (this->IsExternal()) return false; // Already an external string. 4008 if (this->IsExternal()) return false; // Already an external string.
3795 ENTER_V8; 4009 ENTER_V8;
3796 i::Handle<i::String> obj = Utils::OpenHandle(this); 4010 i::Handle<i::String> obj = Utils::OpenHandle(this);
3797 if (StringTracker::IsFreshUnusedString(obj)) return false; 4011 if (isolate->string_tracker()->IsFreshUnusedString(obj)) {
4012 return false;
4013 }
3798 bool result = obj->MakeExternal(resource); 4014 bool result = obj->MakeExternal(resource);
3799 if (result && !obj->IsSymbol()) { 4015 if (result && !obj->IsSymbol()) {
3800 i::ExternalStringTable::AddString(*obj); 4016 isolate->heap()->external_string_table()->AddString(*obj);
3801 } 4017 }
3802 return result; 4018 return result;
3803 } 4019 }
3804 4020
3805 4021
3806 Local<String> v8::String::NewExternal( 4022 Local<String> v8::String::NewExternal(
3807 v8::String::ExternalAsciiStringResource* resource) { 4023 v8::String::ExternalAsciiStringResource* resource) {
3808 EnsureInitialized("v8::String::NewExternal()"); 4024 i::Isolate* isolate = i::Isolate::Current();
3809 LOG_API("String::NewExternal"); 4025 EnsureInitializedForIsolate(isolate, "v8::String::NewExternal()");
4026 LOG_API(isolate, "String::NewExternal");
3810 ENTER_V8; 4027 ENTER_V8;
3811 i::Handle<i::String> result = NewExternalAsciiStringHandle(resource); 4028 i::Handle<i::String> result = NewExternalAsciiStringHandle(isolate, resource);
3812 i::ExternalStringTable::AddString(*result); 4029 isolate->heap()->external_string_table()->AddString(*result);
3813 return Utils::ToLocal(result); 4030 return Utils::ToLocal(result);
3814 } 4031 }
3815 4032
3816 4033
3817 bool v8::String::MakeExternal( 4034 bool v8::String::MakeExternal(
3818 v8::String::ExternalAsciiStringResource* resource) { 4035 v8::String::ExternalAsciiStringResource* resource) {
3819 if (IsDeadCheck("v8::String::MakeExternal()")) return false; 4036 i::Isolate* isolate = i::Isolate::Current();
4037 if (IsDeadCheck(isolate, "v8::String::MakeExternal()")) return false;
3820 if (this->IsExternal()) return false; // Already an external string. 4038 if (this->IsExternal()) return false; // Already an external string.
3821 ENTER_V8; 4039 ENTER_V8;
3822 i::Handle<i::String> obj = Utils::OpenHandle(this); 4040 i::Handle<i::String> obj = Utils::OpenHandle(this);
3823 if (StringTracker::IsFreshUnusedString(obj)) return false; 4041 if (isolate->string_tracker()->IsFreshUnusedString(obj)) {
4042 return false;
4043 }
3824 bool result = obj->MakeExternal(resource); 4044 bool result = obj->MakeExternal(resource);
3825 if (result && !obj->IsSymbol()) { 4045 if (result && !obj->IsSymbol()) {
3826 i::ExternalStringTable::AddString(*obj); 4046 isolate->heap()->external_string_table()->AddString(*obj);
3827 } 4047 }
3828 return result; 4048 return result;
3829 } 4049 }
3830 4050
3831 4051
3832 bool v8::String::CanMakeExternal() { 4052 bool v8::String::CanMakeExternal() {
3833 if (IsDeadCheck("v8::String::CanMakeExternal()")) return false; 4053 i::Isolate* isolate = i::Isolate::Current();
4054 if (IsDeadCheck(isolate, "v8::String::CanMakeExternal()")) return false;
3834 i::Handle<i::String> obj = Utils::OpenHandle(this); 4055 i::Handle<i::String> obj = Utils::OpenHandle(this);
3835 if (StringTracker::IsFreshUnusedString(obj)) return false; 4056 if (isolate->string_tracker()->IsFreshUnusedString(obj)) {
4057 return false;
4058 }
3836 int size = obj->Size(); // Byte size of the original string. 4059 int size = obj->Size(); // Byte size of the original string.
3837 if (size < i::ExternalString::kSize) 4060 if (size < i::ExternalString::kSize)
3838 return false; 4061 return false;
3839 i::StringShape shape(*obj); 4062 i::StringShape shape(*obj);
3840 return !shape.IsExternal(); 4063 return !shape.IsExternal();
3841 } 4064 }
3842 4065
3843 4066
3844 Local<v8::Object> v8::Object::New() { 4067 Local<v8::Object> v8::Object::New() {
3845 EnsureInitialized("v8::Object::New()"); 4068 i::Isolate* isolate = i::Isolate::Current();
3846 LOG_API("Object::New"); 4069 EnsureInitializedForIsolate(isolate, "v8::Object::New()");
4070 LOG_API(isolate, "Object::New");
3847 ENTER_V8; 4071 ENTER_V8;
3848 i::Handle<i::JSObject> obj = 4072 i::Handle<i::JSObject> obj =
3849 i::Factory::NewJSObject(i::Top::object_function()); 4073 isolate->factory()->NewJSObject(i::Isolate::Current()->object_function());
3850 return Utils::ToLocal(obj); 4074 return Utils::ToLocal(obj);
3851 } 4075 }
3852 4076
3853 4077
3854 Local<v8::Value> v8::Date::New(double time) { 4078 Local<v8::Value> v8::Date::New(double time) {
3855 EnsureInitialized("v8::Date::New()"); 4079 i::Isolate* isolate = i::Isolate::Current();
3856 LOG_API("Date::New"); 4080 EnsureInitializedForIsolate(isolate, "v8::Date::New()");
4081 LOG_API(isolate, "Date::New");
3857 if (isnan(time)) { 4082 if (isnan(time)) {
3858 // Introduce only canonical NaN value into the VM, to avoid signaling NaNs. 4083 // Introduce only canonical NaN value into the VM, to avoid signaling NaNs.
3859 time = i::OS::nan_value(); 4084 time = i::OS::nan_value();
3860 } 4085 }
3861 ENTER_V8; 4086 ENTER_V8;
3862 EXCEPTION_PREAMBLE(); 4087 EXCEPTION_PREAMBLE();
3863 i::Handle<i::Object> obj = 4088 i::Handle<i::Object> obj =
3864 i::Execution::NewDate(time, &has_pending_exception); 4089 i::Execution::NewDate(time, &has_pending_exception);
3865 EXCEPTION_BAILOUT_CHECK(Local<v8::Value>()); 4090 EXCEPTION_BAILOUT_CHECK(Local<v8::Value>());
3866 return Utils::ToLocal(obj); 4091 return Utils::ToLocal(obj);
3867 } 4092 }
3868 4093
3869 4094
3870 double v8::Date::NumberValue() const { 4095 double v8::Date::NumberValue() const {
3871 if (IsDeadCheck("v8::Date::NumberValue()")) return 0; 4096 i::Isolate* isolate = i::Isolate::Current();
3872 LOG_API("Date::NumberValue"); 4097 if (IsDeadCheck(isolate, "v8::Date::NumberValue()")) return 0;
4098 LOG_API(isolate, "Date::NumberValue");
3873 i::Handle<i::Object> obj = Utils::OpenHandle(this); 4099 i::Handle<i::Object> obj = Utils::OpenHandle(this);
3874 i::Handle<i::JSValue> jsvalue = i::Handle<i::JSValue>::cast(obj); 4100 i::Handle<i::JSValue> jsvalue = i::Handle<i::JSValue>::cast(obj);
3875 return jsvalue->value()->Number(); 4101 return jsvalue->value()->Number();
3876 } 4102 }
3877 4103
3878 4104
3879 void v8::Date::DateTimeConfigurationChangeNotification() { 4105 void v8::Date::DateTimeConfigurationChangeNotification() {
3880 ON_BAILOUT("v8::Date::DateTimeConfigurationChangeNotification()", return); 4106 i::Isolate* isolate = i::Isolate::Current();
3881 LOG_API("Date::DateTimeConfigurationChangeNotification"); 4107 ON_BAILOUT(isolate, "v8::Date::DateTimeConfigurationChangeNotification()",
4108 return);
4109 LOG_API(isolate, "Date::DateTimeConfigurationChangeNotification");
3882 ENTER_V8; 4110 ENTER_V8;
3883 4111
3884 HandleScope scope; 4112 i::HandleScope scope(isolate);
3885
3886 // Get the function ResetDateCache (defined in date-delay.js). 4113 // Get the function ResetDateCache (defined in date-delay.js).
3887 i::Handle<i::String> func_name_str = 4114 i::Handle<i::String> func_name_str =
3888 i::Factory::LookupAsciiSymbol("ResetDateCache"); 4115 isolate->factory()->LookupAsciiSymbol("ResetDateCache");
3889 i::MaybeObject* result = i::Top::builtins()->GetProperty(*func_name_str); 4116 i::MaybeObject* result =
4117 isolate->js_builtins_object()->GetProperty(*func_name_str);
3890 i::Object* object_func; 4118 i::Object* object_func;
3891 if (!result->ToObject(&object_func)) { 4119 if (!result->ToObject(&object_func)) {
3892 return; 4120 return;
3893 } 4121 }
3894 4122
3895 if (object_func->IsJSFunction()) { 4123 if (object_func->IsJSFunction()) {
3896 i::Handle<i::JSFunction> func = 4124 i::Handle<i::JSFunction> func =
3897 i::Handle<i::JSFunction>(i::JSFunction::cast(object_func)); 4125 i::Handle<i::JSFunction>(i::JSFunction::cast(object_func));
3898 4126
3899 // Call ResetDateCache(0 but expect no exceptions: 4127 // Call ResetDateCache(0 but expect no exceptions:
3900 bool caught_exception = false; 4128 bool caught_exception = false;
3901 i::Handle<i::Object> result = 4129 i::Handle<i::Object> result =
3902 i::Execution::TryCall(func, i::Top::builtins(), 0, NULL, 4130 i::Execution::TryCall(func, isolate->js_builtins_object(), 0, NULL,
3903 &caught_exception); 4131 &caught_exception);
3904 } 4132 }
3905 } 4133 }
3906 4134
3907 4135
3908 static i::Handle<i::String> RegExpFlagsToString(RegExp::Flags flags) { 4136 static i::Handle<i::String> RegExpFlagsToString(RegExp::Flags flags) {
3909 char flags_buf[3]; 4137 char flags_buf[3];
3910 int num_flags = 0; 4138 int num_flags = 0;
3911 if ((flags & RegExp::kGlobal) != 0) flags_buf[num_flags++] = 'g'; 4139 if ((flags & RegExp::kGlobal) != 0) flags_buf[num_flags++] = 'g';
3912 if ((flags & RegExp::kMultiline) != 0) flags_buf[num_flags++] = 'm'; 4140 if ((flags & RegExp::kMultiline) != 0) flags_buf[num_flags++] = 'm';
3913 if ((flags & RegExp::kIgnoreCase) != 0) flags_buf[num_flags++] = 'i'; 4141 if ((flags & RegExp::kIgnoreCase) != 0) flags_buf[num_flags++] = 'i';
3914 ASSERT(num_flags <= static_cast<int>(ARRAY_SIZE(flags_buf))); 4142 ASSERT(num_flags <= static_cast<int>(ARRAY_SIZE(flags_buf)));
3915 return i::Factory::LookupSymbol( 4143 return FACTORY->LookupSymbol(
3916 i::Vector<const char>(flags_buf, num_flags)); 4144 i::Vector<const char>(flags_buf, num_flags));
3917 } 4145 }
3918 4146
3919 4147
3920 Local<v8::RegExp> v8::RegExp::New(Handle<String> pattern, 4148 Local<v8::RegExp> v8::RegExp::New(Handle<String> pattern,
3921 Flags flags) { 4149 Flags flags) {
3922 EnsureInitialized("v8::RegExp::New()"); 4150 i::Isolate* isolate = i::Isolate::Current();
3923 LOG_API("RegExp::New"); 4151 EnsureInitializedForIsolate(isolate, "v8::RegExp::New()");
4152 LOG_API(isolate, "RegExp::New");
3924 ENTER_V8; 4153 ENTER_V8;
3925 EXCEPTION_PREAMBLE(); 4154 EXCEPTION_PREAMBLE();
3926 i::Handle<i::JSRegExp> obj = i::Execution::NewJSRegExp( 4155 i::Handle<i::JSRegExp> obj = i::Execution::NewJSRegExp(
3927 Utils::OpenHandle(*pattern), 4156 Utils::OpenHandle(*pattern),
3928 RegExpFlagsToString(flags), 4157 RegExpFlagsToString(flags),
3929 &has_pending_exception); 4158 &has_pending_exception);
3930 EXCEPTION_BAILOUT_CHECK(Local<v8::RegExp>()); 4159 EXCEPTION_BAILOUT_CHECK(Local<v8::RegExp>());
3931 return Utils::ToLocal(i::Handle<i::JSRegExp>::cast(obj)); 4160 return Utils::ToLocal(i::Handle<i::JSRegExp>::cast(obj));
3932 } 4161 }
3933 4162
3934 4163
3935 Local<v8::String> v8::RegExp::GetSource() const { 4164 Local<v8::String> v8::RegExp::GetSource() const {
3936 if (IsDeadCheck("v8::RegExp::GetSource()")) return Local<v8::String>(); 4165 i::Isolate* isolate = i::Isolate::Current();
4166 if (IsDeadCheck(isolate, "v8::RegExp::GetSource()")) {
4167 return Local<v8::String>();
4168 }
3937 i::Handle<i::JSRegExp> obj = Utils::OpenHandle(this); 4169 i::Handle<i::JSRegExp> obj = Utils::OpenHandle(this);
3938 return Utils::ToLocal(i::Handle<i::String>(obj->Pattern())); 4170 return Utils::ToLocal(i::Handle<i::String>(obj->Pattern()));
3939 } 4171 }
3940 4172
3941 4173
3942 // Assert that the static flags cast in GetFlags is valid. 4174 // Assert that the static flags cast in GetFlags is valid.
3943 #define REGEXP_FLAG_ASSERT_EQ(api_flag, internal_flag) \ 4175 #define REGEXP_FLAG_ASSERT_EQ(api_flag, internal_flag) \
3944 STATIC_ASSERT(static_cast<int>(v8::RegExp::api_flag) == \ 4176 STATIC_ASSERT(static_cast<int>(v8::RegExp::api_flag) == \
3945 static_cast<int>(i::JSRegExp::internal_flag)) 4177 static_cast<int>(i::JSRegExp::internal_flag))
3946 REGEXP_FLAG_ASSERT_EQ(kNone, NONE); 4178 REGEXP_FLAG_ASSERT_EQ(kNone, NONE);
3947 REGEXP_FLAG_ASSERT_EQ(kGlobal, GLOBAL); 4179 REGEXP_FLAG_ASSERT_EQ(kGlobal, GLOBAL);
3948 REGEXP_FLAG_ASSERT_EQ(kIgnoreCase, IGNORE_CASE); 4180 REGEXP_FLAG_ASSERT_EQ(kIgnoreCase, IGNORE_CASE);
3949 REGEXP_FLAG_ASSERT_EQ(kMultiline, MULTILINE); 4181 REGEXP_FLAG_ASSERT_EQ(kMultiline, MULTILINE);
3950 #undef REGEXP_FLAG_ASSERT_EQ 4182 #undef REGEXP_FLAG_ASSERT_EQ
3951 4183
3952 v8::RegExp::Flags v8::RegExp::GetFlags() const { 4184 v8::RegExp::Flags v8::RegExp::GetFlags() const {
3953 if (IsDeadCheck("v8::RegExp::GetFlags()")) return v8::RegExp::kNone; 4185 if (IsDeadCheck(i::Isolate::Current(), "v8::RegExp::GetFlags()")) {
4186 return v8::RegExp::kNone;
4187 }
3954 i::Handle<i::JSRegExp> obj = Utils::OpenHandle(this); 4188 i::Handle<i::JSRegExp> obj = Utils::OpenHandle(this);
3955 return static_cast<RegExp::Flags>(obj->GetFlags().value()); 4189 return static_cast<RegExp::Flags>(obj->GetFlags().value());
3956 } 4190 }
3957 4191
3958 4192
3959 Local<v8::Array> v8::Array::New(int length) { 4193 Local<v8::Array> v8::Array::New(int length) {
3960 EnsureInitialized("v8::Array::New()"); 4194 i::Isolate* isolate = i::Isolate::Current();
3961 LOG_API("Array::New"); 4195 EnsureInitializedForIsolate(isolate, "v8::Array::New()");
4196 LOG_API(isolate, "Array::New");
3962 ENTER_V8; 4197 ENTER_V8;
3963 int real_length = length > 0 ? length : 0; 4198 int real_length = length > 0 ? length : 0;
3964 i::Handle<i::JSArray> obj = i::Factory::NewJSArray(real_length); 4199 i::Handle<i::JSArray> obj = isolate->factory()->NewJSArray(real_length);
3965 obj->set_length(*i::Factory::NewNumberFromInt(real_length)); 4200 obj->set_length(*isolate->factory()->NewNumberFromInt(real_length));
3966 return Utils::ToLocal(obj); 4201 return Utils::ToLocal(obj);
3967 } 4202 }
3968 4203
3969 4204
3970 uint32_t v8::Array::Length() const { 4205 uint32_t v8::Array::Length() const {
3971 if (IsDeadCheck("v8::Array::Length()")) return 0; 4206 i::Isolate* isolate = i::Isolate::Current();
4207 if (IsDeadCheck(isolate, "v8::Array::Length()")) return 0;
3972 i::Handle<i::JSArray> obj = Utils::OpenHandle(this); 4208 i::Handle<i::JSArray> obj = Utils::OpenHandle(this);
3973 i::Object* length = obj->length(); 4209 i::Object* length = obj->length();
3974 if (length->IsSmi()) { 4210 if (length->IsSmi()) {
3975 return i::Smi::cast(length)->value(); 4211 return i::Smi::cast(length)->value();
3976 } else { 4212 } else {
3977 return static_cast<uint32_t>(length->Number()); 4213 return static_cast<uint32_t>(length->Number());
3978 } 4214 }
3979 } 4215 }
3980 4216
3981 4217
3982 Local<Object> Array::CloneElementAt(uint32_t index) { 4218 Local<Object> Array::CloneElementAt(uint32_t index) {
3983 ON_BAILOUT("v8::Array::CloneElementAt()", return Local<Object>()); 4219 i::Isolate* isolate = i::Isolate::Current();
4220 ON_BAILOUT(isolate, "v8::Array::CloneElementAt()", return Local<Object>());
3984 i::Handle<i::JSObject> self = Utils::OpenHandle(this); 4221 i::Handle<i::JSObject> self = Utils::OpenHandle(this);
3985 if (!self->HasFastElements()) { 4222 if (!self->HasFastElements()) {
3986 return Local<Object>(); 4223 return Local<Object>();
3987 } 4224 }
3988 i::FixedArray* elms = i::FixedArray::cast(self->elements()); 4225 i::FixedArray* elms = i::FixedArray::cast(self->elements());
3989 i::Object* paragon = elms->get(index); 4226 i::Object* paragon = elms->get(index);
3990 if (!paragon->IsJSObject()) { 4227 if (!paragon->IsJSObject()) {
3991 return Local<Object>(); 4228 return Local<Object>();
3992 } 4229 }
3993 i::Handle<i::JSObject> paragon_handle(i::JSObject::cast(paragon)); 4230 i::Handle<i::JSObject> paragon_handle(i::JSObject::cast(paragon));
3994 EXCEPTION_PREAMBLE(); 4231 EXCEPTION_PREAMBLE();
3995 ENTER_V8; 4232 ENTER_V8;
3996 i::Handle<i::JSObject> result = i::Copy(paragon_handle); 4233 i::Handle<i::JSObject> result = i::Copy(paragon_handle);
3997 has_pending_exception = result.is_null(); 4234 has_pending_exception = result.is_null();
3998 EXCEPTION_BAILOUT_CHECK(Local<Object>()); 4235 EXCEPTION_BAILOUT_CHECK(Local<Object>());
3999 return Utils::ToLocal(result); 4236 return Utils::ToLocal(result);
4000 } 4237 }
4001 4238
4002 4239
4003 Local<String> v8::String::NewSymbol(const char* data, int length) { 4240 Local<String> v8::String::NewSymbol(const char* data, int length) {
4004 EnsureInitialized("v8::String::NewSymbol()"); 4241 i::Isolate* isolate = i::Isolate::Current();
4005 LOG_API("String::NewSymbol(char)"); 4242 EnsureInitializedForIsolate(isolate, "v8::String::NewSymbol()");
4243 LOG_API(isolate, "String::NewSymbol(char)");
4006 ENTER_V8; 4244 ENTER_V8;
4007 if (length == -1) length = i::StrLength(data); 4245 if (length == -1) length = i::StrLength(data);
4008 i::Handle<i::String> result = 4246 i::Handle<i::String> result =
4009 i::Factory::LookupSymbol(i::Vector<const char>(data, length)); 4247 FACTORY->LookupSymbol(i::Vector<const char>(data, length));
4010 return Utils::ToLocal(result); 4248 return Utils::ToLocal(result);
4011 } 4249 }
4012 4250
4013 4251
4014 Local<Number> v8::Number::New(double value) { 4252 Local<Number> v8::Number::New(double value) {
4015 EnsureInitialized("v8::Number::New()"); 4253 i::Isolate* isolate = i::Isolate::Current();
4254 EnsureInitializedForIsolate(isolate, "v8::Number::New()");
4016 if (isnan(value)) { 4255 if (isnan(value)) {
4017 // Introduce only canonical NaN value into the VM, to avoid signaling NaNs. 4256 // Introduce only canonical NaN value into the VM, to avoid signaling NaNs.
4018 value = i::OS::nan_value(); 4257 value = i::OS::nan_value();
4019 } 4258 }
4020 ENTER_V8; 4259 ENTER_V8;
4021 i::Handle<i::Object> result = i::Factory::NewNumber(value); 4260 i::Handle<i::Object> result = isolate->factory()->NewNumber(value);
4022 return Utils::NumberToLocal(result); 4261 return Utils::NumberToLocal(result);
4023 } 4262 }
4024 4263
4025 4264
4026 Local<Integer> v8::Integer::New(int32_t value) { 4265 Local<Integer> v8::Integer::New(int32_t value) {
4027 EnsureInitialized("v8::Integer::New()"); 4266 i::Isolate* isolate = i::Isolate::UncheckedCurrent();
4267 EnsureInitializedForIsolate(isolate, "v8::Integer::New()");
4028 if (i::Smi::IsValid(value)) { 4268 if (i::Smi::IsValid(value)) {
4029 return Utils::IntegerToLocal(i::Handle<i::Object>(i::Smi::FromInt(value))); 4269 return Utils::IntegerToLocal(i::Handle<i::Object>(i::Smi::FromInt(value),
4270 isolate));
4030 } 4271 }
4031 ENTER_V8; 4272 ENTER_V8;
4032 i::Handle<i::Object> result = i::Factory::NewNumber(value); 4273 i::Handle<i::Object> result = isolate->factory()->NewNumber(value);
4033 return Utils::IntegerToLocal(result); 4274 return Utils::IntegerToLocal(result);
4034 } 4275 }
4035 4276
4036 4277
4037 Local<Integer> Integer::NewFromUnsigned(uint32_t value) { 4278 Local<Integer> Integer::NewFromUnsigned(uint32_t value) {
4038 bool fits_into_int32_t = (value & (1 << 31)) == 0; 4279 bool fits_into_int32_t = (value & (1 << 31)) == 0;
4039 if (fits_into_int32_t) { 4280 if (fits_into_int32_t) {
4040 return Integer::New(static_cast<int32_t>(value)); 4281 return Integer::New(static_cast<int32_t>(value));
4041 } 4282 }
4042 ENTER_V8; 4283 ENTER_V8;
4043 i::Handle<i::Object> result = i::Factory::NewNumber(value); 4284 i::Handle<i::Object> result = FACTORY->NewNumber(value);
4044 return Utils::IntegerToLocal(result); 4285 return Utils::IntegerToLocal(result);
4045 } 4286 }
4046 4287
4047 4288
4048 void V8::IgnoreOutOfMemoryException() { 4289 void V8::IgnoreOutOfMemoryException() {
4049 thread_local.set_ignore_out_of_memory(true); 4290 EnterIsolateIfNeeded()->handle_scope_implementer()->set_ignore_out_of_memory(
4291 true);
4050 } 4292 }
4051 4293
4052 4294
4053 bool V8::AddMessageListener(MessageCallback that, Handle<Value> data) { 4295 bool V8::AddMessageListener(MessageCallback that, Handle<Value> data) {
4054 EnsureInitialized("v8::V8::AddMessageListener()"); 4296 i::Isolate* isolate = i::Isolate::Current();
4055 ON_BAILOUT("v8::V8::AddMessageListener()", return false); 4297 EnsureInitializedForIsolate(isolate, "v8::V8::AddMessageListener()");
4298 ON_BAILOUT(isolate, "v8::V8::AddMessageListener()", return false);
4056 ENTER_V8; 4299 ENTER_V8;
4057 HandleScope scope; 4300 i::HandleScope scope(isolate);
4058 NeanderArray listeners(i::Factory::message_listeners()); 4301 NeanderArray listeners(isolate->factory()->message_listeners());
4059 NeanderObject obj(2); 4302 NeanderObject obj(2);
4060 obj.set(0, *i::Factory::NewProxy(FUNCTION_ADDR(that))); 4303 obj.set(0, *isolate->factory()->NewProxy(FUNCTION_ADDR(that)));
4061 obj.set(1, data.IsEmpty() ? 4304 obj.set(1, data.IsEmpty() ?
4062 i::Heap::undefined_value() : 4305 HEAP->undefined_value() :
4063 *Utils::OpenHandle(*data)); 4306 *Utils::OpenHandle(*data));
4064 listeners.add(obj.value()); 4307 listeners.add(obj.value());
4065 return true; 4308 return true;
4066 } 4309 }
4067 4310
4068 4311
4069 void V8::RemoveMessageListeners(MessageCallback that) { 4312 void V8::RemoveMessageListeners(MessageCallback that) {
4070 EnsureInitialized("v8::V8::RemoveMessageListener()"); 4313 i::Isolate* isolate = i::Isolate::Current();
4071 ON_BAILOUT("v8::V8::RemoveMessageListeners()", return); 4314 EnsureInitializedForIsolate(isolate, "v8::V8::RemoveMessageListener()");
4315 ON_BAILOUT(isolate, "v8::V8::RemoveMessageListeners()", return);
4072 ENTER_V8; 4316 ENTER_V8;
4073 HandleScope scope; 4317 i::HandleScope scope(isolate);
4074 NeanderArray listeners(i::Factory::message_listeners()); 4318 NeanderArray listeners(isolate->factory()->message_listeners());
4075 for (int i = 0; i < listeners.length(); i++) { 4319 for (int i = 0; i < listeners.length(); i++) {
4076 if (listeners.get(i)->IsUndefined()) continue; // skip deleted ones 4320 if (listeners.get(i)->IsUndefined()) continue; // skip deleted ones
4077 4321
4078 NeanderObject listener(i::JSObject::cast(listeners.get(i))); 4322 NeanderObject listener(i::JSObject::cast(listeners.get(i)));
4079 i::Handle<i::Proxy> callback_obj(i::Proxy::cast(listener.get(0))); 4323 i::Handle<i::Proxy> callback_obj(i::Proxy::cast(listener.get(0)));
4080 if (callback_obj->proxy() == FUNCTION_ADDR(that)) { 4324 if (callback_obj->proxy() == FUNCTION_ADDR(that)) {
4081 listeners.set(i, i::Heap::undefined_value()); 4325 listeners.set(i, HEAP->undefined_value());
4082 } 4326 }
4083 } 4327 }
4084 } 4328 }
4085 4329
4086 4330
4087 void V8::SetCaptureStackTraceForUncaughtExceptions( 4331 void V8::SetCaptureStackTraceForUncaughtExceptions(
4088 bool capture, 4332 bool capture,
4089 int frame_limit, 4333 int frame_limit,
4090 StackTrace::StackTraceOptions options) { 4334 StackTrace::StackTraceOptions options) {
4091 i::Top::SetCaptureStackTraceForUncaughtExceptions( 4335 i::Isolate::Current()->SetCaptureStackTraceForUncaughtExceptions(
4092 capture, 4336 capture,
4093 frame_limit, 4337 frame_limit,
4094 options); 4338 options);
4095 } 4339 }
4096 4340
4097 4341
4098 void V8::SetCounterFunction(CounterLookupCallback callback) { 4342 void V8::SetCounterFunction(CounterLookupCallback callback) {
4099 if (IsDeadCheck("v8::V8::SetCounterFunction()")) return; 4343 i::Isolate* isolate = i::Isolate::Current();
4100 i::StatsTable::SetCounterFunction(callback); 4344 if (IsDeadCheck(isolate, "v8::V8::SetCounterFunction()")) return;
4345 isolate->stats_table()->SetCounterFunction(callback);
4101 } 4346 }
4102 4347
4103 void V8::SetCreateHistogramFunction(CreateHistogramCallback callback) { 4348 void V8::SetCreateHistogramFunction(CreateHistogramCallback callback) {
4104 if (IsDeadCheck("v8::V8::SetCreateHistogramFunction()")) return; 4349 i::Isolate* isolate = i::Isolate::Current();
4105 i::StatsTable::SetCreateHistogramFunction(callback); 4350 if (IsDeadCheck(isolate, "v8::V8::SetCreateHistogramFunction()")) return;
4351 isolate->stats_table()->SetCreateHistogramFunction(callback);
4106 } 4352 }
4107 4353
4108 void V8::SetAddHistogramSampleFunction(AddHistogramSampleCallback callback) { 4354 void V8::SetAddHistogramSampleFunction(AddHistogramSampleCallback callback) {
4109 if (IsDeadCheck("v8::V8::SetAddHistogramSampleFunction()")) return; 4355 i::Isolate* isolate = i::Isolate::Current();
4110 i::StatsTable::SetAddHistogramSampleFunction(callback); 4356 if (IsDeadCheck(isolate, "v8::V8::SetAddHistogramSampleFunction()")) return;
4357 isolate->stats_table()->
4358 SetAddHistogramSampleFunction(callback);
4111 } 4359 }
4112 4360
4113 void V8::EnableSlidingStateWindow() { 4361 void V8::EnableSlidingStateWindow() {
4114 if (IsDeadCheck("v8::V8::EnableSlidingStateWindow()")) return; 4362 i::Isolate* isolate = i::Isolate::Current();
4115 i::Logger::EnableSlidingStateWindow(); 4363 if (IsDeadCheck(isolate, "v8::V8::EnableSlidingStateWindow()")) return;
4364 isolate->logger()->EnableSlidingStateWindow();
4116 } 4365 }
4117 4366
4118 4367
4119 void V8::SetFailedAccessCheckCallbackFunction( 4368 void V8::SetFailedAccessCheckCallbackFunction(
4120 FailedAccessCheckCallback callback) { 4369 FailedAccessCheckCallback callback) {
4121 if (IsDeadCheck("v8::V8::SetFailedAccessCheckCallbackFunction()")) return; 4370 i::Isolate* isolate = i::Isolate::Current();
4122 i::Top::SetFailedAccessCheckCallback(callback); 4371 if (IsDeadCheck(isolate, "v8::V8::SetFailedAccessCheckCallbackFunction()")) {
4372 return;
4373 }
4374 isolate->SetFailedAccessCheckCallback(callback);
4123 } 4375 }
4124 4376
4125
4126 void V8::AddObjectGroup(Persistent<Value>* objects, 4377 void V8::AddObjectGroup(Persistent<Value>* objects,
4127 size_t length, 4378 size_t length,
4128 RetainedObjectInfo* info) { 4379 RetainedObjectInfo* info) {
4129 if (IsDeadCheck("v8::V8::AddObjectGroup()")) return; 4380 i::Isolate* isolate = i::Isolate::Current();
4381 if (IsDeadCheck(isolate, "v8::V8::AddObjectGroup()")) return;
4130 STATIC_ASSERT(sizeof(Persistent<Value>) == sizeof(i::Object**)); 4382 STATIC_ASSERT(sizeof(Persistent<Value>) == sizeof(i::Object**));
4131 i::GlobalHandles::AddObjectGroup( 4383 isolate->global_handles()->AddObjectGroup(
4132 reinterpret_cast<i::Object***>(objects), length, info); 4384 reinterpret_cast<i::Object***>(objects), length, info);
4133 } 4385 }
4134 4386
4135 4387
4136 void V8::AddImplicitReferences(Persistent<Object> parent, 4388 void V8::AddImplicitReferences(Persistent<Object> parent,
4137 Persistent<Value>* children, 4389 Persistent<Value>* children,
4138 size_t length) { 4390 size_t length) {
4139 if (IsDeadCheck("v8::V8::AddImplicitReferences()")) return; 4391 i::Isolate* isolate = i::Isolate::Current();
4392 if (IsDeadCheck(isolate, "v8::V8::AddImplicitReferences()")) return;
4140 STATIC_ASSERT(sizeof(Persistent<Value>) == sizeof(i::Object**)); 4393 STATIC_ASSERT(sizeof(Persistent<Value>) == sizeof(i::Object**));
4141 i::GlobalHandles::AddImplicitReferences( 4394 isolate->global_handles()->AddImplicitReferences(
4142 *Utils::OpenHandle(*parent), 4395 *Utils::OpenHandle(*parent),
4143 reinterpret_cast<i::Object***>(children), length); 4396 reinterpret_cast<i::Object***>(children), length);
4144 } 4397 }
4145 4398
4146 4399
4147 int V8::AdjustAmountOfExternalAllocatedMemory(int change_in_bytes) { 4400 int V8::AdjustAmountOfExternalAllocatedMemory(int change_in_bytes) {
4148 if (IsDeadCheck("v8::V8::AdjustAmountOfExternalAllocatedMemory()")) return 0; 4401 i::Isolate* isolate = i::Isolate::Current();
4149 return i::Heap::AdjustAmountOfExternalAllocatedMemory(change_in_bytes); 4402 if (IsDeadCheck(isolate, "v8::V8::AdjustAmountOfExternalAllocatedMemory()")) {
4403 return 0;
4404 }
4405 return isolate->heap()->AdjustAmountOfExternalAllocatedMemory(
4406 change_in_bytes);
4150 } 4407 }
4151 4408
4152 4409
4153 void V8::SetGlobalGCPrologueCallback(GCCallback callback) { 4410 void V8::SetGlobalGCPrologueCallback(GCCallback callback) {
4154 if (IsDeadCheck("v8::V8::SetGlobalGCPrologueCallback()")) return; 4411 i::Isolate* isolate = i::Isolate::Current();
4155 i::Heap::SetGlobalGCPrologueCallback(callback); 4412 if (IsDeadCheck(isolate, "v8::V8::SetGlobalGCPrologueCallback()")) return;
4413 isolate->heap()->SetGlobalGCPrologueCallback(callback);
4156 } 4414 }
4157 4415
4158 4416
4159 void V8::SetGlobalGCEpilogueCallback(GCCallback callback) { 4417 void V8::SetGlobalGCEpilogueCallback(GCCallback callback) {
4160 if (IsDeadCheck("v8::V8::SetGlobalGCEpilogueCallback()")) return; 4418 i::Isolate* isolate = i::Isolate::Current();
4161 i::Heap::SetGlobalGCEpilogueCallback(callback); 4419 if (IsDeadCheck(isolate, "v8::V8::SetGlobalGCEpilogueCallback()")) return;
4420 isolate->heap()->SetGlobalGCEpilogueCallback(callback);
4162 } 4421 }
4163 4422
4164 4423
4165 void V8::AddGCPrologueCallback(GCPrologueCallback callback, GCType gc_type) { 4424 void V8::AddGCPrologueCallback(GCPrologueCallback callback, GCType gc_type) {
4166 if (IsDeadCheck("v8::V8::AddGCPrologueCallback()")) return; 4425 i::Isolate* isolate = i::Isolate::Current();
4167 i::Heap::AddGCPrologueCallback(callback, gc_type); 4426 if (IsDeadCheck(isolate, "v8::V8::AddGCPrologueCallback()")) return;
4427 isolate->heap()->AddGCPrologueCallback(callback, gc_type);
4168 } 4428 }
4169 4429
4170 4430
4171 void V8::RemoveGCPrologueCallback(GCPrologueCallback callback) { 4431 void V8::RemoveGCPrologueCallback(GCPrologueCallback callback) {
4172 if (IsDeadCheck("v8::V8::RemoveGCPrologueCallback()")) return; 4432 i::Isolate* isolate = i::Isolate::Current();
4173 i::Heap::RemoveGCPrologueCallback(callback); 4433 if (IsDeadCheck(isolate, "v8::V8::RemoveGCPrologueCallback()")) return;
4434 isolate->heap()->RemoveGCPrologueCallback(callback);
4174 } 4435 }
4175 4436
4176 4437
4177 void V8::AddGCEpilogueCallback(GCEpilogueCallback callback, GCType gc_type) { 4438 void V8::AddGCEpilogueCallback(GCEpilogueCallback callback, GCType gc_type) {
4178 if (IsDeadCheck("v8::V8::AddGCEpilogueCallback()")) return; 4439 i::Isolate* isolate = i::Isolate::Current();
4179 i::Heap::AddGCEpilogueCallback(callback, gc_type); 4440 if (IsDeadCheck(isolate, "v8::V8::AddGCEpilogueCallback()")) return;
4441 isolate->heap()->AddGCEpilogueCallback(callback, gc_type);
4180 } 4442 }
4181 4443
4182 4444
4183 void V8::RemoveGCEpilogueCallback(GCEpilogueCallback callback) { 4445 void V8::RemoveGCEpilogueCallback(GCEpilogueCallback callback) {
4184 if (IsDeadCheck("v8::V8::RemoveGCEpilogueCallback()")) return; 4446 i::Isolate* isolate = i::Isolate::Current();
4185 i::Heap::RemoveGCEpilogueCallback(callback); 4447 if (IsDeadCheck(isolate, "v8::V8::RemoveGCEpilogueCallback()")) return;
4448 isolate->heap()->RemoveGCEpilogueCallback(callback);
4186 } 4449 }
4187 4450
4188 4451
4189 void V8::AddMemoryAllocationCallback(MemoryAllocationCallback callback, 4452 void V8::AddMemoryAllocationCallback(MemoryAllocationCallback callback,
4190 ObjectSpace space, 4453 ObjectSpace space,
4191 AllocationAction action) { 4454 AllocationAction action) {
4192 if (IsDeadCheck("v8::V8::AddMemoryAllocationCallback()")) return; 4455 i::Isolate* isolate = i::Isolate::Current();
4193 i::MemoryAllocator::AddMemoryAllocationCallback(callback, 4456 if (IsDeadCheck(isolate, "v8::V8::AddMemoryAllocationCallback()")) return;
4194 space, 4457 isolate->memory_allocator()->AddMemoryAllocationCallback(
4195 action); 4458 callback, space, action);
4196 } 4459 }
4197 4460
4198 4461
4199 void V8::RemoveMemoryAllocationCallback(MemoryAllocationCallback callback) { 4462 void V8::RemoveMemoryAllocationCallback(MemoryAllocationCallback callback) {
4200 if (IsDeadCheck("v8::V8::RemoveMemoryAllocationCallback()")) return; 4463 i::Isolate* isolate = i::Isolate::Current();
4201 i::MemoryAllocator::RemoveMemoryAllocationCallback(callback); 4464 if (IsDeadCheck(isolate, "v8::V8::RemoveMemoryAllocationCallback()")) return;
4465 isolate->memory_allocator()->RemoveMemoryAllocationCallback(
4466 callback);
4202 } 4467 }
4203 4468
4204 4469
4205 void V8::PauseProfiler() { 4470 void V8::PauseProfiler() {
4206 #ifdef ENABLE_LOGGING_AND_PROFILING 4471 #ifdef ENABLE_LOGGING_AND_PROFILING
4207 PauseProfilerEx(PROFILER_MODULE_CPU); 4472 PauseProfilerEx(PROFILER_MODULE_CPU);
4208 #endif 4473 #endif
4209 } 4474 }
4210 4475
4211 4476
4212 void V8::ResumeProfiler() { 4477 void V8::ResumeProfiler() {
4213 #ifdef ENABLE_LOGGING_AND_PROFILING 4478 #ifdef ENABLE_LOGGING_AND_PROFILING
4214 ResumeProfilerEx(PROFILER_MODULE_CPU); 4479 ResumeProfilerEx(PROFILER_MODULE_CPU);
4215 #endif 4480 #endif
4216 } 4481 }
4217 4482
4218 4483
4219 bool V8::IsProfilerPaused() { 4484 bool V8::IsProfilerPaused() {
4220 #ifdef ENABLE_LOGGING_AND_PROFILING 4485 #ifdef ENABLE_LOGGING_AND_PROFILING
4221 return i::Logger::GetActiveProfilerModules() & PROFILER_MODULE_CPU; 4486 return LOGGER->GetActiveProfilerModules() & PROFILER_MODULE_CPU;
4222 #else 4487 #else
4223 return true; 4488 return true;
4224 #endif 4489 #endif
4225 } 4490 }
4226 4491
4227 4492
4228 void V8::ResumeProfilerEx(int flags, int tag) { 4493 void V8::ResumeProfilerEx(int flags, int tag) {
4229 #ifdef ENABLE_LOGGING_AND_PROFILING 4494 #ifdef ENABLE_LOGGING_AND_PROFILING
4230 if (flags & PROFILER_MODULE_HEAP_SNAPSHOT) { 4495 if (flags & PROFILER_MODULE_HEAP_SNAPSHOT) {
4231 // Snapshot mode: resume modules, perform GC, then pause only 4496 // Snapshot mode: resume modules, perform GC, then pause only
4232 // those modules which haven't been started prior to making a 4497 // those modules which haven't been started prior to making a
4233 // snapshot. 4498 // snapshot.
4234 4499
4235 // Make a GC prior to taking a snapshot. 4500 // Make a GC prior to taking a snapshot.
4236 i::Heap::CollectAllGarbage(false); 4501 HEAP->CollectAllGarbage(false);
4237 // Reset snapshot flag and CPU module flags. 4502 // Reset snapshot flag and CPU module flags.
4238 flags &= ~(PROFILER_MODULE_HEAP_SNAPSHOT | PROFILER_MODULE_CPU); 4503 flags &= ~(PROFILER_MODULE_HEAP_SNAPSHOT | PROFILER_MODULE_CPU);
4239 const int current_flags = i::Logger::GetActiveProfilerModules(); 4504 const int current_flags = LOGGER->GetActiveProfilerModules();
4240 i::Logger::ResumeProfiler(flags, tag); 4505 LOGGER->ResumeProfiler(flags, tag);
4241 i::Heap::CollectAllGarbage(false); 4506 HEAP->CollectAllGarbage(false);
4242 i::Logger::PauseProfiler(~current_flags & flags, tag); 4507 LOGGER->PauseProfiler(~current_flags & flags, tag);
4243 } else { 4508 } else {
4244 i::Logger::ResumeProfiler(flags, tag); 4509 LOGGER->ResumeProfiler(flags, tag);
4245 } 4510 }
4246 #endif 4511 #endif
4247 } 4512 }
4248 4513
4249 4514
4250 void V8::PauseProfilerEx(int flags, int tag) { 4515 void V8::PauseProfilerEx(int flags, int tag) {
4251 #ifdef ENABLE_LOGGING_AND_PROFILING 4516 #ifdef ENABLE_LOGGING_AND_PROFILING
4252 i::Logger::PauseProfiler(flags, tag); 4517 LOGGER->PauseProfiler(flags, tag);
4253 #endif 4518 #endif
4254 } 4519 }
4255 4520
4256 4521
4257 int V8::GetActiveProfilerModules() { 4522 int V8::GetActiveProfilerModules() {
4258 #ifdef ENABLE_LOGGING_AND_PROFILING 4523 #ifdef ENABLE_LOGGING_AND_PROFILING
4259 return i::Logger::GetActiveProfilerModules(); 4524 return LOGGER->GetActiveProfilerModules();
4260 #else 4525 #else
4261 return PROFILER_MODULE_NONE; 4526 return PROFILER_MODULE_NONE;
4262 #endif 4527 #endif
4263 } 4528 }
4264 4529
4265 4530
4266 int V8::GetLogLines(int from_pos, char* dest_buf, int max_size) { 4531 int V8::GetLogLines(int from_pos, char* dest_buf, int max_size) {
4267 #ifdef ENABLE_LOGGING_AND_PROFILING 4532 #ifdef ENABLE_LOGGING_AND_PROFILING
4268 ASSERT(max_size >= kMinimumSizeForLogLinesBuffer); 4533 ASSERT(max_size >= kMinimumSizeForLogLinesBuffer);
4269 return i::Logger::GetLogLines(from_pos, dest_buf, max_size); 4534 return LOGGER->GetLogLines(from_pos, dest_buf, max_size);
4270 #endif 4535 #endif
4271 return 0; 4536 return 0;
4272 } 4537 }
4273 4538
4274 4539
4275 int V8::GetCurrentThreadId() { 4540 int V8::GetCurrentThreadId() {
4276 API_ENTRY_CHECK("V8::GetCurrentThreadId()"); 4541 API_ENTRY_CHECK("V8::GetCurrentThreadId()");
4277 EnsureInitialized("V8::GetCurrentThreadId()"); 4542 EnsureInitialized("V8::GetCurrentThreadId()");
4278 return i::Top::thread_id(); 4543 return i::Isolate::Current()->thread_id();
4279 } 4544 }
4280 4545
4281 4546
4282 void V8::TerminateExecution(int thread_id) { 4547 void V8::TerminateExecution(int thread_id) {
4283 if (!i::V8::IsRunning()) return; 4548 if (!i::Isolate::Current()->IsInitialized()) return;
4284 API_ENTRY_CHECK("V8::GetCurrentThreadId()"); 4549 API_ENTRY_CHECK("V8::GetCurrentThreadId()");
4550 i::Isolate* isolate = i::Isolate::Current();
4285 // If the thread_id identifies the current thread just terminate 4551 // If the thread_id identifies the current thread just terminate
4286 // execution right away. Otherwise, ask the thread manager to 4552 // execution right away. Otherwise, ask the thread manager to
4287 // terminate the thread with the given id if any. 4553 // terminate the thread with the given id if any.
4288 if (thread_id == i::Top::thread_id()) { 4554 if (thread_id == isolate->thread_id()) {
4289 i::StackGuard::TerminateExecution(); 4555 isolate->stack_guard()->TerminateExecution();
4290 } else { 4556 } else {
4291 i::ThreadManager::TerminateExecution(thread_id); 4557 isolate->thread_manager()->TerminateExecution(thread_id);
4292 } 4558 }
4293 } 4559 }
4294 4560
4295 4561
4296 void V8::TerminateExecution() { 4562 void V8::TerminateExecution(Isolate* isolate) {
4297 if (!i::V8::IsRunning()) return; 4563 // If no isolate is supplied, use the default isolate.
4298 i::StackGuard::TerminateExecution(); 4564 if (isolate != NULL) {
4565 reinterpret_cast<i::Isolate*>(isolate)->stack_guard()->TerminateExecution();
4566 } else {
4567 i::Isolate::GetDefaultIsolateStackGuard()->TerminateExecution();
4568 }
4299 } 4569 }
4300 4570
4301 4571
4302 bool V8::IsExecutionTerminating() { 4572 bool V8::IsExecutionTerminating() {
4303 if (!i::V8::IsRunning()) return false; 4573 if (!i::Isolate::Current()->IsInitialized()) return false;
4304 if (i::Top::has_scheduled_exception()) { 4574 if (i::Isolate::Current()->has_scheduled_exception()) {
4305 return i::Top::scheduled_exception() == i::Heap::termination_exception(); 4575 return i::Isolate::Current()->scheduled_exception() ==
4576 HEAP->termination_exception();
4306 } 4577 }
4307 return false; 4578 return false;
4308 } 4579 }
4309 4580
4310 4581
4582 Isolate* Isolate::GetCurrent() {
4583 i::Isolate* isolate = i::Isolate::UncheckedCurrent();
4584 return reinterpret_cast<Isolate*>(isolate);
4585 }
4586
4587
4588 Isolate* Isolate::New() {
4589 i::Isolate* isolate = new i::Isolate();
4590 return reinterpret_cast<Isolate*>(isolate);
4591 }
4592
4593
4594 void Isolate::Dispose() {
4595 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
4596 if (!ApiCheck(!isolate->IsInUse(),
4597 "v8::Isolate::Dispose()",
4598 "Disposing the isolate that is entered by a thread.")) {
4599 return;
4600 }
4601 isolate->TearDown();
4602 }
4603
4604
4605 void Isolate::Enter() {
4606 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
4607 isolate->Enter();
4608 }
4609
4610
4611 void Isolate::Exit() {
4612 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
4613 isolate->Exit();
4614 }
4615
4616
4311 String::Utf8Value::Utf8Value(v8::Handle<v8::Value> obj) { 4617 String::Utf8Value::Utf8Value(v8::Handle<v8::Value> obj) {
4312 EnsureInitialized("v8::String::Utf8Value::Utf8Value()"); 4618 EnsureInitialized("v8::String::Utf8Value::Utf8Value()");
4313 if (obj.IsEmpty()) { 4619 if (obj.IsEmpty()) {
4314 str_ = NULL; 4620 str_ = NULL;
4315 length_ = 0; 4621 length_ = 0;
4316 return; 4622 return;
4317 } 4623 }
4318 ENTER_V8; 4624 ENTER_V8;
4319 HandleScope scope; 4625 HandleScope scope;
4320 TryCatch try_catch; 4626 TryCatch try_catch;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
4382 str->Write(str_); 4688 str->Write(str_);
4383 } 4689 }
4384 } 4690 }
4385 4691
4386 4692
4387 String::Value::~Value() { 4693 String::Value::~Value() {
4388 i::DeleteArray(str_); 4694 i::DeleteArray(str_);
4389 } 4695 }
4390 4696
4391 Local<Value> Exception::RangeError(v8::Handle<v8::String> raw_message) { 4697 Local<Value> Exception::RangeError(v8::Handle<v8::String> raw_message) {
4392 LOG_API("RangeError"); 4698 i::Isolate* isolate = i::Isolate::Current();
4393 ON_BAILOUT("v8::Exception::RangeError()", return Local<Value>()); 4699 LOG_API(isolate, "RangeError");
4700 ON_BAILOUT(isolate, "v8::Exception::RangeError()", return Local<Value>());
4394 ENTER_V8; 4701 ENTER_V8;
4395 i::Object* error; 4702 i::Object* error;
4396 { 4703 {
4397 HandleScope scope; 4704 i::HandleScope scope(isolate);
4398 i::Handle<i::String> message = Utils::OpenHandle(*raw_message); 4705 i::Handle<i::String> message = Utils::OpenHandle(*raw_message);
4399 i::Handle<i::Object> result = i::Factory::NewRangeError(message); 4706 i::Handle<i::Object> result = FACTORY->NewRangeError(message);
4400 error = *result; 4707 error = *result;
4401 } 4708 }
4402 i::Handle<i::Object> result(error); 4709 i::Handle<i::Object> result(error);
4403 return Utils::ToLocal(result); 4710 return Utils::ToLocal(result);
4404 } 4711 }
4405 4712
4406 Local<Value> Exception::ReferenceError(v8::Handle<v8::String> raw_message) { 4713 Local<Value> Exception::ReferenceError(v8::Handle<v8::String> raw_message) {
4407 LOG_API("ReferenceError"); 4714 i::Isolate* isolate = i::Isolate::Current();
4408 ON_BAILOUT("v8::Exception::ReferenceError()", return Local<Value>()); 4715 LOG_API(isolate, "ReferenceError");
4716 ON_BAILOUT(isolate, "v8::Exception::ReferenceError()", return Local<Value>());
4409 ENTER_V8; 4717 ENTER_V8;
4410 i::Object* error; 4718 i::Object* error;
4411 { 4719 {
4412 HandleScope scope; 4720 i::HandleScope scope(isolate);
4413 i::Handle<i::String> message = Utils::OpenHandle(*raw_message); 4721 i::Handle<i::String> message = Utils::OpenHandle(*raw_message);
4414 i::Handle<i::Object> result = i::Factory::NewReferenceError(message); 4722 i::Handle<i::Object> result = FACTORY->NewReferenceError(message);
4415 error = *result; 4723 error = *result;
4416 } 4724 }
4417 i::Handle<i::Object> result(error); 4725 i::Handle<i::Object> result(error);
4418 return Utils::ToLocal(result); 4726 return Utils::ToLocal(result);
4419 } 4727 }
4420 4728
4421 Local<Value> Exception::SyntaxError(v8::Handle<v8::String> raw_message) { 4729 Local<Value> Exception::SyntaxError(v8::Handle<v8::String> raw_message) {
4422 LOG_API("SyntaxError"); 4730 i::Isolate* isolate = i::Isolate::Current();
4423 ON_BAILOUT("v8::Exception::SyntaxError()", return Local<Value>()); 4731 LOG_API(isolate, "SyntaxError");
4732 ON_BAILOUT(isolate, "v8::Exception::SyntaxError()", return Local<Value>());
4424 ENTER_V8; 4733 ENTER_V8;
4425 i::Object* error; 4734 i::Object* error;
4426 { 4735 {
4427 HandleScope scope; 4736 i::HandleScope scope(isolate);
4428 i::Handle<i::String> message = Utils::OpenHandle(*raw_message); 4737 i::Handle<i::String> message = Utils::OpenHandle(*raw_message);
4429 i::Handle<i::Object> result = i::Factory::NewSyntaxError(message); 4738 i::Handle<i::Object> result = FACTORY->NewSyntaxError(message);
4430 error = *result; 4739 error = *result;
4431 } 4740 }
4432 i::Handle<i::Object> result(error); 4741 i::Handle<i::Object> result(error);
4433 return Utils::ToLocal(result); 4742 return Utils::ToLocal(result);
4434 } 4743 }
4435 4744
4436 Local<Value> Exception::TypeError(v8::Handle<v8::String> raw_message) { 4745 Local<Value> Exception::TypeError(v8::Handle<v8::String> raw_message) {
4437 LOG_API("TypeError"); 4746 i::Isolate* isolate = i::Isolate::Current();
4438 ON_BAILOUT("v8::Exception::TypeError()", return Local<Value>()); 4747 LOG_API(isolate, "TypeError");
4748 ON_BAILOUT(isolate, "v8::Exception::TypeError()", return Local<Value>());
4439 ENTER_V8; 4749 ENTER_V8;
4440 i::Object* error; 4750 i::Object* error;
4441 { 4751 {
4442 HandleScope scope; 4752 i::HandleScope scope(isolate);
4443 i::Handle<i::String> message = Utils::OpenHandle(*raw_message); 4753 i::Handle<i::String> message = Utils::OpenHandle(*raw_message);
4444 i::Handle<i::Object> result = i::Factory::NewTypeError(message); 4754 i::Handle<i::Object> result = FACTORY->NewTypeError(message);
4445 error = *result; 4755 error = *result;
4446 } 4756 }
4447 i::Handle<i::Object> result(error); 4757 i::Handle<i::Object> result(error);
4448 return Utils::ToLocal(result); 4758 return Utils::ToLocal(result);
4449 } 4759 }
4450 4760
4451 Local<Value> Exception::Error(v8::Handle<v8::String> raw_message) { 4761 Local<Value> Exception::Error(v8::Handle<v8::String> raw_message) {
4452 LOG_API("Error"); 4762 i::Isolate* isolate = i::Isolate::Current();
4453 ON_BAILOUT("v8::Exception::Error()", return Local<Value>()); 4763 LOG_API(isolate, "Error");
4764 ON_BAILOUT(isolate, "v8::Exception::Error()", return Local<Value>());
4454 ENTER_V8; 4765 ENTER_V8;
4455 i::Object* error; 4766 i::Object* error;
4456 { 4767 {
4457 HandleScope scope; 4768 i::HandleScope scope(isolate);
4458 i::Handle<i::String> message = Utils::OpenHandle(*raw_message); 4769 i::Handle<i::String> message = Utils::OpenHandle(*raw_message);
4459 i::Handle<i::Object> result = i::Factory::NewError(message); 4770 i::Handle<i::Object> result = FACTORY->NewError(message);
4460 error = *result; 4771 error = *result;
4461 } 4772 }
4462 i::Handle<i::Object> result(error); 4773 i::Handle<i::Object> result(error);
4463 return Utils::ToLocal(result); 4774 return Utils::ToLocal(result);
4464 } 4775 }
4465 4776
4466 4777
4467 // --- D e b u g S u p p o r t --- 4778 // --- D e b u g S u p p o r t ---
4468 4779
4469 #ifdef ENABLE_DEBUGGER_SUPPORT 4780 #ifdef ENABLE_DEBUGGER_SUPPORT
4470 4781
4471 static v8::Debug::EventCallback event_callback = NULL;
4472
4473 static void EventCallbackWrapper(const v8::Debug::EventDetails& event_details) { 4782 static void EventCallbackWrapper(const v8::Debug::EventDetails& event_details) {
4474 if (event_callback) { 4783 i::Isolate* isolate = i::Isolate::Current();
4475 event_callback(event_details.GetEvent(), 4784 if (isolate->debug_event_callback() != NULL) {
4476 event_details.GetExecutionState(), 4785 isolate->debug_event_callback()(event_details.GetEvent(),
4477 event_details.GetEventData(), 4786 event_details.GetExecutionState(),
4478 event_details.GetCallbackData()); 4787 event_details.GetEventData(),
4788 event_details.GetCallbackData());
4479 } 4789 }
4480 } 4790 }
4481 4791
4482 4792
4483 bool Debug::SetDebugEventListener(EventCallback that, Handle<Value> data) { 4793 bool Debug::SetDebugEventListener(EventCallback that, Handle<Value> data) {
4484 EnsureInitialized("v8::Debug::SetDebugEventListener()"); 4794 i::Isolate* isolate = i::Isolate::Current();
4485 ON_BAILOUT("v8::Debug::SetDebugEventListener()", return false); 4795 EnsureInitializedForIsolate(isolate, "v8::Debug::SetDebugEventListener()");
4796 ON_BAILOUT(isolate, "v8::Debug::SetDebugEventListener()", return false);
4486 ENTER_V8; 4797 ENTER_V8;
4487 4798
4488 event_callback = that; 4799 isolate->set_debug_event_callback(that);
4489 4800
4490 HandleScope scope; 4801 i::HandleScope scope(isolate);
4491 i::Handle<i::Object> proxy = i::Factory::undefined_value(); 4802 i::Handle<i::Object> proxy = isolate->factory()->undefined_value();
4492 if (that != NULL) { 4803 if (that != NULL) {
4493 proxy = i::Factory::NewProxy(FUNCTION_ADDR(EventCallbackWrapper)); 4804 proxy = isolate->factory()->NewProxy(FUNCTION_ADDR(EventCallbackWrapper));
4494 } 4805 }
4495 i::Debugger::SetEventListener(proxy, Utils::OpenHandle(*data)); 4806 isolate->debugger()->SetEventListener(proxy, Utils::OpenHandle(*data));
4496 return true; 4807 return true;
4497 } 4808 }
4498 4809
4499 4810
4500 bool Debug::SetDebugEventListener2(EventCallback2 that, Handle<Value> data) { 4811 bool Debug::SetDebugEventListener2(EventCallback2 that, Handle<Value> data) {
4501 EnsureInitialized("v8::Debug::SetDebugEventListener2()"); 4812 i::Isolate* isolate = i::Isolate::Current();
4502 ON_BAILOUT("v8::Debug::SetDebugEventListener2()", return false); 4813 EnsureInitializedForIsolate(isolate, "v8::Debug::SetDebugEventListener2()");
4814 ON_BAILOUT(isolate, "v8::Debug::SetDebugEventListener2()", return false);
4503 ENTER_V8; 4815 ENTER_V8;
4504 HandleScope scope; 4816 i::HandleScope scope(isolate);
4505 i::Handle<i::Object> proxy = i::Factory::undefined_value(); 4817 i::Handle<i::Object> proxy = isolate->factory()->undefined_value();
4506 if (that != NULL) { 4818 if (that != NULL) {
4507 proxy = i::Factory::NewProxy(FUNCTION_ADDR(that)); 4819 proxy = isolate->factory()->NewProxy(FUNCTION_ADDR(that));
4508 } 4820 }
4509 i::Debugger::SetEventListener(proxy, Utils::OpenHandle(*data)); 4821 isolate->debugger()->SetEventListener(proxy,
4822 Utils::OpenHandle(*data));
4510 return true; 4823 return true;
4511 } 4824 }
4512 4825
4513 4826
4514 bool Debug::SetDebugEventListener(v8::Handle<v8::Object> that, 4827 bool Debug::SetDebugEventListener(v8::Handle<v8::Object> that,
4515 Handle<Value> data) { 4828 Handle<Value> data) {
4516 ON_BAILOUT("v8::Debug::SetDebugEventListener()", return false); 4829 i::Isolate* isolate = i::Isolate::Current();
4830 ON_BAILOUT(isolate, "v8::Debug::SetDebugEventListener()", return false);
4517 ENTER_V8; 4831 ENTER_V8;
4518 i::Debugger::SetEventListener(Utils::OpenHandle(*that), 4832 isolate->debugger()->SetEventListener(Utils::OpenHandle(*that),
4519 Utils::OpenHandle(*data)); 4833 Utils::OpenHandle(*data));
4520 return true; 4834 return true;
4521 } 4835 }
4522 4836
4523 4837
4524 void Debug::DebugBreak() { 4838 void Debug::DebugBreak(Isolate* isolate) {
4525 if (!i::V8::IsRunning()) return; 4839 // If no isolate is supplied, use the default isolate.
4526 i::StackGuard::DebugBreak(); 4840 if (isolate != NULL) {
4841 reinterpret_cast<i::Isolate*>(isolate)->stack_guard()->DebugBreak();
4842 } else {
4843 i::Isolate::GetDefaultIsolateStackGuard()->DebugBreak();
4844 }
4527 } 4845 }
4528 4846
4529 4847
4530 void Debug::CancelDebugBreak() { 4848 void Debug::CancelDebugBreak(Isolate* isolate) {
4531 i::StackGuard::Continue(i::DEBUGBREAK); 4849 // If no isolate is supplied, use the default isolate.
4850 if (isolate != NULL) {
4851 i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
4852 internal_isolate->stack_guard()->Continue(i::DEBUGBREAK);
4853 } else {
4854 i::Isolate::GetDefaultIsolateStackGuard()->Continue(i::DEBUGBREAK);
4855 }
4532 } 4856 }
4533 4857
4534 4858
4535 void Debug::DebugBreakForCommand(ClientData* data) { 4859 void Debug::DebugBreakForCommand(ClientData* data, Isolate* isolate) {
4536 if (!i::V8::IsRunning()) return; 4860 // If no isolate is supplied, use the default isolate.
4537 i::Debugger::EnqueueDebugCommand(data); 4861 if (isolate != NULL) {
4862 i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
4863 internal_isolate->debugger()->EnqueueDebugCommand(data);
4864 } else {
4865 i::Isolate::GetDefaultIsolateDebugger()->EnqueueDebugCommand(data);
4866 }
4538 } 4867 }
4539 4868
4540 4869
4541 static v8::Debug::MessageHandler message_handler = NULL;
4542
4543 static void MessageHandlerWrapper(const v8::Debug::Message& message) { 4870 static void MessageHandlerWrapper(const v8::Debug::Message& message) {
4544 if (message_handler) { 4871 i::Isolate* isolate = i::Isolate::Current();
4872 if (isolate->message_handler()) {
4545 v8::String::Value json(message.GetJSON()); 4873 v8::String::Value json(message.GetJSON());
4546 message_handler(*json, json.length(), message.GetClientData()); 4874 (isolate->message_handler())(*json, json.length(), message.GetClientData());
4547 } 4875 }
4548 } 4876 }
4549 4877
4550 4878
4551 void Debug::SetMessageHandler(v8::Debug::MessageHandler handler, 4879 void Debug::SetMessageHandler(v8::Debug::MessageHandler handler,
4552 bool message_handler_thread) { 4880 bool message_handler_thread) {
4553 EnsureInitialized("v8::Debug::SetMessageHandler"); 4881 EnsureInitialized("v8::Debug::SetMessageHandler");
4554 ENTER_V8; 4882 ENTER_V8;
4883 i::Isolate* isolate = i::Isolate::Current();
4555 // Message handler thread not supported any more. Parameter temporally left in 4884 // Message handler thread not supported any more. Parameter temporally left in
4556 // the API for client compatability reasons. 4885 // the API for client compatability reasons.
4557 CHECK(!message_handler_thread); 4886 CHECK(!message_handler_thread);
4558 4887
4559 // TODO(sgjesse) support the old message handler API through a simple wrapper. 4888 // TODO(sgjesse) support the old message handler API through a simple wrapper.
4560 message_handler = handler; 4889 isolate->set_message_handler(handler);
4561 if (message_handler != NULL) { 4890 if (handler != NULL) {
4562 i::Debugger::SetMessageHandler(MessageHandlerWrapper); 4891 i::Isolate::Current()->debugger()->SetMessageHandler(MessageHandlerWrapper);
4563 } else { 4892 } else {
4564 i::Debugger::SetMessageHandler(NULL); 4893 i::Isolate::Current()->debugger()->SetMessageHandler(NULL);
4565 } 4894 }
4566 } 4895 }
4567 4896
4568 4897
4569 void Debug::SetMessageHandler2(v8::Debug::MessageHandler2 handler) { 4898 void Debug::SetMessageHandler2(v8::Debug::MessageHandler2 handler) {
4570 EnsureInitialized("v8::Debug::SetMessageHandler"); 4899 EnsureInitialized("v8::Debug::SetMessageHandler");
4571 ENTER_V8; 4900 ENTER_V8;
4572 i::Debugger::SetMessageHandler(handler); 4901 i::Isolate::Current()->debugger()->SetMessageHandler(handler);
4573 } 4902 }
4574 4903
4575 4904
4576 void Debug::SendCommand(const uint16_t* command, int length, 4905 void Debug::SendCommand(const uint16_t* command, int length,
4577 ClientData* client_data) { 4906 ClientData* client_data) {
4578 if (!i::V8::IsRunning()) return; 4907 if (!i::Isolate::Current()->IsInitialized()) return;
4579 i::Debugger::ProcessCommand(i::Vector<const uint16_t>(command, length), 4908 i::Isolate::Current()->debugger()->ProcessCommand(
4580 client_data); 4909 i::Vector<const uint16_t>(command, length), client_data);
4581 } 4910 }
4582 4911
4583 4912
4584 void Debug::SetHostDispatchHandler(HostDispatchHandler handler, 4913 void Debug::SetHostDispatchHandler(HostDispatchHandler handler,
4585 int period) { 4914 int period) {
4586 EnsureInitialized("v8::Debug::SetHostDispatchHandler"); 4915 EnsureInitialized("v8::Debug::SetHostDispatchHandler");
4587 ENTER_V8; 4916 ENTER_V8;
4588 i::Debugger::SetHostDispatchHandler(handler, period); 4917 i::Isolate::Current()->debugger()->SetHostDispatchHandler(handler, period);
4589 } 4918 }
4590 4919
4591 4920
4592 void Debug::SetDebugMessageDispatchHandler( 4921 void Debug::SetDebugMessageDispatchHandler(
4593 DebugMessageDispatchHandler handler, bool provide_locker) { 4922 DebugMessageDispatchHandler handler, bool provide_locker) {
4594 EnsureInitialized("v8::Debug::SetDebugMessageDispatchHandler"); 4923 EnsureInitialized("v8::Debug::SetDebugMessageDispatchHandler");
4595 ENTER_V8; 4924 ENTER_V8;
4596 i::Debugger::SetDebugMessageDispatchHandler(handler, provide_locker); 4925 i::Isolate::Current()->debugger()->SetDebugMessageDispatchHandler(
4926 handler, provide_locker);
4597 } 4927 }
4598 4928
4599 4929
4600 Local<Value> Debug::Call(v8::Handle<v8::Function> fun, 4930 Local<Value> Debug::Call(v8::Handle<v8::Function> fun,
4601 v8::Handle<v8::Value> data) { 4931 v8::Handle<v8::Value> data) {
4602 if (!i::V8::IsRunning()) return Local<Value>(); 4932 i::Isolate* isolate = i::Isolate::Current();
4603 ON_BAILOUT("v8::Debug::Call()", return Local<Value>()); 4933 if (!isolate->IsInitialized()) return Local<Value>();
4934 ON_BAILOUT(isolate, "v8::Debug::Call()", return Local<Value>());
4604 ENTER_V8; 4935 ENTER_V8;
4605 i::Handle<i::Object> result; 4936 i::Handle<i::Object> result;
4606 EXCEPTION_PREAMBLE(); 4937 EXCEPTION_PREAMBLE();
4607 if (data.IsEmpty()) { 4938 if (data.IsEmpty()) {
4608 result = i::Debugger::Call(Utils::OpenHandle(*fun), 4939 result =
4609 i::Factory::undefined_value(), 4940 i::Isolate::Current()->debugger()->Call(Utils::OpenHandle(*fun),
4610 &has_pending_exception); 4941 FACTORY->undefined_value(),
4942 &has_pending_exception);
4611 } else { 4943 } else {
4612 result = i::Debugger::Call(Utils::OpenHandle(*fun), 4944 result = i::Isolate::Current()->debugger()->Call(Utils::OpenHandle(*fun),
4613 Utils::OpenHandle(*data), 4945 Utils::OpenHandle(*data),
4614 &has_pending_exception); 4946 &has_pending_exception);
4615 } 4947 }
4616 EXCEPTION_BAILOUT_CHECK(Local<Value>()); 4948 EXCEPTION_BAILOUT_CHECK(Local<Value>());
4617 return Utils::ToLocal(result); 4949 return Utils::ToLocal(result);
4618 } 4950 }
4619 4951
4620 4952
4621 Local<Value> Debug::GetMirror(v8::Handle<v8::Value> obj) { 4953 Local<Value> Debug::GetMirror(v8::Handle<v8::Value> obj) {
4622 if (!i::V8::IsRunning()) return Local<Value>(); 4954 i::Isolate* isolate = i::Isolate::Current();
4623 ON_BAILOUT("v8::Debug::GetMirror()", return Local<Value>()); 4955 if (!isolate->IsInitialized()) return Local<Value>();
4956 ON_BAILOUT(isolate, "v8::Debug::GetMirror()", return Local<Value>());
4624 ENTER_V8; 4957 ENTER_V8;
4625 v8::HandleScope scope; 4958 v8::HandleScope scope;
4626 i::Debug::Load(); 4959 i::Debug* isolate_debug = i::Isolate::Current()->debug();
4627 i::Handle<i::JSObject> debug(i::Debug::debug_context()->global()); 4960 isolate_debug->Load();
4628 i::Handle<i::String> name = i::Factory::LookupAsciiSymbol("MakeMirror"); 4961 i::Handle<i::JSObject> debug(isolate_debug->debug_context()->global());
4962 i::Handle<i::String> name = FACTORY->LookupAsciiSymbol("MakeMirror");
4629 i::Handle<i::Object> fun_obj = i::GetProperty(debug, name); 4963 i::Handle<i::Object> fun_obj = i::GetProperty(debug, name);
4630 i::Handle<i::JSFunction> fun = i::Handle<i::JSFunction>::cast(fun_obj); 4964 i::Handle<i::JSFunction> fun = i::Handle<i::JSFunction>::cast(fun_obj);
4631 v8::Handle<v8::Function> v8_fun = Utils::ToLocal(fun); 4965 v8::Handle<v8::Function> v8_fun = Utils::ToLocal(fun);
4632 const int kArgc = 1; 4966 const int kArgc = 1;
4633 v8::Handle<v8::Value> argv[kArgc] = { obj }; 4967 v8::Handle<v8::Value> argv[kArgc] = { obj };
4634 EXCEPTION_PREAMBLE(); 4968 EXCEPTION_PREAMBLE();
4635 v8::Handle<v8::Value> result = v8_fun->Call(Utils::ToLocal(debug), 4969 v8::Handle<v8::Value> result = v8_fun->Call(Utils::ToLocal(debug),
4636 kArgc, 4970 kArgc,
4637 argv); 4971 argv);
4638 EXCEPTION_BAILOUT_CHECK(Local<Value>()); 4972 EXCEPTION_BAILOUT_CHECK(Local<Value>());
4639 return scope.Close(result); 4973 return scope.Close(result);
4640 } 4974 }
4641 4975
4642 4976
4643 bool Debug::EnableAgent(const char* name, int port, bool wait_for_connection) { 4977 bool Debug::EnableAgent(const char* name, int port, bool wait_for_connection) {
4644 return i::Debugger::StartAgent(name, port, wait_for_connection); 4978 return i::Isolate::Current()->debugger()->StartAgent(name, port,
4979 wait_for_connection);
4645 } 4980 }
4646 4981
4647 void Debug::ProcessDebugMessages() { 4982 void Debug::ProcessDebugMessages() {
4648 i::Execution::ProcessDebugMesssages(true); 4983 i::Execution::ProcessDebugMesssages(true);
4649 } 4984 }
4650 4985
4651 Local<Context> Debug::GetDebugContext() { 4986 Local<Context> Debug::GetDebugContext() {
4652 EnsureInitialized("v8::Debug::GetDebugContext()"); 4987 EnsureInitialized("v8::Debug::GetDebugContext()");
4653 ENTER_V8; 4988 ENTER_V8;
4654 return Utils::ToLocal(i::Debugger::GetDebugContext()); 4989 return Utils::ToLocal(i::Isolate::Current()->debugger()->GetDebugContext());
4655 } 4990 }
4656 4991
4657 #endif // ENABLE_DEBUGGER_SUPPORT 4992 #endif // ENABLE_DEBUGGER_SUPPORT
4658 4993
4659 4994
4660 #ifdef ENABLE_LOGGING_AND_PROFILING 4995 #ifdef ENABLE_LOGGING_AND_PROFILING
4661 4996
4662 Handle<String> CpuProfileNode::GetFunctionName() const { 4997 Handle<String> CpuProfileNode::GetFunctionName() const {
4663 IsDeadCheck("v8::CpuProfileNode::GetFunctionName"); 4998 i::Isolate* isolate = i::Isolate::Current();
4999 IsDeadCheck(isolate, "v8::CpuProfileNode::GetFunctionName");
4664 const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this); 5000 const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this);
4665 const i::CodeEntry* entry = node->entry(); 5001 const i::CodeEntry* entry = node->entry();
4666 if (!entry->has_name_prefix()) { 5002 if (!entry->has_name_prefix()) {
4667 return Handle<String>(ToApi<String>( 5003 return Handle<String>(ToApi<String>(
4668 i::Factory::LookupAsciiSymbol(entry->name()))); 5004 isolate->factory()->LookupAsciiSymbol(entry->name())));
4669 } else { 5005 } else {
4670 return Handle<String>(ToApi<String>(i::Factory::NewConsString( 5006 return Handle<String>(ToApi<String>(isolate->factory()->NewConsString(
4671 i::Factory::LookupAsciiSymbol(entry->name_prefix()), 5007 isolate->factory()->LookupAsciiSymbol(entry->name_prefix()),
4672 i::Factory::LookupAsciiSymbol(entry->name())))); 5008 isolate->factory()->LookupAsciiSymbol(entry->name()))));
4673 } 5009 }
4674 } 5010 }
4675 5011
4676 5012
4677 Handle<String> CpuProfileNode::GetScriptResourceName() const { 5013 Handle<String> CpuProfileNode::GetScriptResourceName() const {
4678 IsDeadCheck("v8::CpuProfileNode::GetScriptResourceName"); 5014 i::Isolate* isolate = i::Isolate::Current();
5015 IsDeadCheck(isolate, "v8::CpuProfileNode::GetScriptResourceName");
4679 const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this); 5016 const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this);
4680 return Handle<String>(ToApi<String>(i::Factory::LookupAsciiSymbol( 5017 return Handle<String>(ToApi<String>(FACTORY->LookupAsciiSymbol(
4681 node->entry()->resource_name()))); 5018 node->entry()->resource_name())));
4682 } 5019 }
4683 5020
4684 5021
4685 int CpuProfileNode::GetLineNumber() const { 5022 int CpuProfileNode::GetLineNumber() const {
4686 IsDeadCheck("v8::CpuProfileNode::GetLineNumber"); 5023 i::Isolate* isolate = i::Isolate::Current();
5024 IsDeadCheck(isolate, "v8::CpuProfileNode::GetLineNumber");
4687 return reinterpret_cast<const i::ProfileNode*>(this)->entry()->line_number(); 5025 return reinterpret_cast<const i::ProfileNode*>(this)->entry()->line_number();
4688 } 5026 }
4689 5027
4690 5028
4691 double CpuProfileNode::GetTotalTime() const { 5029 double CpuProfileNode::GetTotalTime() const {
4692 IsDeadCheck("v8::CpuProfileNode::GetTotalTime"); 5030 i::Isolate* isolate = i::Isolate::Current();
5031 IsDeadCheck(isolate, "v8::CpuProfileNode::GetTotalTime");
4693 return reinterpret_cast<const i::ProfileNode*>(this)->GetTotalMillis(); 5032 return reinterpret_cast<const i::ProfileNode*>(this)->GetTotalMillis();
4694 } 5033 }
4695 5034
4696 5035
4697 double CpuProfileNode::GetSelfTime() const { 5036 double CpuProfileNode::GetSelfTime() const {
4698 IsDeadCheck("v8::CpuProfileNode::GetSelfTime"); 5037 i::Isolate* isolate = i::Isolate::Current();
5038 IsDeadCheck(isolate, "v8::CpuProfileNode::GetSelfTime");
4699 return reinterpret_cast<const i::ProfileNode*>(this)->GetSelfMillis(); 5039 return reinterpret_cast<const i::ProfileNode*>(this)->GetSelfMillis();
4700 } 5040 }
4701 5041
4702 5042
4703 double CpuProfileNode::GetTotalSamplesCount() const { 5043 double CpuProfileNode::GetTotalSamplesCount() const {
4704 IsDeadCheck("v8::CpuProfileNode::GetTotalSamplesCount"); 5044 i::Isolate* isolate = i::Isolate::Current();
5045 IsDeadCheck(isolate, "v8::CpuProfileNode::GetTotalSamplesCount");
4705 return reinterpret_cast<const i::ProfileNode*>(this)->total_ticks(); 5046 return reinterpret_cast<const i::ProfileNode*>(this)->total_ticks();
4706 } 5047 }
4707 5048
4708 5049
4709 double CpuProfileNode::GetSelfSamplesCount() const { 5050 double CpuProfileNode::GetSelfSamplesCount() const {
4710 IsDeadCheck("v8::CpuProfileNode::GetSelfSamplesCount"); 5051 i::Isolate* isolate = i::Isolate::Current();
5052 IsDeadCheck(isolate, "v8::CpuProfileNode::GetSelfSamplesCount");
4711 return reinterpret_cast<const i::ProfileNode*>(this)->self_ticks(); 5053 return reinterpret_cast<const i::ProfileNode*>(this)->self_ticks();
4712 } 5054 }
4713 5055
4714 5056
4715 unsigned CpuProfileNode::GetCallUid() const { 5057 unsigned CpuProfileNode::GetCallUid() const {
4716 IsDeadCheck("v8::CpuProfileNode::GetCallUid"); 5058 i::Isolate* isolate = i::Isolate::Current();
5059 IsDeadCheck(isolate, "v8::CpuProfileNode::GetCallUid");
4717 return reinterpret_cast<const i::ProfileNode*>(this)->entry()->GetCallUid(); 5060 return reinterpret_cast<const i::ProfileNode*>(this)->entry()->GetCallUid();
4718 } 5061 }
4719 5062
4720 5063
4721 int CpuProfileNode::GetChildrenCount() const { 5064 int CpuProfileNode::GetChildrenCount() const {
4722 IsDeadCheck("v8::CpuProfileNode::GetChildrenCount"); 5065 i::Isolate* isolate = i::Isolate::Current();
5066 IsDeadCheck(isolate, "v8::CpuProfileNode::GetChildrenCount");
4723 return reinterpret_cast<const i::ProfileNode*>(this)->children()->length(); 5067 return reinterpret_cast<const i::ProfileNode*>(this)->children()->length();
4724 } 5068 }
4725 5069
4726 5070
4727 const CpuProfileNode* CpuProfileNode::GetChild(int index) const { 5071 const CpuProfileNode* CpuProfileNode::GetChild(int index) const {
4728 IsDeadCheck("v8::CpuProfileNode::GetChild"); 5072 i::Isolate* isolate = i::Isolate::Current();
5073 IsDeadCheck(isolate, "v8::CpuProfileNode::GetChild");
4729 const i::ProfileNode* child = 5074 const i::ProfileNode* child =
4730 reinterpret_cast<const i::ProfileNode*>(this)->children()->at(index); 5075 reinterpret_cast<const i::ProfileNode*>(this)->children()->at(index);
4731 return reinterpret_cast<const CpuProfileNode*>(child); 5076 return reinterpret_cast<const CpuProfileNode*>(child);
4732 } 5077 }
4733 5078
4734 5079
4735 unsigned CpuProfile::GetUid() const { 5080 unsigned CpuProfile::GetUid() const {
4736 IsDeadCheck("v8::CpuProfile::GetUid"); 5081 i::Isolate* isolate = i::Isolate::Current();
5082 IsDeadCheck(isolate, "v8::CpuProfile::GetUid");
4737 return reinterpret_cast<const i::CpuProfile*>(this)->uid(); 5083 return reinterpret_cast<const i::CpuProfile*>(this)->uid();
4738 } 5084 }
4739 5085
4740 5086
4741 Handle<String> CpuProfile::GetTitle() const { 5087 Handle<String> CpuProfile::GetTitle() const {
4742 IsDeadCheck("v8::CpuProfile::GetTitle"); 5088 i::Isolate* isolate = i::Isolate::Current();
5089 IsDeadCheck(isolate, "v8::CpuProfile::GetTitle");
4743 const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this); 5090 const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this);
4744 return Handle<String>(ToApi<String>(i::Factory::LookupAsciiSymbol( 5091 return Handle<String>(ToApi<String>(FACTORY->LookupAsciiSymbol(
4745 profile->title()))); 5092 profile->title())));
4746 } 5093 }
4747 5094
4748 5095
4749 const CpuProfileNode* CpuProfile::GetBottomUpRoot() const { 5096 const CpuProfileNode* CpuProfile::GetBottomUpRoot() const {
4750 IsDeadCheck("v8::CpuProfile::GetBottomUpRoot"); 5097 i::Isolate* isolate = i::Isolate::Current();
5098 IsDeadCheck(isolate, "v8::CpuProfile::GetBottomUpRoot");
4751 const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this); 5099 const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this);
4752 return reinterpret_cast<const CpuProfileNode*>(profile->bottom_up()->root()); 5100 return reinterpret_cast<const CpuProfileNode*>(profile->bottom_up()->root());
4753 } 5101 }
4754 5102
4755 5103
4756 const CpuProfileNode* CpuProfile::GetTopDownRoot() const { 5104 const CpuProfileNode* CpuProfile::GetTopDownRoot() const {
4757 IsDeadCheck("v8::CpuProfile::GetTopDownRoot"); 5105 i::Isolate* isolate = i::Isolate::Current();
5106 IsDeadCheck(isolate, "v8::CpuProfile::GetTopDownRoot");
4758 const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this); 5107 const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this);
4759 return reinterpret_cast<const CpuProfileNode*>(profile->top_down()->root()); 5108 return reinterpret_cast<const CpuProfileNode*>(profile->top_down()->root());
4760 } 5109 }
4761 5110
4762 5111
4763 int CpuProfiler::GetProfilesCount() { 5112 int CpuProfiler::GetProfilesCount() {
4764 IsDeadCheck("v8::CpuProfiler::GetProfilesCount"); 5113 i::Isolate* isolate = i::Isolate::Current();
5114 IsDeadCheck(isolate, "v8::CpuProfiler::GetProfilesCount");
4765 return i::CpuProfiler::GetProfilesCount(); 5115 return i::CpuProfiler::GetProfilesCount();
4766 } 5116 }
4767 5117
4768 5118
4769 const CpuProfile* CpuProfiler::GetProfile(int index, 5119 const CpuProfile* CpuProfiler::GetProfile(int index,
4770 Handle<Value> security_token) { 5120 Handle<Value> security_token) {
4771 IsDeadCheck("v8::CpuProfiler::GetProfile"); 5121 i::Isolate* isolate = i::Isolate::Current();
5122 IsDeadCheck(isolate, "v8::CpuProfiler::GetProfile");
4772 return reinterpret_cast<const CpuProfile*>( 5123 return reinterpret_cast<const CpuProfile*>(
4773 i::CpuProfiler::GetProfile( 5124 i::CpuProfiler::GetProfile(
4774 security_token.IsEmpty() ? NULL : *Utils::OpenHandle(*security_token), 5125 security_token.IsEmpty() ? NULL : *Utils::OpenHandle(*security_token),
4775 index)); 5126 index));
4776 } 5127 }
4777 5128
4778 5129
4779 const CpuProfile* CpuProfiler::FindProfile(unsigned uid, 5130 const CpuProfile* CpuProfiler::FindProfile(unsigned uid,
4780 Handle<Value> security_token) { 5131 Handle<Value> security_token) {
4781 IsDeadCheck("v8::CpuProfiler::FindProfile"); 5132 i::Isolate* isolate = i::Isolate::Current();
5133 IsDeadCheck(isolate, "v8::CpuProfiler::FindProfile");
4782 return reinterpret_cast<const CpuProfile*>( 5134 return reinterpret_cast<const CpuProfile*>(
4783 i::CpuProfiler::FindProfile( 5135 i::CpuProfiler::FindProfile(
4784 security_token.IsEmpty() ? NULL : *Utils::OpenHandle(*security_token), 5136 security_token.IsEmpty() ? NULL : *Utils::OpenHandle(*security_token),
4785 uid)); 5137 uid));
4786 } 5138 }
4787 5139
4788 5140
4789 void CpuProfiler::StartProfiling(Handle<String> title) { 5141 void CpuProfiler::StartProfiling(Handle<String> title) {
4790 IsDeadCheck("v8::CpuProfiler::StartProfiling"); 5142 i::Isolate* isolate = i::Isolate::Current();
5143 IsDeadCheck(isolate, "v8::CpuProfiler::StartProfiling");
4791 i::CpuProfiler::StartProfiling(*Utils::OpenHandle(*title)); 5144 i::CpuProfiler::StartProfiling(*Utils::OpenHandle(*title));
4792 } 5145 }
4793 5146
4794 5147
4795 const CpuProfile* CpuProfiler::StopProfiling(Handle<String> title, 5148 const CpuProfile* CpuProfiler::StopProfiling(Handle<String> title,
4796 Handle<Value> security_token) { 5149 Handle<Value> security_token) {
4797 IsDeadCheck("v8::CpuProfiler::StopProfiling"); 5150 i::Isolate* isolate = i::Isolate::Current();
5151 IsDeadCheck(isolate, "v8::CpuProfiler::StopProfiling");
4798 return reinterpret_cast<const CpuProfile*>( 5152 return reinterpret_cast<const CpuProfile*>(
4799 i::CpuProfiler::StopProfiling( 5153 i::CpuProfiler::StopProfiling(
4800 security_token.IsEmpty() ? NULL : *Utils::OpenHandle(*security_token), 5154 security_token.IsEmpty() ? NULL : *Utils::OpenHandle(*security_token),
4801 *Utils::OpenHandle(*title))); 5155 *Utils::OpenHandle(*title)));
4802 } 5156 }
4803 5157
4804 5158
4805 static i::HeapGraphEdge* ToInternal(const HeapGraphEdge* edge) { 5159 static i::HeapGraphEdge* ToInternal(const HeapGraphEdge* edge) {
4806 return const_cast<i::HeapGraphEdge*>( 5160 return const_cast<i::HeapGraphEdge*>(
4807 reinterpret_cast<const i::HeapGraphEdge*>(edge)); 5161 reinterpret_cast<const i::HeapGraphEdge*>(edge));
4808 } 5162 }
4809 5163
4810 HeapGraphEdge::Type HeapGraphEdge::GetType() const { 5164 HeapGraphEdge::Type HeapGraphEdge::GetType() const {
4811 IsDeadCheck("v8::HeapGraphEdge::GetType"); 5165 i::Isolate* isolate = i::Isolate::Current();
5166 IsDeadCheck(isolate, "v8::HeapGraphEdge::GetType");
4812 return static_cast<HeapGraphEdge::Type>(ToInternal(this)->type()); 5167 return static_cast<HeapGraphEdge::Type>(ToInternal(this)->type());
4813 } 5168 }
4814 5169
4815 5170
4816 Handle<Value> HeapGraphEdge::GetName() const { 5171 Handle<Value> HeapGraphEdge::GetName() const {
4817 IsDeadCheck("v8::HeapGraphEdge::GetName"); 5172 i::Isolate* isolate = i::Isolate::Current();
5173 IsDeadCheck(isolate, "v8::HeapGraphEdge::GetName");
4818 i::HeapGraphEdge* edge = ToInternal(this); 5174 i::HeapGraphEdge* edge = ToInternal(this);
4819 switch (edge->type()) { 5175 switch (edge->type()) {
4820 case i::HeapGraphEdge::kContextVariable: 5176 case i::HeapGraphEdge::kContextVariable:
4821 case i::HeapGraphEdge::kInternal: 5177 case i::HeapGraphEdge::kInternal:
4822 case i::HeapGraphEdge::kProperty: 5178 case i::HeapGraphEdge::kProperty:
4823 case i::HeapGraphEdge::kShortcut: 5179 case i::HeapGraphEdge::kShortcut:
4824 return Handle<String>(ToApi<String>(i::Factory::LookupAsciiSymbol( 5180 return Handle<String>(ToApi<String>(FACTORY->LookupAsciiSymbol(
4825 edge->name()))); 5181 edge->name())));
4826 case i::HeapGraphEdge::kElement: 5182 case i::HeapGraphEdge::kElement:
4827 case i::HeapGraphEdge::kHidden: 5183 case i::HeapGraphEdge::kHidden:
4828 return Handle<Number>(ToApi<Number>(i::Factory::NewNumberFromInt( 5184 return Handle<Number>(ToApi<Number>(FACTORY->NewNumberFromInt(
4829 edge->index()))); 5185 edge->index())));
4830 default: UNREACHABLE(); 5186 default: UNREACHABLE();
4831 } 5187 }
4832 return ImplementationUtilities::Undefined(); 5188 return ImplementationUtilities::Undefined();
4833 } 5189 }
4834 5190
4835 5191
4836 const HeapGraphNode* HeapGraphEdge::GetFromNode() const { 5192 const HeapGraphNode* HeapGraphEdge::GetFromNode() const {
4837 IsDeadCheck("v8::HeapGraphEdge::GetFromNode"); 5193 i::Isolate* isolate = i::Isolate::Current();
5194 IsDeadCheck(isolate, "v8::HeapGraphEdge::GetFromNode");
4838 const i::HeapEntry* from = ToInternal(this)->From(); 5195 const i::HeapEntry* from = ToInternal(this)->From();
4839 return reinterpret_cast<const HeapGraphNode*>(from); 5196 return reinterpret_cast<const HeapGraphNode*>(from);
4840 } 5197 }
4841 5198
4842 5199
4843 const HeapGraphNode* HeapGraphEdge::GetToNode() const { 5200 const HeapGraphNode* HeapGraphEdge::GetToNode() const {
4844 IsDeadCheck("v8::HeapGraphEdge::GetToNode"); 5201 i::Isolate* isolate = i::Isolate::Current();
5202 IsDeadCheck(isolate, "v8::HeapGraphEdge::GetToNode");
4845 const i::HeapEntry* to = ToInternal(this)->to(); 5203 const i::HeapEntry* to = ToInternal(this)->to();
4846 return reinterpret_cast<const HeapGraphNode*>(to); 5204 return reinterpret_cast<const HeapGraphNode*>(to);
4847 } 5205 }
4848 5206
4849 5207
4850 static i::HeapGraphPath* ToInternal(const HeapGraphPath* path) { 5208 static i::HeapGraphPath* ToInternal(const HeapGraphPath* path) {
4851 return const_cast<i::HeapGraphPath*>( 5209 return const_cast<i::HeapGraphPath*>(
4852 reinterpret_cast<const i::HeapGraphPath*>(path)); 5210 reinterpret_cast<const i::HeapGraphPath*>(path));
4853 } 5211 }
4854 5212
(...skipping 20 matching lines...) Expand all
4875 } 5233 }
4876 5234
4877 5235
4878 static i::HeapEntry* ToInternal(const HeapGraphNode* entry) { 5236 static i::HeapEntry* ToInternal(const HeapGraphNode* entry) {
4879 return const_cast<i::HeapEntry*>( 5237 return const_cast<i::HeapEntry*>(
4880 reinterpret_cast<const i::HeapEntry*>(entry)); 5238 reinterpret_cast<const i::HeapEntry*>(entry));
4881 } 5239 }
4882 5240
4883 5241
4884 HeapGraphNode::Type HeapGraphNode::GetType() const { 5242 HeapGraphNode::Type HeapGraphNode::GetType() const {
4885 IsDeadCheck("v8::HeapGraphNode::GetType"); 5243 i::Isolate* isolate = i::Isolate::Current();
5244 IsDeadCheck(isolate, "v8::HeapGraphNode::GetType");
4886 return static_cast<HeapGraphNode::Type>(ToInternal(this)->type()); 5245 return static_cast<HeapGraphNode::Type>(ToInternal(this)->type());
4887 } 5246 }
4888 5247
4889 5248
4890 Handle<String> HeapGraphNode::GetName() const { 5249 Handle<String> HeapGraphNode::GetName() const {
4891 IsDeadCheck("v8::HeapGraphNode::GetName"); 5250 i::Isolate* isolate = i::Isolate::Current();
4892 return Handle<String>(ToApi<String>(i::Factory::LookupAsciiSymbol( 5251 IsDeadCheck(isolate, "v8::HeapGraphNode::GetName");
5252 return Handle<String>(ToApi<String>(FACTORY->LookupAsciiSymbol(
4893 ToInternal(this)->name()))); 5253 ToInternal(this)->name())));
4894 } 5254 }
4895 5255
4896 5256
4897 uint64_t HeapGraphNode::GetId() const { 5257 uint64_t HeapGraphNode::GetId() const {
4898 IsDeadCheck("v8::HeapGraphNode::GetId"); 5258 i::Isolate* isolate = i::Isolate::Current();
5259 IsDeadCheck(isolate, "v8::HeapGraphNode::GetId");
4899 ASSERT(ToInternal(this)->snapshot()->type() != i::HeapSnapshot::kAggregated); 5260 ASSERT(ToInternal(this)->snapshot()->type() != i::HeapSnapshot::kAggregated);
4900 return ToInternal(this)->id(); 5261 return ToInternal(this)->id();
4901 } 5262 }
4902 5263
4903 5264
4904 int HeapGraphNode::GetInstancesCount() const { 5265 int HeapGraphNode::GetInstancesCount() const {
4905 IsDeadCheck("v8::HeapGraphNode::GetInstancesCount"); 5266 i::Isolate* isolate = i::Isolate::Current();
5267 IsDeadCheck(isolate, "v8::HeapGraphNode::GetInstancesCount");
4906 ASSERT(ToInternal(this)->snapshot()->type() == i::HeapSnapshot::kAggregated); 5268 ASSERT(ToInternal(this)->snapshot()->type() == i::HeapSnapshot::kAggregated);
4907 return static_cast<int>(ToInternal(this)->id()); 5269 return static_cast<int>(ToInternal(this)->id());
4908 } 5270 }
4909 5271
4910 5272
4911 int HeapGraphNode::GetSelfSize() const { 5273 int HeapGraphNode::GetSelfSize() const {
4912 IsDeadCheck("v8::HeapGraphNode::GetSelfSize"); 5274 i::Isolate* isolate = i::Isolate::Current();
5275 IsDeadCheck(isolate, "v8::HeapGraphNode::GetSelfSize");
4913 return ToInternal(this)->self_size(); 5276 return ToInternal(this)->self_size();
4914 } 5277 }
4915 5278
4916 5279
4917 int HeapGraphNode::GetRetainedSize(bool exact) const { 5280 int HeapGraphNode::GetRetainedSize(bool exact) const {
4918 IsDeadCheck("v8::HeapSnapshot::GetRetainedSize"); 5281 i::Isolate* isolate = i::Isolate::Current();
5282 IsDeadCheck(isolate, "v8::HeapSnapshot::GetRetainedSize");
4919 return ToInternal(this)->RetainedSize(exact); 5283 return ToInternal(this)->RetainedSize(exact);
4920 } 5284 }
4921 5285
4922 5286
4923 int HeapGraphNode::GetChildrenCount() const { 5287 int HeapGraphNode::GetChildrenCount() const {
4924 IsDeadCheck("v8::HeapSnapshot::GetChildrenCount"); 5288 i::Isolate* isolate = i::Isolate::Current();
5289 IsDeadCheck(isolate, "v8::HeapSnapshot::GetChildrenCount");
4925 return ToInternal(this)->children().length(); 5290 return ToInternal(this)->children().length();
4926 } 5291 }
4927 5292
4928 5293
4929 const HeapGraphEdge* HeapGraphNode::GetChild(int index) const { 5294 const HeapGraphEdge* HeapGraphNode::GetChild(int index) const {
4930 IsDeadCheck("v8::HeapSnapshot::GetChild"); 5295 i::Isolate* isolate = i::Isolate::Current();
5296 IsDeadCheck(isolate, "v8::HeapSnapshot::GetChild");
4931 return reinterpret_cast<const HeapGraphEdge*>( 5297 return reinterpret_cast<const HeapGraphEdge*>(
4932 &ToInternal(this)->children()[index]); 5298 &ToInternal(this)->children()[index]);
4933 } 5299 }
4934 5300
4935 5301
4936 int HeapGraphNode::GetRetainersCount() const { 5302 int HeapGraphNode::GetRetainersCount() const {
4937 IsDeadCheck("v8::HeapSnapshot::GetRetainersCount"); 5303 i::Isolate* isolate = i::Isolate::Current();
5304 IsDeadCheck(isolate, "v8::HeapSnapshot::GetRetainersCount");
4938 return ToInternal(this)->retainers().length(); 5305 return ToInternal(this)->retainers().length();
4939 } 5306 }
4940 5307
4941 5308
4942 const HeapGraphEdge* HeapGraphNode::GetRetainer(int index) const { 5309 const HeapGraphEdge* HeapGraphNode::GetRetainer(int index) const {
4943 IsDeadCheck("v8::HeapSnapshot::GetRetainer"); 5310 i::Isolate* isolate = i::Isolate::Current();
5311 IsDeadCheck(isolate, "v8::HeapSnapshot::GetRetainer");
4944 return reinterpret_cast<const HeapGraphEdge*>( 5312 return reinterpret_cast<const HeapGraphEdge*>(
4945 ToInternal(this)->retainers()[index]); 5313 ToInternal(this)->retainers()[index]);
4946 } 5314 }
4947 5315
4948 5316
4949 int HeapGraphNode::GetRetainingPathsCount() const { 5317 int HeapGraphNode::GetRetainingPathsCount() const {
4950 IsDeadCheck("v8::HeapSnapshot::GetRetainingPathsCount"); 5318 i::Isolate* isolate = i::Isolate::Current();
5319 IsDeadCheck(isolate, "v8::HeapSnapshot::GetRetainingPathsCount");
4951 return ToInternal(this)->GetRetainingPaths()->length(); 5320 return ToInternal(this)->GetRetainingPaths()->length();
4952 } 5321 }
4953 5322
4954 5323
4955 const HeapGraphPath* HeapGraphNode::GetRetainingPath(int index) const { 5324 const HeapGraphPath* HeapGraphNode::GetRetainingPath(int index) const {
4956 IsDeadCheck("v8::HeapSnapshot::GetRetainingPath"); 5325 i::Isolate* isolate = i::Isolate::Current();
5326 IsDeadCheck(isolate, "v8::HeapSnapshot::GetRetainingPath");
4957 return reinterpret_cast<const HeapGraphPath*>( 5327 return reinterpret_cast<const HeapGraphPath*>(
4958 ToInternal(this)->GetRetainingPaths()->at(index)); 5328 ToInternal(this)->GetRetainingPaths()->at(index));
4959 } 5329 }
4960 5330
4961 5331
4962 const HeapGraphNode* HeapGraphNode::GetDominatorNode() const { 5332 const HeapGraphNode* HeapGraphNode::GetDominatorNode() const {
4963 IsDeadCheck("v8::HeapSnapshot::GetDominatorNode"); 5333 i::Isolate* isolate = i::Isolate::Current();
5334 IsDeadCheck(isolate, "v8::HeapSnapshot::GetDominatorNode");
4964 return reinterpret_cast<const HeapGraphNode*>(ToInternal(this)->dominator()); 5335 return reinterpret_cast<const HeapGraphNode*>(ToInternal(this)->dominator());
4965 } 5336 }
4966 5337
4967 5338
4968 const HeapGraphNode* HeapSnapshotsDiff::GetAdditionsRoot() const { 5339 const HeapGraphNode* HeapSnapshotsDiff::GetAdditionsRoot() const {
4969 IsDeadCheck("v8::HeapSnapshotsDiff::GetAdditionsRoot"); 5340 i::Isolate* isolate = i::Isolate::Current();
5341 IsDeadCheck(isolate, "v8::HeapSnapshotsDiff::GetAdditionsRoot");
4970 i::HeapSnapshotsDiff* diff = 5342 i::HeapSnapshotsDiff* diff =
4971 const_cast<i::HeapSnapshotsDiff*>( 5343 const_cast<i::HeapSnapshotsDiff*>(
4972 reinterpret_cast<const i::HeapSnapshotsDiff*>(this)); 5344 reinterpret_cast<const i::HeapSnapshotsDiff*>(this));
4973 return reinterpret_cast<const HeapGraphNode*>(diff->additions_root()); 5345 return reinterpret_cast<const HeapGraphNode*>(diff->additions_root());
4974 } 5346 }
4975 5347
4976 5348
4977 const HeapGraphNode* HeapSnapshotsDiff::GetDeletionsRoot() const { 5349 const HeapGraphNode* HeapSnapshotsDiff::GetDeletionsRoot() const {
4978 IsDeadCheck("v8::HeapSnapshotsDiff::GetDeletionsRoot"); 5350 i::Isolate* isolate = i::Isolate::Current();
5351 IsDeadCheck(isolate, "v8::HeapSnapshotsDiff::GetDeletionsRoot");
4979 i::HeapSnapshotsDiff* diff = 5352 i::HeapSnapshotsDiff* diff =
4980 const_cast<i::HeapSnapshotsDiff*>( 5353 const_cast<i::HeapSnapshotsDiff*>(
4981 reinterpret_cast<const i::HeapSnapshotsDiff*>(this)); 5354 reinterpret_cast<const i::HeapSnapshotsDiff*>(this));
4982 return reinterpret_cast<const HeapGraphNode*>(diff->deletions_root()); 5355 return reinterpret_cast<const HeapGraphNode*>(diff->deletions_root());
4983 } 5356 }
4984 5357
4985 5358
4986 static i::HeapSnapshot* ToInternal(const HeapSnapshot* snapshot) { 5359 static i::HeapSnapshot* ToInternal(const HeapSnapshot* snapshot) {
4987 return const_cast<i::HeapSnapshot*>( 5360 return const_cast<i::HeapSnapshot*>(
4988 reinterpret_cast<const i::HeapSnapshot*>(snapshot)); 5361 reinterpret_cast<const i::HeapSnapshot*>(snapshot));
4989 } 5362 }
4990 5363
4991 5364
4992 HeapSnapshot::Type HeapSnapshot::GetType() const { 5365 HeapSnapshot::Type HeapSnapshot::GetType() const {
4993 IsDeadCheck("v8::HeapSnapshot::GetType"); 5366 i::Isolate* isolate = i::Isolate::Current();
5367 IsDeadCheck(isolate, "v8::HeapSnapshot::GetType");
4994 return static_cast<HeapSnapshot::Type>(ToInternal(this)->type()); 5368 return static_cast<HeapSnapshot::Type>(ToInternal(this)->type());
4995 } 5369 }
4996 5370
4997 5371
4998 unsigned HeapSnapshot::GetUid() const { 5372 unsigned HeapSnapshot::GetUid() const {
4999 IsDeadCheck("v8::HeapSnapshot::GetUid"); 5373 i::Isolate* isolate = i::Isolate::Current();
5374 IsDeadCheck(isolate, "v8::HeapSnapshot::GetUid");
5000 return ToInternal(this)->uid(); 5375 return ToInternal(this)->uid();
5001 } 5376 }
5002 5377
5003 5378
5004 Handle<String> HeapSnapshot::GetTitle() const { 5379 Handle<String> HeapSnapshot::GetTitle() const {
5005 IsDeadCheck("v8::HeapSnapshot::GetTitle"); 5380 i::Isolate* isolate = i::Isolate::Current();
5006 return Handle<String>(ToApi<String>(i::Factory::LookupAsciiSymbol( 5381 IsDeadCheck(isolate, "v8::HeapSnapshot::GetTitle");
5382 return Handle<String>(ToApi<String>(FACTORY->LookupAsciiSymbol(
5007 ToInternal(this)->title()))); 5383 ToInternal(this)->title())));
5008 } 5384 }
5009 5385
5010 5386
5011 const HeapGraphNode* HeapSnapshot::GetRoot() const { 5387 const HeapGraphNode* HeapSnapshot::GetRoot() const {
5012 IsDeadCheck("v8::HeapSnapshot::GetHead"); 5388 i::Isolate* isolate = i::Isolate::Current();
5389 IsDeadCheck(isolate, "v8::HeapSnapshot::GetHead");
5013 return reinterpret_cast<const HeapGraphNode*>(ToInternal(this)->root()); 5390 return reinterpret_cast<const HeapGraphNode*>(ToInternal(this)->root());
5014 } 5391 }
5015 5392
5016 5393
5017 const HeapGraphNode* HeapSnapshot::GetNodeById(uint64_t id) const { 5394 const HeapGraphNode* HeapSnapshot::GetNodeById(uint64_t id) const {
5018 IsDeadCheck("v8::HeapSnapshot::GetNodeById"); 5395 i::Isolate* isolate = i::Isolate::Current();
5396 IsDeadCheck(isolate, "v8::HeapSnapshot::GetNodeById");
5019 return reinterpret_cast<const HeapGraphNode*>( 5397 return reinterpret_cast<const HeapGraphNode*>(
5020 ToInternal(this)->GetEntryById(id)); 5398 ToInternal(this)->GetEntryById(id));
5021 } 5399 }
5022 5400
5023 5401
5024 const HeapSnapshotsDiff* HeapSnapshot::CompareWith( 5402 const HeapSnapshotsDiff* HeapSnapshot::CompareWith(
5025 const HeapSnapshot* snapshot) const { 5403 const HeapSnapshot* snapshot) const {
5026 IsDeadCheck("v8::HeapSnapshot::CompareWith"); 5404 i::Isolate* isolate = i::Isolate::Current();
5405 IsDeadCheck(isolate, "v8::HeapSnapshot::CompareWith");
5027 return reinterpret_cast<const HeapSnapshotsDiff*>( 5406 return reinterpret_cast<const HeapSnapshotsDiff*>(
5028 ToInternal(this)->CompareWith(ToInternal(snapshot))); 5407 ToInternal(this)->CompareWith(ToInternal(snapshot)));
5029 } 5408 }
5030 5409
5031 5410
5032 void HeapSnapshot::Serialize(OutputStream* stream, 5411 void HeapSnapshot::Serialize(OutputStream* stream,
5033 HeapSnapshot::SerializationFormat format) const { 5412 HeapSnapshot::SerializationFormat format) const {
5034 IsDeadCheck("v8::HeapSnapshot::Serialize"); 5413 i::Isolate* isolate = i::Isolate::Current();
5414 IsDeadCheck(isolate, "v8::HeapSnapshot::Serialize");
5035 ApiCheck(format == kJSON, 5415 ApiCheck(format == kJSON,
5036 "v8::HeapSnapshot::Serialize", 5416 "v8::HeapSnapshot::Serialize",
5037 "Unknown serialization format"); 5417 "Unknown serialization format");
5038 ApiCheck(stream->GetOutputEncoding() == OutputStream::kAscii, 5418 ApiCheck(stream->GetOutputEncoding() == OutputStream::kAscii,
5039 "v8::HeapSnapshot::Serialize", 5419 "v8::HeapSnapshot::Serialize",
5040 "Unsupported output encoding"); 5420 "Unsupported output encoding");
5041 ApiCheck(stream->GetChunkSize() > 0, 5421 ApiCheck(stream->GetChunkSize() > 0,
5042 "v8::HeapSnapshot::Serialize", 5422 "v8::HeapSnapshot::Serialize",
5043 "Invalid stream chunk size"); 5423 "Invalid stream chunk size");
5044 i::HeapSnapshotJSONSerializer serializer(ToInternal(this)); 5424 i::HeapSnapshotJSONSerializer serializer(ToInternal(this));
5045 serializer.Serialize(stream); 5425 serializer.Serialize(stream);
5046 } 5426 }
5047 5427
5048 5428
5049 int HeapProfiler::GetSnapshotsCount() { 5429 int HeapProfiler::GetSnapshotsCount() {
5050 IsDeadCheck("v8::HeapProfiler::GetSnapshotsCount"); 5430 i::Isolate* isolate = i::Isolate::Current();
5431 IsDeadCheck(isolate, "v8::HeapProfiler::GetSnapshotsCount");
5051 return i::HeapProfiler::GetSnapshotsCount(); 5432 return i::HeapProfiler::GetSnapshotsCount();
5052 } 5433 }
5053 5434
5054 5435
5055 const HeapSnapshot* HeapProfiler::GetSnapshot(int index) { 5436 const HeapSnapshot* HeapProfiler::GetSnapshot(int index) {
5056 IsDeadCheck("v8::HeapProfiler::GetSnapshot"); 5437 i::Isolate* isolate = i::Isolate::Current();
5438 IsDeadCheck(isolate, "v8::HeapProfiler::GetSnapshot");
5057 return reinterpret_cast<const HeapSnapshot*>( 5439 return reinterpret_cast<const HeapSnapshot*>(
5058 i::HeapProfiler::GetSnapshot(index)); 5440 i::HeapProfiler::GetSnapshot(index));
5059 } 5441 }
5060 5442
5061 5443
5062 const HeapSnapshot* HeapProfiler::FindSnapshot(unsigned uid) { 5444 const HeapSnapshot* HeapProfiler::FindSnapshot(unsigned uid) {
5063 IsDeadCheck("v8::HeapProfiler::FindSnapshot"); 5445 i::Isolate* isolate = i::Isolate::Current();
5446 IsDeadCheck(isolate, "v8::HeapProfiler::FindSnapshot");
5064 return reinterpret_cast<const HeapSnapshot*>( 5447 return reinterpret_cast<const HeapSnapshot*>(
5065 i::HeapProfiler::FindSnapshot(uid)); 5448 i::HeapProfiler::FindSnapshot(uid));
5066 } 5449 }
5067 5450
5068 5451
5069 const HeapSnapshot* HeapProfiler::TakeSnapshot(Handle<String> title, 5452 const HeapSnapshot* HeapProfiler::TakeSnapshot(Handle<String> title,
5070 HeapSnapshot::Type type, 5453 HeapSnapshot::Type type,
5071 ActivityControl* control) { 5454 ActivityControl* control) {
5072 IsDeadCheck("v8::HeapProfiler::TakeSnapshot"); 5455 i::Isolate* isolate = i::Isolate::Current();
5456 IsDeadCheck(isolate, "v8::HeapProfiler::TakeSnapshot");
5073 i::HeapSnapshot::Type internal_type = i::HeapSnapshot::kFull; 5457 i::HeapSnapshot::Type internal_type = i::HeapSnapshot::kFull;
5074 switch (type) { 5458 switch (type) {
5075 case HeapSnapshot::kFull: 5459 case HeapSnapshot::kFull:
5076 internal_type = i::HeapSnapshot::kFull; 5460 internal_type = i::HeapSnapshot::kFull;
5077 break; 5461 break;
5078 case HeapSnapshot::kAggregated: 5462 case HeapSnapshot::kAggregated:
5079 internal_type = i::HeapSnapshot::kAggregated; 5463 internal_type = i::HeapSnapshot::kAggregated;
5080 break; 5464 break;
5081 default: 5465 default:
5082 UNREACHABLE(); 5466 UNREACHABLE();
5083 } 5467 }
5084 return reinterpret_cast<const HeapSnapshot*>( 5468 return reinterpret_cast<const HeapSnapshot*>(
5085 i::HeapProfiler::TakeSnapshot( 5469 i::HeapProfiler::TakeSnapshot(
5086 *Utils::OpenHandle(*title), internal_type, control)); 5470 *Utils::OpenHandle(*title), internal_type, control));
5087 } 5471 }
5088 5472
5089 5473
5090 void HeapProfiler::DefineWrapperClass(uint16_t class_id, 5474 void HeapProfiler::DefineWrapperClass(uint16_t class_id,
5091 WrapperInfoCallback callback) { 5475 WrapperInfoCallback callback) {
5092 i::HeapProfiler::DefineWrapperClass(class_id, callback); 5476 i::Isolate::Current()->heap_profiler()->DefineWrapperClass(class_id,
5477 callback);
5093 } 5478 }
5094 5479
5095 #endif // ENABLE_LOGGING_AND_PROFILING 5480 #endif // ENABLE_LOGGING_AND_PROFILING
5096 5481
5097 5482
5098 v8::Testing::StressType internal::Testing::stress_type_ = 5483 v8::Testing::StressType internal::Testing::stress_type_ =
5099 v8::Testing::kStressTypeOpt; 5484 v8::Testing::kStressTypeOpt;
5100 5485
5101 5486
5102 void Testing::SetStressRunType(Testing::StressType type) { 5487 void Testing::SetStressRunType(Testing::StressType type) {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
5157 5542
5158 5543
5159 void Testing::DeoptimizeAll() { 5544 void Testing::DeoptimizeAll() {
5160 internal::Deoptimizer::DeoptimizeAll(); 5545 internal::Deoptimizer::DeoptimizeAll();
5161 } 5546 }
5162 5547
5163 5548
5164 namespace internal { 5549 namespace internal {
5165 5550
5166 5551
5167 HandleScopeImplementer* HandleScopeImplementer::instance() {
5168 return &thread_local;
5169 }
5170
5171
5172 void HandleScopeImplementer::FreeThreadResources() { 5552 void HandleScopeImplementer::FreeThreadResources() {
5173 thread_local.Free(); 5553 Free();
5174 } 5554 }
5175 5555
5176 5556
5177 char* HandleScopeImplementer::ArchiveThread(char* storage) { 5557 char* HandleScopeImplementer::ArchiveThread(char* storage) {
5178 return thread_local.ArchiveThreadHelper(storage); 5558 Isolate* isolate = Isolate::Current();
5179 }
5180
5181
5182 char* HandleScopeImplementer::ArchiveThreadHelper(char* storage) {
5183 v8::ImplementationUtilities::HandleScopeData* current = 5559 v8::ImplementationUtilities::HandleScopeData* current =
5184 v8::ImplementationUtilities::CurrentHandleScope(); 5560 isolate->handle_scope_data();
5185 handle_scope_data_ = *current; 5561 handle_scope_data_ = *current;
5186 memcpy(storage, this, sizeof(*this)); 5562 memcpy(storage, this, sizeof(*this));
5187 5563
5188 ResetAfterArchive(); 5564 ResetAfterArchive();
5189 current->Initialize(); 5565 current->Initialize();
5190 5566
5191 return storage + ArchiveSpacePerThread(); 5567 return storage + ArchiveSpacePerThread();
5192 } 5568 }
5193 5569
5194 5570
5195 int HandleScopeImplementer::ArchiveSpacePerThread() { 5571 int HandleScopeImplementer::ArchiveSpacePerThread() {
5196 return sizeof(thread_local); 5572 return sizeof(HandleScopeImplementer);
5197 } 5573 }
5198 5574
5199 5575
5200 char* HandleScopeImplementer::RestoreThread(char* storage) { 5576 char* HandleScopeImplementer::RestoreThread(char* storage) {
5201 return thread_local.RestoreThreadHelper(storage);
5202 }
5203
5204
5205 char* HandleScopeImplementer::RestoreThreadHelper(char* storage) {
5206 memcpy(this, storage, sizeof(*this)); 5577 memcpy(this, storage, sizeof(*this));
5207 *v8::ImplementationUtilities::CurrentHandleScope() = handle_scope_data_; 5578 *Isolate::Current()->handle_scope_data() = handle_scope_data_;
5208 return storage + ArchiveSpacePerThread(); 5579 return storage + ArchiveSpacePerThread();
5209 } 5580 }
5210 5581
5211 5582
5212 void HandleScopeImplementer::IterateThis(ObjectVisitor* v) { 5583 void HandleScopeImplementer::IterateThis(ObjectVisitor* v) {
5213 // Iterate over all handles in the blocks except for the last. 5584 // Iterate over all handles in the blocks except for the last.
5214 for (int i = blocks()->length() - 2; i >= 0; --i) { 5585 for (int i = blocks()->length() - 2; i >= 0; --i) {
5215 Object** block = blocks()->at(i); 5586 Object** block = blocks()->at(i);
5216 v->VisitPointers(block, &block[kHandleBlockSize]); 5587 v->VisitPointers(block, &block[kHandleBlockSize]);
5217 } 5588 }
5218 5589
5219 // Iterate over live handles in the last block (if any). 5590 // Iterate over live handles in the last block (if any).
5220 if (!blocks()->is_empty()) { 5591 if (!blocks()->is_empty()) {
5221 v->VisitPointers(blocks()->last(), handle_scope_data_.next); 5592 v->VisitPointers(blocks()->last(), handle_scope_data_.next);
5222 } 5593 }
5223 5594
5224 if (!saved_contexts_.is_empty()) { 5595 if (!saved_contexts_.is_empty()) {
5225 Object** start = reinterpret_cast<Object**>(&saved_contexts_.first()); 5596 Object** start = reinterpret_cast<Object**>(&saved_contexts_.first());
5226 v->VisitPointers(start, start + saved_contexts_.length()); 5597 v->VisitPointers(start, start + saved_contexts_.length());
5227 } 5598 }
5228 } 5599 }
5229 5600
5230 5601
5231 void HandleScopeImplementer::Iterate(ObjectVisitor* v) { 5602 void HandleScopeImplementer::Iterate(ObjectVisitor* v) {
5232 v8::ImplementationUtilities::HandleScopeData* current = 5603 v8::ImplementationUtilities::HandleScopeData* current =
5233 v8::ImplementationUtilities::CurrentHandleScope(); 5604 Isolate::Current()->handle_scope_data();
5234 thread_local.handle_scope_data_ = *current; 5605 handle_scope_data_ = *current;
5235 thread_local.IterateThis(v); 5606 IterateThis(v);
5236 } 5607 }
5237 5608
5238 5609
5239 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) { 5610 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) {
5240 HandleScopeImplementer* thread_local = 5611 HandleScopeImplementer* thread_local =
5241 reinterpret_cast<HandleScopeImplementer*>(storage); 5612 reinterpret_cast<HandleScopeImplementer*>(storage);
5242 thread_local->IterateThis(v); 5613 thread_local->IterateThis(v);
5243 return storage + ArchiveSpacePerThread(); 5614 return storage + ArchiveSpacePerThread();
5244 } 5615 }
5245 5616
5246 } } // namespace v8::internal 5617 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/api.h ('k') | src/apiutils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698