Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(526)

Side by Side Diff: src/extensions/i18n/i18n-utils.cc

Issue 21133006: introduce eternal handles (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: returns handles, added tests Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « include/v8.h ('k') | src/global-handles.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
144 // static 165 // static
145 v8::Local<v8::ObjectTemplate> Utils::GetTemplate(v8::Isolate* isolate) { 166 v8::Local<v8::ObjectTemplate> Utils::GetTemplate(v8::Isolate* isolate) {
146 i::Isolate* internal = reinterpret_cast<i::Isolate*>(isolate); 167 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 } 168 }
158 169
159 170
160 // static 171 // static
161 v8::Local<v8::ObjectTemplate> Utils::GetTemplate2(v8::Isolate* isolate) { 172 v8::Local<v8::ObjectTemplate> Utils::GetTemplate2(v8::Isolate* isolate) {
162 i::Isolate* internal = reinterpret_cast<i::Isolate*>(isolate); 173 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 } 174 }
174 175
176
175 } // namespace v8_i18n 177 } // namespace v8_i18n
OLDNEW
« no previous file with comments | « include/v8.h ('k') | src/global-handles.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698