X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fv8%2Fsrc%2Ffactory.cc;h=20b963bee84ce727c75487de67476461888b0d56;hb=004985e17e624662a4c85c76a7654039dc83f028;hp=5460d3e847fe89325da9fda3d6bd330888121371;hpb=2f108dbacb161091e42a3479f4e171339b7e7623;p=platform%2Fframework%2Fweb%2Fcrosswalk.git diff --git a/src/v8/src/factory.cc b/src/v8/src/factory.cc index 5460d3e..20b963b 100644 --- a/src/v8/src/factory.cc +++ b/src/v8/src/factory.cc @@ -1,52 +1,61 @@ -// Copyright 2013 the V8 project authors. All rights reserved. -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following -// disclaimer in the documentation and/or other materials provided -// with the distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived -// from this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#include "v8.h" - -#include "api.h" -#include "debug.h" -#include "execution.h" +// Copyright 2014 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + #include "factory.h" + +#include "conversions.h" #include "isolate-inl.h" #include "macro-assembler.h" -#include "objects.h" -#include "objects-visiting.h" -#include "platform.h" -#include "scopeinfo.h" namespace v8 { namespace internal { -Handle Factory::NewBox(Handle value, PretenureFlag pretenure) { +template +Handle Factory::New(Handle map, AllocationSpace space) { + CALL_HEAP_FUNCTION( + isolate(), + isolate()->heap()->Allocate(*map, space), + T); +} + + +template +Handle Factory::New(Handle map, + AllocationSpace space, + Handle allocation_site) { + CALL_HEAP_FUNCTION( + isolate(), + isolate()->heap()->Allocate(*map, space, *allocation_site), + T); +} + + +Handle Factory::NewFillerObject(int size, + bool double_align, + AllocationSpace space) { CALL_HEAP_FUNCTION( isolate(), - isolate()->heap()->AllocateBox(*value, pretenure), - Box); + isolate()->heap()->AllocateFillerObject(size, double_align, space), + HeapObject); +} + + +Handle Factory::NewBox(Handle value) { + Handle result = Handle::cast(NewStruct(BOX_TYPE)); + result->set_value(*value); + return result; +} + + +Handle Factory::NewOddball(Handle map, + const char* to_string, + Handle to_number, + byte kind) { + Handle oddball = New(map, OLD_POINTER_SPACE); + Oddball::Initialize(isolate(), oddball, to_string, to_number, kind); + return oddball; } @@ -64,7 +73,9 @@ Handle Factory::NewFixedArrayWithHoles(int size, ASSERT(0 <= size); CALL_HEAP_FUNCTION( isolate(), - isolate()->heap()->AllocateFixedArrayWithHoles(size, pretenure), + isolate()->heap()->AllocateFixedArrayWithFiller(size, + pretenure, + *the_hole_value()), FixedArray); } @@ -77,13 +88,29 @@ Handle Factory::NewUninitializedFixedArray(int size) { } -Handle Factory::NewFixedDoubleArray(int size, - PretenureFlag pretenure) { +Handle Factory::NewFixedDoubleArray(int size, + PretenureFlag pretenure) { ASSERT(0 <= size); CALL_HEAP_FUNCTION( isolate(), isolate()->heap()->AllocateUninitializedFixedDoubleArray(size, pretenure), - FixedDoubleArray); + FixedArrayBase); +} + + +Handle Factory::NewFixedDoubleArrayWithHoles( + int size, + PretenureFlag pretenure) { + ASSERT(0 <= size); + Handle array = NewFixedDoubleArray(size, pretenure); + if (size > 0) { + Handle double_array = + Handle::cast(array); + for (int i = 0; i < size; ++i) { + double_array->set_the_hole(i); + } + } + return array; } @@ -104,113 +131,31 @@ Handle Factory::NewConstantPoolArray( } -Handle Factory::NewNameDictionary(int at_least_space_for) { - ASSERT(0 <= at_least_space_for); - CALL_HEAP_FUNCTION(isolate(), - NameDictionary::Allocate(isolate()->heap(), - at_least_space_for), - NameDictionary); -} - - -Handle Factory::NewSeededNumberDictionary( - int at_least_space_for) { - ASSERT(0 <= at_least_space_for); - CALL_HEAP_FUNCTION(isolate(), - SeededNumberDictionary::Allocate(isolate()->heap(), - at_least_space_for), - SeededNumberDictionary); -} - - -Handle Factory::NewUnseededNumberDictionary( - int at_least_space_for) { - ASSERT(0 <= at_least_space_for); - CALL_HEAP_FUNCTION(isolate(), - UnseededNumberDictionary::Allocate(isolate()->heap(), - at_least_space_for), - UnseededNumberDictionary); -} - - -Handle Factory::NewObjectHashSet(int at_least_space_for) { - ASSERT(0 <= at_least_space_for); - CALL_HEAP_FUNCTION(isolate(), - ObjectHashSet::Allocate(isolate()->heap(), - at_least_space_for), - ObjectHashSet); -} - - -Handle Factory::NewObjectHashTable( - int at_least_space_for, - MinimumCapacity capacity_option) { - ASSERT(0 <= at_least_space_for); - CALL_HEAP_FUNCTION(isolate(), - ObjectHashTable::Allocate(isolate()->heap(), - at_least_space_for, - capacity_option), - ObjectHashTable); -} - - -Handle Factory::NewWeakHashTable(int at_least_space_for) { - ASSERT(0 <= at_least_space_for); - CALL_HEAP_FUNCTION( - isolate(), - WeakHashTable::Allocate(isolate()->heap(), - at_least_space_for, - USE_DEFAULT_MINIMUM_CAPACITY, - TENURED), - WeakHashTable); -} - - -Handle Factory::NewDescriptorArray(int number_of_descriptors, - int slack) { - ASSERT(0 <= number_of_descriptors); - CALL_HEAP_FUNCTION(isolate(), - DescriptorArray::Allocate( - isolate(), number_of_descriptors, slack), - DescriptorArray); -} - - -Handle Factory::NewDeoptimizationInputData( - int deopt_entry_count, - PretenureFlag pretenure) { - ASSERT(deopt_entry_count > 0); - CALL_HEAP_FUNCTION(isolate(), - DeoptimizationInputData::Allocate(isolate(), - deopt_entry_count, - pretenure), - DeoptimizationInputData); +Handle Factory::NewOrderedHashSet() { + return OrderedHashSet::Allocate(isolate(), 4); } -Handle Factory::NewDeoptimizationOutputData( - int deopt_entry_count, - PretenureFlag pretenure) { - ASSERT(deopt_entry_count > 0); - CALL_HEAP_FUNCTION(isolate(), - DeoptimizationOutputData::Allocate(isolate(), - deopt_entry_count, - pretenure), - DeoptimizationOutputData); +Handle Factory::NewOrderedHashMap() { + return OrderedHashMap::Allocate(isolate(), 4); } Handle Factory::NewAccessorPair() { - CALL_HEAP_FUNCTION(isolate(), - isolate()->heap()->AllocateAccessorPair(), - AccessorPair); + Handle accessors = + Handle::cast(NewStruct(ACCESSOR_PAIR_TYPE)); + accessors->set_getter(*the_hole_value(), SKIP_WRITE_BARRIER); + accessors->set_setter(*the_hole_value(), SKIP_WRITE_BARRIER); + accessors->set_access_flags(Smi::FromInt(0), SKIP_WRITE_BARRIER); + return accessors; } Handle Factory::NewTypeFeedbackInfo() { - CALL_HEAP_FUNCTION(isolate(), - isolate()->heap()->AllocateTypeFeedbackInfo(), - TypeFeedbackInfo); + Handle info = + Handle::cast(NewStruct(TYPE_FEEDBACK_INFO_TYPE)); + info->initialize_storage(); + return info; } @@ -223,9 +168,8 @@ Handle Factory::InternalizeUtf8String(Vector string) { // Internalized strings are created in the old generation (data space). Handle Factory::InternalizeString(Handle string) { - CALL_HEAP_FUNCTION(isolate(), - isolate()->heap()->InternalizeString(*string), - String); + if (string->IsInternalizedString()) return string; + return StringTable::LookupString(isolate(), string); } @@ -250,9 +194,7 @@ Handle Factory::InternalizeTwoByteString(Vector string) { template Handle Factory::InternalizeStringWithKey(StringTableKey* key) { - CALL_HEAP_FUNCTION(isolate(), - isolate()->heap()->InternalizeStringWithKey(key), - String); + return StringTable::LookupKey(isolate(), key); } @@ -262,25 +204,50 @@ template Handle Factory::InternalizeStringWithKey< SubStringKey > (SubStringKey* key); -Handle Factory::NewStringFromOneByte(Vector string, - PretenureFlag pretenure) { - CALL_HEAP_FUNCTION( +MaybeHandle Factory::NewStringFromOneByte(Vector string, + PretenureFlag pretenure) { + int length = string.length(); + if (length == 1) { + return LookupSingleCharacterStringFromCode(string[0]); + } + Handle result; + ASSIGN_RETURN_ON_EXCEPTION( isolate(), - isolate()->heap()->AllocateStringFromOneByte(string, pretenure), + result, + NewRawOneByteString(string.length(), pretenure), String); + + DisallowHeapAllocation no_gc; + // Copy the characters into the new object. + CopyChars(SeqOneByteString::cast(*result)->GetChars(), + string.start(), + length); + return result; } -Handle Factory::NewStringFromUtf8(Vector string, - PretenureFlag pretenure) { +MaybeHandle Factory::NewStringFromUtf8(Vector string, + PretenureFlag pretenure) { + // Check for ASCII first since this is the common case. + const char* start = string.start(); + int length = string.length(); + int non_ascii_start = String::NonAsciiStart(start, length); + if (non_ascii_start >= length) { + // If the string is ASCII, we do not need to convert the characters + // since UTF8 is backwards compatible with ASCII. + return NewStringFromOneByte(Vector::cast(string), pretenure); + } + // Non-ASCII and we need to decode. CALL_HEAP_FUNCTION( isolate(), - isolate()->heap()->AllocateStringFromUtf8(string, pretenure), + isolate()->heap()->AllocateStringFromUtf8Slow(string, + non_ascii_start, + pretenure), String); } -Handle Factory::NewStringFromTwoByte(Vector string, - PretenureFlag pretenure) { +MaybeHandle Factory::NewStringFromTwoByte(Vector string, + PretenureFlag pretenure) { CALL_HEAP_FUNCTION( isolate(), isolate()->heap()->AllocateStringFromTwoByte(string, pretenure), @@ -288,8 +255,74 @@ Handle Factory::NewStringFromTwoByte(Vector string, } -Handle Factory::NewRawOneByteString(int length, - PretenureFlag pretenure) { +Handle Factory::NewInternalizedStringFromUtf8(Vector str, + int chars, + uint32_t hash_field) { + CALL_HEAP_FUNCTION( + isolate(), + isolate()->heap()->AllocateInternalizedStringFromUtf8( + str, chars, hash_field), + String); +} + + +MUST_USE_RESULT Handle Factory::NewOneByteInternalizedString( + Vector str, + uint32_t hash_field) { + CALL_HEAP_FUNCTION( + isolate(), + isolate()->heap()->AllocateOneByteInternalizedString(str, hash_field), + String); +} + + +MUST_USE_RESULT Handle Factory::NewTwoByteInternalizedString( + Vector str, + uint32_t hash_field) { + CALL_HEAP_FUNCTION( + isolate(), + isolate()->heap()->AllocateTwoByteInternalizedString(str, hash_field), + String); +} + + +Handle Factory::NewInternalizedStringImpl( + Handle string, int chars, uint32_t hash_field) { + CALL_HEAP_FUNCTION( + isolate(), + isolate()->heap()->AllocateInternalizedStringImpl( + *string, chars, hash_field), + String); +} + + +MaybeHandle Factory::InternalizedStringMapForString( + Handle string) { + // If the string is in new space it cannot be used as internalized. + if (isolate()->heap()->InNewSpace(*string)) return MaybeHandle(); + + // Find the corresponding internalized string map for strings. + switch (string->map()->instance_type()) { + case STRING_TYPE: return internalized_string_map(); + case ASCII_STRING_TYPE: return ascii_internalized_string_map(); + case EXTERNAL_STRING_TYPE: return external_internalized_string_map(); + case EXTERNAL_ASCII_STRING_TYPE: + return external_ascii_internalized_string_map(); + case EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE: + return external_internalized_string_with_one_byte_data_map(); + case SHORT_EXTERNAL_STRING_TYPE: + return short_external_internalized_string_map(); + case SHORT_EXTERNAL_ASCII_STRING_TYPE: + return short_external_ascii_internalized_string_map(); + case SHORT_EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE: + return short_external_internalized_string_with_one_byte_data_map(); + default: return MaybeHandle(); // No match found. + } +} + + +MaybeHandle Factory::NewRawOneByteString( + int length, PretenureFlag pretenure) { CALL_HEAP_FUNCTION( isolate(), isolate()->heap()->AllocateRawOneByteString(length, pretenure), @@ -297,8 +330,8 @@ Handle Factory::NewRawOneByteString(int length, } -Handle Factory::NewRawTwoByteString(int length, - PretenureFlag pretenure) { +MaybeHandle Factory::NewRawTwoByteString( + int length, PretenureFlag pretenure) { CALL_HEAP_FUNCTION( isolate(), isolate()->heap()->AllocateRawTwoByteString(length, pretenure), @@ -306,6 +339,30 @@ Handle Factory::NewRawTwoByteString(int length, } +Handle Factory::LookupSingleCharacterStringFromCode(uint32_t code) { + if (code <= String::kMaxOneByteCharCodeU) { + { + DisallowHeapAllocation no_allocation; + Object* value = single_character_string_cache()->get(code); + if (value != *undefined_value()) { + return handle(String::cast(value), isolate()); + } + } + uint8_t buffer[1]; + buffer[0] = static_cast(code); + Handle result = + InternalizeOneByteString(Vector(buffer, 1)); + single_character_string_cache()->set(code, *result); + return result; + } + ASSERT(code <= String::kMaxUtf16CodeUnitU); + + Handle result = NewRawTwoByteString(1).ToHandleChecked(); + result->SeqTwoByteStringSet(0, static_cast(code)); + return result; +} + + // Returns true for a character in a range. Both limits are inclusive. static inline bool Between(uint32_t character, uint32_t from, uint32_t to) { // This makes uses of the the unsigned wraparound. @@ -319,10 +376,10 @@ static inline Handle MakeOrFindTwoCharacterString(Isolate* isolate, // Numeric strings have a different hash algorithm not known by // LookupTwoCharsStringIfExists, so we skip this step for such strings. if (!Between(c1, '0', '9') || !Between(c2, '0', '9')) { - String* result; - StringTable* table = isolate->heap()->string_table(); - if (table->LookupTwoCharsStringIfExists(c1, c2, &result)) { - return handle(result); + Handle result; + if (StringTable::LookupTwoCharsStringIfExists(isolate, c1, c2). + ToHandle(&result)) { + return result; } } @@ -331,13 +388,15 @@ static inline Handle MakeOrFindTwoCharacterString(Isolate* isolate, if (static_cast(c1 | c2) <= String::kMaxOneByteCharCodeU) { // We can do this. ASSERT(IsPowerOf2(String::kMaxOneByteCharCodeU + 1)); // because of this. - Handle str = isolate->factory()->NewRawOneByteString(2); + Handle str = + isolate->factory()->NewRawOneByteString(2).ToHandleChecked(); uint8_t* dest = str->GetChars(); dest[0] = static_cast(c1); dest[1] = static_cast(c2); return str; } else { - Handle str = isolate->factory()->NewRawTwoByteString(2); + Handle str = + isolate->factory()->NewRawTwoByteString(2).ToHandleChecked(); uc16* dest = str->GetChars(); dest[0] = c1; dest[1] = c2; @@ -358,17 +417,8 @@ Handle ConcatStringContent(Handle result, } -Handle Factory::NewRawConsString(String::Encoding encoding) { - Handle map = (encoding == String::ONE_BYTE_ENCODING) - ? cons_ascii_string_map() : cons_string_map(); - CALL_HEAP_FUNCTION(isolate(), - isolate()->heap()->Allocate(*map, NEW_SPACE), - ConsString); -} - - -Handle Factory::NewConsString(Handle left, - Handle right) { +MaybeHandle Factory::NewConsString(Handle left, + Handle right) { int left_length = left->length(); if (left_length == 0) return right; int right_length = right->length(); @@ -385,8 +435,7 @@ Handle Factory::NewConsString(Handle left, // Make sure that an out of memory exception is thrown if the length // of the new cons string is too large. if (length > String::kMaxLength || length < 0) { - isolate()->ThrowInvalidStringLength(); - return Handle::null(); + return isolate()->Throw(NewInvalidStringLengthError()); } bool left_is_one_byte = left->IsOneByteRepresentation(); @@ -413,7 +462,8 @@ Handle Factory::NewConsString(Handle left, STATIC_ASSERT(ConsString::kMinLength <= String::kMaxLength); if (is_one_byte) { - Handle result = NewRawOneByteString(length); + Handle result = + NewRawOneByteString(length).ToHandleChecked(); DisallowHeapAllocation no_gc; uint8_t* dest = result->GetChars(); // Copy left part. @@ -430,14 +480,15 @@ Handle Factory::NewConsString(Handle left, } return (is_one_byte_data_in_two_byte_string) - ? ConcatStringContent(NewRawOneByteString(length), left, right) - : ConcatStringContent(NewRawTwoByteString(length), left, right); + ? ConcatStringContent( + NewRawOneByteString(length).ToHandleChecked(), left, right) + : ConcatStringContent( + NewRawTwoByteString(length).ToHandleChecked(), left, right); } - Handle result = NewRawConsString( - (is_one_byte || is_one_byte_data_in_two_byte_string) - ? String::ONE_BYTE_ENCODING - : String::TWO_BYTE_ENCODING); + Handle map = (is_one_byte || is_one_byte_data_in_two_byte_string) + ? cons_ascii_string_map() : cons_string_map(); + Handle result = New(map, NEW_SPACE); DisallowHeapAllocation no_gc; WriteBarrierMode mode = result->GetWriteBarrierMode(no_gc); @@ -455,23 +506,14 @@ Handle Factory::NewFlatConcatString(Handle first, int total_length = first->length() + second->length(); if (first->IsOneByteRepresentation() && second->IsOneByteRepresentation()) { return ConcatStringContent( - NewRawOneByteString(total_length), first, second); + NewRawOneByteString(total_length).ToHandleChecked(), first, second); } else { return ConcatStringContent( - NewRawTwoByteString(total_length), first, second); + NewRawTwoByteString(total_length).ToHandleChecked(), first, second); } } -Handle Factory::NewRawSlicedString(String::Encoding encoding) { - Handle map = (encoding == String::ONE_BYTE_ENCODING) - ? sliced_ascii_string_map() : sliced_string_map(); - CALL_HEAP_FUNCTION(isolate(), - isolate()->heap()->Allocate(*map, NEW_SPACE), - SlicedString); -} - - Handle Factory::NewProperSubString(Handle str, int begin, int end) { @@ -480,12 +522,12 @@ Handle Factory::NewProperSubString(Handle str, #endif ASSERT(begin > 0 || end < str->length()); - str = FlattenGetString(str); + str = String::Flatten(str); int length = end - begin; if (length <= 0) return empty_string(); if (length == 1) { - return LookupSingleCharacterStringFromCode(isolate(), str->Get(begin)); + return LookupSingleCharacterStringFromCode(str->Get(begin)); } if (length == 2) { // Optimization for 2-byte strings often used as keys in a decompression @@ -498,15 +540,15 @@ Handle Factory::NewProperSubString(Handle str, if (!FLAG_string_slices || length < SlicedString::kMinLength) { if (str->IsOneByteRepresentation()) { - Handle result = NewRawOneByteString(length); - ASSERT(!result.is_null()); + Handle result = + NewRawOneByteString(length).ToHandleChecked(); uint8_t* dest = result->GetChars(); DisallowHeapAllocation no_gc; String::WriteToFlat(*str, dest, begin, end); return result; } else { - Handle result = NewRawTwoByteString(length); - ASSERT(!result.is_null()); + Handle result = + NewRawTwoByteString(length).ToHandleChecked(); uc16* dest = result->GetChars(); DisallowHeapAllocation no_gc; String::WriteToFlat(*str, dest, begin, end); @@ -523,9 +565,9 @@ Handle Factory::NewProperSubString(Handle str, } ASSERT(str->IsSeqString() || str->IsExternalString()); - Handle slice = NewRawSlicedString( - str->IsOneByteRepresentation() ? String::ONE_BYTE_ENCODING - : String::TWO_BYTE_ENCODING); + Handle map = str->IsOneByteRepresentation() ? sliced_ascii_string_map() + : sliced_string_map(); + Handle slice = New(map, NEW_SPACE); slice->set_hash_field(String::kEmptyHashField); slice->set_length(length); @@ -535,21 +577,47 @@ Handle Factory::NewProperSubString(Handle str, } -Handle Factory::NewExternalStringFromAscii( +MaybeHandle Factory::NewExternalStringFromAscii( const ExternalAsciiString::Resource* resource) { - CALL_HEAP_FUNCTION( - isolate(), - isolate()->heap()->AllocateExternalStringFromAscii(resource), - String); + size_t length = resource->length(); + if (length > static_cast(String::kMaxLength)) { + isolate()->ThrowInvalidStringLength(); + return MaybeHandle(); + } + + Handle map = external_ascii_string_map(); + Handle external_string = + New(map, NEW_SPACE); + external_string->set_length(static_cast(length)); + external_string->set_hash_field(String::kEmptyHashField); + external_string->set_resource(resource); + + return external_string; } -Handle Factory::NewExternalStringFromTwoByte( +MaybeHandle Factory::NewExternalStringFromTwoByte( const ExternalTwoByteString::Resource* resource) { - CALL_HEAP_FUNCTION( - isolate(), - isolate()->heap()->AllocateExternalStringFromTwoByte(resource), - String); + size_t length = resource->length(); + if (length > static_cast(String::kMaxLength)) { + isolate()->ThrowInvalidStringLength(); + return MaybeHandle(); + } + + // For small strings we check whether the resource contains only + // one byte characters. If yes, we use a different string map. + static const size_t kOneByteCheckLengthLimit = 32; + bool is_one_byte = length <= kOneByteCheckLengthLimit && + String::IsOneByte(resource->data(), static_cast(length)); + Handle map = is_one_byte ? + external_string_with_one_byte_data_map() : external_string_map(); + Handle external_string = + New(map, NEW_SPACE); + external_string->set_length(static_cast(length)); + external_string->set_hash_field(String::kEmptyHashField); + external_string->set_resource(resource); + + return external_string; } @@ -562,44 +630,59 @@ Handle Factory::NewSymbol() { Handle Factory::NewPrivateSymbol() { - CALL_HEAP_FUNCTION( - isolate(), - isolate()->heap()->AllocatePrivateSymbol(), - Symbol); + Handle symbol = NewSymbol(); + symbol->set_is_private(true); + return symbol; } Handle Factory::NewNativeContext() { - CALL_HEAP_FUNCTION( - isolate(), - isolate()->heap()->AllocateNativeContext(), - Context); + Handle array = NewFixedArray(Context::NATIVE_CONTEXT_SLOTS); + array->set_map_no_write_barrier(*native_context_map()); + Handle context = Handle::cast(array); + context->set_js_array_maps(*undefined_value()); + ASSERT(context->IsNativeContext()); + return context; } Handle Factory::NewGlobalContext(Handle function, Handle scope_info) { - CALL_HEAP_FUNCTION( - isolate(), - isolate()->heap()->AllocateGlobalContext(*function, *scope_info), - Context); + Handle array = + NewFixedArray(scope_info->ContextLength(), TENURED); + array->set_map_no_write_barrier(*global_context_map()); + Handle context = Handle::cast(array); + context->set_closure(*function); + context->set_previous(function->context()); + context->set_extension(*scope_info); + context->set_global_object(function->context()->global_object()); + ASSERT(context->IsGlobalContext()); + return context; } Handle Factory::NewModuleContext(Handle scope_info) { - CALL_HEAP_FUNCTION( - isolate(), - isolate()->heap()->AllocateModuleContext(*scope_info), - Context); + Handle array = + NewFixedArray(scope_info->ContextLength(), TENURED); + array->set_map_no_write_barrier(*module_context_map()); + // Instance link will be set later. + Handle context = Handle::cast(array); + context->set_extension(Smi::FromInt(0)); + return context; } Handle Factory::NewFunctionContext(int length, Handle function) { - CALL_HEAP_FUNCTION( - isolate(), - isolate()->heap()->AllocateFunctionContext(length, *function), - Context); + ASSERT(length >= Context::MIN_CONTEXT_SLOTS); + Handle array = NewFixedArray(length); + array->set_map_no_write_barrier(*function_context_map()); + Handle context = Handle::cast(array); + context->set_closure(*function); + context->set_previous(function->context()); + context->set_extension(Smi::FromInt(0)); + context->set_global_object(function->context()->global_object()); + return context; } @@ -607,35 +690,45 @@ Handle Factory::NewCatchContext(Handle function, Handle previous, Handle name, Handle thrown_object) { - CALL_HEAP_FUNCTION( - isolate(), - isolate()->heap()->AllocateCatchContext(*function, - *previous, - *name, - *thrown_object), - Context); + STATIC_ASSERT(Context::MIN_CONTEXT_SLOTS == Context::THROWN_OBJECT_INDEX); + Handle array = NewFixedArray(Context::MIN_CONTEXT_SLOTS + 1); + array->set_map_no_write_barrier(*catch_context_map()); + Handle context = Handle::cast(array); + context->set_closure(*function); + context->set_previous(*previous); + context->set_extension(*name); + context->set_global_object(previous->global_object()); + context->set(Context::THROWN_OBJECT_INDEX, *thrown_object); + return context; } Handle Factory::NewWithContext(Handle function, Handle previous, - Handle extension) { - CALL_HEAP_FUNCTION( - isolate(), - isolate()->heap()->AllocateWithContext(*function, *previous, *extension), - Context); + Handle extension) { + Handle array = NewFixedArray(Context::MIN_CONTEXT_SLOTS); + array->set_map_no_write_barrier(*with_context_map()); + Handle context = Handle::cast(array); + context->set_closure(*function); + context->set_previous(*previous); + context->set_extension(*extension); + context->set_global_object(previous->global_object()); + return context; } Handle Factory::NewBlockContext(Handle function, Handle previous, Handle scope_info) { - CALL_HEAP_FUNCTION( - isolate(), - isolate()->heap()->AllocateBlockContext(*function, - *previous, - *scope_info), - Context); + Handle array = + NewFixedArrayWithHoles(scope_info->ContextLength()); + array->set_map_no_write_barrier(*block_context_map()); + Handle context = Handle::cast(array); + context->set_closure(*function); + context->set_previous(*previous); + context->set_extension(*scope_info); + context->set_global_object(previous->global_object()); + return context; } @@ -647,6 +740,15 @@ Handle Factory::NewStruct(InstanceType type) { } +Handle Factory::NewCodeCache() { + Handle code_cache = + Handle::cast(NewStruct(CODE_CACHE_TYPE)); + code_cache->set_default_cache(*empty_fixed_array(), SKIP_WRITE_BARRIER); + code_cache->set_normal_type_cache(*undefined_value(), SKIP_WRITE_BARRIER); + return code_cache; +} + + Handle Factory::NewAliasedArgumentsEntry( int aliased_context_slot) { Handle entry = Handle::cast( @@ -783,10 +885,14 @@ Handle Factory::NewPropertyCell(Handle value) { Handle Factory::NewAllocationSite() { - CALL_HEAP_FUNCTION( - isolate(), - isolate()->heap()->AllocateAllocationSite(), - AllocationSite); + Handle map = allocation_site_map(); + Handle site = New(map, OLD_POINTER_SPACE); + site->Initialize(); + + // Link the site + site->set_weak_next(isolate()->heap()->allocation_sites_list()); + isolate()->heap()->set_allocation_sites_list(*site); + return site; } @@ -823,52 +929,43 @@ Handle Factory::NewFunctionPrototype(Handle function) { JSObject::SetLocalPropertyIgnoreAttributes(prototype, constructor_string(), function, - DONT_ENUM); + DONT_ENUM).Assert(); } return prototype; } -Handle Factory::CopyWithPreallocatedFieldDescriptors(Handle src) { - CALL_HEAP_FUNCTION( - isolate(), src->CopyWithPreallocatedFieldDescriptors(), Map); +Handle Factory::CopyJSObject(Handle object) { + CALL_HEAP_FUNCTION(isolate(), + isolate()->heap()->CopyJSObject(*object, NULL), + JSObject); } -Handle Factory::CopyMap(Handle src, - int extra_inobject_properties) { - Handle copy = CopyWithPreallocatedFieldDescriptors(src); - // Check that we do not overflow the instance size when adding the - // extra inobject properties. - int instance_size_delta = extra_inobject_properties * kPointerSize; - int max_instance_size_delta = - JSObject::kMaxInstanceSize - copy->instance_size(); - int max_extra_properties = max_instance_size_delta >> kPointerSizeLog2; - if (extra_inobject_properties > max_extra_properties) { - // If the instance size overflows, we allocate as many properties - // as we can as inobject properties. - instance_size_delta = max_instance_size_delta; - extra_inobject_properties = max_extra_properties; - } - // Adjust the map with the extra inobject properties. - int inobject_properties = - copy->inobject_properties() + extra_inobject_properties; - copy->set_inobject_properties(inobject_properties); - copy->set_unused_property_fields(inobject_properties); - copy->set_instance_size(copy->instance_size() + instance_size_delta); - copy->set_visitor_id(StaticVisitorBase::GetVisitorId(*copy)); - return copy; +Handle Factory::CopyJSObjectWithAllocationSite( + Handle object, + Handle site) { + CALL_HEAP_FUNCTION(isolate(), + isolate()->heap()->CopyJSObject( + *object, + site.is_null() ? NULL : *site), + JSObject); } -Handle Factory::CopyMap(Handle src) { - CALL_HEAP_FUNCTION(isolate(), src->Copy(), Map); +Handle Factory::CopyFixedArrayWithMap(Handle array, + Handle map) { + CALL_HEAP_FUNCTION(isolate(), + isolate()->heap()->CopyFixedArrayWithMap(*array, *map), + FixedArray); } Handle Factory::CopyFixedArray(Handle array) { - CALL_HEAP_FUNCTION(isolate(), array->Copy(), FixedArray); + CALL_HEAP_FUNCTION(isolate(), + isolate()->heap()->CopyFixedArray(*array), + FixedArray); } @@ -881,69 +978,37 @@ Handle Factory::CopyAndTenureFixedCOWArray( } -Handle Factory::CopySizeFixedArray(Handle array, - int new_length, - PretenureFlag pretenure) { - CALL_HEAP_FUNCTION(isolate(), - array->CopySize(new_length, pretenure), - FixedArray); -} - - Handle Factory::CopyFixedDoubleArray( Handle array) { - CALL_HEAP_FUNCTION(isolate(), array->Copy(), FixedDoubleArray); + CALL_HEAP_FUNCTION(isolate(), + isolate()->heap()->CopyFixedDoubleArray(*array), + FixedDoubleArray); } Handle Factory::CopyConstantPoolArray( Handle array) { - CALL_HEAP_FUNCTION(isolate(), array->Copy(), ConstantPoolArray); -} - - -Handle Factory::BaseNewFunctionFromSharedFunctionInfo( - Handle function_info, - Handle function_map, - PretenureFlag pretenure) { - CALL_HEAP_FUNCTION( - isolate(), - isolate()->heap()->AllocateFunction(*function_map, - *function_info, - isolate()->heap()->the_hole_value(), - pretenure), - JSFunction); -} - - -static Handle MapForNewFunction(Isolate *isolate, - Handle function_info) { - Context *context = isolate->context()->native_context(); - int map_index = Context::FunctionMapIndex(function_info->strict_mode(), - function_info->is_generator()); - return Handle(Map::cast(context->get(map_index))); + CALL_HEAP_FUNCTION(isolate(), + isolate()->heap()->CopyConstantPoolArray(*array), + ConstantPoolArray); } Handle Factory::NewFunctionFromSharedFunctionInfo( - Handle function_info, + Handle info, Handle context, PretenureFlag pretenure) { - Handle result = BaseNewFunctionFromSharedFunctionInfo( - function_info, - MapForNewFunction(isolate(), function_info), - pretenure); + Handle result = NewFunction( + info, context, the_hole_value(), pretenure); - if (function_info->ic_age() != isolate()->heap()->global_ic_age()) { - function_info->ResetForNewContext(isolate()->heap()->global_ic_age()); + if (info->ic_age() != isolate()->heap()->global_ic_age()) { + info->ResetForNewContext(isolate()->heap()->global_ic_age()); } - result->set_context(*context); - - int index = function_info->SearchOptimizedCodeMap(context->native_context(), - BailoutId::None()); - if (!function_info->bound() && index < 0) { - int number_of_literals = function_info->num_literals(); + int index = info->SearchOptimizedCodeMap(context->native_context(), + BailoutId::None()); + if (!info->bound() && index < 0) { + int number_of_literals = info->num_literals(); Handle literals = NewFixedArray(number_of_literals, pretenure); if (number_of_literals > 0) { // Store the native context in the literals array prefix. This @@ -957,10 +1022,9 @@ Handle Factory::NewFunctionFromSharedFunctionInfo( if (index > 0) { // Caching of optimized code enabled and optimized code found. - FixedArray* literals = - function_info->GetLiteralsFromOptimizedCodeMap(index); + FixedArray* literals = info->GetLiteralsFromOptimizedCodeMap(index); if (literals != NULL) result->set_literals(literals); - Code* code = function_info->GetCodeFromOptimizedCodeMap(index); + Code* code = info->GetCodeFromOptimizedCodeMap(index); ASSERT(!code->marked_for_deoptimization()); result->ReplaceCode(code); return result; @@ -969,9 +1033,9 @@ Handle Factory::NewFunctionFromSharedFunctionInfo( if (isolate()->use_crankshaft() && FLAG_always_opt && result->is_compiled() && - !function_info->is_toplevel() && - function_info->allows_lazy_compilation() && - !function_info->optimization_disabled() && + !info->is_toplevel() && + info->allows_lazy_compilation() && + !info->optimization_disabled() && !isolate()->DebuggerHasBreakPoints()) { result->MarkForOptimization(); } @@ -981,25 +1045,36 @@ Handle Factory::NewFunctionFromSharedFunctionInfo( Handle Factory::NewNumber(double value, PretenureFlag pretenure) { - CALL_HEAP_FUNCTION( - isolate(), - isolate()->heap()->NumberFromDouble(value, pretenure), Object); + // We need to distinguish the minus zero value and this cannot be + // done after conversion to int. Doing this by comparing bit + // patterns is faster than using fpclassify() et al. + if (IsMinusZero(value)) return NewHeapNumber(-0.0, pretenure); + + int int_value = FastD2I(value); + if (value == int_value && Smi::IsValid(int_value)) { + return handle(Smi::FromInt(int_value), isolate()); + } + + // Materialize the value in the heap. + return NewHeapNumber(value, pretenure); } Handle Factory::NewNumberFromInt(int32_t value, PretenureFlag pretenure) { - CALL_HEAP_FUNCTION( - isolate(), - isolate()->heap()->NumberFromInt32(value, pretenure), Object); + if (Smi::IsValid(value)) return handle(Smi::FromInt(value), isolate()); + // Bypass NumberFromDouble to avoid various redundant checks. + return NewHeapNumber(FastI2D(value), pretenure); } Handle Factory::NewNumberFromUint(uint32_t value, - PretenureFlag pretenure) { - CALL_HEAP_FUNCTION( - isolate(), - isolate()->heap()->NumberFromUint32(value, pretenure), Object); + PretenureFlag pretenure) { + int32_t int32v = static_cast(value); + if (int32v >= 0 && Smi::IsValid(int32v)) { + return handle(Smi::FromInt(int32v), isolate()); + } + return NewHeapNumber(FastUI2D(value), pretenure); } @@ -1019,20 +1094,19 @@ Handle Factory::NewFloat32x4(float32x4_value_t value, } -Handle Factory::NewInt32x4(int32x4_value_t value, - PretenureFlag pretenure) { +Handle Factory::NewFloat64x2(float64x2_value_t value, + PretenureFlag pretenure) { CALL_HEAP_FUNCTION( isolate(), - isolate()->heap()->AllocateInt32x4(value, pretenure), Int32x4); + isolate()->heap()->AllocateFloat64x2(value, pretenure), Float64x2); } -Handle Factory::NewNeanderObject() { +Handle Factory::NewInt32x4(int32x4_value_t value, + PretenureFlag pretenure) { CALL_HEAP_FUNCTION( isolate(), - isolate()->heap()->AllocateJSObjectFromMap( - isolate()->heap()->neander_map()), - JSObject); + isolate()->heap()->AllocateInt32x4(value, pretenure), Int32x4); } @@ -1131,7 +1205,7 @@ Handle Factory::EmergencyNewError(const char* message, space--; if (space > 0) { Handle arg_str = Handle::cast( - Object::GetElementNoExceptionThrown(isolate(), args, i)); + Object::GetElement(isolate(), args, i).ToHandleChecked()); SmartArrayPointer arg = arg_str->ToCString(); Vector v2(p, static_cast(space)); OS::StrNCpy(v2, arg.get(), space); @@ -1145,8 +1219,7 @@ Handle Factory::EmergencyNewError(const char* message, } else { buffer[kBufferSize - 1] = '\0'; } - Handle error_string = NewStringFromUtf8(CStrVector(buffer), TENURED); - return error_string; + return NewStringFromUtf8(CStrVector(buffer), TENURED).ToHandleChecked(); } @@ -1154,9 +1227,8 @@ Handle Factory::NewError(const char* maker, const char* message, Handle args) { Handle make_str = InternalizeUtf8String(maker); - Handle fun_obj( - isolate()->js_builtins_object()->GetPropertyNoExceptionThrown(*make_str), - isolate()); + Handle fun_obj = Object::GetProperty( + isolate()->js_builtins_object(), make_str).ToHandleChecked(); // If the builtins haven't been properly configured yet this error // constructor may not have been defined. Bail out. if (!fun_obj->IsJSFunction()) { @@ -1168,12 +1240,15 @@ Handle Factory::NewError(const char* maker, // Invoke the JavaScript factory method. If an exception is thrown while // running the factory method, use the exception as the result. - bool caught_exception; - Handle result = Execution::TryCall(fun, - isolate()->js_builtins_object(), - ARRAY_SIZE(argv), - argv, - &caught_exception); + Handle result; + Handle exception; + if (!Execution::TryCall(fun, + isolate()->js_builtins_object(), + ARRAY_SIZE(argv), + argv, + &exception).ToHandle(&result)) { + return exception; + } return result; } @@ -1186,41 +1261,49 @@ Handle Factory::NewError(Handle message) { Handle Factory::NewError(const char* constructor, Handle message) { Handle constr = InternalizeUtf8String(constructor); - Handle fun = Handle( - JSFunction::cast(isolate()->js_builtins_object()-> - GetPropertyNoExceptionThrown(*constr))); + Handle fun = Handle::cast(Object::GetProperty( + isolate()->js_builtins_object(), constr).ToHandleChecked()); Handle argv[] = { message }; // Invoke the JavaScript factory method. If an exception is thrown while // running the factory method, use the exception as the result. - bool caught_exception; - Handle result = Execution::TryCall(fun, - isolate()->js_builtins_object(), - ARRAY_SIZE(argv), - argv, - &caught_exception); + Handle result; + Handle exception; + if (!Execution::TryCall(fun, + isolate()->js_builtins_object(), + ARRAY_SIZE(argv), + argv, + &exception).ToHandle(&result)) { + return exception; + } return result; } -Handle Factory::NewFunction(Handle name, +Handle Factory::NewFunction(MaybeHandle maybe_prototype, + Handle name, InstanceType type, int instance_size, Handle code, bool force_initial_map) { // Allocate the function - Handle function = NewFunction(name, the_hole_value()); - - // Set up the code pointer in both the shared function info and in - // the function itself. - function->shared()->set_code(*code); - function->set_code(*code); + Handle function = NewFunction(name, code, maybe_prototype); - if (force_initial_map || - type != JS_OBJECT_TYPE || - instance_size != JSObject::kHeaderSize) { + Handle prototype; + if (maybe_prototype.ToHandle(&prototype) && + (force_initial_map || + type != JS_OBJECT_TYPE || + instance_size != JSObject::kHeaderSize)) { Handle initial_map = NewMap(type, instance_size); - Handle prototype = NewFunctionPrototype(function); + if (prototype->IsJSObject()) { + JSObject::SetLocalPropertyIgnoreAttributes( + Handle::cast(prototype), + constructor_string(), + function, + DONT_ENUM).Assert(); + } else if (!function->shared()->is_generator()) { + prototype = NewFunctionPrototype(function); + } initial_map->set_prototype(*prototype); function->set_initial_map(*initial_map); initial_map->set_constructor(*function); @@ -1233,6 +1316,16 @@ Handle Factory::NewFunction(Handle name, } +Handle Factory::NewFunction(Handle name, + InstanceType type, + int instance_size, + Handle code, + bool force_initial_map) { + return NewFunction( + the_hole_value(), name, type, instance_size, code, force_initial_map); +} + + Handle Factory::NewFunctionWithPrototype(Handle name, InstanceType type, int instance_size, @@ -1240,12 +1333,7 @@ Handle Factory::NewFunctionWithPrototype(Handle name, Handle code, bool force_initial_map) { // Allocate the function. - Handle function = NewFunction(name, prototype); - - // Set up the code pointer in both the shared function info and in - // the function itself. - function->shared()->set_code(*code); - function->set_code(*code); + Handle function = NewFunction(name, code, prototype); if (force_initial_map || type != JS_OBJECT_TYPE || @@ -1262,29 +1350,38 @@ Handle Factory::NewFunctionWithPrototype(Handle name, } -Handle Factory::NewFunctionWithoutPrototype(Handle name, - Handle code) { - Handle function = NewFunctionWithoutPrototype(name, SLOPPY); - function->shared()->set_code(*code); - function->set_code(*code); - ASSERT(!function->has_initial_map()); - ASSERT(!function->has_prototype()); - return function; +Handle Factory::NewIteratorResultObject(Handle value, + bool done) { + Handle map(isolate()->native_context()->iterator_result_map()); + Handle result = NewJSObjectFromMap(map, NOT_TENURED, false); + result->InObjectPropertyAtPut( + JSGeneratorObject::kResultValuePropertyIndex, *value); + result->InObjectPropertyAtPut( + JSGeneratorObject::kResultDonePropertyIndex, *ToBoolean(done)); + return result; } Handle Factory::NewScopeInfo(int length) { - CALL_HEAP_FUNCTION( - isolate(), - isolate()->heap()->AllocateScopeInfo(length), - ScopeInfo); + Handle array = NewFixedArray(length, TENURED); + array->set_map_no_write_barrier(*scope_info_map()); + Handle scope_info = Handle::cast(array); + return scope_info; } Handle Factory::NewExternal(void* value) { + Handle foreign = NewForeign(static_cast
(value)); + Handle external = NewJSObjectFromMap(external_map()); + external->SetInternalField(0, *foreign); + return external; +} + + +Handle Factory::NewCodeRaw(int object_size, bool immovable) { CALL_HEAP_FUNCTION(isolate(), - isolate()->heap()->AllocateExternal(value), - JSObject); + isolate()->heap()->AllocateCode(object_size, immovable), + Code); } @@ -1294,11 +1391,60 @@ Handle Factory::NewCode(const CodeDesc& desc, bool immovable, bool crankshafted, int prologue_offset) { - CALL_HEAP_FUNCTION(isolate(), - isolate()->heap()->CreateCode( - desc, flags, self_ref, immovable, crankshafted, - prologue_offset), - Code); + Handle reloc_info = NewByteArray(desc.reloc_size, TENURED); + Handle constant_pool = + desc.origin->NewConstantPool(isolate()); + + // Compute size. + int body_size = RoundUp(desc.instr_size, kObjectAlignment); + int obj_size = Code::SizeFor(body_size); + + Handle code = NewCodeRaw(obj_size, immovable); + ASSERT(!isolate()->code_range()->exists() || + isolate()->code_range()->contains(code->address())); + + // The code object has not been fully initialized yet. We rely on the + // fact that no allocation will happen from this point on. + DisallowHeapAllocation no_gc; + code->set_gc_metadata(Smi::FromInt(0)); + code->set_ic_age(isolate()->heap()->global_ic_age()); + code->set_instruction_size(desc.instr_size); + code->set_relocation_info(*reloc_info); + code->set_flags(flags); + code->set_raw_kind_specific_flags1(0); + code->set_raw_kind_specific_flags2(0); + code->set_is_crankshafted(crankshafted); + code->set_deoptimization_data(*empty_fixed_array(), SKIP_WRITE_BARRIER); + code->set_raw_type_feedback_info(*undefined_value()); + code->set_next_code_link(*undefined_value()); + code->set_handler_table(*empty_fixed_array(), SKIP_WRITE_BARRIER); + code->set_prologue_offset(prologue_offset); + if (code->kind() == Code::OPTIMIZED_FUNCTION) { + code->set_marked_for_deoptimization(false); + } + + desc.origin->PopulateConstantPool(*constant_pool); + code->set_constant_pool(*constant_pool); + + if (code->kind() == Code::FUNCTION) { + code->set_has_debug_break_slots(isolate()->debugger()->IsDebuggerActive()); + } + + // Allow self references to created code object by patching the handle to + // point to the newly allocated Code object. + if (!self_ref.is_null()) *(self_ref.location()) = *code; + + // Migrate generated code. + // The generated code can contain Object** values (typically from handles) + // that are dereferenced during the copy to point directly to the actual heap + // objects. These pointers can include references to the code object itself, + // through the self_reference parameter. + code->CopyFrom(desc); + +#ifdef VERIFY_HEAP + if (FLAG_verify_heap) code->ObjectVerify(); +#endif + return code; } @@ -1338,28 +1484,14 @@ Handle Factory::NewJSObjectWithMemento( Handle Factory::NewJSModule(Handle context, Handle scope_info) { - CALL_HEAP_FUNCTION( - isolate(), - isolate()->heap()->AllocateJSModule(*context, *scope_info), JSModule); -} - - -// TODO(mstarzinger): Temporary wrapper until handlified. -static Handle NameDictionaryAdd(Handle dict, - Handle name, - Handle value, - PropertyDetails details) { - CALL_HEAP_FUNCTION(dict->GetIsolate(), - dict->Add(*name, *value, details), - NameDictionary); -} - - -static Handle NewGlobalObjectFromMap(Isolate* isolate, - Handle map) { - CALL_HEAP_FUNCTION(isolate, - isolate->heap()->Allocate(*map, OLD_POINTER_SPACE), - GlobalObject); + // Allocate a fresh map. Modules do not have a prototype. + Handle map = NewMap(JS_MODULE_TYPE, JSModule::kSize); + // Allocate the object based on the map. + Handle module = + Handle::cast(NewJSObjectFromMap(map, TENURED)); + module->set_context(*context); + module->set_scope_info(*scope_info); + return module; } @@ -1385,7 +1517,8 @@ Handle Factory::NewGlobalObject(Handle constructor) { // Allocate a dictionary object for backing storage. int at_least_space_for = map->NumberOfOwnDescriptors() * 2 + initial_size; - Handle dictionary = NewNameDictionary(at_least_space_for); + Handle dictionary = + NameDictionary::New(isolate(), at_least_space_for); // The global object might be created from an object template with accessors. // Fill these accessors into the dictionary. @@ -1397,11 +1530,12 @@ Handle Factory::NewGlobalObject(Handle constructor) { Handle name(descs->GetKey(i)); Handle value(descs->GetCallbacksObject(i), isolate()); Handle cell = NewPropertyCell(value); - NameDictionaryAdd(dictionary, name, cell, d); + // |dictionary| already contains enough space for all properties. + USE(NameDictionary::Add(dictionary, name, cell, d)); } // Allocate the global object and initialize it with the backing store. - Handle global = NewGlobalObjectFromMap(isolate(), map); + Handle global = New(map, OLD_POINTER_SPACE); isolate()->heap()->InitializeJSObjectFromMap(*global, *dictionary, *map); // Create a new map for the global object. @@ -1435,20 +1569,24 @@ Handle Factory::NewJSObjectFromMap( Handle Factory::NewJSArray(ElementsKind elements_kind, + PretenureFlag pretenure) { + Context* native_context = isolate()->context()->native_context(); + JSFunction* array_function = native_context->array_function(); + Map* map = array_function->initial_map(); + Map* transition_map = isolate()->get_initial_js_array_map(elements_kind); + if (transition_map != NULL) map = transition_map; + return Handle::cast(NewJSObjectFromMap(handle(map), pretenure)); +} + + +Handle Factory::NewJSArray(ElementsKind elements_kind, int length, int capacity, + ArrayStorageAllocationMode mode, PretenureFlag pretenure) { - if (capacity != 0) { - elements_kind = GetHoleyElementsKind(elements_kind); - } - CALL_HEAP_FUNCTION(isolate(), - isolate()->heap()->AllocateJSArrayAndStorage( - elements_kind, - length, - capacity, - INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE, - pretenure), - JSArray); + Handle array = NewJSArray(elements_kind, pretenure); + NewJSArrayStorage(array, length, capacity, mode); + return array; } @@ -1457,25 +1595,48 @@ Handle Factory::NewJSArrayWithElements(Handle elements, int length, PretenureFlag pretenure) { ASSERT(length <= elements->length()); - CALL_HEAP_FUNCTION( - isolate(), - isolate()->heap()->AllocateJSArrayWithElements(*elements, - elements_kind, - length, - pretenure), - JSArray); + Handle array = NewJSArray(elements_kind, pretenure); + + array->set_elements(*elements); + array->set_length(Smi::FromInt(length)); + JSObject::ValidateElements(array); + return array; } void Factory::NewJSArrayStorage(Handle array, - int length, - int capacity, - ArrayStorageAllocationMode mode) { - CALL_HEAP_FUNCTION_VOID(isolate(), - isolate()->heap()->AllocateJSArrayStorage(*array, - length, - capacity, - mode)); + int length, + int capacity, + ArrayStorageAllocationMode mode) { + ASSERT(capacity >= length); + + if (capacity == 0) { + array->set_length(Smi::FromInt(0)); + array->set_elements(*empty_fixed_array()); + return; + } + + Handle elms; + ElementsKind elements_kind = array->GetElementsKind(); + if (IsFastDoubleElementsKind(elements_kind)) { + if (mode == DONT_INITIALIZE_ARRAY_ELEMENTS) { + elms = NewFixedDoubleArray(capacity); + } else { + ASSERT(mode == INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE); + elms = NewFixedDoubleArrayWithHoles(capacity); + } + } else { + ASSERT(IsFastSmiOrObjectElementsKind(elements_kind)); + if (mode == DONT_INITIALIZE_ARRAY_ELEMENTS) { + elms = NewUninitializedFixedArray(capacity); + } else { + ASSERT(mode == INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE); + elms = NewFixedArrayWithHoles(capacity); + } + } + + array->set_elements(*elms); + array->set_length(Smi::FromInt(length)); } @@ -1542,26 +1703,147 @@ Handle Factory::NewJSTypedArray(ExternalArrayType type) { Handle Factory::NewJSProxy(Handle handler, Handle prototype) { - CALL_HEAP_FUNCTION( - isolate(), - isolate()->heap()->AllocateJSProxy(*handler, *prototype), - JSProxy); + // Allocate map. + // TODO(rossberg): Once we optimize proxies, think about a scheme to share + // maps. Will probably depend on the identity of the handler object, too. + Handle map = NewMap(JS_PROXY_TYPE, JSProxy::kSize); + map->set_prototype(*prototype); + + // Allocate the proxy object. + Handle result = New(map, NEW_SPACE); + result->InitializeBody(map->instance_size(), Smi::FromInt(0)); + result->set_handler(*handler); + result->set_hash(*undefined_value(), SKIP_WRITE_BARRIER); + return result; +} + + +Handle Factory::NewJSFunctionProxy(Handle handler, + Handle call_trap, + Handle construct_trap, + Handle prototype) { + // Allocate map. + // TODO(rossberg): Once we optimize proxies, think about a scheme to share + // maps. Will probably depend on the identity of the handler object, too. + Handle map = NewMap(JS_FUNCTION_PROXY_TYPE, JSFunctionProxy::kSize); + map->set_prototype(*prototype); + + // Allocate the proxy object. + Handle result = New(map, NEW_SPACE); + result->InitializeBody(map->instance_size(), Smi::FromInt(0)); + result->set_handler(*handler); + result->set_hash(*undefined_value(), SKIP_WRITE_BARRIER); + result->set_call_trap(*call_trap); + result->set_construct_trap(*construct_trap); + return result; +} + + +void Factory::ReinitializeJSReceiver(Handle object, + InstanceType type, + int size) { + ASSERT(type >= FIRST_JS_OBJECT_TYPE); + + // Allocate fresh map. + // TODO(rossberg): Once we optimize proxies, cache these maps. + Handle map = NewMap(type, size); + + // Check that the receiver has at least the size of the fresh object. + int size_difference = object->map()->instance_size() - map->instance_size(); + ASSERT(size_difference >= 0); + + map->set_prototype(object->map()->prototype()); + + // Allocate the backing storage for the properties. + int prop_size = map->InitialPropertiesLength(); + Handle properties = NewFixedArray(prop_size, TENURED); + + Heap* heap = isolate()->heap(); + MaybeHandle shared; + if (type == JS_FUNCTION_TYPE) { + OneByteStringKey key(STATIC_ASCII_VECTOR(""), + heap->HashSeed()); + Handle name = InternalizeStringWithKey(&key); + shared = NewSharedFunctionInfo(name); + } + + // In order to keep heap in consistent state there must be no allocations + // before object re-initialization is finished and filler object is installed. + DisallowHeapAllocation no_allocation; + + // Reset the map for the object. + object->set_map(*map); + Handle jsobj = Handle::cast(object); + + // Reinitialize the object from the constructor map. + heap->InitializeJSObjectFromMap(*jsobj, *properties, *map); + + // Functions require some minimal initialization. + if (type == JS_FUNCTION_TYPE) { + map->set_function_with_prototype(true); + Handle js_function = Handle::cast(object); + Handle context(isolate()->context()->native_context()); + InitializeFunction(js_function, shared.ToHandleChecked(), + context, null_value()); + } + + // Put in filler if the new object is smaller than the old. + if (size_difference > 0) { + heap->CreateFillerObjectAt( + object->address() + map->instance_size(), size_difference); + } +} + + +void Factory::ReinitializeJSGlobalProxy(Handle object, + Handle constructor) { + ASSERT(constructor->has_initial_map()); + Handle map(constructor->initial_map(), isolate()); + + // Check that the already allocated object has the same size and type as + // objects allocated using the constructor. + ASSERT(map->instance_size() == object->map()->instance_size()); + ASSERT(map->instance_type() == object->map()->instance_type()); + + // Allocate the backing storage for the properties. + int prop_size = map->InitialPropertiesLength(); + Handle properties = NewFixedArray(prop_size, TENURED); + + // In order to keep heap in consistent state there must be no allocations + // before object re-initialization is finished. + DisallowHeapAllocation no_allocation; + + // Reset the map for the object. + object->set_map(constructor->initial_map()); + + Heap* heap = isolate()->heap(); + // Reinitialize the object from the constructor map. + heap->InitializeJSObjectFromMap(*object, *properties, *map); } void Factory::BecomeJSObject(Handle object) { - CALL_HEAP_FUNCTION_VOID( - isolate(), - isolate()->heap()->ReinitializeJSReceiver( - *object, JS_OBJECT_TYPE, JSObject::kHeaderSize)); + ReinitializeJSReceiver(object, JS_OBJECT_TYPE, JSObject::kHeaderSize); } void Factory::BecomeJSFunction(Handle object) { - CALL_HEAP_FUNCTION_VOID( + ReinitializeJSReceiver(object, JS_FUNCTION_TYPE, JSFunction::kSize); +} + + +Handle Factory::NewTypeFeedbackVector(int slot_count) { + // Ensure we can skip the write barrier + ASSERT_EQ(isolate()->heap()->uninitialized_symbol(), + *TypeFeedbackInfo::UninitializedSentinel(isolate())); + + CALL_HEAP_FUNCTION( isolate(), - isolate()->heap()->ReinitializeJSReceiver( - *object, JS_FUNCTION_TYPE, JSFunction::kSize)); + isolate()->heap()->AllocateFixedArrayWithFiller( + slot_count, + TENURED, + *TypeFeedbackInfo::UninitializedSentinel(isolate())), + FixedArray); } @@ -1570,10 +1852,12 @@ Handle Factory::NewSharedFunctionInfo( int number_of_literals, bool is_generator, Handle code, - Handle scope_info) { + Handle scope_info, + Handle feedback_vector) { Handle shared = NewSharedFunctionInfo(name); shared->set_code(*code); shared->set_scope_info(*scope_info); + shared->set_feedback_vector(*feedback_vector); int literals_array_size = number_of_literals; // If the function contains object, regexp or array literals, // allocate extra space for a literals array prefix containing the @@ -1597,113 +1881,204 @@ Handle Factory::NewJSMessageObject( int end_position, Handle script, Handle stack_frames) { - CALL_HEAP_FUNCTION(isolate(), - isolate()->heap()->AllocateJSMessageObject(*type, - *arguments, - start_position, - end_position, - *script, - *stack_frames), - JSMessageObject); + Handle map = message_object_map(); + Handle message = New(map, NEW_SPACE); + message->set_properties(*empty_fixed_array(), SKIP_WRITE_BARRIER); + message->initialize_elements(); + message->set_elements(*empty_fixed_array(), SKIP_WRITE_BARRIER); + message->set_type(*type); + message->set_arguments(*arguments); + message->set_start_position(start_position); + message->set_end_position(end_position); + message->set_script(*script); + message->set_stack_frames(*stack_frames); + return message; } Handle Factory::NewSharedFunctionInfo(Handle name) { - CALL_HEAP_FUNCTION(isolate(), - isolate()->heap()->AllocateSharedFunctionInfo(*name), - SharedFunctionInfo); -} - - -Handle Factory::NumberToString(Handle number) { - CALL_HEAP_FUNCTION(isolate(), - isolate()->heap()->NumberToString(*number), String); -} - - -Handle Factory::Uint32ToString(uint32_t value) { - CALL_HEAP_FUNCTION(isolate(), - isolate()->heap()->Uint32ToString(value), String); + Handle map = shared_function_info_map(); + Handle share = New(map, + OLD_POINTER_SPACE); + + // Set pointer fields. + share->set_name(*name); + Code* illegal = isolate()->builtins()->builtin(Builtins::kIllegal); + share->set_code(illegal); + share->set_optimized_code_map(Smi::FromInt(0)); + share->set_scope_info(ScopeInfo::Empty(isolate())); + Code* construct_stub = + isolate()->builtins()->builtin(Builtins::kJSConstructStubGeneric); + share->set_construct_stub(construct_stub); + share->set_instance_class_name(*Object_string()); + share->set_function_data(*undefined_value(), SKIP_WRITE_BARRIER); + share->set_script(*undefined_value(), SKIP_WRITE_BARRIER); + share->set_debug_info(*undefined_value(), SKIP_WRITE_BARRIER); + share->set_inferred_name(*empty_string(), SKIP_WRITE_BARRIER); + share->set_feedback_vector(*empty_fixed_array(), SKIP_WRITE_BARRIER); + share->set_initial_map(*undefined_value(), SKIP_WRITE_BARRIER); + share->set_profiler_ticks(0); + share->set_ast_node_count(0); + share->set_counters(0); + + // Set integer fields (smi or int, depending on the architecture). + share->set_length(0); + share->set_formal_parameter_count(0); + share->set_expected_nof_properties(0); + share->set_num_literals(0); + share->set_start_position_and_type(0); + share->set_end_position(0); + share->set_function_token_position(0); + // All compiler hints default to false or 0. + share->set_compiler_hints(0); + share->set_opt_count_and_bailout_reason(0); + + return share; +} + + +static inline int NumberCacheHash(Handle cache, + Handle number) { + int mask = (cache->length() >> 1) - 1; + if (number->IsSmi()) { + return Handle::cast(number)->value() & mask; + } else { + DoubleRepresentation rep(number->Number()); + return + (static_cast(rep.bits) ^ static_cast(rep.bits >> 32)) & mask; + } } -Handle Factory::DictionaryAtNumberPut( - Handle dictionary, - uint32_t key, - Handle value) { - CALL_HEAP_FUNCTION(isolate(), - dictionary->AtNumberPut(key, *value), - SeededNumberDictionary); +Handle Factory::GetNumberStringCache(Handle number) { + DisallowHeapAllocation no_gc; + int hash = NumberCacheHash(number_string_cache(), number); + Object* key = number_string_cache()->get(hash * 2); + if (key == *number || (key->IsHeapNumber() && number->IsHeapNumber() && + key->Number() == number->Number())) { + return Handle( + String::cast(number_string_cache()->get(hash * 2 + 1)), isolate()); + } + return undefined_value(); +} + + +void Factory::SetNumberStringCache(Handle number, + Handle string) { + int hash = NumberCacheHash(number_string_cache(), number); + if (number_string_cache()->get(hash * 2) != *undefined_value()) { + int full_size = isolate()->heap()->FullSizeNumberStringCacheLength(); + if (number_string_cache()->length() != full_size) { + // The first time we have a hash collision, we move to the full sized + // number string cache. The idea is to have a small number string + // cache in the snapshot to keep boot-time memory usage down. + // If we expand the number string cache already while creating + // the snapshot then that didn't work out. + ASSERT(!Serializer::enabled(isolate()) || FLAG_extra_code != NULL); + Handle new_cache = NewFixedArray(full_size, TENURED); + isolate()->heap()->set_number_string_cache(*new_cache); + return; + } + } + number_string_cache()->set(hash * 2, *number); + number_string_cache()->set(hash * 2 + 1, *string); } -Handle Factory::DictionaryAtNumberPut( - Handle dictionary, - uint32_t key, - Handle value) { - CALL_HEAP_FUNCTION(isolate(), - dictionary->AtNumberPut(key, *value), - UnseededNumberDictionary); -} +Handle Factory::NumberToString(Handle number, + bool check_number_string_cache) { + isolate()->counters()->number_to_string_runtime()->Increment(); + if (check_number_string_cache) { + Handle cached = GetNumberStringCache(number); + if (!cached->IsUndefined()) return Handle::cast(cached); + } + char arr[100]; + Vector buffer(arr, ARRAY_SIZE(arr)); + const char* str; + if (number->IsSmi()) { + int num = Handle::cast(number)->value(); + str = IntToCString(num, buffer); + } else { + double num = Handle::cast(number)->value(); + str = DoubleToCString(num, buffer); + } -Handle Factory::NewFunctionHelper(Handle name, - Handle prototype) { - Handle function_share = NewSharedFunctionInfo(name); - CALL_HEAP_FUNCTION( - isolate(), - isolate()->heap()->AllocateFunction(*isolate()->sloppy_function_map(), - *function_share, - *prototype), - JSFunction); + // We tenure the allocated string since it is referenced from the + // number-string cache which lives in the old space. + Handle js_string = NewStringFromAsciiChecked(str, TENURED); + SetNumberStringCache(number, js_string); + return js_string; +} + + +void Factory::InitializeFunction(Handle function, + Handle info, + Handle context, + MaybeHandle maybe_prototype) { + function->initialize_properties(); + function->initialize_elements(); + function->set_shared(*info); + function->set_code(info->code()); + function->set_context(*context); + Handle prototype; + if (maybe_prototype.ToHandle(&prototype)) { + ASSERT(!prototype->IsMap()); + } else { + prototype = the_hole_value(); + } + function->set_prototype_or_initial_map(*prototype); + function->set_literals_or_bindings(*empty_fixed_array()); + function->set_next_function_link(*undefined_value()); } -Handle Factory::NewFunction(Handle name, - Handle prototype) { - Handle fun = NewFunctionHelper(name, prototype); - fun->set_context(isolate()->context()->native_context()); - return fun; -} - +static Handle MapForNewFunction(Isolate* isolate, + Handle function_info, + MaybeHandle maybe_prototype) { + if (maybe_prototype.is_null()) { + return function_info->strict_mode() == SLOPPY + ? isolate->sloppy_function_without_prototype_map() + : isolate->strict_function_without_prototype_map(); + } -Handle Factory::NewFunctionWithoutPrototypeHelper( - Handle name, - StrictMode strict_mode) { - Handle function_share = NewSharedFunctionInfo(name); - Handle map = strict_mode == SLOPPY - ? isolate()->sloppy_function_without_prototype_map() - : isolate()->strict_function_without_prototype_map(); - CALL_HEAP_FUNCTION(isolate(), - isolate()->heap()->AllocateFunction( - *map, - *function_share, - *the_hole_value()), - JSFunction); + Context* context = isolate->context()->native_context(); + int map_index = Context::FunctionMapIndex(function_info->strict_mode(), + function_info->is_generator()); + return Handle(Map::cast(context->get(map_index))); } -Handle Factory::NewFunctionWithoutPrototype( - Handle name, - StrictMode strict_mode) { - Handle fun = NewFunctionWithoutPrototypeHelper(name, strict_mode); - fun->set_context(isolate()->context()->native_context()); - return fun; +Handle Factory::NewFunction(Handle info, + Handle context, + MaybeHandle maybe_prototype, + PretenureFlag pretenure) { + Handle map = MapForNewFunction(isolate(), info, maybe_prototype); + AllocationSpace space = pretenure == TENURED ? OLD_POINTER_SPACE : NEW_SPACE; + Handle result = New(map, space); + InitializeFunction(result, info, context, maybe_prototype); + return result; } -Handle Factory::ToObject(Handle object) { - CALL_HEAP_FUNCTION(isolate(), object->ToObject(isolate()), Object); +Handle Factory::NewFunction(Handle name, + Handle code, + MaybeHandle maybe_prototype) { + Handle info = NewSharedFunctionInfo(name); + info->set_code(*code); + Handle context(isolate()->context()->native_context()); + return NewFunction(info, context, maybe_prototype); } -Handle Factory::ToObject(Handle object, - Handle native_context) { - CALL_HEAP_FUNCTION(isolate(), object->ToObject(*native_context), Object); +Handle Factory::NewFunctionWithPrototype(Handle name, + Handle prototype) { + Handle info = NewSharedFunctionInfo(name); + Handle context(isolate()->context()->native_context()); + return NewFunction(info, context, prototype); } -#ifdef ENABLE_DEBUGGER_SUPPORT Handle Factory::NewDebugInfo(Handle shared) { // Get the original code of the function. Handle code(shared->code()); @@ -1733,7 +2108,6 @@ Handle Factory::NewDebugInfo(Handle shared) { return debug_info; } -#endif Handle Factory::NewArgumentsObject(Handle callee, @@ -1745,7 +2119,9 @@ Handle Factory::NewArgumentsObject(Handle callee, Handle Factory::CreateApiFunction( - Handle obj, ApiInstanceType instance_type) { + Handle obj, + Handle prototype, + ApiInstanceType instance_type) { Handle code = isolate()->builtins()->HandleApiCall(); Handle construct_stub = isolate()->builtins()->JSConstructStubApi(); @@ -1781,24 +2157,31 @@ Handle Factory::CreateApiFunction( break; } - Handle result = - NewFunction(Factory::empty_string(), - type, - instance_size, - code, - true); + MaybeHandle maybe_prototype = prototype; + if (obj->remove_prototype()) maybe_prototype = MaybeHandle(); - // Set length. - result->shared()->set_length(obj->length()); + Handle result = NewFunction( + maybe_prototype, Factory::empty_string(), type, + instance_size, code, true); - // Set class name. - Handle class_name = Handle(obj->class_name(), isolate()); + result->shared()->set_length(obj->length()); + Handle class_name(obj->class_name(), isolate()); if (class_name->IsString()) { result->shared()->set_instance_class_name(*class_name); result->shared()->set_name(*class_name); } + result->shared()->set_function_data(*obj); + result->shared()->set_construct_stub(*construct_stub); + result->shared()->DontAdaptArguments(); + + if (obj->remove_prototype()) { + ASSERT(result->shared()->IsApiFunction()); + return result; + } + // Down from here is only valid for API functions that can be used as a + // constructor (don't set the "remove prototype" flag). - Handle map = Handle(result->initial_map()); + Handle map(result->initial_map()); // Mark as undetectable if needed. if (obj->undetectable()) { @@ -1828,10 +2211,6 @@ Handle Factory::CreateApiFunction( map->set_has_instance_call_handler(); } - result->shared()->set_function_data(*obj); - result->shared()->set_construct_stub(*construct_stub); - result->shared()->DontAdaptArguments(); - // Recursively copy parent instance templates' accessors, // 'data' may be modified. int max_number_of_additional_properties = 0; @@ -1898,7 +2277,7 @@ Handle Factory::CreateApiFunction( // Install accumulated static accessors for (int i = 0; i < valid_descriptors; i++) { Handle accessor(AccessorInfo::cast(array->get(i))); - JSObject::SetAccessor(result, accessor); + JSObject::SetAccessor(result, accessor).Assert(); } ASSERT(result->shared()->IsApiFunction()); @@ -1906,32 +2285,13 @@ Handle Factory::CreateApiFunction( } -Handle Factory::NewMapCache(int at_least_space_for) { - CALL_HEAP_FUNCTION(isolate(), - MapCache::Allocate(isolate()->heap(), - at_least_space_for), - MapCache); -} - - -MUST_USE_RESULT static MaybeObject* UpdateMapCacheWith(Context* context, - FixedArray* keys, - Map* map) { - Object* result; - { MaybeObject* maybe_result = - MapCache::cast(context->map_cache())->Put(keys, map); - if (!maybe_result->ToObject(&result)) return maybe_result; - } - context->set_map_cache(MapCache::cast(result)); - return result; -} - - Handle Factory::AddToMapCache(Handle context, Handle keys, Handle map) { - CALL_HEAP_FUNCTION(isolate(), - UpdateMapCacheWith(*context, *keys, *map), MapCache); + Handle map_cache = handle(MapCache::cast(context->map_cache())); + Handle result = MapCache::Put(map_cache, keys, map); + context->set_map_cache(*result); + return result; } @@ -1939,7 +2299,7 @@ Handle Factory::ObjectLiteralMapFromCache(Handle context, Handle keys) { if (context->map_cache()->IsUndefined()) { // Allocate the new map cache for the native context. - Handle new_cache = NewMapCache(24); + Handle new_cache = MapCache::New(isolate(), 24); context->set_map_cache(*new_cache); } // Check to see whether there is a matching element in the cache. @@ -1948,11 +2308,10 @@ Handle Factory::ObjectLiteralMapFromCache(Handle context, Handle result = Handle(cache->Lookup(*keys), isolate()); if (result->IsMap()) return Handle::cast(result); // Create a new map and add it to the cache. - Handle map = - CopyMap(Handle(context->object_function()->initial_map()), - keys->length()); + Handle map = Map::Create( + handle(context->object_function()), keys->length()); AddToMapCache(context, keys, map); - return Handle(map); + return map; } @@ -1992,28 +2351,25 @@ void Factory::SetRegExpIrregexpData(Handle regexp, -void Factory::ConfigureInstance(Handle desc, - Handle instance, - bool* pending_exception) { +MaybeHandle Factory::ConfigureInstance( + Handle desc, Handle instance) { // Configure the instance by adding the properties specified by the // instance template. Handle instance_template(desc->instance_template(), isolate()); if (!instance_template->IsUndefined()) { - Execution::ConfigureInstance(isolate(), - instance, - instance_template, - pending_exception); - } else { - *pending_exception = false; + RETURN_ON_EXCEPTION( + isolate(), + Execution::ConfigureInstance(isolate(), instance, instance_template), + FunctionTemplateInfo); } + return desc; } Handle Factory::GlobalConstantFor(Handle name) { - Heap* h = isolate()->heap(); - if (name->Equals(h->undefined_string())) return undefined_value(); - if (name->Equals(h->nan_string())) return nan_value(); - if (name->Equals(h->infinity_string())) return infinity_value(); + if (String::Equals(name, undefined_string())) return undefined_value(); + if (String::Equals(name, nan_string())) return nan_value(); + if (String::Equals(name, infinity_string())) return infinity_value(); return Handle::null(); }