| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 } | 134 } |
| 135 | 135 |
| 136 for (int32_t i = 0; i < length - 1; ++i) { | 136 for (int32_t i = 0; i < length - 1; ++i) { |
| 137 target[i] = static_cast<UChar>(source[i]); | 137 target[i] = static_cast<UChar>(source[i]); |
| 138 } | 138 } |
| 139 | 139 |
| 140 target[length - 1] = 0x0u; | 140 target[length - 1] = 0x0u; |
| 141 } | 141 } |
| 142 | 142 |
| 143 | 143 |
| 144 static v8::Local<v8::ObjectTemplate> ToLocal(i::Handle<i::Object> handle) { | |
| 145 return v8::Utils::ToLocal(i::Handle<i::ObjectTemplateInfo>::cast(handle)); | |
| 146 } | |
| 147 | |
| 148 | |
| 149 template<int internal_fields, i::EternalHandles::SingletonHandle field> | |
| 150 static v8::Local<v8::ObjectTemplate> GetEternal(v8::Isolate* external) { | |
| 151 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(external); | |
| 152 if (isolate->eternal_handles()->Exists(field)) { | |
| 153 return ToLocal(isolate->eternal_handles()->GetSingleton(field)); | |
| 154 } | |
| 155 v8::Local<v8::ObjectTemplate> raw_template(v8::ObjectTemplate::New()); | |
| 156 raw_template->SetInternalFieldCount(internal_fields); | |
| 157 return ToLocal( | |
| 158 isolate->eternal_handles()->CreateSingleton( | |
| 159 isolate, | |
| 160 *v8::Utils::OpenHandle(*raw_template), | |
| 161 field)); | |
| 162 } | |
| 163 | |
| 164 | |
| 165 // static | 144 // static |
| 166 v8::Local<v8::ObjectTemplate> Utils::GetTemplate(v8::Isolate* isolate) { | 145 v8::Local<v8::ObjectTemplate> Utils::GetTemplate(v8::Isolate* isolate) { |
| 167 return GetEternal<1, i::EternalHandles::I18N_TEMPLATE_ONE>(isolate); | 146 i::Isolate* internal = reinterpret_cast<i::Isolate*>(isolate); |
| 147 if (internal->heap()->i18n_template_one() == |
| 148 internal->heap()->the_hole_value()) { |
| 149 v8::Local<v8::ObjectTemplate> raw_template(v8::ObjectTemplate::New()); |
| 150 raw_template->SetInternalFieldCount(1); |
| 151 internal->heap() |
| 152 ->SetI18nTemplateOne(*v8::Utils::OpenHandle(*raw_template)); |
| 153 } |
| 154 |
| 155 return v8::Utils::ToLocal(i::Handle<i::ObjectTemplateInfo>::cast( |
| 156 internal->factory()->i18n_template_one())); |
| 168 } | 157 } |
| 169 | 158 |
| 170 | 159 |
| 171 // static | 160 // static |
| 172 v8::Local<v8::ObjectTemplate> Utils::GetTemplate2(v8::Isolate* isolate) { | 161 v8::Local<v8::ObjectTemplate> Utils::GetTemplate2(v8::Isolate* isolate) { |
| 173 return GetEternal<2, i::EternalHandles::I18N_TEMPLATE_TWO>(isolate); | 162 i::Isolate* internal = reinterpret_cast<i::Isolate*>(isolate); |
| 163 if (internal->heap()->i18n_template_two() == |
| 164 internal->heap()->the_hole_value()) { |
| 165 v8::Local<v8::ObjectTemplate> raw_template(v8::ObjectTemplate::New()); |
| 166 raw_template->SetInternalFieldCount(2); |
| 167 internal->heap() |
| 168 ->SetI18nTemplateTwo(*v8::Utils::OpenHandle(*raw_template)); |
| 169 } |
| 170 |
| 171 return v8::Utils::ToLocal(i::Handle<i::ObjectTemplateInfo>::cast( |
| 172 internal->factory()->i18n_template_two())); |
| 174 } | 173 } |
| 175 | 174 |
| 176 | |
| 177 } // namespace v8_i18n | 175 } // namespace v8_i18n |
| OLD | NEW |