| 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 5913 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5924 | 5924 |
| 5925 | 5925 |
| 5926 i::Handle<i::String> NewExternalAsciiStringHandle(i::Isolate* isolate, | 5926 i::Handle<i::String> NewExternalAsciiStringHandle(i::Isolate* isolate, |
| 5927 v8::String::ExternalAsciiStringResource* resource) { | 5927 v8::String::ExternalAsciiStringResource* resource) { |
| 5928 i::Handle<i::String> result = | 5928 i::Handle<i::String> result = |
| 5929 isolate->factory()->NewExternalStringFromAscii(resource); | 5929 isolate->factory()->NewExternalStringFromAscii(resource); |
| 5930 return result; | 5930 return result; |
| 5931 } | 5931 } |
| 5932 | 5932 |
| 5933 | 5933 |
| 5934 bool RedirectToExternalString(i::Isolate* isolate, | |
| 5935 i::Handle<i::String> parent, | |
| 5936 i::Handle<i::String> external) { | |
| 5937 if (parent->IsConsString()) { | |
| 5938 i::Handle<i::ConsString> cons = i::Handle<i::ConsString>::cast(parent); | |
| 5939 cons->set_first(*external); | |
| 5940 cons->set_second(isolate->heap()->empty_string()); | |
| 5941 } else { | |
| 5942 ASSERT(parent->IsSlicedString()); | |
| 5943 i::Handle<i::SlicedString> slice = i::Handle<i::SlicedString>::cast(parent); | |
| 5944 slice->set_parent(*external); | |
| 5945 slice->set_offset(0); | |
| 5946 } | |
| 5947 return true; | |
| 5948 } | |
| 5949 | |
| 5950 | |
| 5951 Local<String> v8::String::NewExternal( | 5934 Local<String> v8::String::NewExternal( |
| 5952 v8::String::ExternalStringResource* resource) { | 5935 v8::String::ExternalStringResource* resource) { |
| 5953 i::Isolate* isolate = i::Isolate::Current(); | 5936 i::Isolate* isolate = i::Isolate::Current(); |
| 5954 EnsureInitializedForIsolate(isolate, "v8::String::NewExternal()"); | 5937 EnsureInitializedForIsolate(isolate, "v8::String::NewExternal()"); |
| 5955 LOG_API(isolate, "String::NewExternal"); | 5938 LOG_API(isolate, "String::NewExternal"); |
| 5956 ENTER_V8(isolate); | 5939 ENTER_V8(isolate); |
| 5957 CHECK(resource && resource->data()); | 5940 CHECK(resource && resource->data()); |
| 5958 i::Handle<i::String> result = NewExternalStringHandle(isolate, resource); | 5941 i::Handle<i::String> result = NewExternalStringHandle(isolate, resource); |
| 5959 isolate->heap()->external_string_table()->AddString(*result); | 5942 isolate->heap()->external_string_table()->AddString(*result); |
| 5960 return Utils::ToLocal(result); | 5943 return Utils::ToLocal(result); |
| 5961 } | 5944 } |
| 5962 | 5945 |
| 5963 | 5946 |
| 5964 bool v8::String::MakeExternal(v8::String::ExternalStringResource* resource) { | 5947 bool v8::String::MakeExternal(v8::String::ExternalStringResource* resource) { |
| 5965 i::Handle<i::String> obj = Utils::OpenHandle(this); | 5948 i::Handle<i::String> obj = Utils::OpenHandle(this); |
| 5966 i::Isolate* isolate = obj->GetIsolate(); | 5949 i::Isolate* isolate = obj->GetIsolate(); |
| 5967 if (IsDeadCheck(isolate, "v8::String::MakeExternal()")) return false; | 5950 if (IsDeadCheck(isolate, "v8::String::MakeExternal()")) return false; |
| 5968 if (i::StringShape(*obj).IsExternalTwoByte()) { | 5951 if (i::StringShape(*obj).IsExternalTwoByte()) { |
| 5969 return false; // Already an external string. | 5952 return false; // Already an external string. |
| 5970 } | 5953 } |
| 5971 ENTER_V8(isolate); | 5954 ENTER_V8(isolate); |
| 5972 if (isolate->string_tracker()->IsFreshUnusedString(obj)) { | 5955 if (isolate->string_tracker()->IsFreshUnusedString(obj)) { |
| 5973 return false; | 5956 return false; |
| 5974 } | 5957 } |
| 5975 if (isolate->heap()->IsInGCPostProcessing()) { | 5958 if (isolate->heap()->IsInGCPostProcessing()) { |
| 5976 return false; | 5959 return false; |
| 5977 } | 5960 } |
| 5978 CHECK(resource && resource->data()); | 5961 CHECK(resource && resource->data()); |
| 5979 | 5962 bool result = obj->MakeExternal(resource); |
| 5980 bool result; | 5963 if (result && !obj->IsInternalizedString()) { |
| 5981 i::Handle<i::String> external; | 5964 isolate->heap()->external_string_table()->AddString(*obj); |
| 5982 if (isolate->heap()->old_pointer_space()->Contains(*obj)) { | |
| 5983 // We do not allow external strings in the old pointer space. Instead of | |
| 5984 // converting the string in-place, we keep the cons/sliced string and | |
| 5985 // point it to a newly-allocated external string. | |
| 5986 external = NewExternalStringHandle(isolate, resource); | |
| 5987 result = RedirectToExternalString(isolate, obj, external); | |
| 5988 } else { | |
| 5989 result = obj->MakeExternal(resource); | |
| 5990 external = obj; | |
| 5991 } | |
| 5992 | |
| 5993 ASSERT(external->IsExternalString()); | |
| 5994 if (result && !external->IsInternalizedString()) { | |
| 5995 isolate->heap()->external_string_table()->AddString(*external); | |
| 5996 } | 5965 } |
| 5997 return result; | 5966 return result; |
| 5998 } | 5967 } |
| 5999 | 5968 |
| 6000 | 5969 |
| 6001 Local<String> v8::String::NewExternal( | 5970 Local<String> v8::String::NewExternal( |
| 6002 v8::String::ExternalAsciiStringResource* resource) { | 5971 v8::String::ExternalAsciiStringResource* resource) { |
| 6003 i::Isolate* isolate = i::Isolate::Current(); | 5972 i::Isolate* isolate = i::Isolate::Current(); |
| 6004 EnsureInitializedForIsolate(isolate, "v8::String::NewExternal()"); | 5973 EnsureInitializedForIsolate(isolate, "v8::String::NewExternal()"); |
| 6005 LOG_API(isolate, "String::NewExternal"); | 5974 LOG_API(isolate, "String::NewExternal"); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 6020 return false; // Already an external string. | 5989 return false; // Already an external string. |
| 6021 } | 5990 } |
| 6022 ENTER_V8(isolate); | 5991 ENTER_V8(isolate); |
| 6023 if (isolate->string_tracker()->IsFreshUnusedString(obj)) { | 5992 if (isolate->string_tracker()->IsFreshUnusedString(obj)) { |
| 6024 return false; | 5993 return false; |
| 6025 } | 5994 } |
| 6026 if (isolate->heap()->IsInGCPostProcessing()) { | 5995 if (isolate->heap()->IsInGCPostProcessing()) { |
| 6027 return false; | 5996 return false; |
| 6028 } | 5997 } |
| 6029 CHECK(resource && resource->data()); | 5998 CHECK(resource && resource->data()); |
| 6030 | 5999 bool result = obj->MakeExternal(resource); |
| 6031 bool result; | 6000 if (result && !obj->IsInternalizedString()) { |
| 6032 i::Handle<i::String> external; | 6001 isolate->heap()->external_string_table()->AddString(*obj); |
| 6033 if (isolate->heap()->old_pointer_space()->Contains(*obj)) { | |
| 6034 // We do not allow external strings in the old pointer space. Instead of | |
| 6035 // converting the string in-place, we keep the cons/sliced string and | |
| 6036 // point it to a newly-allocated external string. | |
| 6037 external = NewExternalAsciiStringHandle(isolate, resource); | |
| 6038 result = RedirectToExternalString(isolate, obj, external); | |
| 6039 } else { | |
| 6040 result = obj->MakeExternal(resource); | |
| 6041 external = obj; | |
| 6042 } | |
| 6043 | |
| 6044 ASSERT(external->IsExternalString()); | |
| 6045 if (result && !external->IsInternalizedString()) { | |
| 6046 isolate->heap()->external_string_table()->AddString(*external); | |
| 6047 } | 6002 } |
| 6048 return result; | 6003 return result; |
| 6049 } | 6004 } |
| 6050 | 6005 |
| 6051 | 6006 |
| 6052 bool v8::String::CanMakeExternal() { | 6007 bool v8::String::CanMakeExternal() { |
| 6053 if (!internal::FLAG_clever_optimizations) return false; | 6008 if (!internal::FLAG_clever_optimizations) return false; |
| 6054 i::Handle<i::String> obj = Utils::OpenHandle(this); | 6009 i::Handle<i::String> obj = Utils::OpenHandle(this); |
| 6055 i::Isolate* isolate = obj->GetIsolate(); | 6010 i::Isolate* isolate = obj->GetIsolate(); |
| 6056 if (IsDeadCheck(isolate, "v8::String::CanMakeExternal()")) return false; | 6011 if (IsDeadCheck(isolate, "v8::String::CanMakeExternal()")) return false; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 6077 i::Isolate* isolate = i::Isolate::Current(); | 6032 i::Isolate* isolate = i::Isolate::Current(); |
| 6078 EnsureInitializedForIsolate(isolate, "v8::NumberObject::New()"); | 6033 EnsureInitializedForIsolate(isolate, "v8::NumberObject::New()"); |
| 6079 LOG_API(isolate, "NumberObject::New"); | 6034 LOG_API(isolate, "NumberObject::New"); |
| 6080 ENTER_V8(isolate); | 6035 ENTER_V8(isolate); |
| 6081 i::Handle<i::Object> number = isolate->factory()->NewNumber(value); | 6036 i::Handle<i::Object> number = isolate->factory()->NewNumber(value); |
| 6082 i::Handle<i::Object> obj = isolate->factory()->ToObject(number); | 6037 i::Handle<i::Object> obj = isolate->factory()->ToObject(number); |
| 6083 return Utils::ToLocal(obj); | 6038 return Utils::ToLocal(obj); |
| 6084 } | 6039 } |
| 6085 | 6040 |
| 6086 | 6041 |
| 6087 double v8::NumberObject::ValueOf() const { | 6042 double v8::NumberObject::NumberValue() const { |
| 6088 i::Isolate* isolate = i::Isolate::Current(); | 6043 i::Isolate* isolate = i::Isolate::Current(); |
| 6089 if (IsDeadCheck(isolate, "v8::NumberObject::NumberValue()")) return 0; | 6044 if (IsDeadCheck(isolate, "v8::NumberObject::NumberValue()")) return 0; |
| 6090 LOG_API(isolate, "NumberObject::NumberValue"); | 6045 LOG_API(isolate, "NumberObject::NumberValue"); |
| 6091 i::Handle<i::Object> obj = Utils::OpenHandle(this); | 6046 i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 6092 i::Handle<i::JSValue> jsvalue = i::Handle<i::JSValue>::cast(obj); | 6047 i::Handle<i::JSValue> jsvalue = i::Handle<i::JSValue>::cast(obj); |
| 6093 return jsvalue->value()->Number(); | 6048 return jsvalue->value()->Number(); |
| 6094 } | 6049 } |
| 6095 | 6050 |
| 6096 | 6051 |
| 6097 Local<v8::Value> v8::BooleanObject::New(bool value) { | 6052 Local<v8::Value> v8::BooleanObject::New(bool value) { |
| 6098 i::Isolate* isolate = i::Isolate::Current(); | 6053 i::Isolate* isolate = i::Isolate::Current(); |
| 6099 EnsureInitializedForIsolate(isolate, "v8::BooleanObject::New()"); | 6054 EnsureInitializedForIsolate(isolate, "v8::BooleanObject::New()"); |
| 6100 LOG_API(isolate, "BooleanObject::New"); | 6055 LOG_API(isolate, "BooleanObject::New"); |
| 6101 ENTER_V8(isolate); | 6056 ENTER_V8(isolate); |
| 6102 i::Handle<i::Object> boolean(value | 6057 i::Handle<i::Object> boolean(value |
| 6103 ? isolate->heap()->true_value() | 6058 ? isolate->heap()->true_value() |
| 6104 : isolate->heap()->false_value(), | 6059 : isolate->heap()->false_value(), |
| 6105 isolate); | 6060 isolate); |
| 6106 i::Handle<i::Object> obj = isolate->factory()->ToObject(boolean); | 6061 i::Handle<i::Object> obj = isolate->factory()->ToObject(boolean); |
| 6107 return Utils::ToLocal(obj); | 6062 return Utils::ToLocal(obj); |
| 6108 } | 6063 } |
| 6109 | 6064 |
| 6110 | 6065 |
| 6111 bool v8::BooleanObject::ValueOf() const { | 6066 bool v8::BooleanObject::BooleanValue() const { |
| 6112 i::Isolate* isolate = i::Isolate::Current(); | 6067 i::Isolate* isolate = i::Isolate::Current(); |
| 6113 if (IsDeadCheck(isolate, "v8::BooleanObject::BooleanValue()")) return 0; | 6068 if (IsDeadCheck(isolate, "v8::BooleanObject::BooleanValue()")) return 0; |
| 6114 LOG_API(isolate, "BooleanObject::BooleanValue"); | 6069 LOG_API(isolate, "BooleanObject::BooleanValue"); |
| 6115 i::Handle<i::Object> obj = Utils::OpenHandle(this); | 6070 i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 6116 i::Handle<i::JSValue> jsvalue = i::Handle<i::JSValue>::cast(obj); | 6071 i::Handle<i::JSValue> jsvalue = i::Handle<i::JSValue>::cast(obj); |
| 6117 return jsvalue->value()->IsTrue(); | 6072 return jsvalue->value()->IsTrue(); |
| 6118 } | 6073 } |
| 6119 | 6074 |
| 6120 | 6075 |
| 6121 Local<v8::Value> v8::StringObject::New(Handle<String> value) { | 6076 Local<v8::Value> v8::StringObject::New(Handle<String> value) { |
| 6122 i::Isolate* isolate = i::Isolate::Current(); | 6077 i::Isolate* isolate = i::Isolate::Current(); |
| 6123 EnsureInitializedForIsolate(isolate, "v8::StringObject::New()"); | 6078 EnsureInitializedForIsolate(isolate, "v8::StringObject::New()"); |
| 6124 LOG_API(isolate, "StringObject::New"); | 6079 LOG_API(isolate, "StringObject::New"); |
| 6125 ENTER_V8(isolate); | 6080 ENTER_V8(isolate); |
| 6126 i::Handle<i::Object> obj = | 6081 i::Handle<i::Object> obj = |
| 6127 isolate->factory()->ToObject(Utils::OpenHandle(*value)); | 6082 isolate->factory()->ToObject(Utils::OpenHandle(*value)); |
| 6128 return Utils::ToLocal(obj); | 6083 return Utils::ToLocal(obj); |
| 6129 } | 6084 } |
| 6130 | 6085 |
| 6131 | 6086 |
| 6132 Local<v8::String> v8::StringObject::ValueOf() const { | 6087 Local<v8::String> v8::StringObject::StringValue() const { |
| 6133 i::Isolate* isolate = i::Isolate::Current(); | 6088 i::Isolate* isolate = i::Isolate::Current(); |
| 6134 if (IsDeadCheck(isolate, "v8::StringObject::StringValue()")) { | 6089 if (IsDeadCheck(isolate, "v8::StringObject::StringValue()")) { |
| 6135 return Local<v8::String>(); | 6090 return Local<v8::String>(); |
| 6136 } | 6091 } |
| 6137 LOG_API(isolate, "StringObject::StringValue"); | 6092 LOG_API(isolate, "StringObject::StringValue"); |
| 6138 i::Handle<i::Object> obj = Utils::OpenHandle(this); | 6093 i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 6139 i::Handle<i::JSValue> jsvalue = i::Handle<i::JSValue>::cast(obj); | 6094 i::Handle<i::JSValue> jsvalue = i::Handle<i::JSValue>::cast(obj); |
| 6140 return Utils::ToLocal( | 6095 return Utils::ToLocal( |
| 6141 i::Handle<i::String>(i::String::cast(jsvalue->value()))); | 6096 i::Handle<i::String>(i::String::cast(jsvalue->value()))); |
| 6142 } | 6097 } |
| 6143 | 6098 |
| 6144 | 6099 |
| 6145 Local<v8::Value> v8::SymbolObject::New(Isolate* isolate, Handle<Symbol> value) { | 6100 Local<v8::Value> v8::SymbolObject::New(Isolate* isolate, Handle<Symbol> value) { |
| 6146 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 6101 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 6147 EnsureInitializedForIsolate(i_isolate, "v8::SymbolObject::New()"); | 6102 EnsureInitializedForIsolate(i_isolate, "v8::SymbolObject::New()"); |
| 6148 LOG_API(i_isolate, "SymbolObject::New"); | 6103 LOG_API(i_isolate, "SymbolObject::New"); |
| 6149 ENTER_V8(i_isolate); | 6104 ENTER_V8(i_isolate); |
| 6150 i::Handle<i::Object> obj = | 6105 i::Handle<i::Object> obj = |
| 6151 i_isolate->factory()->ToObject(Utils::OpenHandle(*value)); | 6106 i_isolate->factory()->ToObject(Utils::OpenHandle(*value)); |
| 6152 return Utils::ToLocal(obj); | 6107 return Utils::ToLocal(obj); |
| 6153 } | 6108 } |
| 6154 | 6109 |
| 6155 | 6110 |
| 6156 Local<v8::Symbol> v8::SymbolObject::ValueOf() const { | 6111 Local<v8::Symbol> v8::SymbolObject::SymbolValue() const { |
| 6157 i::Isolate* isolate = i::Isolate::Current(); | 6112 i::Isolate* isolate = i::Isolate::Current(); |
| 6158 if (IsDeadCheck(isolate, "v8::SymbolObject::SymbolValue()")) | 6113 if (IsDeadCheck(isolate, "v8::SymbolObject::SymbolValue()")) |
| 6159 return Local<v8::Symbol>(); | 6114 return Local<v8::Symbol>(); |
| 6160 LOG_API(isolate, "SymbolObject::SymbolValue"); | 6115 LOG_API(isolate, "SymbolObject::SymbolValue"); |
| 6161 i::Handle<i::Object> obj = Utils::OpenHandle(this); | 6116 i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 6162 i::Handle<i::JSValue> jsvalue = i::Handle<i::JSValue>::cast(obj); | 6117 i::Handle<i::JSValue> jsvalue = i::Handle<i::JSValue>::cast(obj); |
| 6163 return Utils::ToLocal( | 6118 return Utils::ToLocal( |
| 6164 i::Handle<i::Symbol>(i::Symbol::cast(jsvalue->value()))); | 6119 i::Handle<i::Symbol>(i::Symbol::cast(jsvalue->value()))); |
| 6165 } | 6120 } |
| 6166 | 6121 |
| 6167 | 6122 |
| 6168 Local<v8::Value> v8::Date::New(double time) { | 6123 Local<v8::Value> v8::Date::New(double time) { |
| 6169 i::Isolate* isolate = i::Isolate::Current(); | 6124 i::Isolate* isolate = i::Isolate::Current(); |
| 6170 EnsureInitializedForIsolate(isolate, "v8::Date::New()"); | 6125 EnsureInitializedForIsolate(isolate, "v8::Date::New()"); |
| 6171 LOG_API(isolate, "Date::New"); | 6126 LOG_API(isolate, "Date::New"); |
| 6172 if (std::isnan(time)) { | 6127 if (std::isnan(time)) { |
| 6173 // Introduce only canonical NaN value into the VM, to avoid signaling NaNs. | 6128 // Introduce only canonical NaN value into the VM, to avoid signaling NaNs. |
| 6174 time = i::OS::nan_value(); | 6129 time = i::OS::nan_value(); |
| 6175 } | 6130 } |
| 6176 ENTER_V8(isolate); | 6131 ENTER_V8(isolate); |
| 6177 EXCEPTION_PREAMBLE(isolate); | 6132 EXCEPTION_PREAMBLE(isolate); |
| 6178 i::Handle<i::Object> obj = | 6133 i::Handle<i::Object> obj = |
| 6179 i::Execution::NewDate(time, &has_pending_exception); | 6134 i::Execution::NewDate(time, &has_pending_exception); |
| 6180 EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::Value>()); | 6135 EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::Value>()); |
| 6181 return Utils::ToLocal(obj); | 6136 return Utils::ToLocal(obj); |
| 6182 } | 6137 } |
| 6183 | 6138 |
| 6184 | 6139 |
| 6185 double v8::Date::ValueOf() const { | 6140 double v8::Date::NumberValue() const { |
| 6186 i::Isolate* isolate = i::Isolate::Current(); | 6141 i::Isolate* isolate = i::Isolate::Current(); |
| 6187 if (IsDeadCheck(isolate, "v8::Date::NumberValue()")) return 0; | 6142 if (IsDeadCheck(isolate, "v8::Date::NumberValue()")) return 0; |
| 6188 LOG_API(isolate, "Date::NumberValue"); | 6143 LOG_API(isolate, "Date::NumberValue"); |
| 6189 i::Handle<i::Object> obj = Utils::OpenHandle(this); | 6144 i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 6190 i::Handle<i::JSDate> jsdate = i::Handle<i::JSDate>::cast(obj); | 6145 i::Handle<i::JSDate> jsdate = i::Handle<i::JSDate>::cast(obj); |
| 6191 return jsdate->value()->Number(); | 6146 return jsdate->value()->Number(); |
| 6192 } | 6147 } |
| 6193 | 6148 |
| 6194 | 6149 |
| 6195 void v8::Date::DateTimeConfigurationChangeNotification() { | 6150 void v8::Date::DateTimeConfigurationChangeNotification() { |
| (...skipping 1902 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8098 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); | 8053 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); |
| 8099 Address callback_address = | 8054 Address callback_address = |
| 8100 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 8055 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
| 8101 VMState<EXTERNAL> state(isolate); | 8056 VMState<EXTERNAL> state(isolate); |
| 8102 ExternalCallbackScope call_scope(isolate, callback_address); | 8057 ExternalCallbackScope call_scope(isolate, callback_address); |
| 8103 return callback(info); | 8058 return callback(info); |
| 8104 } | 8059 } |
| 8105 | 8060 |
| 8106 | 8061 |
| 8107 } } // namespace v8::internal | 8062 } } // namespace v8::internal |
| OLD | NEW |