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

Side by Side Diff: src/runtime.cc

Issue 22764007: Move i18n break iterator C++ code to runtime (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: updates 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 | « src/runtime.h ('k') | tools/gyp/v8.gyp » ('j') | tools/gyp/v8.gyp » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 #include "unicode/coll.h" 73 #include "unicode/coll.h"
74 #include "unicode/curramt.h" 74 #include "unicode/curramt.h"
75 #include "unicode/datefmt.h" 75 #include "unicode/datefmt.h"
76 #include "unicode/dcfmtsym.h" 76 #include "unicode/dcfmtsym.h"
77 #include "unicode/decimfmt.h" 77 #include "unicode/decimfmt.h"
78 #include "unicode/dtfmtsym.h" 78 #include "unicode/dtfmtsym.h"
79 #include "unicode/dtptngen.h" 79 #include "unicode/dtptngen.h"
80 #include "unicode/locid.h" 80 #include "unicode/locid.h"
81 #include "unicode/numfmt.h" 81 #include "unicode/numfmt.h"
82 #include "unicode/numsys.h" 82 #include "unicode/numsys.h"
83 #include "unicode/rbbi.h"
83 #include "unicode/smpdtfmt.h" 84 #include "unicode/smpdtfmt.h"
84 #include "unicode/timezone.h" 85 #include "unicode/timezone.h"
85 #include "unicode/uchar.h" 86 #include "unicode/uchar.h"
86 #include "unicode/ucol.h" 87 #include "unicode/ucol.h"
87 #include "unicode/ucurr.h" 88 #include "unicode/ucurr.h"
88 #include "unicode/uloc.h" 89 #include "unicode/uloc.h"
89 #include "unicode/unum.h" 90 #include "unicode/unum.h"
90 #include "unicode/uversion.h" 91 #include "unicode/uversion.h"
91 #endif 92 #endif
92 93
(...skipping 13769 matching lines...) Expand 10 before | Expand all | Expand 10 after
13862 UErrorCode status = U_ZERO_ERROR; 13863 UErrorCode status = U_ZERO_ERROR;
13863 UCollationResult result = collator->compare(u_string1, 13864 UCollationResult result = collator->compare(u_string1,
13864 string_value1.length(), 13865 string_value1.length(),
13865 u_string2, 13866 u_string2,
13866 string_value2.length(), 13867 string_value2.length(),
13867 status); 13868 status);
13868 if (U_FAILURE(status)) return isolate->ThrowIllegalOperation(); 13869 if (U_FAILURE(status)) return isolate->ThrowIllegalOperation();
13869 13870
13870 return *isolate->factory()->NewNumberFromInt(result); 13871 return *isolate->factory()->NewNumberFromInt(result);
13871 } 13872 }
13873
13874
13875 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateBreakIterator) {
13876 HandleScope scope(isolate);
13877
13878 ASSERT(args.length() == 3);
13879
13880 CONVERT_ARG_HANDLE_CHECKED(String, locale, 0);
13881 CONVERT_ARG_HANDLE_CHECKED(JSObject, options, 1);
13882 CONVERT_ARG_HANDLE_CHECKED(JSObject, resolved, 2);
13883
13884 Handle<ObjectTemplateInfo> break_iterator_template =
13885 I18N::GetTemplate2(isolate);
13886
13887 // Create an empty object wrapper.
13888 bool has_pending_exception = false;
13889 Handle<JSObject> local_object = Execution::InstantiateObject(
13890 break_iterator_template, &has_pending_exception);
13891 if (has_pending_exception) {
13892 ASSERT(isolate->has_pending_exception());
13893 return Failure::Exception();
13894 }
13895
13896 // Set break iterator as internal field of the resulting JS object.
13897 icu::BreakIterator* break_iterator = BreakIterator::InitializeBreakIterator(
13898 isolate, locale, options, resolved);
13899
13900 if (!break_iterator) return isolate->ThrowIllegalOperation();
13901
13902 local_object->SetInternalField(0, reinterpret_cast<Smi*>(break_iterator));
13903 // Make sure that the pointer to adopted text is NULL.
13904 local_object->SetInternalField(1, reinterpret_cast<Smi*>(NULL));
13905
13906 RETURN_IF_EMPTY_HANDLE(isolate,
13907 JSObject::SetLocalPropertyIgnoreAttributes(
13908 local_object,
13909 isolate->factory()->NewStringFromAscii(CStrVector("breakIterator")),
13910 isolate->factory()->NewStringFromAscii(CStrVector("valid")),
13911 NONE));
13912
13913 Persistent<v8::Object> wrapper(reinterpret_cast<v8::Isolate*>(isolate),
13914 v8::Utils::ToLocal(local_object));
13915 // Make object handle weak so we can delete the break iterator once GC kicks
13916 // in.
13917 wrapper.MakeWeak<void>(NULL, &BreakIterator::DeleteBreakIterator);
13918 wrapper.ClearAndLeak();
13919 return *local_object;
13920 }
13921
13922
13923 RUNTIME_FUNCTION(MaybeObject*, Runtime_BreakIteratorAdoptText) {
13924 HandleScope scope(isolate);
13925
13926 ASSERT(args.length() == 2);
13927
13928 CONVERT_ARG_HANDLE_CHECKED(JSObject, break_iterator_holder, 0);
13929 CONVERT_ARG_HANDLE_CHECKED(String, text, 1);
13930
13931 icu::BreakIterator* break_iterator =
13932 BreakIterator::UnpackBreakIterator(isolate, break_iterator_holder);
13933 if (!break_iterator) return isolate->ThrowIllegalOperation();
13934
13935 icu::UnicodeString* u_text = reinterpret_cast<icu::UnicodeString*>(
13936 break_iterator_holder->GetInternalField(1));
13937 delete u_text;
13938
13939 v8::String::Value text_value(v8::Utils::ToLocal(text));
13940 u_text = new icu::UnicodeString(
13941 reinterpret_cast<const UChar*>(*text_value), text_value.length());
13942 break_iterator_holder->SetInternalField(1, reinterpret_cast<Smi*>(u_text));
13943
13944 break_iterator->setText(*u_text);
13945
13946 return isolate->heap()->undefined_value();
13947 }
13948
13949
13950 RUNTIME_FUNCTION(MaybeObject*, Runtime_BreakIteratorFirst) {
13951 HandleScope scope(isolate);
13952
13953 ASSERT(args.length() == 1);
13954
13955 CONVERT_ARG_HANDLE_CHECKED(JSObject, break_iterator_holder, 0);
13956
13957 icu::BreakIterator* break_iterator =
13958 BreakIterator::UnpackBreakIterator(isolate, break_iterator_holder);
13959 if (!break_iterator) return isolate->ThrowIllegalOperation();
13960
13961 return *isolate->factory()->NewNumberFromInt(break_iterator->first());
13962 }
13963
13964
13965 RUNTIME_FUNCTION(MaybeObject*, Runtime_BreakIteratorNext) {
13966 HandleScope scope(isolate);
13967
13968 ASSERT(args.length() == 1);
13969
13970 CONVERT_ARG_HANDLE_CHECKED(JSObject, break_iterator_holder, 0);
13971
13972 icu::BreakIterator* break_iterator =
13973 BreakIterator::UnpackBreakIterator(isolate, break_iterator_holder);
13974 if (!break_iterator) return isolate->ThrowIllegalOperation();
13975
13976 return *isolate->factory()->NewNumberFromInt(break_iterator->next());
13977 }
13978
13979
13980 RUNTIME_FUNCTION(MaybeObject*, Runtime_BreakIteratorCurrent) {
13981 HandleScope scope(isolate);
13982
13983 ASSERT(args.length() == 1);
13984
13985 CONVERT_ARG_HANDLE_CHECKED(JSObject, break_iterator_holder, 0);
13986
13987 icu::BreakIterator* break_iterator =
13988 BreakIterator::UnpackBreakIterator(isolate, break_iterator_holder);
13989 if (!break_iterator) return isolate->ThrowIllegalOperation();
13990
13991 return *isolate->factory()->NewNumberFromInt(break_iterator->current());
13992 }
13993
13994
13995 RUNTIME_FUNCTION(MaybeObject*, Runtime_BreakIteratorBreakType) {
13996 HandleScope scope(isolate);
13997
13998 ASSERT(args.length() == 1);
13999
14000 CONVERT_ARG_HANDLE_CHECKED(JSObject, break_iterator_holder, 0);
14001
14002 icu::BreakIterator* break_iterator =
14003 BreakIterator::UnpackBreakIterator(isolate, break_iterator_holder);
14004 if (!break_iterator) return isolate->ThrowIllegalOperation();
14005
14006 // TODO(cira): Remove cast once ICU fixes base BreakIterator class.
14007 icu::RuleBasedBreakIterator* rule_based_iterator =
14008 static_cast<icu::RuleBasedBreakIterator*>(break_iterator);
14009 int32_t status = rule_based_iterator->getRuleStatus();
14010 // Keep return values in sync with JavaScript BreakType enum.
14011 if (status >= UBRK_WORD_NONE && status < UBRK_WORD_NONE_LIMIT) {
14012 return *isolate->factory()->NewStringFromAscii(CStrVector("none"));
14013 } else if (status >= UBRK_WORD_NUMBER && status < UBRK_WORD_NUMBER_LIMIT) {
14014 return *isolate->factory()->NewStringFromAscii(CStrVector("number"));
14015 } else if (status >= UBRK_WORD_LETTER && status < UBRK_WORD_LETTER_LIMIT) {
14016 return *isolate->factory()->NewStringFromAscii(CStrVector("letter"));
14017 } else if (status >= UBRK_WORD_KANA && status < UBRK_WORD_KANA_LIMIT) {
14018 return *isolate->factory()->NewStringFromAscii(CStrVector("kana"));
14019 } else if (status >= UBRK_WORD_IDEO && status < UBRK_WORD_IDEO_LIMIT) {
14020 return *isolate->factory()->NewStringFromAscii(CStrVector("ideo"));
14021 } else {
14022 return *isolate->factory()->NewStringFromAscii(CStrVector("unknown"));
14023 }
14024 }
13872 #endif // V8_I18N_SUPPORT 14025 #endif // V8_I18N_SUPPORT
13873 14026
13874 14027
13875 // Finds the script object from the script data. NOTE: This operation uses 14028 // Finds the script object from the script data. NOTE: This operation uses
13876 // heap traversal to find the function generated for the source position 14029 // heap traversal to find the function generated for the source position
13877 // for the requested break point. For lazily compiled functions several heap 14030 // for the requested break point. For lazily compiled functions several heap
13878 // traversals might be required rendering this operation as a rather slow 14031 // traversals might be required rendering this operation as a rather slow
13879 // operation. However for setting break points which is normally done through 14032 // operation. However for setting break points which is normally done through
13880 // some kind of user interaction the performance is not crucial. 14033 // some kind of user interaction the performance is not crucial.
13881 static Handle<Object> Runtime_GetScriptFromScriptName( 14034 static Handle<Object> Runtime_GetScriptFromScriptName(
(...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after
14478 // Handle last resort GC and make sure to allow future allocations 14631 // Handle last resort GC and make sure to allow future allocations
14479 // to grow the heap without causing GCs (if possible). 14632 // to grow the heap without causing GCs (if possible).
14480 isolate->counters()->gc_last_resort_from_js()->Increment(); 14633 isolate->counters()->gc_last_resort_from_js()->Increment();
14481 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, 14634 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags,
14482 "Runtime::PerformGC"); 14635 "Runtime::PerformGC");
14483 } 14636 }
14484 } 14637 }
14485 14638
14486 14639
14487 } } // namespace v8::internal 14640 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/runtime.h ('k') | tools/gyp/v8.gyp » ('j') | tools/gyp/v8.gyp » ('J')

Powered by Google App Engine
This is Rietveld 408576698