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

Side by Side Diff: src/runtime.cc

Issue 200363002: Handlify callers of Object::GetElement. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: addressed comments Created 6 years, 9 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/objects-inl.h ('k') | test/cctest/test-api.cc » ('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 4782 matching lines...) Expand 10 before | Expand all | Expand 10 after
4793 } 4793 }
4794 4794
4795 // Handle [] indexing on String objects 4795 // Handle [] indexing on String objects
4796 if (object->IsStringObjectWithCharacterAt(index)) { 4796 if (object->IsStringObjectWithCharacterAt(index)) {
4797 Handle<JSValue> js_value = Handle<JSValue>::cast(object); 4797 Handle<JSValue> js_value = Handle<JSValue>::cast(object);
4798 Handle<Object> result = 4798 Handle<Object> result =
4799 GetCharAt(Handle<String>(String::cast(js_value->value())), index); 4799 GetCharAt(Handle<String>(String::cast(js_value->value())), index);
4800 if (!result->IsUndefined()) return *result; 4800 if (!result->IsUndefined()) return *result;
4801 } 4801 }
4802 4802
4803 Handle<Object> result;
4803 if (object->IsString() || object->IsNumber() || object->IsBoolean()) { 4804 if (object->IsString() || object->IsNumber() || object->IsBoolean()) {
4804 return object->GetPrototype(isolate)->GetElement(isolate, index); 4805 Handle<Object> proto(object->GetPrototype(isolate), isolate);
4806 result = Object::GetElement(isolate, proto, index);
4807 } else {
4808 result = Object::GetElement(isolate, object, index);
4805 } 4809 }
4806 4810 RETURN_IF_EMPTY_HANDLE(isolate, result);
4807 return object->GetElement(isolate, index); 4811 return *result;
4808 } 4812 }
4809 4813
4810 4814
4811 static Handle<Name> ToName(Isolate* isolate, Handle<Object> key) { 4815 static Handle<Name> ToName(Isolate* isolate, Handle<Object> key) {
4812 if (key->IsName()) { 4816 if (key->IsName()) {
4813 return Handle<Name>::cast(key); 4817 return Handle<Name>::cast(key);
4814 } else { 4818 } else {
4815 bool has_pending_exception = false; 4819 bool has_pending_exception = false;
4816 Handle<Object> converted = 4820 Handle<Object> converted =
4817 Execution::ToString(isolate, key, &has_pending_exception); 4821 Execution::ToString(isolate, key, &has_pending_exception);
(...skipping 1157 matching lines...) Expand 10 before | Expand all | Expand 10 after
5975 Handle<Object> converted = 5979 Handle<Object> converted =
5976 Execution::ToString(isolate, args.at<Object>(0), &exception); 5980 Execution::ToString(isolate, args.at<Object>(0), &exception);
5977 if (exception) return Failure::Exception(); 5981 if (exception) return Failure::Exception();
5978 Handle<String> key = Handle<String>::cast(converted); 5982 Handle<String> key = Handle<String>::cast(converted);
5979 5983
5980 // Try to convert the string key into an array index. 5984 // Try to convert the string key into an array index.
5981 if (key->AsArrayIndex(&index)) { 5985 if (key->AsArrayIndex(&index)) {
5982 if (index < n) { 5986 if (index < n) {
5983 return frame->GetParameter(index); 5987 return frame->GetParameter(index);
5984 } else { 5988 } else {
5985 return isolate->initial_object_prototype()->GetElement(isolate, index); 5989 Handle<Object> initial_prototype(isolate->initial_object_prototype());
5990 Handle<Object> result =
5991 Object::GetElement(isolate, initial_prototype, index);
5992 RETURN_IF_EMPTY_HANDLE(isolate, result);
5993 return *result;
5986 } 5994 }
5987 } 5995 }
5988 5996
5989 // Handle special arguments properties. 5997 // Handle special arguments properties.
5990 if (key->Equals(isolate->heap()->length_string())) return Smi::FromInt(n); 5998 if (key->Equals(isolate->heap()->length_string())) return Smi::FromInt(n);
5991 if (key->Equals(isolate->heap()->callee_string())) { 5999 if (key->Equals(isolate->heap()->callee_string())) {
5992 JSFunction* function = frame->function(); 6000 JSFunction* function = frame->function();
5993 if (function->shared()->strict_mode() == STRICT) { 6001 if (function->shared()->strict_mode() == STRICT) {
5994 return isolate->Throw(*isolate->factory()->NewTypeError( 6002 return isolate->Throw(*isolate->factory()->NewTypeError(
5995 "strict_arguments_callee", HandleVector<Object>(NULL, 0))); 6003 "strict_arguments_callee", HandleVector<Object>(NULL, 0)));
(...skipping 2823 matching lines...) Expand 10 before | Expand all | Expand 10 after
8819 SmartArrayPointer<Handle<Object> > argv_large_buffer; 8827 SmartArrayPointer<Handle<Object> > argv_large_buffer;
8820 Handle<Object>* argv = argv_small_buffer; 8828 Handle<Object>* argv = argv_small_buffer;
8821 if (argc > argv_small_size) { 8829 if (argc > argv_small_size) {
8822 argv = new Handle<Object>[argc]; 8830 argv = new Handle<Object>[argc];
8823 if (argv == NULL) return isolate->StackOverflow(); 8831 if (argv == NULL) return isolate->StackOverflow();
8824 argv_large_buffer = SmartArrayPointer<Handle<Object> >(argv); 8832 argv_large_buffer = SmartArrayPointer<Handle<Object> >(argv);
8825 } 8833 }
8826 8834
8827 for (int i = 0; i < argc; ++i) { 8835 for (int i = 0; i < argc; ++i) {
8828 argv[i] = Object::GetElement(isolate, arguments, offset + i); 8836 argv[i] = Object::GetElement(isolate, arguments, offset + i);
8837 RETURN_IF_EMPTY_HANDLE(isolate, argv[i]);
8829 } 8838 }
8830 8839
8831 bool threw; 8840 bool threw;
8832 Handle<Object> result = Execution::Call( 8841 Handle<Object> result = Execution::Call(
8833 isolate, fun, receiver, argc, argv, &threw, true); 8842 isolate, fun, receiver, argc, argv, &threw, true);
8834 8843
8835 if (threw) return Failure::Exception(); 8844 if (threw) return Failure::Exception();
8836 return *result; 8845 return *result;
8837 } 8846 }
8838 8847
(...skipping 4843 matching lines...) Expand 10 before | Expand all | Expand 10 after
13682 13691
13683 CONVERT_ARG_HANDLE_CHECKED(JSArray, input, 0); 13692 CONVERT_ARG_HANDLE_CHECKED(JSArray, input, 0);
13684 13693
13685 uint32_t length = static_cast<uint32_t>(input->length()->Number()); 13694 uint32_t length = static_cast<uint32_t>(input->length()->Number());
13686 Handle<FixedArray> output = isolate->factory()->NewFixedArray(length); 13695 Handle<FixedArray> output = isolate->factory()->NewFixedArray(length);
13687 Handle<Name> maximized = 13696 Handle<Name> maximized =
13688 isolate->factory()->NewStringFromAscii(CStrVector("maximized")); 13697 isolate->factory()->NewStringFromAscii(CStrVector("maximized"));
13689 Handle<Name> base = 13698 Handle<Name> base =
13690 isolate->factory()->NewStringFromAscii(CStrVector("base")); 13699 isolate->factory()->NewStringFromAscii(CStrVector("base"));
13691 for (unsigned int i = 0; i < length; ++i) { 13700 for (unsigned int i = 0; i < length; ++i) {
13692 MaybeObject* maybe_string = input->GetElement(isolate, i); 13701 Handle<Object> locale_id = Object::GetElement(isolate, input, i);
13693 Object* locale_id; 13702 RETURN_IF_EMPTY_HANDLE(isolate, locale_id);
13694 if (!maybe_string->ToObject(&locale_id) || !locale_id->IsString()) { 13703 if (!locale_id->IsString()) {
13695 return isolate->Throw(isolate->heap()->illegal_argument_string()); 13704 return isolate->Throw(isolate->heap()->illegal_argument_string());
13696 } 13705 }
13697 13706
13698 v8::String::Utf8Value utf8_locale_id( 13707 v8::String::Utf8Value utf8_locale_id(
13699 v8::Utils::ToLocal(Handle<String>(String::cast(locale_id)))); 13708 v8::Utils::ToLocal(Handle<String>::cast(locale_id)));
13700 13709
13701 UErrorCode error = U_ZERO_ERROR; 13710 UErrorCode error = U_ZERO_ERROR;
13702 13711
13703 // Convert from BCP47 to ICU format. 13712 // Convert from BCP47 to ICU format.
13704 // de-DE-u-co-phonebk -> de_DE@collation=phonebook 13713 // de-DE-u-co-phonebk -> de_DE@collation=phonebook
13705 char icu_locale[ULOC_FULLNAME_CAPACITY]; 13714 char icu_locale[ULOC_FULLNAME_CAPACITY];
13706 int icu_locale_length = 0; 13715 int icu_locale_length = 0;
13707 uloc_forLanguageTag(*utf8_locale_id, icu_locale, ULOC_FULLNAME_CAPACITY, 13716 uloc_forLanguageTag(*utf8_locale_id, icu_locale, ULOC_FULLNAME_CAPACITY,
13708 &icu_locale_length, &error); 13717 &icu_locale_length, &error);
13709 if (U_FAILURE(error) || icu_locale_length == 0) { 13718 if (U_FAILURE(error) || icu_locale_length == 0) {
(...skipping 836 matching lines...) Expand 10 before | Expand all | Expand 10 after
14546 INLINE_FUNCTION_LIST(ADD_ENTRY) 14555 INLINE_FUNCTION_LIST(ADD_ENTRY)
14547 #undef ADD_ENTRY 14556 #undef ADD_ENTRY
14548 ASSERT_EQ(index, entry_count); 14557 ASSERT_EQ(index, entry_count);
14549 Handle<JSArray> result = factory->NewJSArrayWithElements(elements); 14558 Handle<JSArray> result = factory->NewJSArrayWithElements(elements);
14550 return *result; 14559 return *result;
14551 } 14560 }
14552 #endif 14561 #endif
14553 14562
14554 14563
14555 RUNTIME_FUNCTION(MaybeObject*, Runtime_Log) { 14564 RUNTIME_FUNCTION(MaybeObject*, Runtime_Log) {
14556 SealHandleScope shs(isolate); 14565 HandleScope handle_scope(isolate);
14557 ASSERT(args.length() == 2); 14566 ASSERT(args.length() == 2);
14558 CONVERT_ARG_CHECKED(String, format, 0); 14567 CONVERT_ARG_HANDLE_CHECKED(String, format, 0);
14559 CONVERT_ARG_CHECKED(JSArray, elms, 1); 14568 CONVERT_ARG_HANDLE_CHECKED(JSArray, elms, 1);
14560 DisallowHeapAllocation no_gc; 14569
14561 String::FlatContent format_content = format->GetFlatContent(); 14570 SmartArrayPointer<char> format_chars = format->ToCString();
14562 RUNTIME_ASSERT(format_content.IsAscii()); 14571 isolate->logger()->LogRuntime(
14563 Vector<const uint8_t> chars = format_content.ToOneByteVector(); 14572 Vector<const char>(format_chars.get(), format->length()), elms);
14564 isolate->logger()->LogRuntime(Vector<const char>::cast(chars), elms);
14565 return isolate->heap()->undefined_value(); 14573 return isolate->heap()->undefined_value();
14566 } 14574 }
14567 14575
14568 14576
14569 RUNTIME_FUNCTION(MaybeObject*, Runtime_IS_VAR) { 14577 RUNTIME_FUNCTION(MaybeObject*, Runtime_IS_VAR) {
14570 UNREACHABLE(); // implemented as macro in the parser 14578 UNREACHABLE(); // implemented as macro in the parser
14571 return NULL; 14579 return NULL;
14572 } 14580 }
14573 14581
14574 14582
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
14974 // Handle last resort GC and make sure to allow future allocations 14982 // Handle last resort GC and make sure to allow future allocations
14975 // to grow the heap without causing GCs (if possible). 14983 // to grow the heap without causing GCs (if possible).
14976 isolate->counters()->gc_last_resort_from_js()->Increment(); 14984 isolate->counters()->gc_last_resort_from_js()->Increment();
14977 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, 14985 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags,
14978 "Runtime::PerformGC"); 14986 "Runtime::PerformGC");
14979 } 14987 }
14980 } 14988 }
14981 14989
14982 14990
14983 } } // namespace v8::internal 14991 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/objects-inl.h ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698