Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 4691 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4702 | 4702 |
| 4703 int String::Write(uint16_t* buffer, | 4703 int String::Write(uint16_t* buffer, |
| 4704 int start, | 4704 int start, |
| 4705 int length, | 4705 int length, |
| 4706 int options) const { | 4706 int options) const { |
| 4707 return WriteHelper(this, buffer, start, length, options); | 4707 return WriteHelper(this, buffer, start, length, options); |
| 4708 } | 4708 } |
| 4709 | 4709 |
| 4710 | 4710 |
| 4711 bool v8::String::IsExternal() const { | 4711 bool v8::String::IsExternal() const { |
| 4712 i::Handle<i::String> str = Utils::OpenHandle(this); | 4712 i::DisallowHeapAllocation no_gc; |
| 4713 EnsureInitializedForIsolate(str->GetIsolate(), "v8::String::IsExternal()"); | 4713 i::String* str = *Utils::OpenHandle(this); |
| 4714 return i::StringShape(*str).IsExternalTwoByte(); | 4714 if (i::StringShape(str).IsCons()) { |
|
dcarney
2014/02/04 15:10:05
extract these 4 lines into a static function
| |
| 4715 i::ConsString* cons = i::ConsString::cast(str); | |
| 4716 if (cons->second()->length() == 0) str = cons->first(); | |
| 4717 } | |
| 4718 return i::StringShape(str).IsExternalTwoByte(); | |
| 4715 } | 4719 } |
| 4716 | 4720 |
| 4717 | 4721 |
| 4718 bool v8::String::IsExternalAscii() const { | 4722 bool v8::String::IsExternalAscii() const { |
| 4719 i::Handle<i::String> str = Utils::OpenHandle(this); | 4723 i::DisallowHeapAllocation no_gc; |
| 4720 return i::StringShape(*str).IsExternalAscii(); | 4724 i::String* str = *Utils::OpenHandle(this); |
| 4725 if (i::StringShape(str).IsCons()) { | |
| 4726 i::ConsString* cons = i::ConsString::cast(str); | |
| 4727 if (cons->second()->length() == 0) str = cons->first(); | |
| 4728 } | |
| 4729 return i::StringShape(str).IsExternalAscii(); | |
| 4721 } | 4730 } |
| 4722 | 4731 |
| 4723 | 4732 |
| 4724 void v8::String::VerifyExternalStringResource( | 4733 void v8::String::VerifyExternalStringResource( |
| 4725 v8::String::ExternalStringResource* value) const { | 4734 v8::String::ExternalStringResource* value) const { |
| 4726 i::Handle<i::String> str = Utils::OpenHandle(this); | 4735 i::DisallowHeapAllocation no_gc; |
| 4736 i::String* str = *Utils::OpenHandle(this); | |
| 4727 const v8::String::ExternalStringResource* expected; | 4737 const v8::String::ExternalStringResource* expected; |
| 4728 if (i::StringShape(*str).IsExternalTwoByte()) { | 4738 if (i::StringShape(str).IsCons()) { |
| 4729 const void* resource = | 4739 i::ConsString* cons = i::ConsString::cast(str); |
| 4730 i::Handle<i::ExternalTwoByteString>::cast(str)->resource(); | 4740 if (cons->second()->length() == 0) str = cons->first(); |
| 4741 } | |
| 4742 if (i::StringShape(str).IsExternalTwoByte()) { | |
| 4743 const void* resource = i::ExternalTwoByteString::cast(str)->resource(); | |
| 4731 expected = reinterpret_cast<const ExternalStringResource*>(resource); | 4744 expected = reinterpret_cast<const ExternalStringResource*>(resource); |
| 4732 } else { | 4745 } else { |
| 4733 expected = NULL; | 4746 expected = NULL; |
| 4734 } | 4747 } |
| 4735 CHECK_EQ(expected, value); | 4748 CHECK_EQ(expected, value); |
| 4736 } | 4749 } |
| 4737 | 4750 |
| 4751 | |
| 4738 void v8::String::VerifyExternalStringResourceBase( | 4752 void v8::String::VerifyExternalStringResourceBase( |
| 4739 v8::String::ExternalStringResourceBase* value, Encoding encoding) const { | 4753 v8::String::ExternalStringResourceBase* value, Encoding encoding) const { |
| 4740 i::Handle<i::String> str = Utils::OpenHandle(this); | 4754 i::DisallowHeapAllocation no_gc; |
| 4755 i::String* str = *Utils::OpenHandle(this); | |
| 4741 const v8::String::ExternalStringResourceBase* expected; | 4756 const v8::String::ExternalStringResourceBase* expected; |
| 4742 Encoding expectedEncoding; | 4757 Encoding expectedEncoding; |
| 4743 if (i::StringShape(*str).IsExternalAscii()) { | 4758 if (i::StringShape(str).IsCons()) { |
| 4744 const void* resource = | 4759 i::ConsString* cons = i::ConsString::cast(str); |
| 4745 i::Handle<i::ExternalAsciiString>::cast(str)->resource(); | 4760 if (cons->second()->length() == 0) str = cons->first(); |
| 4761 } | |
| 4762 if (i::StringShape(str).IsExternalAscii()) { | |
| 4763 const void* resource = i::ExternalAsciiString::cast(str)->resource(); | |
| 4746 expected = reinterpret_cast<const ExternalStringResourceBase*>(resource); | 4764 expected = reinterpret_cast<const ExternalStringResourceBase*>(resource); |
| 4747 expectedEncoding = ASCII_ENCODING; | 4765 expectedEncoding = ASCII_ENCODING; |
| 4748 } else if (i::StringShape(*str).IsExternalTwoByte()) { | 4766 } else if (str->IsExternalTwoByteString()) { |
| 4749 const void* resource = | 4767 const void* resource = i::ExternalTwoByteString::cast(str)->resource(); |
| 4750 i::Handle<i::ExternalTwoByteString>::cast(str)->resource(); | |
| 4751 expected = reinterpret_cast<const ExternalStringResourceBase*>(resource); | 4768 expected = reinterpret_cast<const ExternalStringResourceBase*>(resource); |
| 4752 expectedEncoding = TWO_BYTE_ENCODING; | 4769 expectedEncoding = TWO_BYTE_ENCODING; |
| 4753 } else { | 4770 } else { |
| 4754 expected = NULL; | 4771 expected = NULL; |
| 4755 expectedEncoding = str->IsOneByteRepresentation() ? ASCII_ENCODING | 4772 expectedEncoding = str->IsOneByteRepresentation() ? ASCII_ENCODING |
| 4756 : TWO_BYTE_ENCODING; | 4773 : TWO_BYTE_ENCODING; |
| 4757 } | 4774 } |
| 4758 CHECK_EQ(expected, value); | 4775 CHECK_EQ(expected, value); |
| 4759 CHECK_EQ(expectedEncoding, encoding); | 4776 CHECK_EQ(expectedEncoding, encoding); |
| 4760 } | 4777 } |
| 4761 | 4778 |
| 4779 | |
| 4780 i::Object* v8::String::GetRedirectedString(i::Object* cons) { | |
| 4781 ASSERT(cons->IsConsString()); | |
| 4782 i::ConsString* cons_string = i::ConsString::cast(cons); | |
| 4783 if (cons_string->second()->length() == 0) { | |
| 4784 return cons_string->first(); | |
| 4785 } | |
| 4786 return cons; | |
| 4787 } | |
| 4788 | |
| 4789 | |
| 4762 const v8::String::ExternalAsciiStringResource* | 4790 const v8::String::ExternalAsciiStringResource* |
| 4763 v8::String::GetExternalAsciiStringResource() const { | 4791 v8::String::GetExternalAsciiStringResource() const { |
| 4764 i::Handle<i::String> str = Utils::OpenHandle(this); | 4792 i::DisallowHeapAllocation no_gc; |
| 4765 if (i::StringShape(*str).IsExternalAscii()) { | 4793 i::String* str = *Utils::OpenHandle(this); |
| 4766 const void* resource = | 4794 if (i::StringShape(str).IsCons()) { |
| 4767 i::Handle<i::ExternalAsciiString>::cast(str)->resource(); | 4795 i::ConsString* cons = i::ConsString::cast(str); |
| 4796 if (cons->second()->length() == 0) str = cons->first(); | |
| 4797 } | |
| 4798 if (i::StringShape(str).IsExternalAscii()) { | |
| 4799 const void* resource = i::ExternalAsciiString::cast(str)->resource(); | |
| 4768 return reinterpret_cast<const ExternalAsciiStringResource*>(resource); | 4800 return reinterpret_cast<const ExternalAsciiStringResource*>(resource); |
| 4769 } else { | 4801 } else { |
| 4770 return NULL; | 4802 return NULL; |
| 4771 } | 4803 } |
| 4772 } | 4804 } |
| 4773 | 4805 |
| 4774 | 4806 |
| 4775 Local<Value> Symbol::Name() const { | 4807 Local<Value> Symbol::Name() const { |
| 4776 i::Handle<i::Symbol> sym = Utils::OpenHandle(this); | 4808 i::Handle<i::Symbol> sym = Utils::OpenHandle(this); |
| 4777 i::Handle<i::Object> name(sym->name(), sym->GetIsolate()); | 4809 i::Handle<i::Object> name(sym->name(), sym->GetIsolate()); |
| (...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5422 static i::Handle<i::String> NewExternalAsciiStringHandle( | 5454 static i::Handle<i::String> NewExternalAsciiStringHandle( |
| 5423 i::Isolate* isolate, | 5455 i::Isolate* isolate, |
| 5424 v8::String::ExternalAsciiStringResource* resource) { | 5456 v8::String::ExternalAsciiStringResource* resource) { |
| 5425 return isolate->factory()->NewExternalStringFromAscii(resource); | 5457 return isolate->factory()->NewExternalStringFromAscii(resource); |
| 5426 } | 5458 } |
| 5427 | 5459 |
| 5428 | 5460 |
| 5429 static bool RedirectToExternalString(i::Isolate* isolate, | 5461 static bool RedirectToExternalString(i::Isolate* isolate, |
| 5430 i::Handle<i::String> parent, | 5462 i::Handle<i::String> parent, |
| 5431 i::Handle<i::String> external) { | 5463 i::Handle<i::String> external) { |
| 5432 if (parent->IsConsString()) { | 5464 ASSERT(parent->IsConsString() || parent->IsSlicedString()); |
| 5433 i::Handle<i::ConsString> cons = i::Handle<i::ConsString>::cast(parent); | 5465 // Replace the map to a cons string of suitable encoding. |
| 5434 cons->set_first(*external); | 5466 parent->set_map_no_write_barrier(external->IsOneByteRepresentation() |
| 5435 cons->set_second(isolate->heap()->empty_string()); | 5467 ? isolate->heap()->cons_ascii_string_map() |
| 5436 } else { | 5468 : isolate->heap()->cons_string_map()); |
| 5437 ASSERT(parent->IsSlicedString()); | 5469 i::Handle<i::ConsString> cons = i::Handle<i::ConsString>::cast(parent); |
| 5438 i::Handle<i::SlicedString> slice = i::Handle<i::SlicedString>::cast(parent); | 5470 cons->set_first(*external); |
| 5439 slice->set_parent(*external); | 5471 cons->set_second(isolate->heap()->empty_string()); |
| 5440 slice->set_offset(0); | |
| 5441 } | |
| 5442 return true; | 5472 return true; |
| 5443 } | 5473 } |
| 5444 | 5474 |
| 5445 | 5475 |
| 5446 Local<String> v8::String::NewExternal( | 5476 Local<String> v8::String::NewExternal( |
| 5447 Isolate* isolate, | 5477 Isolate* isolate, |
| 5448 v8::String::ExternalStringResource* resource) { | 5478 v8::String::ExternalStringResource* resource) { |
| 5449 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 5479 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 5450 EnsureInitializedForIsolate(i_isolate, "v8::String::NewExternal()"); | 5480 EnsureInitializedForIsolate(i_isolate, "v8::String::NewExternal()"); |
| 5451 LOG_API(i_isolate, "String::NewExternal"); | 5481 LOG_API(i_isolate, "String::NewExternal"); |
| (...skipping 1940 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7392 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); | 7422 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); |
| 7393 Address callback_address = | 7423 Address callback_address = |
| 7394 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 7424 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
| 7395 VMState<EXTERNAL> state(isolate); | 7425 VMState<EXTERNAL> state(isolate); |
| 7396 ExternalCallbackScope call_scope(isolate, callback_address); | 7426 ExternalCallbackScope call_scope(isolate, callback_address); |
| 7397 callback(info); | 7427 callback(info); |
| 7398 } | 7428 } |
| 7399 | 7429 |
| 7400 | 7430 |
| 7401 } } // namespace v8::internal | 7431 } } // namespace v8::internal |
| OLD | NEW |