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

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

Powered by Google App Engine
This is Rietveld 408576698