| Index: src/runtime.cc
|
| diff --git a/src/runtime.cc b/src/runtime.cc
|
| index a9121ce851d578c650e45d2083bbbdd857bcb489..6213594155d909ff898f01daa5290065e1a6067c 100644
|
| --- a/src/runtime.cc
|
| +++ b/src/runtime.cc
|
| @@ -83,6 +83,7 @@
|
| #include "unicode/smpdtfmt.h"
|
| #include "unicode/timezone.h"
|
| #include "unicode/uchar.h"
|
| +#include "unicode/ucol.h"
|
| #include "unicode/ucurr.h"
|
| #include "unicode/uloc.h"
|
| #include "unicode/unum.h"
|
| @@ -13795,6 +13796,79 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_InternalNumberParse) {
|
| return isolate->heap()->undefined_value();
|
| }
|
| }
|
| +
|
| +
|
| +RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateCollator) {
|
| + HandleScope scope(isolate);
|
| +
|
| + ASSERT(args.length() == 3);
|
| +
|
| + CONVERT_ARG_HANDLE_CHECKED(String, locale, 0);
|
| + CONVERT_ARG_HANDLE_CHECKED(JSObject, options, 1);
|
| + CONVERT_ARG_HANDLE_CHECKED(JSObject, resolved, 2);
|
| +
|
| + Handle<ObjectTemplateInfo> collator_template = I18N::GetTemplate(isolate);
|
| +
|
| + // Create an empty object wrapper.
|
| + bool has_pending_exception = false;
|
| + Handle<JSObject> local_object = Execution::InstantiateObject(
|
| + collator_template, &has_pending_exception);
|
| + if (has_pending_exception) {
|
| + ASSERT(isolate->has_pending_exception());
|
| + return Failure::Exception();
|
| + }
|
| +
|
| + // Set collator as internal field of the resulting JS object.
|
| + icu::Collator* collator = Collator::InitializeCollator(
|
| + isolate, locale, options, resolved);
|
| +
|
| + if (!collator) return isolate->ThrowIllegalOperation();
|
| +
|
| + local_object->SetInternalField(0, reinterpret_cast<Smi*>(collator));
|
| +
|
| + RETURN_IF_EMPTY_HANDLE(isolate,
|
| + JSObject::SetLocalPropertyIgnoreAttributes(
|
| + local_object,
|
| + isolate->factory()->NewStringFromAscii(CStrVector("collator")),
|
| + isolate->factory()->NewStringFromAscii(CStrVector("valid")),
|
| + NONE));
|
| +
|
| + Persistent<v8::Object> wrapper(reinterpret_cast<v8::Isolate*>(isolate),
|
| + v8::Utils::ToLocal(local_object));
|
| + // Make object handle weak so we can delete the collator once GC kicks in.
|
| + wrapper.MakeWeak<void>(NULL, &Collator::DeleteCollator);
|
| + Handle<Object> result = Utils::OpenPersistent(wrapper);
|
| + wrapper.ClearAndLeak();
|
| + return *result;
|
| +}
|
| +
|
| +
|
| +RUNTIME_FUNCTION(MaybeObject*, Runtime_InternalCompare) {
|
| + HandleScope scope(isolate);
|
| +
|
| + ASSERT(args.length() == 3);
|
| +
|
| + CONVERT_ARG_HANDLE_CHECKED(JSObject, collator_holder, 0);
|
| + CONVERT_ARG_HANDLE_CHECKED(String, string1, 1);
|
| + CONVERT_ARG_HANDLE_CHECKED(String, string2, 2);
|
| +
|
| + icu::Collator* collator = Collator::UnpackCollator(isolate, collator_holder);
|
| + if (!collator) return isolate->ThrowIllegalOperation();
|
| +
|
| + v8::String::Value string_value1(v8::Utils::ToLocal(string1));
|
| + v8::String::Value string_value2(v8::Utils::ToLocal(string2));
|
| + const UChar* u_string1 = reinterpret_cast<const UChar*>(*string_value1);
|
| + const UChar* u_string2 = reinterpret_cast<const UChar*>(*string_value2);
|
| + UErrorCode status = U_ZERO_ERROR;
|
| + UCollationResult result = collator->compare(u_string1,
|
| + string_value1.length(),
|
| + u_string2,
|
| + string_value2.length(),
|
| + status);
|
| + if (U_FAILURE(status)) return isolate->ThrowIllegalOperation();
|
| +
|
| + return *isolate->factory()->NewNumberFromInt(result);
|
| +}
|
| #endif // V8_I18N_SUPPORT
|
|
|
|
|
|
|