| OLD | NEW |
| 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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 static i::HandleScopeImplementer thread_local; | 108 static i::HandleScopeImplementer thread_local; |
| 109 | 109 |
| 110 | 110 |
| 111 // --- E x c e p t i o n B e h a v i o r --- | 111 // --- E x c e p t i o n B e h a v i o r --- |
| 112 | 112 |
| 113 | 113 |
| 114 static FatalErrorCallback exception_behavior = NULL; | 114 static FatalErrorCallback exception_behavior = NULL; |
| 115 | 115 |
| 116 static void DefaultFatalErrorHandler(const char* location, | 116 static void DefaultFatalErrorHandler(const char* location, |
| 117 const char* message) { | 117 const char* message) { |
| 118 ENTER_V8; | 118 #ifdef ENABLE_VMSTATE_TRACKING |
| 119 i::VMState __state__(i::OTHER); |
| 120 #endif |
| 119 API_Fatal(location, message); | 121 API_Fatal(location, message); |
| 120 } | 122 } |
| 121 | 123 |
| 122 | 124 |
| 123 static FatalErrorCallback& GetFatalErrorHandler() { | 125 static FatalErrorCallback& GetFatalErrorHandler() { |
| 124 if (exception_behavior == NULL) { | 126 if (exception_behavior == NULL) { |
| 125 exception_behavior = DefaultFatalErrorHandler; | 127 exception_behavior = DefaultFatalErrorHandler; |
| 126 } | 128 } |
| 127 return exception_behavior; | 129 return exception_behavior; |
| 128 } | 130 } |
| (...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 661 // --- T e m p l a t e --- | 663 // --- T e m p l a t e --- |
| 662 | 664 |
| 663 | 665 |
| 664 static void InitializeTemplate(i::Handle<i::TemplateInfo> that, int type) { | 666 static void InitializeTemplate(i::Handle<i::TemplateInfo> that, int type) { |
| 665 that->set_tag(i::Smi::FromInt(type)); | 667 that->set_tag(i::Smi::FromInt(type)); |
| 666 } | 668 } |
| 667 | 669 |
| 668 | 670 |
| 669 void Template::Set(v8::Handle<String> name, v8::Handle<Data> value, | 671 void Template::Set(v8::Handle<String> name, v8::Handle<Data> value, |
| 670 v8::PropertyAttribute attribute) { | 672 v8::PropertyAttribute attribute) { |
| 671 if (IsDeadCheck("v8::Template::SetProperty()")) return; | 673 if (IsDeadCheck("v8::Template::Set()")) return; |
| 672 ENTER_V8; | 674 ENTER_V8; |
| 673 HandleScope scope; | 675 HandleScope scope; |
| 674 i::Handle<i::Object> list(Utils::OpenHandle(this)->property_list()); | 676 i::Handle<i::Object> list(Utils::OpenHandle(this)->property_list()); |
| 675 if (list->IsUndefined()) { | 677 if (list->IsUndefined()) { |
| 676 list = NeanderArray().value(); | 678 list = NeanderArray().value(); |
| 677 Utils::OpenHandle(this)->set_property_list(*list); | 679 Utils::OpenHandle(this)->set_property_list(*list); |
| 678 } | 680 } |
| 679 NeanderArray array(list); | 681 NeanderArray array(list); |
| 680 array.add(Utils::OpenHandle(*name)); | 682 array.add(Utils::OpenHandle(*name)); |
| 681 array.add(Utils::OpenHandle(*value)); | 683 array.add(Utils::OpenHandle(*value)); |
| (...skipping 789 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1471 return scope.Close(result); | 1473 return scope.Close(result); |
| 1472 } | 1474 } |
| 1473 | 1475 |
| 1474 | 1476 |
| 1475 v8::Handle<Value> Message::GetScriptResourceName() const { | 1477 v8::Handle<Value> Message::GetScriptResourceName() const { |
| 1476 if (IsDeadCheck("v8::Message::GetScriptResourceName()")) { | 1478 if (IsDeadCheck("v8::Message::GetScriptResourceName()")) { |
| 1477 return Local<String>(); | 1479 return Local<String>(); |
| 1478 } | 1480 } |
| 1479 ENTER_V8; | 1481 ENTER_V8; |
| 1480 HandleScope scope; | 1482 HandleScope scope; |
| 1481 i::Handle<i::JSObject> obj = | 1483 i::Handle<i::JSMessageObject> message = |
| 1482 i::Handle<i::JSObject>::cast(Utils::OpenHandle(this)); | 1484 i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this)); |
| 1483 // Return this.script.name. | 1485 // Return this.script.name. |
| 1484 i::Handle<i::JSValue> script = | 1486 i::Handle<i::JSValue> script = |
| 1485 i::Handle<i::JSValue>::cast(GetProperty(obj, "script")); | 1487 i::Handle<i::JSValue>::cast(i::Handle<i::Object>(message->script())); |
| 1486 i::Handle<i::Object> resource_name(i::Script::cast(script->value())->name()); | 1488 i::Handle<i::Object> resource_name(i::Script::cast(script->value())->name()); |
| 1487 return scope.Close(Utils::ToLocal(resource_name)); | 1489 return scope.Close(Utils::ToLocal(resource_name)); |
| 1488 } | 1490 } |
| 1489 | 1491 |
| 1490 | 1492 |
| 1491 v8::Handle<Value> Message::GetScriptData() const { | 1493 v8::Handle<Value> Message::GetScriptData() const { |
| 1492 if (IsDeadCheck("v8::Message::GetScriptResourceData()")) { | 1494 if (IsDeadCheck("v8::Message::GetScriptResourceData()")) { |
| 1493 return Local<Value>(); | 1495 return Local<Value>(); |
| 1494 } | 1496 } |
| 1495 ENTER_V8; | 1497 ENTER_V8; |
| 1496 HandleScope scope; | 1498 HandleScope scope; |
| 1497 i::Handle<i::JSObject> obj = | 1499 i::Handle<i::JSMessageObject> message = |
| 1498 i::Handle<i::JSObject>::cast(Utils::OpenHandle(this)); | 1500 i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this)); |
| 1499 // Return this.script.data. | 1501 // Return this.script.data. |
| 1500 i::Handle<i::JSValue> script = | 1502 i::Handle<i::JSValue> script = |
| 1501 i::Handle<i::JSValue>::cast(GetProperty(obj, "script")); | 1503 i::Handle<i::JSValue>::cast(i::Handle<i::Object>(message->script())); |
| 1502 i::Handle<i::Object> data(i::Script::cast(script->value())->data()); | 1504 i::Handle<i::Object> data(i::Script::cast(script->value())->data()); |
| 1503 return scope.Close(Utils::ToLocal(data)); | 1505 return scope.Close(Utils::ToLocal(data)); |
| 1504 } | 1506 } |
| 1505 | 1507 |
| 1506 | 1508 |
| 1507 v8::Handle<v8::StackTrace> Message::GetStackTrace() const { | 1509 v8::Handle<v8::StackTrace> Message::GetStackTrace() const { |
| 1508 if (IsDeadCheck("v8::Message::GetStackTrace()")) { | 1510 if (IsDeadCheck("v8::Message::GetStackTrace()")) { |
| 1509 return Local<v8::StackTrace>(); | 1511 return Local<v8::StackTrace>(); |
| 1510 } | 1512 } |
| 1511 ENTER_V8; | 1513 ENTER_V8; |
| 1512 HandleScope scope; | 1514 HandleScope scope; |
| 1513 i::Handle<i::JSObject> obj = | 1515 i::Handle<i::JSMessageObject> message = |
| 1514 i::Handle<i::JSObject>::cast(Utils::OpenHandle(this)); | 1516 i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this)); |
| 1515 i::Handle<i::Object> stackFramesObj = GetProperty(obj, "stackFrames"); | 1517 i::Handle<i::Object> stackFramesObj(message->stack_frames()); |
| 1516 if (!stackFramesObj->IsJSArray()) return v8::Handle<v8::StackTrace>(); | 1518 if (!stackFramesObj->IsJSArray()) return v8::Handle<v8::StackTrace>(); |
| 1517 i::Handle<i::JSArray> stackTrace = | 1519 i::Handle<i::JSArray> stackTrace = |
| 1518 i::Handle<i::JSArray>::cast(stackFramesObj); | 1520 i::Handle<i::JSArray>::cast(stackFramesObj); |
| 1519 return scope.Close(Utils::StackTraceToLocal(stackTrace)); | 1521 return scope.Close(Utils::StackTraceToLocal(stackTrace)); |
| 1520 } | 1522 } |
| 1521 | 1523 |
| 1522 | 1524 |
| 1523 static i::Handle<i::Object> CallV8HeapFunction(const char* name, | 1525 static i::Handle<i::Object> CallV8HeapFunction(const char* name, |
| 1524 i::Handle<i::Object> recv, | 1526 i::Handle<i::Object> recv, |
| 1525 int argc, | 1527 int argc, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1545 1, | 1547 1, |
| 1546 argv, | 1548 argv, |
| 1547 has_pending_exception); | 1549 has_pending_exception); |
| 1548 } | 1550 } |
| 1549 | 1551 |
| 1550 | 1552 |
| 1551 int Message::GetLineNumber() const { | 1553 int Message::GetLineNumber() const { |
| 1552 ON_BAILOUT("v8::Message::GetLineNumber()", return kNoLineNumberInfo); | 1554 ON_BAILOUT("v8::Message::GetLineNumber()", return kNoLineNumberInfo); |
| 1553 ENTER_V8; | 1555 ENTER_V8; |
| 1554 HandleScope scope; | 1556 HandleScope scope; |
| 1557 |
| 1555 EXCEPTION_PREAMBLE(); | 1558 EXCEPTION_PREAMBLE(); |
| 1556 i::Handle<i::Object> result = CallV8HeapFunction("GetLineNumber", | 1559 i::Handle<i::Object> result = CallV8HeapFunction("GetLineNumber", |
| 1557 Utils::OpenHandle(this), | 1560 Utils::OpenHandle(this), |
| 1558 &has_pending_exception); | 1561 &has_pending_exception); |
| 1559 EXCEPTION_BAILOUT_CHECK(0); | 1562 EXCEPTION_BAILOUT_CHECK(0); |
| 1560 return static_cast<int>(result->Number()); | 1563 return static_cast<int>(result->Number()); |
| 1561 } | 1564 } |
| 1562 | 1565 |
| 1563 | 1566 |
| 1564 int Message::GetStartPosition() const { | 1567 int Message::GetStartPosition() const { |
| 1565 if (IsDeadCheck("v8::Message::GetStartPosition()")) return 0; | 1568 if (IsDeadCheck("v8::Message::GetStartPosition()")) return 0; |
| 1566 ENTER_V8; | 1569 ENTER_V8; |
| 1567 HandleScope scope; | 1570 HandleScope scope; |
| 1568 | 1571 i::Handle<i::JSMessageObject> message = |
| 1569 i::Handle<i::JSObject> data_obj = Utils::OpenHandle(this); | 1572 i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this)); |
| 1570 return static_cast<int>(GetProperty(data_obj, "startPos")->Number()); | 1573 return message->start_position(); |
| 1571 } | 1574 } |
| 1572 | 1575 |
| 1573 | 1576 |
| 1574 int Message::GetEndPosition() const { | 1577 int Message::GetEndPosition() const { |
| 1575 if (IsDeadCheck("v8::Message::GetEndPosition()")) return 0; | 1578 if (IsDeadCheck("v8::Message::GetEndPosition()")) return 0; |
| 1576 ENTER_V8; | 1579 ENTER_V8; |
| 1577 HandleScope scope; | 1580 HandleScope scope; |
| 1578 i::Handle<i::JSObject> data_obj = Utils::OpenHandle(this); | 1581 i::Handle<i::JSMessageObject> message = |
| 1579 return static_cast<int>(GetProperty(data_obj, "endPos")->Number()); | 1582 i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this)); |
| 1583 return message->end_position(); |
| 1580 } | 1584 } |
| 1581 | 1585 |
| 1582 | 1586 |
| 1583 int Message::GetStartColumn() const { | 1587 int Message::GetStartColumn() const { |
| 1584 if (IsDeadCheck("v8::Message::GetStartColumn()")) return kNoColumnInfo; | 1588 if (IsDeadCheck("v8::Message::GetStartColumn()")) return kNoColumnInfo; |
| 1585 ENTER_V8; | 1589 ENTER_V8; |
| 1586 HandleScope scope; | 1590 HandleScope scope; |
| 1587 i::Handle<i::JSObject> data_obj = Utils::OpenHandle(this); | 1591 i::Handle<i::JSObject> data_obj = Utils::OpenHandle(this); |
| 1588 EXCEPTION_PREAMBLE(); | 1592 EXCEPTION_PREAMBLE(); |
| 1589 i::Handle<i::Object> start_col_obj = CallV8HeapFunction( | 1593 i::Handle<i::Object> start_col_obj = CallV8HeapFunction( |
| 1590 "GetPositionInLine", | 1594 "GetPositionInLine", |
| 1591 data_obj, | 1595 data_obj, |
| 1592 &has_pending_exception); | 1596 &has_pending_exception); |
| 1593 EXCEPTION_BAILOUT_CHECK(0); | 1597 EXCEPTION_BAILOUT_CHECK(0); |
| 1594 return static_cast<int>(start_col_obj->Number()); | 1598 return static_cast<int>(start_col_obj->Number()); |
| 1595 } | 1599 } |
| 1596 | 1600 |
| 1597 | 1601 |
| 1598 int Message::GetEndColumn() const { | 1602 int Message::GetEndColumn() const { |
| 1599 if (IsDeadCheck("v8::Message::GetEndColumn()")) return kNoColumnInfo; | 1603 if (IsDeadCheck("v8::Message::GetEndColumn()")) return kNoColumnInfo; |
| 1600 ENTER_V8; | 1604 ENTER_V8; |
| 1601 HandleScope scope; | 1605 HandleScope scope; |
| 1602 i::Handle<i::JSObject> data_obj = Utils::OpenHandle(this); | 1606 i::Handle<i::JSObject> data_obj = Utils::OpenHandle(this); |
| 1603 EXCEPTION_PREAMBLE(); | 1607 EXCEPTION_PREAMBLE(); |
| 1604 i::Handle<i::Object> start_col_obj = CallV8HeapFunction( | 1608 i::Handle<i::Object> start_col_obj = CallV8HeapFunction( |
| 1605 "GetPositionInLine", | 1609 "GetPositionInLine", |
| 1606 data_obj, | 1610 data_obj, |
| 1607 &has_pending_exception); | 1611 &has_pending_exception); |
| 1608 EXCEPTION_BAILOUT_CHECK(0); | 1612 EXCEPTION_BAILOUT_CHECK(0); |
| 1609 int start = static_cast<int>(GetProperty(data_obj, "startPos")->Number()); | 1613 i::Handle<i::JSMessageObject> message = |
| 1610 int end = static_cast<int>(GetProperty(data_obj, "endPos")->Number()); | 1614 i::Handle<i::JSMessageObject>::cast(data_obj); |
| 1615 int start = message->start_position(); |
| 1616 int end = message->end_position(); |
| 1611 return static_cast<int>(start_col_obj->Number()) + (end - start); | 1617 return static_cast<int>(start_col_obj->Number()) + (end - start); |
| 1612 } | 1618 } |
| 1613 | 1619 |
| 1614 | 1620 |
| 1615 Local<String> Message::GetSourceLine() const { | 1621 Local<String> Message::GetSourceLine() const { |
| 1616 ON_BAILOUT("v8::Message::GetSourceLine()", return Local<String>()); | 1622 ON_BAILOUT("v8::Message::GetSourceLine()", return Local<String>()); |
| 1617 ENTER_V8; | 1623 ENTER_V8; |
| 1618 HandleScope scope; | 1624 HandleScope scope; |
| 1619 EXCEPTION_PREAMBLE(); | 1625 EXCEPTION_PREAMBLE(); |
| 1620 i::Handle<i::Object> result = CallV8HeapFunction("GetSourceLine", | 1626 i::Handle<i::Object> result = CallV8HeapFunction("GetSourceLine", |
| (...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2193 bool Value::Equals(Handle<Value> that) const { | 2199 bool Value::Equals(Handle<Value> that) const { |
| 2194 if (IsDeadCheck("v8::Value::Equals()") | 2200 if (IsDeadCheck("v8::Value::Equals()") |
| 2195 || EmptyCheck("v8::Value::Equals()", this) | 2201 || EmptyCheck("v8::Value::Equals()", this) |
| 2196 || EmptyCheck("v8::Value::Equals()", that)) { | 2202 || EmptyCheck("v8::Value::Equals()", that)) { |
| 2197 return false; | 2203 return false; |
| 2198 } | 2204 } |
| 2199 LOG_API("Equals"); | 2205 LOG_API("Equals"); |
| 2200 ENTER_V8; | 2206 ENTER_V8; |
| 2201 i::Handle<i::Object> obj = Utils::OpenHandle(this); | 2207 i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 2202 i::Handle<i::Object> other = Utils::OpenHandle(*that); | 2208 i::Handle<i::Object> other = Utils::OpenHandle(*that); |
| 2209 // If both obj and other are JSObjects, we'd better compare by identity |
| 2210 // immediately when going into JS builtin. The reason is Invoke |
| 2211 // would overwrite global object receiver with global proxy. |
| 2212 if (obj->IsJSObject() && other->IsJSObject()) { |
| 2213 return *obj == *other; |
| 2214 } |
| 2203 i::Object** args[1] = { other.location() }; | 2215 i::Object** args[1] = { other.location() }; |
| 2204 EXCEPTION_PREAMBLE(); | 2216 EXCEPTION_PREAMBLE(); |
| 2205 i::Handle<i::Object> result = | 2217 i::Handle<i::Object> result = |
| 2206 CallV8HeapFunction("EQUALS", obj, 1, args, &has_pending_exception); | 2218 CallV8HeapFunction("EQUALS", obj, 1, args, &has_pending_exception); |
| 2207 EXCEPTION_BAILOUT_CHECK(false); | 2219 EXCEPTION_BAILOUT_CHECK(false); |
| 2208 return *result == i::Smi::FromInt(i::EQUAL); | 2220 return *result == i::Smi::FromInt(i::EQUAL); |
| 2209 } | 2221 } |
| 2210 | 2222 |
| 2211 | 2223 |
| 2212 bool Value::StrictEquals(Handle<Value> that) const { | 2224 bool Value::StrictEquals(Handle<Value> that) const { |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2642 EXCEPTION_BAILOUT_CHECK(Local<Object>()); | 2654 EXCEPTION_BAILOUT_CHECK(Local<Object>()); |
| 2643 return Utils::ToLocal(result); | 2655 return Utils::ToLocal(result); |
| 2644 } | 2656 } |
| 2645 | 2657 |
| 2646 | 2658 |
| 2647 int v8::Object::GetIdentityHash() { | 2659 int v8::Object::GetIdentityHash() { |
| 2648 ON_BAILOUT("v8::Object::GetIdentityHash()", return 0); | 2660 ON_BAILOUT("v8::Object::GetIdentityHash()", return 0); |
| 2649 ENTER_V8; | 2661 ENTER_V8; |
| 2650 HandleScope scope; | 2662 HandleScope scope; |
| 2651 i::Handle<i::JSObject> self = Utils::OpenHandle(this); | 2663 i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2652 i::Handle<i::Object> hidden_props(i::GetHiddenProperties(self, true)); | 2664 i::Handle<i::Object> hidden_props_obj(i::GetHiddenProperties(self, true)); |
| 2653 i::Handle<i::Object> hash_symbol = i::Factory::identity_hash_symbol(); | 2665 if (!hidden_props_obj->IsJSObject()) { |
| 2654 i::Handle<i::Object> hash = i::GetProperty(hidden_props, hash_symbol); | 2666 // We failed to create hidden properties. That's a detached |
| 2667 // global proxy. |
| 2668 ASSERT(hidden_props_obj->IsUndefined()); |
| 2669 return 0; |
| 2670 } |
| 2671 i::Handle<i::JSObject> hidden_props = |
| 2672 i::Handle<i::JSObject>::cast(hidden_props_obj); |
| 2673 i::Handle<i::String> hash_symbol = i::Factory::identity_hash_symbol(); |
| 2674 if (hidden_props->HasLocalProperty(*hash_symbol)) { |
| 2675 i::Handle<i::Object> hash = i::GetProperty(hidden_props, hash_symbol); |
| 2676 CHECK(!hash.is_null()); |
| 2677 CHECK(hash->IsSmi()); |
| 2678 return i::Smi::cast(*hash)->value(); |
| 2679 } |
| 2680 |
| 2655 int hash_value; | 2681 int hash_value; |
| 2656 if (hash->IsSmi()) { | 2682 int attempts = 0; |
| 2657 hash_value = i::Smi::cast(*hash)->value(); | 2683 do { |
| 2658 } else { | 2684 // Generate a random 32-bit hash value but limit range to fit |
| 2659 int attempts = 0; | 2685 // within a smi. |
| 2660 do { | 2686 hash_value = i::V8::Random() & i::Smi::kMaxValue; |
| 2661 // Generate a random 32-bit hash value but limit range to fit | 2687 attempts++; |
| 2662 // within a smi. | 2688 } while (hash_value == 0 && attempts < 30); |
| 2663 hash_value = i::V8::Random() & i::Smi::kMaxValue; | 2689 hash_value = hash_value != 0 ? hash_value : 1; // never return 0 |
| 2664 attempts++; | 2690 CHECK(!i::SetLocalPropertyIgnoreAttributes( |
| 2665 } while (hash_value == 0 && attempts < 30); | 2691 hidden_props, |
| 2666 hash_value = hash_value != 0 ? hash_value : 1; // never return 0 | 2692 hash_symbol, |
| 2667 i::SetProperty(hidden_props, | 2693 i::Handle<i::Object>(i::Smi::FromInt(hash_value)), |
| 2668 hash_symbol, | 2694 static_cast<PropertyAttributes>(None)).is_null()); |
| 2669 i::Handle<i::Object>(i::Smi::FromInt(hash_value)), | 2695 |
| 2670 static_cast<PropertyAttributes>(None)); | |
| 2671 } | |
| 2672 return hash_value; | 2696 return hash_value; |
| 2673 } | 2697 } |
| 2674 | 2698 |
| 2675 | 2699 |
| 2676 bool v8::Object::SetHiddenValue(v8::Handle<v8::String> key, | 2700 bool v8::Object::SetHiddenValue(v8::Handle<v8::String> key, |
| 2677 v8::Handle<v8::Value> value) { | 2701 v8::Handle<v8::Value> value) { |
| 2678 ON_BAILOUT("v8::Object::SetHiddenValue()", return false); | 2702 ON_BAILOUT("v8::Object::SetHiddenValue()", return false); |
| 2679 ENTER_V8; | 2703 ENTER_V8; |
| 2680 HandleScope scope; | 2704 HandleScope scope; |
| 2681 i::Handle<i::JSObject> self = Utils::OpenHandle(this); | 2705 i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2738 "length exceeds max acceptable value")) { | 2762 "length exceeds max acceptable value")) { |
| 2739 return; | 2763 return; |
| 2740 } | 2764 } |
| 2741 i::Handle<i::JSObject> self = Utils::OpenHandle(this); | 2765 i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2742 if (!ApiCheck(!self->IsJSArray(), | 2766 if (!ApiCheck(!self->IsJSArray(), |
| 2743 "v8::Object::SetIndexedPropertiesToPixelData()", | 2767 "v8::Object::SetIndexedPropertiesToPixelData()", |
| 2744 "JSArray is not supported")) { | 2768 "JSArray is not supported")) { |
| 2745 return; | 2769 return; |
| 2746 } | 2770 } |
| 2747 i::Handle<i::PixelArray> pixels = i::Factory::NewPixelArray(length, data); | 2771 i::Handle<i::PixelArray> pixels = i::Factory::NewPixelArray(length, data); |
| 2748 i::Handle<i::Map> slow_map = | 2772 i::Handle<i::Map> pixel_array_map = |
| 2749 i::Factory::GetSlowElementsMap(i::Handle<i::Map>(self->map())); | 2773 i::Factory::GetPixelArrayElementsMap(i::Handle<i::Map>(self->map())); |
| 2750 self->set_map(*slow_map); | 2774 self->set_map(*pixel_array_map); |
| 2751 self->set_elements(*pixels); | 2775 self->set_elements(*pixels); |
| 2752 } | 2776 } |
| 2753 | 2777 |
| 2754 | 2778 |
| 2755 bool v8::Object::HasIndexedPropertiesInPixelData() { | 2779 bool v8::Object::HasIndexedPropertiesInPixelData() { |
| 2756 ON_BAILOUT("v8::HasIndexedPropertiesInPixelData()", return false); | 2780 ON_BAILOUT("v8::HasIndexedPropertiesInPixelData()", return false); |
| 2757 i::Handle<i::JSObject> self = Utils::OpenHandle(this); | 2781 i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2758 return self->HasPixelElements(); | 2782 return self->HasPixelElements(); |
| 2759 } | 2783 } |
| 2760 | 2784 |
| (...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3259 "v8::Object::SetInternalField()", | 3283 "v8::Object::SetInternalField()", |
| 3260 "Writing internal field out of bounds")) { | 3284 "Writing internal field out of bounds")) { |
| 3261 return; | 3285 return; |
| 3262 } | 3286 } |
| 3263 ENTER_V8; | 3287 ENTER_V8; |
| 3264 i::Handle<i::Object> val = Utils::OpenHandle(*value); | 3288 i::Handle<i::Object> val = Utils::OpenHandle(*value); |
| 3265 obj->SetInternalField(index, *val); | 3289 obj->SetInternalField(index, *val); |
| 3266 } | 3290 } |
| 3267 | 3291 |
| 3268 | 3292 |
| 3293 static bool CanBeEncodedAsSmi(void* ptr) { |
| 3294 const uintptr_t address = reinterpret_cast<uintptr_t>(ptr); |
| 3295 return ((address & i::kEncodablePointerMask) == 0); |
| 3296 } |
| 3297 |
| 3298 |
| 3299 static i::Smi* EncodeAsSmi(void* ptr) { |
| 3300 ASSERT(CanBeEncodedAsSmi(ptr)); |
| 3301 const uintptr_t address = reinterpret_cast<uintptr_t>(ptr); |
| 3302 i::Smi* result = reinterpret_cast<i::Smi*>(address << i::kPointerToSmiShift); |
| 3303 ASSERT(i::Internals::HasSmiTag(result)); |
| 3304 ASSERT_EQ(result, i::Smi::FromInt(result->value())); |
| 3305 ASSERT_EQ(ptr, i::Internals::GetExternalPointerFromSmi(result)); |
| 3306 return result; |
| 3307 } |
| 3308 |
| 3309 |
| 3269 void v8::Object::SetPointerInInternalField(int index, void* value) { | 3310 void v8::Object::SetPointerInInternalField(int index, void* value) { |
| 3270 ENTER_V8; | 3311 ENTER_V8; |
| 3271 i::Object* as_object = reinterpret_cast<i::Object*>(value); | 3312 if (CanBeEncodedAsSmi(value)) { |
| 3272 if (as_object->IsSmi()) { | 3313 Utils::OpenHandle(this)->SetInternalField(index, EncodeAsSmi(value)); |
| 3273 Utils::OpenHandle(this)->SetInternalField(index, as_object); | 3314 } else { |
| 3274 return; | 3315 HandleScope scope; |
| 3316 i::Handle<i::Proxy> proxy = |
| 3317 i::Factory::NewProxy(reinterpret_cast<i::Address>(value), i::TENURED); |
| 3318 if (!proxy.is_null()) |
| 3319 Utils::OpenHandle(this)->SetInternalField(index, *proxy); |
| 3275 } | 3320 } |
| 3276 HandleScope scope; | 3321 ASSERT_EQ(value, GetPointerFromInternalField(index)); |
| 3277 i::Handle<i::Proxy> proxy = | |
| 3278 i::Factory::NewProxy(reinterpret_cast<i::Address>(value), i::TENURED); | |
| 3279 if (!proxy.is_null()) | |
| 3280 Utils::OpenHandle(this)->SetInternalField(index, *proxy); | |
| 3281 } | 3322 } |
| 3282 | 3323 |
| 3283 | 3324 |
| 3284 // --- E n v i r o n m e n t --- | 3325 // --- E n v i r o n m e n t --- |
| 3285 | 3326 |
| 3286 bool v8::V8::Initialize() { | 3327 bool v8::V8::Initialize() { |
| 3287 if (i::V8::IsRunning()) return true; | 3328 if (i::V8::IsRunning()) return true; |
| 3288 HandleScope scope; | 3329 HandleScope scope; |
| 3289 if (i::Snapshot::Initialize()) return true; | 3330 if (i::Snapshot::Initialize()) return true; |
| 3290 return i::V8::Initialize(NULL); | 3331 return i::V8::Initialize(NULL); |
| 3291 } | 3332 } |
| 3292 | 3333 |
| 3293 | 3334 |
| 3294 bool v8::V8::Dispose() { | 3335 bool v8::V8::Dispose() { |
| 3295 i::V8::TearDown(); | 3336 i::V8::TearDown(); |
| 3296 return true; | 3337 return true; |
| 3297 } | 3338 } |
| 3298 | 3339 |
| 3299 | 3340 |
| 3300 HeapStatistics::HeapStatistics(): total_heap_size_(0), | 3341 HeapStatistics::HeapStatistics(): total_heap_size_(0), |
| 3301 total_heap_size_executable_(0), | 3342 total_heap_size_executable_(0), |
| 3302 used_heap_size_(0) { } | 3343 used_heap_size_(0), |
| 3344 heap_size_limit_(0) { } |
| 3303 | 3345 |
| 3304 | 3346 |
| 3305 void v8::V8::GetHeapStatistics(HeapStatistics* heap_statistics) { | 3347 void v8::V8::GetHeapStatistics(HeapStatistics* heap_statistics) { |
| 3306 heap_statistics->set_total_heap_size(i::Heap::CommittedMemory()); | 3348 heap_statistics->set_total_heap_size(i::Heap::CommittedMemory()); |
| 3307 heap_statistics->set_total_heap_size_executable( | 3349 heap_statistics->set_total_heap_size_executable( |
| 3308 i::Heap::CommittedMemoryExecutable()); | 3350 i::Heap::CommittedMemoryExecutable()); |
| 3309 heap_statistics->set_used_heap_size(i::Heap::SizeOfObjects()); | 3351 heap_statistics->set_used_heap_size(i::Heap::SizeOfObjects()); |
| 3352 heap_statistics->set_heap_size_limit(i::Heap::MaxReserved()); |
| 3310 } | 3353 } |
| 3311 | 3354 |
| 3312 | 3355 |
| 3313 bool v8::V8::IdleNotification() { | 3356 bool v8::V8::IdleNotification() { |
| 3314 // Returning true tells the caller that it need not | 3357 // Returning true tells the caller that it need not |
| 3315 // continue to call IdleNotification. | 3358 // continue to call IdleNotification. |
| 3316 if (!i::V8::IsRunning()) return true; | 3359 if (!i::V8::IsRunning()) return true; |
| 3317 return i::V8::IdleNotification(); | 3360 return i::V8::IdleNotification(); |
| 3318 } | 3361 } |
| 3319 | 3362 |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3553 static void* ExternalValueImpl(i::Handle<i::Object> obj) { | 3596 static void* ExternalValueImpl(i::Handle<i::Object> obj) { |
| 3554 return reinterpret_cast<void*>(i::Proxy::cast(*obj)->proxy()); | 3597 return reinterpret_cast<void*>(i::Proxy::cast(*obj)->proxy()); |
| 3555 } | 3598 } |
| 3556 | 3599 |
| 3557 | 3600 |
| 3558 Local<Value> v8::External::Wrap(void* data) { | 3601 Local<Value> v8::External::Wrap(void* data) { |
| 3559 STATIC_ASSERT(sizeof(data) == sizeof(i::Address)); | 3602 STATIC_ASSERT(sizeof(data) == sizeof(i::Address)); |
| 3560 LOG_API("External::Wrap"); | 3603 LOG_API("External::Wrap"); |
| 3561 EnsureInitialized("v8::External::Wrap()"); | 3604 EnsureInitialized("v8::External::Wrap()"); |
| 3562 ENTER_V8; | 3605 ENTER_V8; |
| 3563 i::Object* as_object = reinterpret_cast<i::Object*>(data); | 3606 |
| 3564 if (as_object->IsSmi()) { | 3607 v8::Local<v8::Value> result = CanBeEncodedAsSmi(data) |
| 3565 return Utils::ToLocal(i::Handle<i::Object>(as_object)); | 3608 ? Utils::ToLocal(i::Handle<i::Object>(EncodeAsSmi(data))) |
| 3566 } | 3609 : v8::Local<v8::Value>(ExternalNewImpl(data)); |
| 3567 return ExternalNewImpl(data); | 3610 |
| 3611 ASSERT_EQ(data, Unwrap(result)); |
| 3612 return result; |
| 3568 } | 3613 } |
| 3569 | 3614 |
| 3570 | 3615 |
| 3571 void* v8::Object::SlowGetPointerFromInternalField(int index) { | 3616 void* v8::Object::SlowGetPointerFromInternalField(int index) { |
| 3572 i::Handle<i::JSObject> obj = Utils::OpenHandle(this); | 3617 i::Handle<i::JSObject> obj = Utils::OpenHandle(this); |
| 3573 i::Object* value = obj->GetInternalField(index); | 3618 i::Object* value = obj->GetInternalField(index); |
| 3574 if (value->IsSmi()) { | 3619 if (value->IsSmi()) { |
| 3575 return value; | 3620 return i::Internals::GetExternalPointerFromSmi(value); |
| 3576 } else if (value->IsProxy()) { | 3621 } else if (value->IsProxy()) { |
| 3577 return reinterpret_cast<void*>(i::Proxy::cast(value)->proxy()); | 3622 return reinterpret_cast<void*>(i::Proxy::cast(value)->proxy()); |
| 3578 } else { | 3623 } else { |
| 3579 return NULL; | 3624 return NULL; |
| 3580 } | 3625 } |
| 3581 } | 3626 } |
| 3582 | 3627 |
| 3583 | 3628 |
| 3584 void* v8::External::FullUnwrap(v8::Handle<v8::Value> wrapper) { | 3629 void* v8::External::FullUnwrap(v8::Handle<v8::Value> wrapper) { |
| 3585 if (IsDeadCheck("v8::External::Unwrap()")) return 0; | 3630 if (IsDeadCheck("v8::External::Unwrap()")) return 0; |
| 3586 i::Handle<i::Object> obj = Utils::OpenHandle(*wrapper); | 3631 i::Handle<i::Object> obj = Utils::OpenHandle(*wrapper); |
| 3587 void* result; | 3632 void* result; |
| 3588 if (obj->IsSmi()) { | 3633 if (obj->IsSmi()) { |
| 3589 // The external value was an aligned pointer. | 3634 result = i::Internals::GetExternalPointerFromSmi(*obj); |
| 3590 result = *obj; | |
| 3591 } else if (obj->IsProxy()) { | 3635 } else if (obj->IsProxy()) { |
| 3592 result = ExternalValueImpl(obj); | 3636 result = ExternalValueImpl(obj); |
| 3593 } else { | 3637 } else { |
| 3594 result = NULL; | 3638 result = NULL; |
| 3595 } | 3639 } |
| 3596 ASSERT_EQ(result, QuickUnwrap(wrapper)); | 3640 ASSERT_EQ(result, QuickUnwrap(wrapper)); |
| 3597 return result; | 3641 return result; |
| 3598 } | 3642 } |
| 3599 | 3643 |
| 3600 | 3644 |
| (...skipping 1535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5136 | 5180 |
| 5137 | 5181 |
| 5138 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) { | 5182 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) { |
| 5139 HandleScopeImplementer* thread_local = | 5183 HandleScopeImplementer* thread_local = |
| 5140 reinterpret_cast<HandleScopeImplementer*>(storage); | 5184 reinterpret_cast<HandleScopeImplementer*>(storage); |
| 5141 thread_local->IterateThis(v); | 5185 thread_local->IterateThis(v); |
| 5142 return storage + ArchiveSpacePerThread(); | 5186 return storage + ArchiveSpacePerThread(); |
| 5143 } | 5187 } |
| 5144 | 5188 |
| 5145 } } // namespace v8::internal | 5189 } } // namespace v8::internal |
| OLD | NEW |