| 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 761 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 772 isolate->set_context(last_context); | 772 isolate->set_context(last_context); |
| 773 } | 773 } |
| 774 | 774 |
| 775 | 775 |
| 776 static void* DecodeSmiToAligned(i::Object* value, const char* location) { | 776 static void* DecodeSmiToAligned(i::Object* value, const char* location) { |
| 777 ApiCheck(value->IsSmi(), location, "Not a Smi"); | 777 ApiCheck(value->IsSmi(), location, "Not a Smi"); |
| 778 return reinterpret_cast<void*>(value); | 778 return reinterpret_cast<void*>(value); |
| 779 } | 779 } |
| 780 | 780 |
| 781 | 781 |
| 782 static i::Smi* EncodeAlignedAsSmi(const void* value, const char* location) { | 782 static i::Smi* EncodeAlignedAsSmi(void* value, const char* location) { |
| 783 i::Smi* smi = const_cast<i::Smi*>(reinterpret_cast<const i::Smi*>(value)); | 783 i::Smi* smi = reinterpret_cast<i::Smi*>(value); |
| 784 ApiCheck(smi->IsSmi(), location, "Pointer is not aligned"); | 784 ApiCheck(smi->IsSmi(), location, "Pointer is not aligned"); |
| 785 return smi; | 785 return smi; |
| 786 } | 786 } |
| 787 | 787 |
| 788 | 788 |
| 789 static i::Handle<i::FixedArray> EmbedderDataFor(Context* context, | 789 static i::Handle<i::FixedArray> EmbedderDataFor(Context* context, |
| 790 int index, | 790 int index, |
| 791 bool can_grow, | 791 bool can_grow, |
| 792 const char* location) { | 792 const char* location) { |
| 793 i::Handle<i::Context> env = Utils::OpenHandle(context); | 793 i::Handle<i::Context> env = Utils::OpenHandle(context); |
| (...skipping 5136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5930 } | 5930 } |
| 5931 | 5931 |
| 5932 | 5932 |
| 5933 Local<String> v8::String::NewExternal( | 5933 Local<String> v8::String::NewExternal( |
| 5934 v8::String::ExternalStringResource* resource) { | 5934 v8::String::ExternalStringResource* resource) { |
| 5935 i::Isolate* isolate = i::Isolate::Current(); | 5935 i::Isolate* isolate = i::Isolate::Current(); |
| 5936 EnsureInitializedForIsolate(isolate, "v8::String::NewExternal()"); | 5936 EnsureInitializedForIsolate(isolate, "v8::String::NewExternal()"); |
| 5937 LOG_API(isolate, "String::NewExternal"); | 5937 LOG_API(isolate, "String::NewExternal"); |
| 5938 ENTER_V8(isolate); | 5938 ENTER_V8(isolate); |
| 5939 CHECK(resource && resource->data()); | 5939 CHECK(resource && resource->data()); |
| 5940 // Resource pointers need to look like Smis since ExternalString objects | |
| 5941 // are sometimes put into old pointer space (see i::String::MakeExternal). | |
| 5942 CHECK(EncodeAlignedAsSmi(resource, "v8::String::NewExternal()")); | |
| 5943 CHECK(EncodeAlignedAsSmi(resource->data(), "v8::String::NewExternal()")); | |
| 5944 i::Handle<i::String> result = NewExternalStringHandle(isolate, resource); | 5940 i::Handle<i::String> result = NewExternalStringHandle(isolate, resource); |
| 5945 isolate->heap()->external_string_table()->AddString(*result); | 5941 isolate->heap()->external_string_table()->AddString(*result); |
| 5946 return Utils::ToLocal(result); | 5942 return Utils::ToLocal(result); |
| 5947 } | 5943 } |
| 5948 | 5944 |
| 5949 | 5945 |
| 5950 bool v8::String::MakeExternal(v8::String::ExternalStringResource* resource) { | 5946 bool v8::String::MakeExternal(v8::String::ExternalStringResource* resource) { |
| 5951 i::Handle<i::String> obj = Utils::OpenHandle(this); | 5947 i::Handle<i::String> obj = Utils::OpenHandle(this); |
| 5952 i::Isolate* isolate = obj->GetIsolate(); | 5948 i::Isolate* isolate = obj->GetIsolate(); |
| 5953 if (IsDeadCheck(isolate, "v8::String::MakeExternal()")) return false; | 5949 if (IsDeadCheck(isolate, "v8::String::MakeExternal()")) return false; |
| 5954 if (i::StringShape(*obj).IsExternalTwoByte()) { | 5950 if (i::StringShape(*obj).IsExternalTwoByte()) { |
| 5955 return false; // Already an external string. | 5951 return false; // Already an external string. |
| 5956 } | 5952 } |
| 5957 ENTER_V8(isolate); | 5953 ENTER_V8(isolate); |
| 5958 if (isolate->string_tracker()->IsFreshUnusedString(obj)) { | 5954 if (isolate->string_tracker()->IsFreshUnusedString(obj)) { |
| 5959 return false; | 5955 return false; |
| 5960 } | 5956 } |
| 5961 if (isolate->heap()->IsInGCPostProcessing()) { | 5957 if (isolate->heap()->IsInGCPostProcessing()) { |
| 5962 return false; | 5958 return false; |
| 5963 } | 5959 } |
| 5964 CHECK(resource && resource->data()); | 5960 CHECK(resource && resource->data()); |
| 5965 // Resource pointers need to look like Smis since ExternalString objects | |
| 5966 // are sometimes put into old pointer space (see i::String::MakeExternal). | |
| 5967 CHECK(EncodeAlignedAsSmi(resource, "v8::String::MakeExternal()")); | |
| 5968 CHECK(EncodeAlignedAsSmi(resource->data(), "v8::String::MakeExternal()")); | |
| 5969 bool result = obj->MakeExternal(resource); | 5961 bool result = obj->MakeExternal(resource); |
| 5970 if (result && !obj->IsInternalizedString()) { | 5962 if (result && !obj->IsInternalizedString()) { |
| 5971 isolate->heap()->external_string_table()->AddString(*obj); | 5963 isolate->heap()->external_string_table()->AddString(*obj); |
| 5972 } | 5964 } |
| 5973 return result; | 5965 return result; |
| 5974 } | 5966 } |
| 5975 | 5967 |
| 5976 | 5968 |
| 5977 Local<String> v8::String::NewExternal( | 5969 Local<String> v8::String::NewExternal( |
| 5978 v8::String::ExternalAsciiStringResource* resource) { | 5970 v8::String::ExternalAsciiStringResource* resource) { |
| 5979 i::Isolate* isolate = i::Isolate::Current(); | 5971 i::Isolate* isolate = i::Isolate::Current(); |
| 5980 EnsureInitializedForIsolate(isolate, "v8::String::NewExternal()"); | 5972 EnsureInitializedForIsolate(isolate, "v8::String::NewExternal()"); |
| 5981 LOG_API(isolate, "String::NewExternal"); | 5973 LOG_API(isolate, "String::NewExternal"); |
| 5982 ENTER_V8(isolate); | 5974 ENTER_V8(isolate); |
| 5983 CHECK(resource && resource->data()); | 5975 CHECK(resource && resource->data()); |
| 5984 // Resource pointers need to look like Smis since ExternalString objects | |
| 5985 // are sometimes put into old pointer space (see i::String::MakeExternal). | |
| 5986 CHECK(EncodeAlignedAsSmi(resource, "v8::String::NewExternal()")); | |
| 5987 CHECK(EncodeAlignedAsSmi(resource->data(), "v8::String::NewExternal()")); | |
| 5988 i::Handle<i::String> result = NewExternalAsciiStringHandle(isolate, resource); | 5976 i::Handle<i::String> result = NewExternalAsciiStringHandle(isolate, resource); |
| 5989 isolate->heap()->external_string_table()->AddString(*result); | 5977 isolate->heap()->external_string_table()->AddString(*result); |
| 5990 return Utils::ToLocal(result); | 5978 return Utils::ToLocal(result); |
| 5991 } | 5979 } |
| 5992 | 5980 |
| 5993 | 5981 |
| 5994 bool v8::String::MakeExternal( | 5982 bool v8::String::MakeExternal( |
| 5995 v8::String::ExternalAsciiStringResource* resource) { | 5983 v8::String::ExternalAsciiStringResource* resource) { |
| 5996 i::Handle<i::String> obj = Utils::OpenHandle(this); | 5984 i::Handle<i::String> obj = Utils::OpenHandle(this); |
| 5997 i::Isolate* isolate = obj->GetIsolate(); | 5985 i::Isolate* isolate = obj->GetIsolate(); |
| 5998 if (IsDeadCheck(isolate, "v8::String::MakeExternal()")) return false; | 5986 if (IsDeadCheck(isolate, "v8::String::MakeExternal()")) return false; |
| 5999 if (i::StringShape(*obj).IsExternalTwoByte()) { | 5987 if (i::StringShape(*obj).IsExternalTwoByte()) { |
| 6000 return false; // Already an external string. | 5988 return false; // Already an external string. |
| 6001 } | 5989 } |
| 6002 ENTER_V8(isolate); | 5990 ENTER_V8(isolate); |
| 6003 if (isolate->string_tracker()->IsFreshUnusedString(obj)) { | 5991 if (isolate->string_tracker()->IsFreshUnusedString(obj)) { |
| 6004 return false; | 5992 return false; |
| 6005 } | 5993 } |
| 6006 if (isolate->heap()->IsInGCPostProcessing()) { | 5994 if (isolate->heap()->IsInGCPostProcessing()) { |
| 6007 return false; | 5995 return false; |
| 6008 } | 5996 } |
| 6009 CHECK(resource && resource->data()); | 5997 CHECK(resource && resource->data()); |
| 6010 // Resource pointers need to look like Smis since ExternalString objects | |
| 6011 // are sometimes put into old pointer space (see i::String::MakeExternal). | |
| 6012 CHECK(EncodeAlignedAsSmi(resource, "v8::String::MakeExternal()")); | |
| 6013 CHECK(EncodeAlignedAsSmi(resource->data(), "v8::String::MakeExternal()")); | |
| 6014 bool result = obj->MakeExternal(resource); | 5998 bool result = obj->MakeExternal(resource); |
| 6015 if (result && !obj->IsInternalizedString()) { | 5999 if (result && !obj->IsInternalizedString()) { |
| 6016 isolate->heap()->external_string_table()->AddString(*obj); | 6000 isolate->heap()->external_string_table()->AddString(*obj); |
| 6017 } | 6001 } |
| 6018 return result; | 6002 return result; |
| 6019 } | 6003 } |
| 6020 | 6004 |
| 6021 | 6005 |
| 6022 bool v8::String::CanMakeExternal() { | 6006 bool v8::String::CanMakeExternal() { |
| 6023 if (!internal::FLAG_clever_optimizations) return false; | 6007 if (!internal::FLAG_clever_optimizations) return false; |
| (...skipping 2044 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8068 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); | 8052 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); |
| 8069 Address callback_address = | 8053 Address callback_address = |
| 8070 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 8054 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
| 8071 VMState<EXTERNAL> state(isolate); | 8055 VMState<EXTERNAL> state(isolate); |
| 8072 ExternalCallbackScope call_scope(isolate, callback_address); | 8056 ExternalCallbackScope call_scope(isolate, callback_address); |
| 8073 return callback(info); | 8057 return callback(info); |
| 8074 } | 8058 } |
| 8075 | 8059 |
| 8076 | 8060 |
| 8077 } } // namespace v8::internal | 8061 } } // namespace v8::internal |
| OLD | NEW |