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 template<int internal_fields, i::EternalHandles::IndexedHandle field> |
| 145 static v8::Local<v8::ObjectTemplate> GetEternal(v8::Isolate* external) { |
| 146 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(external); |
| 147 int index = isolate->eternal_handles()->GetIndex(field); |
| 148 if (index == i::EternalHandles::kInvalidIndex) { |
| 149 v8::Local<v8::ObjectTemplate> raw_template(v8::ObjectTemplate::New()); |
| 150 raw_template->SetInternalFieldCount(internal_fields); |
| 151 index = isolate->eternal_handles()->CreateIndexed( |
| 152 isolate, |
| 153 *v8::Utils::OpenHandle(*raw_template), |
| 154 field); |
| 155 } |
| 156 i::Object** location = isolate->eternal_handles()->Get(index); |
| 157 i::Handle<i::Object> handle = i::Handle<i::Object>(location); |
| 158 return v8::Utils::ToLocal(i::Handle<i::ObjectTemplateInfo>::cast(handle)); |
| 159 } |
| 160 |
| 161 |
144 // static | 162 // static |
145 v8::Local<v8::ObjectTemplate> Utils::GetTemplate(v8::Isolate* isolate) { | 163 v8::Local<v8::ObjectTemplate> Utils::GetTemplate(v8::Isolate* isolate) { |
146 i::Isolate* internal = reinterpret_cast<i::Isolate*>(isolate); | 164 return GetEternal<1, i::EternalHandles::I18N_TEMPLATE_ONE>(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())); | |
157 } | 165 } |
158 | 166 |
159 | 167 |
160 // static | 168 // static |
161 v8::Local<v8::ObjectTemplate> Utils::GetTemplate2(v8::Isolate* isolate) { | 169 v8::Local<v8::ObjectTemplate> Utils::GetTemplate2(v8::Isolate* isolate) { |
162 i::Isolate* internal = reinterpret_cast<i::Isolate*>(isolate); | 170 return GetEternal<2, i::EternalHandles::I18N_TEMPLATE_TWO>(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())); | |
173 } | 171 } |
174 | 172 |
| 173 |
175 } // namespace v8_i18n | 174 } // namespace v8_i18n |
OLD | NEW |