| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 SHARED_FUNCTION_INFO_TYPE); | 294 SHARED_FUNCTION_INFO_TYPE); |
| 295 } | 295 } |
| 296 | 296 |
| 297 | 297 |
| 298 bool Object::IsJSValue() { | 298 bool Object::IsJSValue() { |
| 299 return Object::IsHeapObject() | 299 return Object::IsHeapObject() |
| 300 && HeapObject::cast(this)->map()->instance_type() == JS_VALUE_TYPE; | 300 && HeapObject::cast(this)->map()->instance_type() == JS_VALUE_TYPE; |
| 301 } | 301 } |
| 302 | 302 |
| 303 | 303 |
| 304 bool Object::IsStringWrapper() { |
| 305 return IsJSValue() && JSValue::cast(this)->value()->IsString(); |
| 306 } |
| 307 |
| 308 |
| 304 bool Object::IsProxy() { | 309 bool Object::IsProxy() { |
| 305 return Object::IsHeapObject() | 310 return Object::IsHeapObject() |
| 306 && HeapObject::cast(this)->map()->instance_type() == PROXY_TYPE; | 311 && HeapObject::cast(this)->map()->instance_type() == PROXY_TYPE; |
| 307 } | 312 } |
| 308 | 313 |
| 309 | 314 |
| 310 bool Object::IsBoolean() { | 315 bool Object::IsBoolean() { |
| 311 return IsTrue() || IsFalse(); | 316 return IsTrue() || IsFalse(); |
| 312 } | 317 } |
| 313 | 318 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 (HeapObject::cast(this)->map()->instance_type() == | 375 (HeapObject::cast(this)->map()->instance_type() == |
| 371 JS_GLOBAL_PROXY_TYPE); | 376 JS_GLOBAL_PROXY_TYPE); |
| 372 ASSERT(!result || IsAccessCheckNeeded()); | 377 ASSERT(!result || IsAccessCheckNeeded()); |
| 373 return result; | 378 return result; |
| 374 } | 379 } |
| 375 | 380 |
| 376 | 381 |
| 377 bool Object::IsGlobalObject() { | 382 bool Object::IsGlobalObject() { |
| 378 if (!IsHeapObject()) return false; | 383 if (!IsHeapObject()) return false; |
| 379 | 384 |
| 380 InstanceType type = HeapObject::cast(this)->map()->instance_type(); | 385 InstanceType type = HeapObject::cast(this)->map()->instance_type(); |
| 381 return type == JS_GLOBAL_OBJECT_TYPE || | 386 return type == JS_GLOBAL_OBJECT_TYPE || |
| 382 type == JS_BUILTINS_OBJECT_TYPE; | 387 type == JS_BUILTINS_OBJECT_TYPE; |
| 383 } | 388 } |
| 384 | 389 |
| 385 | 390 |
| 386 bool Object::IsJSGlobalObject() { | 391 bool Object::IsJSGlobalObject() { |
| 387 return IsHeapObject() && | 392 return IsHeapObject() && |
| 388 (HeapObject::cast(this)->map()->instance_type() == | 393 (HeapObject::cast(this)->map()->instance_type() == |
| 389 JS_GLOBAL_OBJECT_TYPE); | 394 JS_GLOBAL_OBJECT_TYPE); |
| 390 } | 395 } |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 545 #define WRITE_SHORT_FIELD(p, offset, value) \ | 550 #define WRITE_SHORT_FIELD(p, offset, value) \ |
| 546 (*reinterpret_cast<uint16_t*>(FIELD_ADDR(p, offset)) = value) | 551 (*reinterpret_cast<uint16_t*>(FIELD_ADDR(p, offset)) = value) |
| 547 | 552 |
| 548 #define READ_BYTE_FIELD(p, offset) \ | 553 #define READ_BYTE_FIELD(p, offset) \ |
| 549 (*reinterpret_cast<byte*>(FIELD_ADDR(p, offset))) | 554 (*reinterpret_cast<byte*>(FIELD_ADDR(p, offset))) |
| 550 | 555 |
| 551 #define WRITE_BYTE_FIELD(p, offset, value) \ | 556 #define WRITE_BYTE_FIELD(p, offset, value) \ |
| 552 (*reinterpret_cast<byte*>(FIELD_ADDR(p, offset)) = value) | 557 (*reinterpret_cast<byte*>(FIELD_ADDR(p, offset)) = value) |
| 553 | 558 |
| 554 | 559 |
| 555 Object* HeapObject::GetHeapObjectField(HeapObject* obj, int index) { | 560 Object** HeapObject::RawField(HeapObject* obj, int byte_offset) { |
| 556 return READ_FIELD(obj, HeapObject::kHeaderSize + kPointerSize * index); | 561 return &READ_FIELD(obj, byte_offset); |
| 557 } | 562 } |
| 558 | 563 |
| 559 | 564 |
| 560 int Smi::value() { | 565 int Smi::value() { |
| 561 return reinterpret_cast<int>(this) >> kSmiTagSize; | 566 return reinterpret_cast<int>(this) >> kSmiTagSize; |
| 562 } | 567 } |
| 563 | 568 |
| 564 | 569 |
| 565 Smi* Smi::FromInt(int value) { | 570 Smi* Smi::FromInt(int value) { |
| 566 ASSERT(Smi::IsValid(value)); | 571 ASSERT(Smi::IsValid(value)); |
| (...skipping 697 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1264 bool String::Equals(String* other) { | 1269 bool String::Equals(String* other) { |
| 1265 if (other == this) return true; | 1270 if (other == this) return true; |
| 1266 if (IsSymbol() && other->IsSymbol()) return false; | 1271 if (IsSymbol() && other->IsSymbol()) return false; |
| 1267 return SlowEquals(other); | 1272 return SlowEquals(other); |
| 1268 } | 1273 } |
| 1269 | 1274 |
| 1270 | 1275 |
| 1271 int String::length() { | 1276 int String::length() { |
| 1272 uint32_t len = READ_INT_FIELD(this, kLengthOffset); | 1277 uint32_t len = READ_INT_FIELD(this, kLengthOffset); |
| 1273 | 1278 |
| 1274 switch (size_tag()) { | 1279 ASSERT(kShortStringTag + kLongLengthShift == kShortLengthShift); |
| 1275 case kShortStringTag: | 1280 ASSERT(kMediumStringTag + kLongLengthShift == kMediumLengthShift); |
| 1276 return len >> kShortLengthShift; | 1281 ASSERT(kLongStringTag == 0); |
| 1277 case kMediumStringTag: | 1282 |
| 1278 return len >> kMediumLengthShift; | 1283 return len >> (size_tag() + kLongLengthShift); |
| 1279 case kLongStringTag: | |
| 1280 return len >> kLongLengthShift; | |
| 1281 default: | |
| 1282 break; | |
| 1283 } | |
| 1284 UNREACHABLE(); | |
| 1285 return 0; | |
| 1286 } | 1284 } |
| 1287 | 1285 |
| 1288 | 1286 |
| 1289 void String::set_length(int value) { | 1287 void String::set_length(int value) { |
| 1290 switch (size_tag()) { | 1288 ASSERT(kShortStringTag + kLongLengthShift == kShortLengthShift); |
| 1291 case kShortStringTag: | 1289 ASSERT(kMediumStringTag + kLongLengthShift == kMediumLengthShift); |
| 1292 WRITE_INT_FIELD(this, kLengthOffset, value << kShortLengthShift); | 1290 ASSERT(kLongStringTag == 0); |
| 1293 break; | 1291 |
| 1294 case kMediumStringTag: | 1292 WRITE_INT_FIELD(this, |
| 1295 WRITE_INT_FIELD(this, kLengthOffset, value << kMediumLengthShift); | 1293 kLengthOffset, |
| 1296 break; | 1294 value << (size_tag() + kLongLengthShift)); |
| 1297 case kLongStringTag: | |
| 1298 WRITE_INT_FIELD(this, kLengthOffset, value << kLongLengthShift); | |
| 1299 break; | |
| 1300 default: | |
| 1301 UNREACHABLE(); | |
| 1302 break; | |
| 1303 } | |
| 1304 } | 1295 } |
| 1305 | 1296 |
| 1306 | 1297 |
| 1307 uint32_t String::length_field() { | 1298 uint32_t String::length_field() { |
| 1308 return READ_UINT32_FIELD(this, kLengthOffset); | 1299 return READ_UINT32_FIELD(this, kLengthOffset); |
| 1309 } | 1300 } |
| 1310 | 1301 |
| 1311 | 1302 |
| 1312 void String::set_length_field(uint32_t value) { | 1303 void String::set_length_field(uint32_t value) { |
| 1313 WRITE_UINT32_FIELD(this, kLengthOffset, value); | 1304 WRITE_UINT32_FIELD(this, kLengthOffset, value); |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1477 | 1468 |
| 1478 void SeqTwoByteString::SeqTwoByteStringSet(int index, uint16_t value) { | 1469 void SeqTwoByteString::SeqTwoByteStringSet(int index, uint16_t value) { |
| 1479 ASSERT(index >= 0 && index < length()); | 1470 ASSERT(index >= 0 && index < length()); |
| 1480 WRITE_SHORT_FIELD(this, kHeaderSize + index * kShortSize, value); | 1471 WRITE_SHORT_FIELD(this, kHeaderSize + index * kShortSize, value); |
| 1481 } | 1472 } |
| 1482 | 1473 |
| 1483 | 1474 |
| 1484 int SeqTwoByteString::SeqTwoByteStringSize(Map* map) { | 1475 int SeqTwoByteString::SeqTwoByteStringSize(Map* map) { |
| 1485 uint32_t length = READ_INT_FIELD(this, kLengthOffset); | 1476 uint32_t length = READ_INT_FIELD(this, kLengthOffset); |
| 1486 | 1477 |
| 1478 ASSERT(kShortStringTag + kLongLengthShift == kShortLengthShift); |
| 1479 ASSERT(kMediumStringTag + kLongLengthShift == kMediumLengthShift); |
| 1480 ASSERT(kLongStringTag == 0); |
| 1481 |
| 1487 // Use the map (and not 'this') to compute the size tag, since | 1482 // Use the map (and not 'this') to compute the size tag, since |
| 1488 // TwoByteStringSize is called during GC when maps are encoded. | 1483 // TwoByteStringSize is called during GC when maps are encoded. |
| 1489 switch (map_size_tag(map)) { | 1484 length >>= map_size_tag(map) + kLongLengthShift; |
| 1490 case kShortStringTag: | 1485 |
| 1491 length = length >> kShortLengthShift; | |
| 1492 break; | |
| 1493 case kMediumStringTag: | |
| 1494 length = length >> kMediumLengthShift; | |
| 1495 break; | |
| 1496 case kLongStringTag: | |
| 1497 length = length >> kLongLengthShift; | |
| 1498 break; | |
| 1499 default: | |
| 1500 break; | |
| 1501 } | |
| 1502 return SizeFor(length); | 1486 return SizeFor(length); |
| 1503 } | 1487 } |
| 1504 | 1488 |
| 1505 | 1489 |
| 1506 int SeqAsciiString::SeqAsciiStringSize(Map* map) { | 1490 int SeqAsciiString::SeqAsciiStringSize(Map* map) { |
| 1507 uint32_t length = READ_INT_FIELD(this, kLengthOffset); | 1491 uint32_t length = READ_INT_FIELD(this, kLengthOffset); |
| 1508 | 1492 |
| 1493 ASSERT(kShortStringTag + kLongLengthShift == kShortLengthShift); |
| 1494 ASSERT(kMediumStringTag + kLongLengthShift == kMediumLengthShift); |
| 1495 ASSERT(kLongStringTag == 0); |
| 1496 |
| 1509 // Use the map (and not 'this') to compute the size tag, since | 1497 // Use the map (and not 'this') to compute the size tag, since |
| 1510 // AsciiStringSize is called during GC when maps are encoded. | 1498 // AsciiStringSize is called during GC when maps are encoded. |
| 1511 switch (map_size_tag(map)) { | 1499 length >>= map_size_tag(map) + kLongLengthShift; |
| 1512 case kShortStringTag: | |
| 1513 length = length >> kShortLengthShift; | |
| 1514 break; | |
| 1515 case kMediumStringTag: | |
| 1516 length = length >> kMediumLengthShift; | |
| 1517 break; | |
| 1518 case kLongStringTag: | |
| 1519 length = length >> kLongLengthShift; | |
| 1520 break; | |
| 1521 default: | |
| 1522 break; | |
| 1523 } | |
| 1524 | 1500 |
| 1525 return SizeFor(length); | 1501 return SizeFor(length); |
| 1526 } | 1502 } |
| 1527 | 1503 |
| 1528 | 1504 |
| 1529 Object* ConsString::first() { | 1505 Object* ConsString::first() { |
| 1530 return READ_FIELD(this, kFirstOffset); | 1506 return READ_FIELD(this, kFirstOffset); |
| 1531 } | 1507 } |
| 1532 | 1508 |
| 1533 | 1509 |
| (...skipping 850 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2384 #undef WRITE_INT_FIELD | 2360 #undef WRITE_INT_FIELD |
| 2385 #undef READ_SHORT_FIELD | 2361 #undef READ_SHORT_FIELD |
| 2386 #undef WRITE_SHORT_FIELD | 2362 #undef WRITE_SHORT_FIELD |
| 2387 #undef READ_BYTE_FIELD | 2363 #undef READ_BYTE_FIELD |
| 2388 #undef WRITE_BYTE_FIELD | 2364 #undef WRITE_BYTE_FIELD |
| 2389 | 2365 |
| 2390 | 2366 |
| 2391 } } // namespace v8::internal | 2367 } } // namespace v8::internal |
| 2392 | 2368 |
| 2393 #endif // V8_OBJECTS_INL_H_ | 2369 #endif // V8_OBJECTS_INL_H_ |
| OLD | NEW |