OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <stdlib.h> | 5 #include <stdlib.h> |
6 #include <limits> | 6 #include <limits> |
7 | 7 |
8 #include "src/v8.h" | 8 #include "src/v8.h" |
9 | 9 |
10 #include "src/accessors.h" | 10 #include "src/accessors.h" |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
288 boilerplate, element_index, value, SLOPPY); | 288 boilerplate, element_index, value, SLOPPY); |
289 } else { | 289 } else { |
290 // Non-uint32 number. | 290 // Non-uint32 number. |
291 ASSERT(key->IsNumber()); | 291 ASSERT(key->IsNumber()); |
292 double num = key->Number(); | 292 double num = key->Number(); |
293 char arr[100]; | 293 char arr[100]; |
294 Vector<char> buffer(arr, ARRAY_SIZE(arr)); | 294 Vector<char> buffer(arr, ARRAY_SIZE(arr)); |
295 const char* str = DoubleToCString(num, buffer); | 295 const char* str = DoubleToCString(num, buffer); |
296 Handle<String> name = isolate->factory()->NewStringFromAsciiChecked(str); | 296 Handle<String> name = isolate->factory()->NewStringFromAsciiChecked(str); |
297 maybe_result = JSObject::SetOwnPropertyIgnoreAttributes( | 297 maybe_result = JSObject::SetOwnPropertyIgnoreAttributes( |
298 boilerplate, name, value, NONE, | 298 boilerplate, name, value, NONE, value_type, mode); |
299 value_type, mode); | |
300 } | 299 } |
301 // If setting the property on the boilerplate throws an | 300 // If setting the property on the boilerplate throws an |
302 // exception, the exception is converted to an empty handle in | 301 // exception, the exception is converted to an empty handle in |
303 // the handle based operations. In that case, we need to | 302 // the handle based operations. In that case, we need to |
304 // convert back to an exception. | 303 // convert back to an exception. |
305 RETURN_ON_EXCEPTION(isolate, maybe_result, Object); | 304 RETURN_ON_EXCEPTION(isolate, maybe_result, Object); |
306 } | 305 } |
307 | 306 |
308 // Transform to fast properties if necessary. For object literals with | 307 // Transform to fast properties if necessary. For object literals with |
309 // containing function literals we defer this operation until after all | 308 // containing function literals we defer this operation until after all |
(...skipping 2100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2410 | 2409 |
2411 // Lookup the property as own on the global object. If it isn't | 2410 // Lookup the property as own on the global object. If it isn't |
2412 // there, we add the property and take special precautions to always | 2411 // there, we add the property and take special precautions to always |
2413 // add it even in case of callbacks in the prototype chain (this rules | 2412 // add it even in case of callbacks in the prototype chain (this rules |
2414 // out using SetProperty). We use SetOwnPropertyIgnoreAttributes instead | 2413 // out using SetProperty). We use SetOwnPropertyIgnoreAttributes instead |
2415 LookupResult lookup(isolate); | 2414 LookupResult lookup(isolate); |
2416 global->LookupOwn(name, &lookup); | 2415 global->LookupOwn(name, &lookup); |
2417 if (!lookup.IsFound()) { | 2416 if (!lookup.IsFound()) { |
2418 HandleScope handle_scope(isolate); | 2417 HandleScope handle_scope(isolate); |
2419 Handle<GlobalObject> global(isolate->context()->global_object()); | 2418 Handle<GlobalObject> global(isolate->context()->global_object()); |
2420 RETURN_FAILURE_ON_EXCEPTION( | 2419 JSObject::InitializeProperty(global, name, value, attributes); |
2421 isolate, | |
2422 JSObject::SetOwnPropertyIgnoreAttributes(global, name, value, | |
2423 attributes)); | |
2424 return *value; | 2420 return *value; |
2425 } | 2421 } |
2426 | 2422 |
2427 if (!lookup.IsReadOnly()) { | 2423 if (!lookup.IsReadOnly()) { |
2428 // Restore global object from context (in case of GC) and continue | 2424 // Restore global object from context (in case of GC) and continue |
2429 // with setting the value. | 2425 // with setting the value. |
2430 HandleScope handle_scope(isolate); | 2426 HandleScope handle_scope(isolate); |
2431 Handle<GlobalObject> global(isolate->context()->global_object()); | 2427 Handle<GlobalObject> global(isolate->context()->global_object()); |
2432 | 2428 |
2433 // BUG 1213575: Handle the case where we have to set a read-only | 2429 // BUG 1213575: Handle the case where we have to set a read-only |
(...skipping 5692 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8126 // is happy about the number of fields. | 8122 // is happy about the number of fields. |
8127 RUNTIME_ASSERT(bound_function->RemovePrototype()); | 8123 RUNTIME_ASSERT(bound_function->RemovePrototype()); |
8128 Handle<Map> bound_function_map( | 8124 Handle<Map> bound_function_map( |
8129 isolate->native_context()->bound_function_map()); | 8125 isolate->native_context()->bound_function_map()); |
8130 JSObject::MigrateToMap(bound_function, bound_function_map); | 8126 JSObject::MigrateToMap(bound_function, bound_function_map); |
8131 Handle<String> length_string = isolate->factory()->length_string(); | 8127 Handle<String> length_string = isolate->factory()->length_string(); |
8132 PropertyAttributes attr = | 8128 PropertyAttributes attr = |
8133 static_cast<PropertyAttributes>(DONT_DELETE | DONT_ENUM | READ_ONLY); | 8129 static_cast<PropertyAttributes>(DONT_DELETE | DONT_ENUM | READ_ONLY); |
8134 RETURN_FAILURE_ON_EXCEPTION( | 8130 RETURN_FAILURE_ON_EXCEPTION( |
8135 isolate, | 8131 isolate, |
8136 JSObject::SetOwnPropertyIgnoreAttributes(bound_function, length_string, | 8132 JSObject::SetOwnPropertyIgnoreAttributes( |
rossberg
2014/06/27 10:51:02
Why can't InitProperty be used here?
Toon Verwaest
2014/06/30 11:39:38
Because "length" is already declared on the bound_
| |
8137 new_length, attr)); | 8133 bound_function, length_string, new_length, attr)); |
8138 return *bound_function; | 8134 return *bound_function; |
8139 } | 8135 } |
8140 | 8136 |
8141 | 8137 |
8142 RUNTIME_FUNCTION(Runtime_BoundFunctionGetBindings) { | 8138 RUNTIME_FUNCTION(Runtime_BoundFunctionGetBindings) { |
8143 HandleScope handles(isolate); | 8139 HandleScope handles(isolate); |
8144 ASSERT(args.length() == 1); | 8140 ASSERT(args.length() == 1); |
8145 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, callable, 0); | 8141 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, callable, 0); |
8146 if (callable->IsJSFunction()) { | 8142 if (callable->IsJSFunction()) { |
8147 Handle<JSFunction> function = Handle<JSFunction>::cast(callable); | 8143 Handle<JSFunction> function = Handle<JSFunction>::cast(callable); |
(...skipping 5642 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
13790 // de_DE -> de-DE | 13786 // de_DE -> de-DE |
13791 char base_locale[ULOC_FULLNAME_CAPACITY]; | 13787 char base_locale[ULOC_FULLNAME_CAPACITY]; |
13792 uloc_toLanguageTag( | 13788 uloc_toLanguageTag( |
13793 icu_base_locale, base_locale, ULOC_FULLNAME_CAPACITY, FALSE, &error); | 13789 icu_base_locale, base_locale, ULOC_FULLNAME_CAPACITY, FALSE, &error); |
13794 | 13790 |
13795 if (U_FAILURE(error)) { | 13791 if (U_FAILURE(error)) { |
13796 return isolate->Throw(*factory->illegal_argument_string()); | 13792 return isolate->Throw(*factory->illegal_argument_string()); |
13797 } | 13793 } |
13798 | 13794 |
13799 Handle<JSObject> result = factory->NewJSObject(isolate->object_function()); | 13795 Handle<JSObject> result = factory->NewJSObject(isolate->object_function()); |
13800 RETURN_FAILURE_ON_EXCEPTION(isolate, | 13796 Handle<String> value = factory->NewStringFromAsciiChecked(base_max_locale); |
13801 JSObject::SetOwnPropertyIgnoreAttributes( | 13797 JSObject::InitializeProperty(result, maximized, value, NONE); |
13802 result, | 13798 value = factory->NewStringFromAsciiChecked(base_locale); |
13803 maximized, | 13799 JSObject::InitializeProperty(result, base, value, NONE); |
13804 factory->NewStringFromAsciiChecked(base_max_locale), | |
13805 NONE)); | |
13806 RETURN_FAILURE_ON_EXCEPTION(isolate, | |
13807 JSObject::SetOwnPropertyIgnoreAttributes( | |
13808 result, | |
13809 base, | |
13810 factory->NewStringFromAsciiChecked(base_locale), | |
13811 NONE)); | |
13812 output->set(i, *result); | 13800 output->set(i, *result); |
13813 } | 13801 } |
13814 | 13802 |
13815 Handle<JSArray> result = factory->NewJSArrayWithElements(output); | 13803 Handle<JSArray> result = factory->NewJSArrayWithElements(output); |
13816 result->set_length(Smi::FromInt(length)); | 13804 result->set_length(Smi::FromInt(length)); |
13817 return *result; | 13805 return *result; |
13818 } | 13806 } |
13819 | 13807 |
13820 | 13808 |
13821 RUNTIME_FUNCTION(Runtime_IsInitializedIntlObject) { | 13809 RUNTIME_FUNCTION(Runtime_IsInitializedIntlObject) { |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
13918 Execution::InstantiateObject(date_format_template)); | 13906 Execution::InstantiateObject(date_format_template)); |
13919 | 13907 |
13920 // Set date time formatter as internal field of the resulting JS object. | 13908 // Set date time formatter as internal field of the resulting JS object. |
13921 icu::SimpleDateFormat* date_format = DateFormat::InitializeDateTimeFormat( | 13909 icu::SimpleDateFormat* date_format = DateFormat::InitializeDateTimeFormat( |
13922 isolate, locale, options, resolved); | 13910 isolate, locale, options, resolved); |
13923 | 13911 |
13924 if (!date_format) return isolate->ThrowIllegalOperation(); | 13912 if (!date_format) return isolate->ThrowIllegalOperation(); |
13925 | 13913 |
13926 local_object->SetInternalField(0, reinterpret_cast<Smi*>(date_format)); | 13914 local_object->SetInternalField(0, reinterpret_cast<Smi*>(date_format)); |
13927 | 13915 |
13928 RETURN_FAILURE_ON_EXCEPTION(isolate, | 13916 Factory* factory = isolate->factory(); |
13929 JSObject::SetOwnPropertyIgnoreAttributes( | 13917 Handle<String> key = factory->NewStringFromStaticAscii("dateFormat"); |
13930 local_object, | 13918 Handle<String> value = factory->NewStringFromStaticAscii("valid"); |
13931 isolate->factory()->NewStringFromStaticAscii("dateFormat"), | 13919 JSObject::InitializeProperty(local_object, key, value, NONE); |
13932 isolate->factory()->NewStringFromStaticAscii("valid"), | |
13933 NONE)); | |
13934 | 13920 |
13935 // Make object handle weak so we can delete the data format once GC kicks in. | 13921 // Make object handle weak so we can delete the data format once GC kicks in. |
13936 Handle<Object> wrapper = isolate->global_handles()->Create(*local_object); | 13922 Handle<Object> wrapper = isolate->global_handles()->Create(*local_object); |
13937 GlobalHandles::MakeWeak(wrapper.location(), | 13923 GlobalHandles::MakeWeak(wrapper.location(), |
13938 reinterpret_cast<void*>(wrapper.location()), | 13924 reinterpret_cast<void*>(wrapper.location()), |
13939 DateFormat::DeleteDateFormat); | 13925 DateFormat::DeleteDateFormat); |
13940 return *local_object; | 13926 return *local_object; |
13941 } | 13927 } |
13942 | 13928 |
13943 | 13929 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
14017 Execution::InstantiateObject(number_format_template)); | 14003 Execution::InstantiateObject(number_format_template)); |
14018 | 14004 |
14019 // Set number formatter as internal field of the resulting JS object. | 14005 // Set number formatter as internal field of the resulting JS object. |
14020 icu::DecimalFormat* number_format = NumberFormat::InitializeNumberFormat( | 14006 icu::DecimalFormat* number_format = NumberFormat::InitializeNumberFormat( |
14021 isolate, locale, options, resolved); | 14007 isolate, locale, options, resolved); |
14022 | 14008 |
14023 if (!number_format) return isolate->ThrowIllegalOperation(); | 14009 if (!number_format) return isolate->ThrowIllegalOperation(); |
14024 | 14010 |
14025 local_object->SetInternalField(0, reinterpret_cast<Smi*>(number_format)); | 14011 local_object->SetInternalField(0, reinterpret_cast<Smi*>(number_format)); |
14026 | 14012 |
14027 RETURN_FAILURE_ON_EXCEPTION(isolate, | 14013 Factory* factory = isolate->factory(); |
14028 JSObject::SetOwnPropertyIgnoreAttributes( | 14014 Handle<String> key = factory->NewStringFromStaticAscii("numberFormat"); |
14029 local_object, | 14015 Handle<String> value = factory->NewStringFromStaticAscii("valid"); |
14030 isolate->factory()->NewStringFromStaticAscii("numberFormat"), | 14016 JSObject::InitializeProperty(local_object, key, value, NONE); |
14031 isolate->factory()->NewStringFromStaticAscii("valid"), | |
14032 NONE)); | |
14033 | 14017 |
14034 Handle<Object> wrapper = isolate->global_handles()->Create(*local_object); | 14018 Handle<Object> wrapper = isolate->global_handles()->Create(*local_object); |
14035 GlobalHandles::MakeWeak(wrapper.location(), | 14019 GlobalHandles::MakeWeak(wrapper.location(), |
14036 reinterpret_cast<void*>(wrapper.location()), | 14020 reinterpret_cast<void*>(wrapper.location()), |
14037 NumberFormat::DeleteNumberFormat); | 14021 NumberFormat::DeleteNumberFormat); |
14038 return *local_object; | 14022 return *local_object; |
14039 } | 14023 } |
14040 | 14024 |
14041 | 14025 |
14042 RUNTIME_FUNCTION(Runtime_InternalNumberFormat) { | 14026 RUNTIME_FUNCTION(Runtime_InternalNumberFormat) { |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
14125 isolate, local_object, Execution::InstantiateObject(collator_template)); | 14109 isolate, local_object, Execution::InstantiateObject(collator_template)); |
14126 | 14110 |
14127 // Set collator as internal field of the resulting JS object. | 14111 // Set collator as internal field of the resulting JS object. |
14128 icu::Collator* collator = Collator::InitializeCollator( | 14112 icu::Collator* collator = Collator::InitializeCollator( |
14129 isolate, locale, options, resolved); | 14113 isolate, locale, options, resolved); |
14130 | 14114 |
14131 if (!collator) return isolate->ThrowIllegalOperation(); | 14115 if (!collator) return isolate->ThrowIllegalOperation(); |
14132 | 14116 |
14133 local_object->SetInternalField(0, reinterpret_cast<Smi*>(collator)); | 14117 local_object->SetInternalField(0, reinterpret_cast<Smi*>(collator)); |
14134 | 14118 |
14135 RETURN_FAILURE_ON_EXCEPTION(isolate, | 14119 Factory* factory = isolate->factory(); |
14136 JSObject::SetOwnPropertyIgnoreAttributes( | 14120 Handle<String> key = factory->NewStringFromStaticAscii("collator"); |
14137 local_object, | 14121 Handle<String> value = factory->NewStringFromStaticAscii("valid"); |
14138 isolate->factory()->NewStringFromStaticAscii("collator"), | 14122 JSObject::InitializeProperty(local_object, key, value, NONE); |
14139 isolate->factory()->NewStringFromStaticAscii("valid"), | |
14140 NONE)); | |
14141 | 14123 |
14142 Handle<Object> wrapper = isolate->global_handles()->Create(*local_object); | 14124 Handle<Object> wrapper = isolate->global_handles()->Create(*local_object); |
14143 GlobalHandles::MakeWeak(wrapper.location(), | 14125 GlobalHandles::MakeWeak(wrapper.location(), |
14144 reinterpret_cast<void*>(wrapper.location()), | 14126 reinterpret_cast<void*>(wrapper.location()), |
14145 Collator::DeleteCollator); | 14127 Collator::DeleteCollator); |
14146 return *local_object; | 14128 return *local_object; |
14147 } | 14129 } |
14148 | 14130 |
14149 | 14131 |
14150 RUNTIME_FUNCTION(Runtime_InternalCompare) { | 14132 RUNTIME_FUNCTION(Runtime_InternalCompare) { |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
14231 // Set break iterator as internal field of the resulting JS object. | 14213 // Set break iterator as internal field of the resulting JS object. |
14232 icu::BreakIterator* break_iterator = BreakIterator::InitializeBreakIterator( | 14214 icu::BreakIterator* break_iterator = BreakIterator::InitializeBreakIterator( |
14233 isolate, locale, options, resolved); | 14215 isolate, locale, options, resolved); |
14234 | 14216 |
14235 if (!break_iterator) return isolate->ThrowIllegalOperation(); | 14217 if (!break_iterator) return isolate->ThrowIllegalOperation(); |
14236 | 14218 |
14237 local_object->SetInternalField(0, reinterpret_cast<Smi*>(break_iterator)); | 14219 local_object->SetInternalField(0, reinterpret_cast<Smi*>(break_iterator)); |
14238 // Make sure that the pointer to adopted text is NULL. | 14220 // Make sure that the pointer to adopted text is NULL. |
14239 local_object->SetInternalField(1, reinterpret_cast<Smi*>(NULL)); | 14221 local_object->SetInternalField(1, reinterpret_cast<Smi*>(NULL)); |
14240 | 14222 |
14241 RETURN_FAILURE_ON_EXCEPTION(isolate, | 14223 Factory* factory = isolate->factory(); |
14242 JSObject::SetOwnPropertyIgnoreAttributes( | 14224 Handle<String> key = factory->NewStringFromStaticAscii("breakIterator"); |
14243 local_object, | 14225 Handle<String> value = factory->NewStringFromStaticAscii("valid"); |
14244 isolate->factory()->NewStringFromStaticAscii("breakIterator"), | 14226 JSObject::InitializeProperty(local_object, key, value, NONE); |
14245 isolate->factory()->NewStringFromStaticAscii("valid"), | |
14246 NONE)); | |
14247 | 14227 |
14248 // Make object handle weak so we can delete the break iterator once GC kicks | 14228 // Make object handle weak so we can delete the break iterator once GC kicks |
14249 // in. | 14229 // in. |
14250 Handle<Object> wrapper = isolate->global_handles()->Create(*local_object); | 14230 Handle<Object> wrapper = isolate->global_handles()->Create(*local_object); |
14251 GlobalHandles::MakeWeak(wrapper.location(), | 14231 GlobalHandles::MakeWeak(wrapper.location(), |
14252 reinterpret_cast<void*>(wrapper.location()), | 14232 reinterpret_cast<void*>(wrapper.location()), |
14253 BreakIterator::DeleteBreakIterator); | 14233 BreakIterator::DeleteBreakIterator); |
14254 return *local_object; | 14234 return *local_object; |
14255 } | 14235 } |
14256 | 14236 |
(...skipping 840 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
15097 } | 15077 } |
15098 return NULL; | 15078 return NULL; |
15099 } | 15079 } |
15100 | 15080 |
15101 | 15081 |
15102 const Runtime::Function* Runtime::FunctionForId(Runtime::FunctionId id) { | 15082 const Runtime::Function* Runtime::FunctionForId(Runtime::FunctionId id) { |
15103 return &(kIntrinsicFunctions[static_cast<int>(id)]); | 15083 return &(kIntrinsicFunctions[static_cast<int>(id)]); |
15104 } | 15084 } |
15105 | 15085 |
15106 } } // namespace v8::internal | 15086 } } // namespace v8::internal |
OLD | NEW |