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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/v8.h ('k') | src/global-handles.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/extensions/i18n/i18n-utils.cc
diff --git a/src/extensions/i18n/i18n-utils.cc b/src/extensions/i18n/i18n-utils.cc
index eac11669047ec407e57c78d4038716a0a7bc18ee..8c87f0715b9651ed3d905e55f6e4828891e155c9 100644
--- a/src/extensions/i18n/i18n-utils.cc
+++ b/src/extensions/i18n/i18n-utils.cc
@@ -141,35 +141,37 @@ void Utils::AsciiToUChar(const char* source,
}
-// static
-v8::Local<v8::ObjectTemplate> Utils::GetTemplate(v8::Isolate* isolate) {
- i::Isolate* internal = reinterpret_cast<i::Isolate*>(isolate);
- if (internal->heap()->i18n_template_one() ==
- internal->heap()->the_hole_value()) {
- v8::Local<v8::ObjectTemplate> raw_template(v8::ObjectTemplate::New());
- raw_template->SetInternalFieldCount(1);
- internal->heap()
- ->SetI18nTemplateOne(*v8::Utils::OpenHandle(*raw_template));
+static v8::Local<v8::ObjectTemplate> ToLocal(i::Handle<i::Object> handle) {
+ return v8::Utils::ToLocal(i::Handle<i::ObjectTemplateInfo>::cast(handle));
+}
+
+
+template<int internal_fields, i::EternalHandles::SingletonHandle field>
+static v8::Local<v8::ObjectTemplate> GetEternal(v8::Isolate* external) {
+ i::Isolate* isolate = reinterpret_cast<i::Isolate*>(external);
+ if (isolate->eternal_handles()->Exists(field)) {
+ return ToLocal(isolate->eternal_handles()->GetSingleton(field));
}
+ v8::Local<v8::ObjectTemplate> raw_template(v8::ObjectTemplate::New());
+ raw_template->SetInternalFieldCount(internal_fields);
+ return ToLocal(
+ isolate->eternal_handles()->CreateSingleton(
+ isolate,
+ *v8::Utils::OpenHandle(*raw_template),
+ field));
+}
- return v8::Utils::ToLocal(i::Handle<i::ObjectTemplateInfo>::cast(
- internal->factory()->i18n_template_one()));
+
+// static
+v8::Local<v8::ObjectTemplate> Utils::GetTemplate(v8::Isolate* isolate) {
+ return GetEternal<1, i::EternalHandles::I18N_TEMPLATE_ONE>(isolate);
}
// static
v8::Local<v8::ObjectTemplate> Utils::GetTemplate2(v8::Isolate* isolate) {
- i::Isolate* internal = reinterpret_cast<i::Isolate*>(isolate);
- if (internal->heap()->i18n_template_two() ==
- internal->heap()->the_hole_value()) {
- v8::Local<v8::ObjectTemplate> raw_template(v8::ObjectTemplate::New());
- raw_template->SetInternalFieldCount(2);
- internal->heap()
- ->SetI18nTemplateTwo(*v8::Utils::OpenHandle(*raw_template));
- }
-
- return v8::Utils::ToLocal(i::Handle<i::ObjectTemplateInfo>::cast(
- internal->factory()->i18n_template_two()));
+ return GetEternal<2, i::EternalHandles::I18N_TEMPLATE_TWO>(isolate);
}
+
} // namespace v8_i18n
« 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