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

Side by Side Diff: src/api.cc

Issue 173348: Api inlining. Made some core functionality available in the api and... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 11 years, 3 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
OLDNEW
1 // Copyright 2009 the V8 project authors. All rights reserved. 1 // Copyright 2009 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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 // --- 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 --- 93 // --- 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 ---
94 94
95 95
96 static i::HandleScopeImplementer thread_local; 96 static i::HandleScopeImplementer thread_local;
97 97
98 98
99 // --- E x c e p t i o n B e h a v i o r --- 99 // --- E x c e p t i o n B e h a v i o r ---
100 100
101 101
102 static FatalErrorCallback exception_behavior = NULL; 102 static FatalErrorCallback exception_behavior = NULL;
103 103 int i::Internals::kJSObjectType = JS_OBJECT_TYPE;
104 int i::Internals::kFirstNonstringType = FIRST_NONSTRING_TYPE;
105 int i::Internals::kProxyType = PROXY_TYPE;
104 106
105 static void DefaultFatalErrorHandler(const char* location, 107 static void DefaultFatalErrorHandler(const char* location,
106 const char* message) { 108 const char* message) {
107 ENTER_V8; 109 ENTER_V8;
108 API_Fatal(location, message); 110 API_Fatal(location, message);
109 } 111 }
110 112
111 113
112 114
113 static FatalErrorCallback& GetFatalErrorHandler() { 115 static FatalErrorCallback& GetFatalErrorHandler() {
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 } 218 }
217 219
218 220
219 ImplementationUtilities::HandleScopeData* 221 ImplementationUtilities::HandleScopeData*
220 ImplementationUtilities::CurrentHandleScope() { 222 ImplementationUtilities::CurrentHandleScope() {
221 return &i::HandleScope::current_; 223 return &i::HandleScope::current_;
222 } 224 }
223 225
224 226
225 #ifdef DEBUG 227 #ifdef DEBUG
226 void ImplementationUtilities::ZapHandleRange(void** begin, void** end) { 228 void ImplementationUtilities::ZapHandleRange(i::Object** begin,
229 i::Object** end) {
227 i::HandleScope::ZapRange(begin, end); 230 i::HandleScope::ZapRange(begin, end);
228 } 231 }
229 #endif 232 #endif
230 233
231 234
232 v8::Handle<v8::Primitive> ImplementationUtilities::Undefined() { 235 v8::Handle<v8::Primitive> ImplementationUtilities::Undefined() {
233 if (!EnsureInitialized("v8::Undefined()")) return v8::Handle<v8::Primitive>(); 236 if (!EnsureInitialized("v8::Undefined()")) return v8::Handle<v8::Primitive>();
234 return v8::Handle<Primitive>(ToApi<Primitive>(i::Factory::undefined_value())); 237 return v8::Handle<Primitive>(ToApi<Primitive>(i::Factory::undefined_value()));
235 } 238 }
236 239
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 constraints->max_old_space_size()); 345 constraints->max_old_space_size());
343 if (!result) return false; 346 if (!result) return false;
344 if (constraints->stack_limit() != NULL) { 347 if (constraints->stack_limit() != NULL) {
345 uintptr_t limit = reinterpret_cast<uintptr_t>(constraints->stack_limit()); 348 uintptr_t limit = reinterpret_cast<uintptr_t>(constraints->stack_limit());
346 i::StackGuard::SetStackLimit(limit); 349 i::StackGuard::SetStackLimit(limit);
347 } 350 }
348 return true; 351 return true;
349 } 352 }
350 353
351 354
352 void** V8::GlobalizeReference(void** obj) { 355 i::Object** V8::GlobalizeReference(i::Object** obj) {
353 if (IsDeadCheck("V8::Persistent::New")) return NULL; 356 if (IsDeadCheck("V8::Persistent::New")) return NULL;
354 LOG_API("Persistent::New"); 357 LOG_API("Persistent::New");
355 i::Handle<i::Object> result = 358 i::Handle<i::Object> result =
356 i::GlobalHandles::Create(*reinterpret_cast<i::Object**>(obj)); 359 i::GlobalHandles::Create(*obj);
357 return reinterpret_cast<void**>(result.location()); 360 return result.location();
358 } 361 }
359 362
360 363
361 void V8::MakeWeak(void** object, void* parameters, 364 void V8::MakeWeak(i::Object** object, void* parameters,
362 WeakReferenceCallback callback) { 365 WeakReferenceCallback callback) {
363 LOG_API("MakeWeak"); 366 LOG_API("MakeWeak");
364 i::GlobalHandles::MakeWeak(reinterpret_cast<i::Object**>(object), parameters, 367 i::GlobalHandles::MakeWeak(object, parameters, callback);
365 callback);
366 } 368 }
367 369
368 370
369 void V8::ClearWeak(void** obj) { 371 void V8::ClearWeak(i::Object** obj) {
370 LOG_API("ClearWeak"); 372 LOG_API("ClearWeak");
371 i::GlobalHandles::ClearWeakness(reinterpret_cast<i::Object**>(obj)); 373 i::GlobalHandles::ClearWeakness(obj);
372 } 374 }
373 375
374 376
375 bool V8::IsGlobalNearDeath(void** obj) { 377 bool V8::IsGlobalNearDeath(i::Object** obj) {
376 LOG_API("IsGlobalNearDeath"); 378 LOG_API("IsGlobalNearDeath");
377 if (!i::V8::IsRunning()) return false; 379 if (!i::V8::IsRunning()) return false;
378 return i::GlobalHandles::IsNearDeath(reinterpret_cast<i::Object**>(obj)); 380 return i::GlobalHandles::IsNearDeath(obj);
379 } 381 }
380 382
381 383
382 bool V8::IsGlobalWeak(void** obj) { 384 bool V8::IsGlobalWeak(i::Object** obj) {
383 LOG_API("IsGlobalWeak"); 385 LOG_API("IsGlobalWeak");
384 if (!i::V8::IsRunning()) return false; 386 if (!i::V8::IsRunning()) return false;
385 return i::GlobalHandles::IsWeak(reinterpret_cast<i::Object**>(obj)); 387 return i::GlobalHandles::IsWeak(obj);
386 } 388 }
387 389
388 390
389 void V8::DisposeGlobal(void** obj) { 391 void V8::DisposeGlobal(i::Object** obj) {
390 LOG_API("DisposeGlobal"); 392 LOG_API("DisposeGlobal");
391 if (!i::V8::IsRunning()) return; 393 if (!i::V8::IsRunning()) return;
392 i::Object** ptr = reinterpret_cast<i::Object**>(obj); 394 if ((*obj)->IsGlobalContext()) i::Heap::NotifyContextDisposed();
393 if ((*ptr)->IsGlobalContext()) i::Heap::NotifyContextDisposed(); 395 i::GlobalHandles::Destroy(obj);
394 i::GlobalHandles::Destroy(ptr);
395 } 396 }
396 397
397 // --- H a n d l e s --- 398 // --- H a n d l e s ---
398 399
399 400
400 HandleScope::HandleScope() : is_closed_(false) { 401 HandleScope::HandleScope() : is_closed_(false) {
401 API_ENTRY_CHECK("HandleScope::HandleScope"); 402 API_ENTRY_CHECK("HandleScope::HandleScope");
402 i::HandleScope::Enter(&previous_); 403 i::HandleScope::Enter(&previous_);
403 } 404 }
404 405
405 406
406 HandleScope::~HandleScope() { 407 HandleScope::~HandleScope() {
407 if (!is_closed_) { 408 if (!is_closed_) {
408 i::HandleScope::Leave(&previous_); 409 i::HandleScope::Leave(&previous_);
409 } 410 }
410 } 411 }
411 412
412 413
413 int HandleScope::NumberOfHandles() { 414 int HandleScope::NumberOfHandles() {
414 return i::HandleScope::NumberOfHandles(); 415 return i::HandleScope::NumberOfHandles();
415 } 416 }
416 417
417 418
418 void** v8::HandleScope::CreateHandle(void* value) { 419 i::Object** v8::HandleScope::CreateHandle(i::Object* value) {
419 return reinterpret_cast<void**>( 420 return i::HandleScope::CreateHandle(value);
420 i::HandleScope::CreateHandle(reinterpret_cast<i::Object*>(value)));
421 } 421 }
422 422
423 423
424 void Context::Enter() { 424 void Context::Enter() {
425 if (IsDeadCheck("v8::Context::Enter()")) return; 425 if (IsDeadCheck("v8::Context::Enter()")) return;
426 ENTER_V8; 426 ENTER_V8;
427 i::Handle<i::Context> env = Utils::OpenHandle(this); 427 i::Handle<i::Context> env = Utils::OpenHandle(this);
428 thread_local.EnterContext(env); 428 thread_local.EnterContext(env);
429 429
430 thread_local.SaveContext(i::GlobalHandles::Create(i::Top::context())); 430 thread_local.SaveContext(i::GlobalHandles::Create(i::Top::context()));
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 raw_result = env->data(); 474 raw_result = env->data();
475 } else { 475 } else {
476 return Local<Value>(); 476 return Local<Value>();
477 } 477 }
478 } 478 }
479 i::Handle<i::Object> result(raw_result); 479 i::Handle<i::Object> result(raw_result);
480 return Utils::ToLocal(result); 480 return Utils::ToLocal(result);
481 } 481 }
482 482
483 483
484 void** v8::HandleScope::RawClose(void** value) { 484 i::Object** v8::HandleScope::RawClose(i::Object** value) {
485 if (!ApiCheck(!is_closed_, 485 if (!ApiCheck(!is_closed_,
486 "v8::HandleScope::Close()", 486 "v8::HandleScope::Close()",
487 "Local scope has already been closed")) { 487 "Local scope has already been closed")) {
488 return 0; 488 return 0;
489 } 489 }
490 LOG_API("CloseHandleScope"); 490 LOG_API("CloseHandleScope");
491 491
492 // Read the result before popping the handle block. 492 // Read the result before popping the handle block.
493 i::Object* result = reinterpret_cast<i::Object*>(*value); 493 i::Object* result = *value;
494 is_closed_ = true; 494 is_closed_ = true;
495 i::HandleScope::Leave(&previous_); 495 i::HandleScope::Leave(&previous_);
496 496
497 // Allocate a new handle on the previous handle block. 497 // Allocate a new handle on the previous handle block.
498 i::Handle<i::Object> handle(result); 498 i::Handle<i::Object> handle(result);
499 return reinterpret_cast<void**>(handle.location()); 499 return handle.location();
500 } 500 }
501 501
502 502
503 // --- N e a n d e r --- 503 // --- N e a n d e r ---
504 504
505 505
506 // A constructor cannot easily return an error value, therefore it is necessary 506 // A constructor cannot easily return an error value, therefore it is necessary
507 // to check for a dead VM with ON_BAILOUT before constructing any Neander 507 // to check for a dead VM with ON_BAILOUT before constructing any Neander
508 // objects. To remind you about this there is no HandleScope in the 508 // objects. To remind you about this there is no HandleScope in the
509 // NeanderObject constructor. When you add one to the site calling the 509 // NeanderObject constructor. When you add one to the site calling the
(...skipping 942 matching lines...) Expand 10 before | Expand all | Expand 10 after
1452 return Utils::OpenHandle(this)->IsFalse(); 1452 return Utils::OpenHandle(this)->IsFalse();
1453 } 1453 }
1454 1454
1455 1455
1456 bool Value::IsFunction() const { 1456 bool Value::IsFunction() const {
1457 if (IsDeadCheck("v8::Value::IsFunction()")) return false; 1457 if (IsDeadCheck("v8::Value::IsFunction()")) return false;
1458 return Utils::OpenHandle(this)->IsJSFunction(); 1458 return Utils::OpenHandle(this)->IsJSFunction();
1459 } 1459 }
1460 1460
1461 1461
1462 bool Value::IsString() const { 1462 bool Value::FullIsString() const {
1463 if (IsDeadCheck("v8::Value::IsString()")) return false; 1463 if (IsDeadCheck("v8::Value::IsString()")) return false;
1464 return Utils::OpenHandle(this)->IsString(); 1464 bool result = Utils::OpenHandle(this)->IsString();
1465 ASSERT_EQ(result, QuickIsString());
1466 return result;
1465 } 1467 }
1466 1468
1467 1469
1468 bool Value::IsArray() const { 1470 bool Value::IsArray() const {
1469 if (IsDeadCheck("v8::Value::IsArray()")) return false; 1471 if (IsDeadCheck("v8::Value::IsArray()")) return false;
1470 return Utils::OpenHandle(this)->IsJSArray(); 1472 return Utils::OpenHandle(this)->IsJSArray();
1471 } 1473 }
1472 1474
1473 1475
1474 bool Value::IsObject() const { 1476 bool Value::IsObject() const {
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
1606 } else { 1608 } else {
1607 ENTER_V8; 1609 ENTER_V8;
1608 EXCEPTION_PREAMBLE(); 1610 EXCEPTION_PREAMBLE();
1609 num = i::Execution::ToInteger(obj, &has_pending_exception); 1611 num = i::Execution::ToInteger(obj, &has_pending_exception);
1610 EXCEPTION_BAILOUT_CHECK(Local<Integer>()); 1612 EXCEPTION_BAILOUT_CHECK(Local<Integer>());
1611 } 1613 }
1612 return Local<Integer>(ToApi<Integer>(num)); 1614 return Local<Integer>(ToApi<Integer>(num));
1613 } 1615 }
1614 1616
1615 1617
1616 External* External::Cast(v8::Value* that) { 1618 void External::CheckCast(v8::Value* that) {
1617 if (IsDeadCheck("v8::External::Cast()")) return 0; 1619 if (IsDeadCheck("v8::External::Cast()")) return;
1618 i::Handle<i::Object> obj = Utils::OpenHandle(that); 1620 i::Handle<i::Object> obj = Utils::OpenHandle(that);
1619 ApiCheck(obj->IsProxy(), 1621 ApiCheck(obj->IsProxy(),
1620 "v8::External::Cast()", 1622 "v8::External::Cast()",
1621 "Could not convert to external"); 1623 "Could not convert to external");
1622 return static_cast<External*>(that);
1623 } 1624 }
1624 1625
1625 1626
1626 v8::Object* v8::Object::Cast(Value* that) { 1627 void v8::Object::CheckCast(Value* that) {
1627 if (IsDeadCheck("v8::Object::Cast()")) return 0; 1628 if (IsDeadCheck("v8::Object::Cast()")) return;
1628 i::Handle<i::Object> obj = Utils::OpenHandle(that); 1629 i::Handle<i::Object> obj = Utils::OpenHandle(that);
1629 ApiCheck(obj->IsJSObject(), 1630 ApiCheck(obj->IsJSObject(),
1630 "v8::Object::Cast()", 1631 "v8::Object::Cast()",
1631 "Could not convert to object"); 1632 "Could not convert to object");
1632 return static_cast<v8::Object*>(that);
1633 } 1633 }
1634 1634
1635 1635
1636 v8::Function* v8::Function::Cast(Value* that) { 1636 void v8::Function::CheckCast(Value* that) {
1637 if (IsDeadCheck("v8::Function::Cast()")) return 0; 1637 if (IsDeadCheck("v8::Function::Cast()")) return;
1638 i::Handle<i::Object> obj = Utils::OpenHandle(that); 1638 i::Handle<i::Object> obj = Utils::OpenHandle(that);
1639 ApiCheck(obj->IsJSFunction(), 1639 ApiCheck(obj->IsJSFunction(),
1640 "v8::Function::Cast()", 1640 "v8::Function::Cast()",
1641 "Could not convert to function"); 1641 "Could not convert to function");
1642 return static_cast<v8::Function*>(that);
1643 } 1642 }
1644 1643
1645 1644
1646 v8::String* v8::String::Cast(v8::Value* that) { 1645 void v8::String::CheckCast(v8::Value* that) {
1647 if (IsDeadCheck("v8::String::Cast()")) return 0; 1646 if (IsDeadCheck("v8::String::Cast()")) return;
1648 i::Handle<i::Object> obj = Utils::OpenHandle(that); 1647 i::Handle<i::Object> obj = Utils::OpenHandle(that);
1649 ApiCheck(obj->IsString(), 1648 ApiCheck(obj->IsString(),
1650 "v8::String::Cast()", 1649 "v8::String::Cast()",
1651 "Could not convert to string"); 1650 "Could not convert to string");
1652 return static_cast<v8::String*>(that);
1653 } 1651 }
1654 1652
1655 1653
1656 v8::Number* v8::Number::Cast(v8::Value* that) { 1654 void v8::Number::CheckCast(v8::Value* that) {
1657 if (IsDeadCheck("v8::Number::Cast()")) return 0; 1655 if (IsDeadCheck("v8::Number::Cast()")) return;
1658 i::Handle<i::Object> obj = Utils::OpenHandle(that); 1656 i::Handle<i::Object> obj = Utils::OpenHandle(that);
1659 ApiCheck(obj->IsNumber(), 1657 ApiCheck(obj->IsNumber(),
1660 "v8::Number::Cast()", 1658 "v8::Number::Cast()",
1661 "Could not convert to number"); 1659 "Could not convert to number");
1662 return static_cast<v8::Number*>(that);
1663 } 1660 }
1664 1661
1665 1662
1666 v8::Integer* v8::Integer::Cast(v8::Value* that) { 1663 void v8::Integer::CheckCast(v8::Value* that) {
1667 if (IsDeadCheck("v8::Integer::Cast()")) return 0; 1664 if (IsDeadCheck("v8::Integer::Cast()")) return;
1668 i::Handle<i::Object> obj = Utils::OpenHandle(that); 1665 i::Handle<i::Object> obj = Utils::OpenHandle(that);
1669 ApiCheck(obj->IsNumber(), 1666 ApiCheck(obj->IsNumber(),
1670 "v8::Integer::Cast()", 1667 "v8::Integer::Cast()",
1671 "Could not convert to number"); 1668 "Could not convert to number");
1672 return static_cast<v8::Integer*>(that);
1673 } 1669 }
1674 1670
1675 1671
1676 v8::Array* v8::Array::Cast(Value* that) { 1672 void v8::Array::CheckCast(Value* that) {
1677 if (IsDeadCheck("v8::Array::Cast()")) return 0; 1673 if (IsDeadCheck("v8::Array::Cast()")) return;
1678 i::Handle<i::Object> obj = Utils::OpenHandle(that); 1674 i::Handle<i::Object> obj = Utils::OpenHandle(that);
1679 ApiCheck(obj->IsJSArray(), 1675 ApiCheck(obj->IsJSArray(),
1680 "v8::Array::Cast()", 1676 "v8::Array::Cast()",
1681 "Could not convert to array"); 1677 "Could not convert to array");
1682 return static_cast<v8::Array*>(that);
1683 } 1678 }
1684 1679
1685 1680
1686 v8::Date* v8::Date::Cast(v8::Value* that) { 1681 void v8::Date::CheckCast(v8::Value* that) {
1687 if (IsDeadCheck("v8::Date::Cast()")) return 0; 1682 if (IsDeadCheck("v8::Date::Cast()")) return;
1688 i::Handle<i::Object> obj = Utils::OpenHandle(that); 1683 i::Handle<i::Object> obj = Utils::OpenHandle(that);
1689 ApiCheck(obj->HasSpecificClassOf(i::Heap::Date_symbol()), 1684 ApiCheck(obj->HasSpecificClassOf(i::Heap::Date_symbol()),
1690 "v8::Date::Cast()", 1685 "v8::Date::Cast()",
1691 "Could not convert to date"); 1686 "Could not convert to date");
1692 return static_cast<v8::Date*>(that);
1693 } 1687 }
1694 1688
1695 1689
1696 bool Value::BooleanValue() const { 1690 bool Value::BooleanValue() const {
1697 if (IsDeadCheck("v8::Value::BooleanValue()")) return false; 1691 if (IsDeadCheck("v8::Value::BooleanValue()")) return false;
1698 LOG_API("BooleanValue"); 1692 LOG_API("BooleanValue");
1699 i::Handle<i::Object> obj = Utils::OpenHandle(this); 1693 i::Handle<i::Object> obj = Utils::OpenHandle(this);
1700 if (obj->IsBoolean()) { 1694 if (obj->IsBoolean()) {
1701 return obj->IsTrue(); 1695 return obj->IsTrue();
1702 } else { 1696 } else {
(...skipping 740 matching lines...) Expand 10 before | Expand all | Expand 10 after
2443 } 2437 }
2444 2438
2445 2439
2446 bool v8::String::IsExternalAscii() const { 2440 bool v8::String::IsExternalAscii() const {
2447 EnsureInitialized("v8::String::IsExternalAscii()"); 2441 EnsureInitialized("v8::String::IsExternalAscii()");
2448 i::Handle<i::String> str = Utils::OpenHandle(this); 2442 i::Handle<i::String> str = Utils::OpenHandle(this);
2449 return i::StringShape(*str).IsExternalAscii(); 2443 return i::StringShape(*str).IsExternalAscii();
2450 } 2444 }
2451 2445
2452 2446
2453 v8::String::ExternalStringResource* 2447 void v8::String::VerifyExternalStringResource(
2454 v8::String::GetExternalStringResource() const { 2448 v8::String::ExternalStringResource* value) const {
2455 EnsureInitialized("v8::String::GetExternalStringResource()");
2456 i::Handle<i::String> str = Utils::OpenHandle(this); 2449 i::Handle<i::String> str = Utils::OpenHandle(this);
2450 v8::String::ExternalStringResource* expected;
2457 if (i::StringShape(*str).IsExternalTwoByte()) { 2451 if (i::StringShape(*str).IsExternalTwoByte()) {
2458 void* resource = i::Handle<i::ExternalTwoByteString>::cast(str)->resource(); 2452 void* resource = i::Handle<i::ExternalTwoByteString>::cast(str)->resource();
2459 return reinterpret_cast<ExternalStringResource*>(resource); 2453 expected = reinterpret_cast<ExternalStringResource*>(resource);
2460 } else { 2454 } else {
2461 return NULL; 2455 expected = NULL;
2462 } 2456 }
2457 CHECK_EQ(expected, value);
2463 } 2458 }
2464 2459
2465 2460
2466 v8::String::ExternalAsciiStringResource* 2461 v8::String::ExternalAsciiStringResource*
2467 v8::String::GetExternalAsciiStringResource() const { 2462 v8::String::GetExternalAsciiStringResource() const {
2468 EnsureInitialized("v8::String::GetExternalAsciiStringResource()"); 2463 EnsureInitialized("v8::String::GetExternalAsciiStringResource()");
2469 i::Handle<i::String> str = Utils::OpenHandle(this); 2464 i::Handle<i::String> str = Utils::OpenHandle(this);
2470 if (i::StringShape(*str).IsExternalAscii()) { 2465 if (i::StringShape(*str).IsExternalAscii()) {
2471 void* resource = i::Handle<i::ExternalAsciiString>::cast(str)->resource(); 2466 void* resource = i::Handle<i::ExternalAsciiString>::cast(str)->resource();
2472 return reinterpret_cast<ExternalAsciiStringResource*>(resource); 2467 return reinterpret_cast<ExternalAsciiStringResource*>(resource);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
2512 } 2507 }
2513 2508
2514 2509
2515 int v8::Object::InternalFieldCount() { 2510 int v8::Object::InternalFieldCount() {
2516 if (IsDeadCheck("v8::Object::InternalFieldCount()")) return 0; 2511 if (IsDeadCheck("v8::Object::InternalFieldCount()")) return 0;
2517 i::Handle<i::JSObject> obj = Utils::OpenHandle(this); 2512 i::Handle<i::JSObject> obj = Utils::OpenHandle(this);
2518 return obj->GetInternalFieldCount(); 2513 return obj->GetInternalFieldCount();
2519 } 2514 }
2520 2515
2521 2516
2522 Local<Value> v8::Object::GetInternalField(int index) { 2517 Local<Value> v8::Object::CheckedGetInternalField(int index) {
2523 if (IsDeadCheck("v8::Object::GetInternalField()")) return Local<Value>(); 2518 if (IsDeadCheck("v8::Object::GetInternalField()")) return Local<Value>();
2524 i::Handle<i::JSObject> obj = Utils::OpenHandle(this); 2519 i::Handle<i::JSObject> obj = Utils::OpenHandle(this);
2525 if (!ApiCheck(index < obj->GetInternalFieldCount(), 2520 if (!ApiCheck(index < obj->GetInternalFieldCount(),
2526 "v8::Object::GetInternalField()", 2521 "v8::Object::GetInternalField()",
2527 "Reading internal field out of bounds")) { 2522 "Reading internal field out of bounds")) {
2528 return Local<Value>(); 2523 return Local<Value>();
2529 } 2524 }
2530 i::Handle<i::Object> value(obj->GetInternalField(index)); 2525 i::Handle<i::Object> value(obj->GetInternalField(index));
2531 return Utils::ToLocal(value); 2526 Local<Value> result = Utils::ToLocal(value);
2527 #ifdef DEBUG
2528 Local<Value> unchecked = UncheckedGetInternalField(index);
2529 ASSERT(unchecked.IsEmpty() || (unchecked == result));
2530 #endif
2531 return result;
2532 } 2532 }
2533 2533
2534 2534
2535 void v8::Object::SetInternalField(int index, v8::Handle<Value> value) { 2535 void v8::Object::SetInternalField(int index, v8::Handle<Value> value) {
2536 if (IsDeadCheck("v8::Object::SetInternalField()")) return; 2536 if (IsDeadCheck("v8::Object::SetInternalField()")) return;
2537 i::Handle<i::JSObject> obj = Utils::OpenHandle(this); 2537 i::Handle<i::JSObject> obj = Utils::OpenHandle(this);
2538 if (!ApiCheck(index < obj->GetInternalFieldCount(), 2538 if (!ApiCheck(index < obj->GetInternalFieldCount(),
2539 "v8::Object::SetInternalField()", 2539 "v8::Object::SetInternalField()",
2540 "Writing internal field out of bounds")) { 2540 "Writing internal field out of bounds")) {
2541 return; 2541 return;
2542 } 2542 }
2543 ENTER_V8; 2543 ENTER_V8;
2544 i::Handle<i::Object> val = Utils::OpenHandle(*value); 2544 i::Handle<i::Object> val = Utils::OpenHandle(*value);
2545 obj->SetInternalField(index, *val); 2545 obj->SetInternalField(index, *val);
2546 } 2546 }
2547 2547
2548 2548
2549 void* v8::Object::GetPointerFromInternalField(int index) {
2550 i::Handle<i::JSObject> obj = Utils::OpenHandle(this);
2551 i::Object* pointer = obj->GetInternalField(index);
2552 if (pointer->IsSmi()) {
2553 // Fast case, aligned native pointer.
2554 return pointer;
2555 }
2556
2557 // Read from uninitialized field.
2558 if (!pointer->IsProxy()) {
2559 // Play safe even if it's something unexpected.
2560 ASSERT(pointer->IsUndefined());
2561 return NULL;
2562 }
2563
2564 // Unaligned native pointer.
2565 return reinterpret_cast<void*>(i::Proxy::cast(pointer)->proxy());
2566 }
2567
2568
2569 void v8::Object::SetPointerInInternalField(int index, void* value) { 2549 void v8::Object::SetPointerInInternalField(int index, void* value) {
2570 i::Handle<i::JSObject> obj = Utils::OpenHandle(this); 2550 SetInternalField(index, External::Wrap(value));
2571 i::Object* as_object = reinterpret_cast<i::Object*>(value);
2572 if (as_object->IsSmi()) {
2573 // Aligned pointer, store as is.
2574 obj->SetInternalField(index, as_object);
2575 } else {
2576 // Currently internal fields are used by DOM wrappers which only
2577 // get garbage collected by the mark-sweep collector, so we
2578 // pretenure the proxy.
2579 HandleScope scope;
2580 i::Handle<i::Proxy> proxy =
2581 i::Factory::NewProxy(reinterpret_cast<i::Address>(value), i::TENURED);
2582 if (!proxy.is_null()) obj->SetInternalField(index, *proxy);
2583 }
2584 } 2551 }
2585 2552
2586 2553
2587 // --- E n v i r o n m e n t --- 2554 // --- E n v i r o n m e n t ---
2588 2555
2589 bool v8::V8::Initialize() { 2556 bool v8::V8::Initialize() {
2590 if (i::V8::IsRunning()) return true; 2557 if (i::V8::IsRunning()) return true;
2591 ENTER_V8; 2558 ENTER_V8;
2592 HandleScope scope; 2559 HandleScope scope;
2593 if (i::Snapshot::Initialize()) { 2560 if (i::Snapshot::Initialize()) {
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
2829 static Local<External> ExternalNewImpl(void* data) { 2796 static Local<External> ExternalNewImpl(void* data) {
2830 return Utils::ToLocal(i::Factory::NewProxy(static_cast<i::Address>(data))); 2797 return Utils::ToLocal(i::Factory::NewProxy(static_cast<i::Address>(data)));
2831 } 2798 }
2832 2799
2833 static void* ExternalValueImpl(i::Handle<i::Object> obj) { 2800 static void* ExternalValueImpl(i::Handle<i::Object> obj) {
2834 return reinterpret_cast<void*>(i::Proxy::cast(*obj)->proxy()); 2801 return reinterpret_cast<void*>(i::Proxy::cast(*obj)->proxy());
2835 } 2802 }
2836 2803
2837 2804
2838 static const intptr_t kAlignedPointerMask = 3; 2805 static const intptr_t kAlignedPointerMask = 3;
2839 static const int kAlignedPointerShift = 2;
2840
2841 2806
2842 Local<Value> v8::External::Wrap(void* data) { 2807 Local<Value> v8::External::Wrap(void* data) {
2843 STATIC_ASSERT(sizeof(data) == sizeof(i::Address)); 2808 STATIC_ASSERT(sizeof(data) == sizeof(i::Address));
2844 LOG_API("External::Wrap"); 2809 LOG_API("External::Wrap");
2845 EnsureInitialized("v8::External::Wrap()"); 2810 EnsureInitialized("v8::External::Wrap()");
2846 ENTER_V8; 2811 ENTER_V8;
2847 if ((reinterpret_cast<intptr_t>(data) & kAlignedPointerMask) == 0) { 2812 if ((reinterpret_cast<intptr_t>(data) & kAlignedPointerMask) == 0) {
2848 uintptr_t data_ptr = reinterpret_cast<uintptr_t>(data); 2813 uintptr_t data_ptr = reinterpret_cast<uintptr_t>(data);
2849 intptr_t data_value = 2814 intptr_t data_value =
2850 static_cast<intptr_t>(data_ptr >> kAlignedPointerShift); 2815 static_cast<intptr_t>(data_ptr >> i::Internals::kAlignedPointerShift);
2851 STATIC_ASSERT(sizeof(data_ptr) == sizeof(data_value)); 2816 STATIC_ASSERT(sizeof(data_ptr) == sizeof(data_value));
2852 if (i::Smi::IsIntptrValid(data_value)) { 2817 if (i::Smi::IsIntptrValid(data_value)) {
2853 i::Handle<i::Object> obj(i::Smi::FromIntptr(data_value)); 2818 i::Handle<i::Object> obj(i::Smi::FromIntptr(data_value));
2854 return Utils::ToLocal(obj); 2819 return Utils::ToLocal(obj);
2855 } 2820 }
2856 } 2821 }
2857 return ExternalNewImpl(data); 2822 return ExternalNewImpl(data);
2858 } 2823 }
2859 2824
2860 2825
2861 void* v8::External::Unwrap(v8::Handle<v8::Value> value) { 2826 void* v8::External::FullUnwrap(v8::Handle<v8::Value> wrapper) {
2862 if (IsDeadCheck("v8::External::Unwrap()")) return 0; 2827 if (IsDeadCheck("v8::External::Unwrap()")) return 0;
2863 i::Handle<i::Object> obj = Utils::OpenHandle(*value); 2828 i::Handle<i::Object> obj = Utils::OpenHandle(*wrapper);
2829 void* result;
2864 if (obj->IsSmi()) { 2830 if (obj->IsSmi()) {
2865 // The external value was an aligned pointer. 2831 // The external value was an aligned pointer.
2866 uintptr_t result = static_cast<uintptr_t>( 2832 uintptr_t value = static_cast<uintptr_t>(
2867 i::Smi::cast(*obj)->value()) << kAlignedPointerShift; 2833 i::Smi::cast(*obj)->value()) << i::Internals::kAlignedPointerShift;
2868 return reinterpret_cast<void*>(result); 2834 result = reinterpret_cast<void*>(value);
2835 } else if (obj->IsProxy()) {
2836 result = ExternalValueImpl(obj);
2837 } else {
2838 result = NULL;
2869 } 2839 }
2870 return ExternalValueImpl(obj); 2840 ASSERT_EQ(result, QuickUnwrap(wrapper));
2841 return result;
2871 } 2842 }
2872 2843
2873 2844
2874 Local<External> v8::External::New(void* data) { 2845 Local<External> v8::External::New(void* data) {
2875 STATIC_ASSERT(sizeof(data) == sizeof(i::Address)); 2846 STATIC_ASSERT(sizeof(data) == sizeof(i::Address));
2876 LOG_API("External::New"); 2847 LOG_API("External::New");
2877 EnsureInitialized("v8::External::New()"); 2848 EnsureInitialized("v8::External::New()");
2878 ENTER_V8; 2849 ENTER_V8;
2879 return ExternalNewImpl(data); 2850 return ExternalNewImpl(data);
2880 } 2851 }
(...skipping 841 matching lines...) Expand 10 before | Expand all | Expand 10 after
3722 3693
3723 char* HandleScopeImplementer::RestoreThreadHelper(char* storage) { 3694 char* HandleScopeImplementer::RestoreThreadHelper(char* storage) {
3724 memcpy(this, storage, sizeof(*this)); 3695 memcpy(this, storage, sizeof(*this));
3725 *v8::ImplementationUtilities::CurrentHandleScope() = handle_scope_data_; 3696 *v8::ImplementationUtilities::CurrentHandleScope() = handle_scope_data_;
3726 return storage + ArchiveSpacePerThread(); 3697 return storage + ArchiveSpacePerThread();
3727 } 3698 }
3728 3699
3729 3700
3730 void HandleScopeImplementer::Iterate( 3701 void HandleScopeImplementer::Iterate(
3731 ObjectVisitor* v, 3702 ObjectVisitor* v,
3732 List<void**>* blocks, 3703 List<i::Object**>* blocks,
3733 v8::ImplementationUtilities::HandleScopeData* handle_data) { 3704 v8::ImplementationUtilities::HandleScopeData* handle_data) {
3734 // Iterate over all handles in the blocks except for the last. 3705 // Iterate over all handles in the blocks except for the last.
3735 for (int i = blocks->length() - 2; i >= 0; --i) { 3706 for (int i = blocks->length() - 2; i >= 0; --i) {
3736 Object** block = 3707 Object** block = blocks->at(i);
3737 reinterpret_cast<Object**>(blocks->at(i));
3738 v->VisitPointers(block, &block[kHandleBlockSize]); 3708 v->VisitPointers(block, &block[kHandleBlockSize]);
3739 } 3709 }
3740 3710
3741 // Iterate over live handles in the last block (if any). 3711 // Iterate over live handles in the last block (if any).
3742 if (!blocks->is_empty()) { 3712 if (!blocks->is_empty()) {
3743 v->VisitPointers(reinterpret_cast<Object**>(blocks->last()), 3713 v->VisitPointers(blocks->last(), handle_data->next);
3744 reinterpret_cast<Object**>(handle_data->next));
3745 } 3714 }
3746 } 3715 }
3747 3716
3748 3717
3749 void HandleScopeImplementer::Iterate(ObjectVisitor* v) { 3718 void HandleScopeImplementer::Iterate(ObjectVisitor* v) {
3750 v8::ImplementationUtilities::HandleScopeData* current = 3719 v8::ImplementationUtilities::HandleScopeData* current =
3751 v8::ImplementationUtilities::CurrentHandleScope(); 3720 v8::ImplementationUtilities::CurrentHandleScope();
3752 Iterate(v, thread_local.Blocks(), current); 3721 Iterate(v, thread_local.Blocks(), current);
3753 } 3722 }
3754 3723
3755 3724
3756 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) { 3725 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) {
3757 HandleScopeImplementer* thread_local = 3726 HandleScopeImplementer* thread_local =
3758 reinterpret_cast<HandleScopeImplementer*>(storage); 3727 reinterpret_cast<HandleScopeImplementer*>(storage);
3759 List<void**>* blocks_of_archived_thread = thread_local->Blocks(); 3728 List<internal::Object**>* blocks_of_archived_thread = thread_local->Blocks();
3760 v8::ImplementationUtilities::HandleScopeData* handle_data_of_archived_thread = 3729 v8::ImplementationUtilities::HandleScopeData* handle_data_of_archived_thread =
3761 &thread_local->handle_scope_data_; 3730 &thread_local->handle_scope_data_;
3762 Iterate(v, blocks_of_archived_thread, handle_data_of_archived_thread); 3731 Iterate(v, blocks_of_archived_thread, handle_data_of_archived_thread);
3763 3732
3764 return storage + ArchiveSpacePerThread(); 3733 return storage + ArchiveSpacePerThread();
3765 } 3734 }
3766 3735
3767 } } // namespace v8::internal 3736 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698