2014-03-31 12:01:02 +00:00
|
|
|
// 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.
|
|
|
|
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/factory.h"
|
2014-03-31 12:01:02 +00:00
|
|
|
|
2014-07-07 13:27:37 +00:00
|
|
|
#include "src/allocation-site-scopes.h"
|
2014-09-02 13:36:35 +00:00
|
|
|
#include "src/base/bits.h"
|
2015-04-09 22:40:16 +00:00
|
|
|
#include "src/bootstrapper.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/conversions.h"
|
|
|
|
#include "src/macro-assembler.h"
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-05-25 10:05:56 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2014-04-15 11:51:34 +00:00
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
Handle<T> Factory::New(Handle<Map> map, AllocationSpace space) {
|
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate(),
|
|
|
|
isolate()->heap()->Allocate(*map, space),
|
|
|
|
T);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
Handle<T> Factory::New(Handle<Map> map,
|
|
|
|
AllocationSpace space,
|
|
|
|
Handle<AllocationSite> allocation_site) {
|
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate(),
|
|
|
|
isolate()->heap()->Allocate(*map, space, *allocation_site),
|
|
|
|
T);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-17 13:15:22 +00:00
|
|
|
Handle<HeapObject> Factory::NewFillerObject(int size,
|
|
|
|
bool double_align,
|
|
|
|
AllocationSpace space) {
|
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate(),
|
|
|
|
isolate()->heap()->AllocateFillerObject(size, double_align, space),
|
|
|
|
HeapObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-07 12:43:35 +00:00
|
|
|
Handle<Box> Factory::NewBox(Handle<Object> value) {
|
|
|
|
Handle<Box> result = Handle<Box>::cast(NewStruct(BOX_TYPE));
|
|
|
|
result->set_value(*value);
|
|
|
|
return result;
|
2013-06-06 15:40:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-07 10:42:45 +00:00
|
|
|
Handle<PrototypeInfo> Factory::NewPrototypeInfo() {
|
|
|
|
Handle<PrototypeInfo> result =
|
|
|
|
Handle<PrototypeInfo>::cast(NewStruct(PROTOTYPE_INFO_TYPE));
|
|
|
|
result->set_prototype_users(WeakFixedArray::Empty());
|
2015-08-08 22:56:15 +00:00
|
|
|
result->set_registry_slot(PrototypeInfo::UNREGISTERED);
|
2015-04-07 10:42:45 +00:00
|
|
|
result->set_validity_cell(Smi::FromInt(0));
|
2015-04-29 09:31:38 +00:00
|
|
|
result->set_constructor_name(Smi::FromInt(0));
|
2015-04-07 10:42:45 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-16 14:15:32 +00:00
|
|
|
Handle<Oddball> Factory::NewOddball(Handle<Map> map,
|
|
|
|
const char* to_string,
|
|
|
|
Handle<Object> to_number,
|
|
|
|
byte kind) {
|
2015-04-07 11:31:57 +00:00
|
|
|
Handle<Oddball> oddball = New<Oddball>(map, OLD_SPACE);
|
2014-04-16 14:15:32 +00:00
|
|
|
Oddball::Initialize(isolate(), oddball, to_string, to_number, kind);
|
|
|
|
return oddball;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
Handle<FixedArray> Factory::NewFixedArray(int size, PretenureFlag pretenure) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(0 <= size);
|
2011-03-18 20:35:07 +00:00
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate(),
|
|
|
|
isolate()->heap()->AllocateFixedArray(size, pretenure),
|
|
|
|
FixedArray);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-14 14:46:15 +00:00
|
|
|
Handle<FixedArray> Factory::NewFixedArrayWithHoles(int size,
|
|
|
|
PretenureFlag pretenure) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(0 <= size);
|
2011-03-18 20:35:07 +00:00
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate(),
|
2014-04-14 16:05:19 +00:00
|
|
|
isolate()->heap()->AllocateFixedArrayWithFiller(size,
|
|
|
|
pretenure,
|
|
|
|
*the_hole_value()),
|
2011-03-18 20:35:07 +00:00
|
|
|
FixedArray);
|
2008-10-29 10:02:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-20 13:01:08 +00:00
|
|
|
Handle<FixedArray> Factory::NewUninitializedFixedArray(int size) {
|
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate(),
|
|
|
|
isolate()->heap()->AllocateUninitializedFixedArray(size),
|
|
|
|
FixedArray);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-24 05:29:00 +00:00
|
|
|
Handle<FixedArrayBase> Factory::NewFixedDoubleArray(int size,
|
2014-04-25 16:02:50 +00:00
|
|
|
PretenureFlag pretenure) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(0 <= size);
|
2011-06-09 10:03:35 +00:00
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate(),
|
|
|
|
isolate()->heap()->AllocateUninitializedFixedDoubleArray(size, pretenure),
|
2014-04-24 05:29:00 +00:00
|
|
|
FixedArrayBase);
|
2011-06-09 10:03:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-24 05:29:00 +00:00
|
|
|
Handle<FixedArrayBase> Factory::NewFixedDoubleArrayWithHoles(
|
2014-04-14 16:05:19 +00:00
|
|
|
int size,
|
|
|
|
PretenureFlag pretenure) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(0 <= size);
|
2014-04-24 05:29:00 +00:00
|
|
|
Handle<FixedArrayBase> array = NewFixedDoubleArray(size, pretenure);
|
|
|
|
if (size > 0) {
|
|
|
|
Handle<FixedDoubleArray> double_array =
|
|
|
|
Handle<FixedDoubleArray>::cast(array);
|
|
|
|
for (int i = 0; i < size; ++i) {
|
|
|
|
double_array->set_the_hole(i);
|
|
|
|
}
|
2014-04-14 16:05:19 +00:00
|
|
|
}
|
|
|
|
return array;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-04 20:41:57 +00:00
|
|
|
Handle<OrderedHashSet> Factory::NewOrderedHashSet() {
|
2014-12-10 18:47:24 +00:00
|
|
|
return OrderedHashSet::Allocate(isolate(), OrderedHashSet::kMinCapacity);
|
2014-04-04 20:41:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<OrderedHashMap> Factory::NewOrderedHashMap() {
|
2014-12-10 18:47:24 +00:00
|
|
|
return OrderedHashMap::Allocate(isolate(), OrderedHashMap::kMinCapacity);
|
2014-04-04 20:41:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-10 16:11:33 +00:00
|
|
|
Handle<AccessorPair> Factory::NewAccessorPair() {
|
2014-04-07 10:12:54 +00:00
|
|
|
Handle<AccessorPair> accessors =
|
|
|
|
Handle<AccessorPair>::cast(NewStruct(ACCESSOR_PAIR_TYPE));
|
|
|
|
accessors->set_getter(*the_hole_value(), SKIP_WRITE_BARRIER);
|
|
|
|
accessors->set_setter(*the_hole_value(), SKIP_WRITE_BARRIER);
|
|
|
|
return accessors;
|
2012-01-10 16:11:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-20 12:57:23 +00:00
|
|
|
Handle<TypeFeedbackInfo> Factory::NewTypeFeedbackInfo() {
|
2014-04-07 10:12:54 +00:00
|
|
|
Handle<TypeFeedbackInfo> info =
|
|
|
|
Handle<TypeFeedbackInfo>::cast(NewStruct(TYPE_FEEDBACK_INFO_TYPE));
|
|
|
|
info->initialize_storage();
|
|
|
|
return info;
|
2012-02-20 12:57:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-28 17:03:34 +00:00
|
|
|
// Internalized strings are created in the old generation (data space).
|
|
|
|
Handle<String> Factory::InternalizeUtf8String(Vector<const char> string) {
|
2014-01-17 10:27:57 +00:00
|
|
|
Utf8StringKey key(string, isolate()->heap()->HashSeed());
|
|
|
|
return InternalizeStringWithKey(&key);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2013-07-05 09:52:11 +00:00
|
|
|
|
2013-02-28 17:03:34 +00:00
|
|
|
// Internalized strings are created in the old generation (data space).
|
|
|
|
Handle<String> Factory::InternalizeString(Handle<String> string) {
|
2014-04-23 15:43:39 +00:00
|
|
|
if (string->IsInternalizedString()) return string;
|
|
|
|
return StringTable::LookupString(isolate(), string);
|
2011-05-24 12:16:23 +00:00
|
|
|
}
|
|
|
|
|
2013-07-05 09:52:11 +00:00
|
|
|
|
2013-02-28 17:03:34 +00:00
|
|
|
Handle<String> Factory::InternalizeOneByteString(Vector<const uint8_t> string) {
|
2014-01-17 10:27:57 +00:00
|
|
|
OneByteStringKey key(string, isolate()->heap()->HashSeed());
|
|
|
|
return InternalizeStringWithKey(&key);
|
2010-12-22 20:14:19 +00:00
|
|
|
}
|
|
|
|
|
2011-05-24 12:16:23 +00:00
|
|
|
|
2013-02-28 17:03:34 +00:00
|
|
|
Handle<String> Factory::InternalizeOneByteString(
|
|
|
|
Handle<SeqOneByteString> string, int from, int length) {
|
2014-08-19 08:53:38 +00:00
|
|
|
SeqOneByteSubStringKey key(string, from, length);
|
2014-01-17 10:27:57 +00:00
|
|
|
return InternalizeStringWithKey(&key);
|
2011-05-24 12:16:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-28 17:03:34 +00:00
|
|
|
Handle<String> Factory::InternalizeTwoByteString(Vector<const uc16> string) {
|
2014-01-17 10:27:57 +00:00
|
|
|
TwoByteStringKey key(string, isolate()->heap()->HashSeed());
|
|
|
|
return InternalizeStringWithKey(&key);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<class StringTableKey>
|
|
|
|
Handle<String> Factory::InternalizeStringWithKey(StringTableKey* key) {
|
2014-04-23 15:43:39 +00:00
|
|
|
return StringTable::LookupKey(isolate(), key);
|
2010-12-22 20:14:19 +00:00
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2014-04-17 13:27:02 +00:00
|
|
|
MaybeHandle<String> Factory::NewStringFromOneByte(Vector<const uint8_t> string,
|
|
|
|
PretenureFlag pretenure) {
|
|
|
|
int length = string.length();
|
2014-06-18 13:26:02 +00:00
|
|
|
if (length == 1) return LookupSingleCharacterStringFromCode(string[0]);
|
2014-04-17 13:27:02 +00:00
|
|
|
Handle<SeqOneByteString> result;
|
|
|
|
ASSIGN_RETURN_ON_EXCEPTION(
|
2011-03-18 20:35:07 +00:00
|
|
|
isolate(),
|
2014-04-17 13:27:02 +00:00
|
|
|
result,
|
|
|
|
NewRawOneByteString(string.length(), pretenure),
|
2011-03-18 20:35:07 +00:00
|
|
|
String);
|
2014-04-17 13:27:02 +00:00
|
|
|
|
|
|
|
DisallowHeapAllocation no_gc;
|
|
|
|
// Copy the characters into the new object.
|
|
|
|
CopyChars(SeqOneByteString::cast(*result)->GetChars(),
|
|
|
|
string.start(),
|
|
|
|
length);
|
|
|
|
return result;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2014-04-17 13:27:02 +00:00
|
|
|
MaybeHandle<String> Factory::NewStringFromUtf8(Vector<const char> string,
|
|
|
|
PretenureFlag pretenure) {
|
2014-04-16 18:28:03 +00:00
|
|
|
// 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<const uint8_t>::cast(string), pretenure);
|
|
|
|
}
|
2014-06-18 13:26:02 +00:00
|
|
|
|
2014-04-16 18:28:03 +00:00
|
|
|
// Non-ASCII and we need to decode.
|
2014-06-18 13:26:02 +00:00
|
|
|
Access<UnicodeCache::Utf8Decoder>
|
|
|
|
decoder(isolate()->unicode_cache()->utf8_decoder());
|
|
|
|
decoder->Reset(string.start() + non_ascii_start,
|
|
|
|
length - non_ascii_start);
|
2015-02-05 07:54:24 +00:00
|
|
|
int utf16_length = static_cast<int>(decoder->Utf16Length());
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(utf16_length > 0);
|
2014-06-18 13:26:02 +00:00
|
|
|
// Allocate string.
|
|
|
|
Handle<SeqTwoByteString> result;
|
|
|
|
ASSIGN_RETURN_ON_EXCEPTION(
|
|
|
|
isolate(), result,
|
|
|
|
NewRawTwoByteString(non_ascii_start + utf16_length, pretenure),
|
2011-03-18 20:35:07 +00:00
|
|
|
String);
|
2014-09-10 12:38:12 +00:00
|
|
|
// Copy ASCII portion.
|
2014-06-18 13:26:02 +00:00
|
|
|
uint16_t* data = result->GetChars();
|
|
|
|
const char* ascii_data = string.start();
|
|
|
|
for (int i = 0; i < non_ascii_start; i++) {
|
|
|
|
*data++ = *ascii_data++;
|
|
|
|
}
|
|
|
|
// Now write the remainder.
|
|
|
|
decoder->WriteUtf16(data, utf16_length);
|
|
|
|
return result;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-17 13:27:02 +00:00
|
|
|
MaybeHandle<String> Factory::NewStringFromTwoByte(Vector<const uc16> string,
|
|
|
|
PretenureFlag pretenure) {
|
2014-06-18 13:26:02 +00:00
|
|
|
int length = string.length();
|
|
|
|
const uc16* start = string.start();
|
|
|
|
if (String::IsOneByte(start, length)) {
|
2014-08-11 14:04:37 +00:00
|
|
|
if (length == 1) return LookupSingleCharacterStringFromCode(string[0]);
|
2014-06-18 13:26:02 +00:00
|
|
|
Handle<SeqOneByteString> result;
|
|
|
|
ASSIGN_RETURN_ON_EXCEPTION(
|
|
|
|
isolate(),
|
|
|
|
result,
|
|
|
|
NewRawOneByteString(length, pretenure),
|
|
|
|
String);
|
|
|
|
CopyChars(result->GetChars(), start, length);
|
|
|
|
return result;
|
|
|
|
} else {
|
|
|
|
Handle<SeqTwoByteString> result;
|
|
|
|
ASSIGN_RETURN_ON_EXCEPTION(
|
|
|
|
isolate(),
|
|
|
|
result,
|
|
|
|
NewRawTwoByteString(length, pretenure),
|
|
|
|
String);
|
|
|
|
CopyChars(result->GetChars(), start, length);
|
|
|
|
return result;
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-25 13:59:33 +00:00
|
|
|
Handle<String> Factory::NewInternalizedStringFromUtf8(Vector<const char> str,
|
|
|
|
int chars,
|
|
|
|
uint32_t hash_field) {
|
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate(),
|
|
|
|
isolate()->heap()->AllocateInternalizedStringFromUtf8(
|
|
|
|
str, chars, hash_field),
|
|
|
|
String);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MUST_USE_RESULT Handle<String> Factory::NewOneByteInternalizedString(
|
|
|
|
Vector<const uint8_t> str,
|
|
|
|
uint32_t hash_field) {
|
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate(),
|
|
|
|
isolate()->heap()->AllocateOneByteInternalizedString(str, hash_field),
|
|
|
|
String);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-19 08:53:38 +00:00
|
|
|
MUST_USE_RESULT Handle<String> Factory::NewOneByteInternalizedSubString(
|
|
|
|
Handle<SeqOneByteString> string, int offset, int length,
|
|
|
|
uint32_t hash_field) {
|
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate(), isolate()->heap()->AllocateOneByteInternalizedString(
|
|
|
|
Vector<const uint8_t>(string->GetChars() + offset, length),
|
|
|
|
hash_field),
|
|
|
|
String);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-25 13:59:33 +00:00
|
|
|
MUST_USE_RESULT Handle<String> Factory::NewTwoByteInternalizedString(
|
|
|
|
Vector<const uc16> str,
|
|
|
|
uint32_t hash_field) {
|
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate(),
|
|
|
|
isolate()->heap()->AllocateTwoByteInternalizedString(str, hash_field),
|
|
|
|
String);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<String> Factory::NewInternalizedStringImpl(
|
2014-04-25 16:02:50 +00:00
|
|
|
Handle<String> string, int chars, uint32_t hash_field) {
|
2014-04-25 13:59:33 +00:00
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate(),
|
2014-04-25 16:02:50 +00:00
|
|
|
isolate()->heap()->AllocateInternalizedStringImpl(
|
|
|
|
*string, chars, hash_field),
|
2014-04-25 13:59:33 +00:00
|
|
|
String);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MaybeHandle<Map> Factory::InternalizedStringMapForString(
|
|
|
|
Handle<String> string) {
|
|
|
|
// If the string is in new space it cannot be used as internalized.
|
|
|
|
if (isolate()->heap()->InNewSpace(*string)) return MaybeHandle<Map>();
|
|
|
|
|
|
|
|
// Find the corresponding internalized string map for strings.
|
|
|
|
switch (string->map()->instance_type()) {
|
|
|
|
case STRING_TYPE: return internalized_string_map();
|
2014-09-10 12:38:12 +00:00
|
|
|
case ONE_BYTE_STRING_TYPE:
|
|
|
|
return one_byte_internalized_string_map();
|
2014-04-25 13:59:33 +00:00
|
|
|
case EXTERNAL_STRING_TYPE: return external_internalized_string_map();
|
2014-09-10 12:38:12 +00:00
|
|
|
case EXTERNAL_ONE_BYTE_STRING_TYPE:
|
|
|
|
return external_one_byte_internalized_string_map();
|
2014-04-25 13:59:33 +00:00
|
|
|
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();
|
2014-09-10 12:38:12 +00:00
|
|
|
case SHORT_EXTERNAL_ONE_BYTE_STRING_TYPE:
|
|
|
|
return short_external_one_byte_internalized_string_map();
|
2014-04-25 13:59:33 +00:00
|
|
|
case SHORT_EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE:
|
|
|
|
return short_external_internalized_string_with_one_byte_data_map();
|
|
|
|
default: return MaybeHandle<Map>(); // No match found.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-03 12:30:08 +00:00
|
|
|
MaybeHandle<SeqOneByteString> Factory::NewRawOneByteString(
|
|
|
|
int length, PretenureFlag pretenure) {
|
2014-06-18 13:26:02 +00:00
|
|
|
if (length > String::kMaxLength || length < 0) {
|
2014-09-01 09:11:44 +00:00
|
|
|
THROW_NEW_ERROR(isolate(), NewInvalidStringLengthError(), SeqOneByteString);
|
2014-06-18 13:26:02 +00:00
|
|
|
}
|
2011-03-18 20:35:07 +00:00
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate(),
|
2012-11-21 10:01:05 +00:00
|
|
|
isolate()->heap()->AllocateRawOneByteString(length, pretenure),
|
2012-11-15 13:31:27 +00:00
|
|
|
SeqOneByteString);
|
2010-07-05 12:49:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-03 12:30:08 +00:00
|
|
|
MaybeHandle<SeqTwoByteString> Factory::NewRawTwoByteString(
|
|
|
|
int length, PretenureFlag pretenure) {
|
2014-06-18 13:26:02 +00:00
|
|
|
if (length > String::kMaxLength || length < 0) {
|
2014-09-01 09:11:44 +00:00
|
|
|
THROW_NEW_ERROR(isolate(), NewInvalidStringLengthError(), SeqTwoByteString);
|
2014-06-18 13:26:02 +00:00
|
|
|
}
|
2011-03-18 20:35:07 +00:00
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate(),
|
|
|
|
isolate()->heap()->AllocateRawTwoByteString(length, pretenure),
|
2011-06-27 09:02:34 +00:00
|
|
|
SeqTwoByteString);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-23 15:43:39 +00:00
|
|
|
Handle<String> 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<uint8_t>(code);
|
|
|
|
Handle<String> result =
|
|
|
|
InternalizeOneByteString(Vector<const uint8_t>(buffer, 1));
|
|
|
|
single_character_string_cache()->set(code, *result);
|
|
|
|
return result;
|
|
|
|
}
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(code <= String::kMaxUtf16CodeUnitU);
|
2014-04-23 15:43:39 +00:00
|
|
|
|
|
|
|
Handle<SeqTwoByteString> result = NewRawTwoByteString(1).ToHandleChecked();
|
|
|
|
result->SeqTwoByteStringSet(0, static_cast<uint16_t>(code));
|
|
|
|
return result;
|
2014-04-08 06:45:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-23 12:37:56 +00:00
|
|
|
// 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.
|
|
|
|
return character - from <= to - from;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline Handle<String> MakeOrFindTwoCharacterString(Isolate* isolate,
|
|
|
|
uint16_t c1,
|
|
|
|
uint16_t c2) {
|
|
|
|
// 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')) {
|
2014-04-30 17:27:40 +00:00
|
|
|
Handle<String> result;
|
|
|
|
if (StringTable::LookupTwoCharsStringIfExists(isolate, c1, c2).
|
|
|
|
ToHandle(&result)) {
|
|
|
|
return result;
|
2013-12-23 12:37:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now we know the length is 2, we might as well make use of that fact
|
|
|
|
// when building the new string.
|
|
|
|
if (static_cast<unsigned>(c1 | c2) <= String::kMaxOneByteCharCodeU) {
|
|
|
|
// We can do this.
|
2014-09-02 13:36:35 +00:00
|
|
|
DCHECK(base::bits::IsPowerOfTwo32(String::kMaxOneByteCharCodeU +
|
|
|
|
1)); // because of this.
|
2014-04-03 12:30:08 +00:00
|
|
|
Handle<SeqOneByteString> str =
|
|
|
|
isolate->factory()->NewRawOneByteString(2).ToHandleChecked();
|
2013-12-23 12:37:56 +00:00
|
|
|
uint8_t* dest = str->GetChars();
|
|
|
|
dest[0] = static_cast<uint8_t>(c1);
|
|
|
|
dest[1] = static_cast<uint8_t>(c2);
|
|
|
|
return str;
|
|
|
|
} else {
|
2014-04-03 12:30:08 +00:00
|
|
|
Handle<SeqTwoByteString> str =
|
|
|
|
isolate->factory()->NewRawTwoByteString(2).ToHandleChecked();
|
2013-12-23 12:37:56 +00:00
|
|
|
uc16* dest = str->GetChars();
|
|
|
|
dest[0] = c1;
|
|
|
|
dest[1] = c2;
|
|
|
|
return str;
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-21 09:24:30 +00:00
|
|
|
template<typename SinkChar, typename StringType>
|
|
|
|
Handle<String> ConcatStringContent(Handle<StringType> result,
|
|
|
|
Handle<String> first,
|
|
|
|
Handle<String> second) {
|
|
|
|
DisallowHeapAllocation pointer_stays_valid;
|
|
|
|
SinkChar* sink = result->GetChars();
|
|
|
|
String::WriteToFlat(*first, sink, 0, first->length());
|
|
|
|
String::WriteToFlat(*second, sink + first->length(), 0, second->length());
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-03 12:30:37 +00:00
|
|
|
MaybeHandle<String> Factory::NewConsString(Handle<String> left,
|
|
|
|
Handle<String> right) {
|
2013-12-23 12:37:56 +00:00
|
|
|
int left_length = left->length();
|
|
|
|
if (left_length == 0) return right;
|
|
|
|
int right_length = right->length();
|
|
|
|
if (right_length == 0) return left;
|
|
|
|
|
|
|
|
int length = left_length + right_length;
|
|
|
|
|
|
|
|
if (length == 2) {
|
|
|
|
uint16_t c1 = left->Get(0);
|
|
|
|
uint16_t c2 = right->Get(0);
|
|
|
|
return MakeOrFindTwoCharacterString(isolate(), c1, c2);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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) {
|
2014-09-01 09:11:44 +00:00
|
|
|
THROW_NEW_ERROR(isolate(), NewInvalidStringLengthError(), String);
|
2013-12-23 12:37:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool left_is_one_byte = left->IsOneByteRepresentation();
|
|
|
|
bool right_is_one_byte = right->IsOneByteRepresentation();
|
|
|
|
bool is_one_byte = left_is_one_byte && right_is_one_byte;
|
|
|
|
bool is_one_byte_data_in_two_byte_string = false;
|
|
|
|
if (!is_one_byte) {
|
|
|
|
// At least one of the strings uses two-byte representation so we
|
2014-09-10 12:38:12 +00:00
|
|
|
// can't use the fast case code for short one-byte strings below, but
|
|
|
|
// we can try to save memory if all chars actually fit in one-byte.
|
2013-12-23 12:37:56 +00:00
|
|
|
is_one_byte_data_in_two_byte_string =
|
|
|
|
left->HasOnlyOneByteChars() && right->HasOnlyOneByteChars();
|
|
|
|
if (is_one_byte_data_in_two_byte_string) {
|
2014-09-10 12:38:12 +00:00
|
|
|
isolate()->counters()->string_add_runtime_ext_to_one_byte()->Increment();
|
2013-12-23 12:37:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the resulting string is small make a flat string.
|
|
|
|
if (length < ConsString::kMinLength) {
|
|
|
|
// Note that neither of the two inputs can be a slice because:
|
|
|
|
STATIC_ASSERT(ConsString::kMinLength <= SlicedString::kMinLength);
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(left->IsFlat());
|
|
|
|
DCHECK(right->IsFlat());
|
2013-12-23 12:37:56 +00:00
|
|
|
|
2014-03-25 09:09:24 +00:00
|
|
|
STATIC_ASSERT(ConsString::kMinLength <= String::kMaxLength);
|
2013-12-23 12:37:56 +00:00
|
|
|
if (is_one_byte) {
|
2014-04-03 12:30:08 +00:00
|
|
|
Handle<SeqOneByteString> result =
|
|
|
|
NewRawOneByteString(length).ToHandleChecked();
|
2013-12-23 12:37:56 +00:00
|
|
|
DisallowHeapAllocation no_gc;
|
|
|
|
uint8_t* dest = result->GetChars();
|
|
|
|
// Copy left part.
|
2014-09-10 12:38:12 +00:00
|
|
|
const uint8_t* src =
|
|
|
|
left->IsExternalString()
|
|
|
|
? Handle<ExternalOneByteString>::cast(left)->GetChars()
|
|
|
|
: Handle<SeqOneByteString>::cast(left)->GetChars();
|
2013-12-23 12:37:56 +00:00
|
|
|
for (int i = 0; i < left_length; i++) *dest++ = src[i];
|
|
|
|
// Copy right part.
|
|
|
|
src = right->IsExternalString()
|
2014-09-10 12:38:12 +00:00
|
|
|
? Handle<ExternalOneByteString>::cast(right)->GetChars()
|
|
|
|
: Handle<SeqOneByteString>::cast(right)->GetChars();
|
2013-12-23 12:37:56 +00:00
|
|
|
for (int i = 0; i < right_length; i++) *dest++ = src[i];
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (is_one_byte_data_in_two_byte_string)
|
2014-04-03 12:30:08 +00:00
|
|
|
? ConcatStringContent<uint8_t>(
|
|
|
|
NewRawOneByteString(length).ToHandleChecked(), left, right)
|
|
|
|
: ConcatStringContent<uc16>(
|
|
|
|
NewRawTwoByteString(length).ToHandleChecked(), left, right);
|
2013-12-23 12:37:56 +00:00
|
|
|
}
|
|
|
|
|
2015-03-30 06:28:35 +00:00
|
|
|
return (is_one_byte || is_one_byte_data_in_two_byte_string)
|
|
|
|
? NewOneByteConsString(length, left, right)
|
|
|
|
: NewTwoByteConsString(length, left, right);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MaybeHandle<String> Factory::NewOneByteConsString(int length,
|
|
|
|
Handle<String> left,
|
|
|
|
Handle<String> right) {
|
|
|
|
return NewRawConsString(cons_one_byte_string_map(), length, left, right);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MaybeHandle<String> Factory::NewTwoByteConsString(int length,
|
|
|
|
Handle<String> left,
|
|
|
|
Handle<String> right) {
|
|
|
|
return NewRawConsString(cons_string_map(), length, left, right);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MaybeHandle<String> Factory::NewRawConsString(Handle<Map> map, int length,
|
|
|
|
Handle<String> left,
|
|
|
|
Handle<String> right) {
|
|
|
|
Handle<ConsString> result = New<ConsString>(map, NEW_SPACE);
|
2013-12-23 12:37:56 +00:00
|
|
|
|
|
|
|
DisallowHeapAllocation no_gc;
|
|
|
|
WriteBarrierMode mode = result->GetWriteBarrierMode(no_gc);
|
|
|
|
|
|
|
|
result->set_hash_field(String::kEmptyHashField);
|
|
|
|
result->set_length(length);
|
|
|
|
result->set_first(*left, mode);
|
|
|
|
result->set_second(*right, mode);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-27 09:02:34 +00:00
|
|
|
Handle<String> Factory::NewProperSubString(Handle<String> str,
|
2011-06-22 14:20:23 +00:00
|
|
|
int begin,
|
|
|
|
int end) {
|
2013-12-23 12:37:56 +00:00
|
|
|
#if VERIFY_HEAP
|
|
|
|
if (FLAG_verify_heap) str->StringVerify();
|
|
|
|
#endif
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(begin > 0 || end < str->length());
|
2013-12-23 12:37:56 +00:00
|
|
|
|
2014-04-22 11:19:27 +00:00
|
|
|
str = String::Flatten(str);
|
|
|
|
|
2013-12-23 12:37:56 +00:00
|
|
|
int length = end - begin;
|
|
|
|
if (length <= 0) return empty_string();
|
|
|
|
if (length == 1) {
|
2014-04-08 06:45:53 +00:00
|
|
|
return LookupSingleCharacterStringFromCode(str->Get(begin));
|
2013-12-23 12:37:56 +00:00
|
|
|
}
|
|
|
|
if (length == 2) {
|
|
|
|
// Optimization for 2-byte strings often used as keys in a decompression
|
|
|
|
// dictionary. Check whether we already have the string in the string
|
|
|
|
// table to prevent creation of many unnecessary strings.
|
|
|
|
uint16_t c1 = str->Get(begin);
|
|
|
|
uint16_t c2 = str->Get(begin + 1);
|
|
|
|
return MakeOrFindTwoCharacterString(isolate(), c1, c2);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!FLAG_string_slices || length < SlicedString::kMinLength) {
|
|
|
|
if (str->IsOneByteRepresentation()) {
|
2014-04-03 12:30:08 +00:00
|
|
|
Handle<SeqOneByteString> result =
|
|
|
|
NewRawOneByteString(length).ToHandleChecked();
|
2013-12-23 12:37:56 +00:00
|
|
|
uint8_t* dest = result->GetChars();
|
|
|
|
DisallowHeapAllocation no_gc;
|
|
|
|
String::WriteToFlat(*str, dest, begin, end);
|
|
|
|
return result;
|
|
|
|
} else {
|
2014-04-03 12:30:08 +00:00
|
|
|
Handle<SeqTwoByteString> result =
|
|
|
|
NewRawTwoByteString(length).ToHandleChecked();
|
2013-12-23 12:37:56 +00:00
|
|
|
uc16* dest = result->GetChars();
|
|
|
|
DisallowHeapAllocation no_gc;
|
|
|
|
String::WriteToFlat(*str, dest, begin, end);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int offset = begin;
|
|
|
|
|
|
|
|
if (str->IsSlicedString()) {
|
|
|
|
Handle<SlicedString> slice = Handle<SlicedString>::cast(str);
|
|
|
|
str = Handle<String>(slice->parent(), isolate());
|
|
|
|
offset += slice->offset();
|
|
|
|
}
|
|
|
|
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(str->IsSeqString() || str->IsExternalString());
|
2014-09-10 12:38:12 +00:00
|
|
|
Handle<Map> map = str->IsOneByteRepresentation()
|
|
|
|
? sliced_one_byte_string_map()
|
|
|
|
: sliced_string_map();
|
2014-04-29 07:02:11 +00:00
|
|
|
Handle<SlicedString> slice = New<SlicedString>(map, NEW_SPACE);
|
2013-12-23 12:37:56 +00:00
|
|
|
|
|
|
|
slice->set_hash_field(String::kEmptyHashField);
|
|
|
|
slice->set_length(length);
|
|
|
|
slice->set_parent(*str);
|
|
|
|
slice->set_offset(offset);
|
|
|
|
return slice;
|
2011-06-22 14:20:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-10 12:38:12 +00:00
|
|
|
MaybeHandle<String> Factory::NewExternalStringFromOneByte(
|
|
|
|
const ExternalOneByteString::Resource* resource) {
|
2014-04-16 13:35:36 +00:00
|
|
|
size_t length = resource->length();
|
|
|
|
if (length > static_cast<size_t>(String::kMaxLength)) {
|
2014-09-01 09:11:44 +00:00
|
|
|
THROW_NEW_ERROR(isolate(), NewInvalidStringLengthError(), String);
|
2014-04-16 13:35:36 +00:00
|
|
|
}
|
|
|
|
|
2014-09-10 12:38:12 +00:00
|
|
|
Handle<Map> map = external_one_byte_string_map();
|
|
|
|
Handle<ExternalOneByteString> external_string =
|
|
|
|
New<ExternalOneByteString>(map, NEW_SPACE);
|
2014-04-16 13:35:36 +00:00
|
|
|
external_string->set_length(static_cast<int>(length));
|
|
|
|
external_string->set_hash_field(String::kEmptyHashField);
|
|
|
|
external_string->set_resource(resource);
|
|
|
|
|
|
|
|
return external_string;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-03 12:41:37 +00:00
|
|
|
MaybeHandle<String> Factory::NewExternalStringFromTwoByte(
|
2011-09-21 13:28:09 +00:00
|
|
|
const ExternalTwoByteString::Resource* resource) {
|
2014-04-16 13:35:36 +00:00
|
|
|
size_t length = resource->length();
|
|
|
|
if (length > static_cast<size_t>(String::kMaxLength)) {
|
2014-09-01 09:11:44 +00:00
|
|
|
THROW_NEW_ERROR(isolate(), NewInvalidStringLengthError(), String);
|
2014-04-16 13:35:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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<int>(length));
|
|
|
|
Handle<Map> map = is_one_byte ?
|
|
|
|
external_string_with_one_byte_data_map() : external_string_map();
|
|
|
|
Handle<ExternalTwoByteString> external_string =
|
|
|
|
New<ExternalTwoByteString>(map, NEW_SPACE);
|
|
|
|
external_string->set_length(static_cast<int>(length));
|
|
|
|
external_string->set_hash_field(String::kEmptyHashField);
|
|
|
|
external_string->set_resource(resource);
|
|
|
|
|
|
|
|
return external_string;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-01 10:34:31 +00:00
|
|
|
Handle<Symbol> Factory::NewSymbol() {
|
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate(),
|
|
|
|
isolate()->heap()->AllocateSymbol(),
|
|
|
|
Symbol);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-16 08:13:33 +00:00
|
|
|
Handle<Symbol> Factory::NewPrivateSymbol(Handle<Object> name) {
|
2014-04-29 13:58:55 +00:00
|
|
|
Handle<Symbol> symbol = NewSymbol();
|
|
|
|
symbol->set_is_private(true);
|
Move hash code from hidden string to a private symbol
* Hash code is now just done with a private own symbol instead of the hidden string, which predates symbols.
* In the long run we should do all hidden properties this way and get rid of the
hidden magic 0-length string with the zero hash code. The advantages include
less complexity and being able to do things from JS in a natural way.
* Initially, the performance of weak set regressed, because it's a little harder
to do the lookup in C++. Instead of heroics in C++ to make things faster I
moved some functionality into JS and got the performance back. JS is supposed to be good at looking up named properties on objects.
* This also changes hash codes of Smis so that they are always Smis.
Performance figures are in the comments to the code review. Summary: Most of js-perf-test/Collections is neutral. Set and Map with object keys are 40-50% better. WeakMap is -5% and WeakSet is +9%. After the measurements, I fixed global proxies, which cost 1% on most tests and 5% on the weak ones :-(.
In the code review comments is a patch with an example of the heroics we could do in C++ to make lookup faster (I hope we don't have to do this. Instead of checking for the property, then doing a new lookup to insert it, we could do one lookup and handle the addition immediately). With the current benchmarks above this buys us nothing, but if we go back to doing more lookups in C++ instead of in stubs and JS then it's a win.
In a similar vein we could give the magic zero hash code to the hash code
symbol. Then when we look up the hash code we would sometimes see the table
with all the hidden properties. This dual use of the field for either the hash
code or the table with all hidden properties and the hash code is rather ugly,
and this CL gets rid of it. I'd be loath to bring it back. On the benchmarks quoted above it's slightly slower than moving the hash code lookup to JS like in this CL.
One worry is that the benchmark results above are more monomorphic than real
world code, so may be overstating the performance benefits of moving to JS. I
think this is part of a general issue we have with handling polymorphic code in
JS and any solutions there will benefit this solution, which boils down to
regular property access. Any improvement there will lift all boats.
R=adamk@chromium.org, verwaest@chromium.org
BUG=
Review URL: https://codereview.chromium.org/1149863005
Cr-Commit-Position: refs/heads/master@{#28622}
2015-05-26 11:26:26 +00:00
|
|
|
if (name->IsString()) {
|
|
|
|
symbol->set_name(*name);
|
|
|
|
} else {
|
|
|
|
DCHECK(name->IsUndefined());
|
|
|
|
}
|
2014-08-12 15:28:20 +00:00
|
|
|
return symbol;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-17 09:03:08 +00:00
|
|
|
Handle<Context> Factory::NewNativeContext() {
|
2015-07-06 16:36:28 +00:00
|
|
|
Handle<FixedArray> array =
|
|
|
|
NewFixedArray(Context::NATIVE_CONTEXT_SLOTS, TENURED);
|
2014-04-07 10:12:54 +00:00
|
|
|
array->set_map_no_write_barrier(*native_context_map());
|
|
|
|
Handle<Context> context = Handle<Context>::cast(array);
|
|
|
|
context->set_js_array_maps(*undefined_value());
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(context->IsNativeContext());
|
2014-04-07 10:12:54 +00:00
|
|
|
return context;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-11-12 11:34:09 +00:00
|
|
|
Handle<Context> Factory::NewScriptContext(Handle<JSFunction> function,
|
2012-08-27 09:40:26 +00:00
|
|
|
Handle<ScopeInfo> scope_info) {
|
2014-04-09 08:51:46 +00:00
|
|
|
Handle<FixedArray> array =
|
|
|
|
NewFixedArray(scope_info->ContextLength(), TENURED);
|
2014-11-12 11:34:09 +00:00
|
|
|
array->set_map_no_write_barrier(*script_context_map());
|
2014-04-09 08:51:46 +00:00
|
|
|
Handle<Context> context = Handle<Context>::cast(array);
|
|
|
|
context->set_closure(*function);
|
|
|
|
context->set_previous(function->context());
|
|
|
|
context->set_extension(*scope_info);
|
|
|
|
context->set_global_object(function->context()->global_object());
|
2014-11-12 11:34:09 +00:00
|
|
|
DCHECK(context->IsScriptContext());
|
2014-04-09 08:51:46 +00:00
|
|
|
return context;
|
2012-08-27 09:40:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-11-12 11:34:09 +00:00
|
|
|
Handle<ScriptContextTable> Factory::NewScriptContextTable() {
|
2014-11-07 16:29:13 +00:00
|
|
|
Handle<FixedArray> array = NewFixedArray(1);
|
2014-11-12 11:34:09 +00:00
|
|
|
array->set_map_no_write_barrier(*script_context_table_map());
|
|
|
|
Handle<ScriptContextTable> context_table =
|
|
|
|
Handle<ScriptContextTable>::cast(array);
|
2014-11-07 16:29:13 +00:00
|
|
|
context_table->set_used(0);
|
|
|
|
return context_table;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-09 08:59:03 +00:00
|
|
|
Handle<Context> Factory::NewModuleContext(Handle<ScopeInfo> scope_info) {
|
2014-04-07 10:12:54 +00:00
|
|
|
Handle<FixedArray> array =
|
|
|
|
NewFixedArray(scope_info->ContextLength(), TENURED);
|
|
|
|
array->set_map_no_write_barrier(*module_context_map());
|
|
|
|
// Instance link will be set later.
|
|
|
|
Handle<Context> context = Handle<Context>::cast(array);
|
|
|
|
context->set_extension(Smi::FromInt(0));
|
|
|
|
return context;
|
2012-04-16 14:43:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
Handle<Context> Factory::NewFunctionContext(int length,
|
2011-06-29 07:41:42 +00:00
|
|
|
Handle<JSFunction> function) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(length >= Context::MIN_CONTEXT_SLOTS);
|
2014-04-09 08:51:46 +00:00
|
|
|
Handle<FixedArray> array = NewFixedArray(length);
|
|
|
|
array->set_map_no_write_barrier(*function_context_map());
|
|
|
|
Handle<Context> context = Handle<Context>::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;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-29 07:41:42 +00:00
|
|
|
Handle<Context> Factory::NewCatchContext(Handle<JSFunction> function,
|
|
|
|
Handle<Context> previous,
|
2011-06-16 06:37:49 +00:00
|
|
|
Handle<String> name,
|
|
|
|
Handle<Object> thrown_object) {
|
2014-04-09 08:51:46 +00:00
|
|
|
STATIC_ASSERT(Context::MIN_CONTEXT_SLOTS == Context::THROWN_OBJECT_INDEX);
|
|
|
|
Handle<FixedArray> array = NewFixedArray(Context::MIN_CONTEXT_SLOTS + 1);
|
|
|
|
array->set_map_no_write_barrier(*catch_context_map());
|
|
|
|
Handle<Context> context = Handle<Context>::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;
|
2011-06-09 11:26:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-29 07:41:42 +00:00
|
|
|
Handle<Context> Factory::NewWithContext(Handle<JSFunction> function,
|
|
|
|
Handle<Context> previous,
|
2014-04-09 08:51:46 +00:00
|
|
|
Handle<JSReceiver> extension) {
|
|
|
|
Handle<FixedArray> array = NewFixedArray(Context::MIN_CONTEXT_SLOTS);
|
|
|
|
array->set_map_no_write_barrier(*with_context_map());
|
|
|
|
Handle<Context> context = Handle<Context>::cast(array);
|
|
|
|
context->set_closure(*function);
|
|
|
|
context->set_previous(*previous);
|
|
|
|
context->set_extension(*extension);
|
|
|
|
context->set_global_object(previous->global_object());
|
|
|
|
return context;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-16 14:43:27 +00:00
|
|
|
Handle<Context> Factory::NewBlockContext(Handle<JSFunction> function,
|
|
|
|
Handle<Context> previous,
|
|
|
|
Handle<ScopeInfo> scope_info) {
|
2014-04-09 08:51:46 +00:00
|
|
|
Handle<FixedArray> array =
|
|
|
|
NewFixedArrayWithHoles(scope_info->ContextLength());
|
|
|
|
array->set_map_no_write_barrier(*block_context_map());
|
|
|
|
Handle<Context> context = Handle<Context>::cast(array);
|
|
|
|
context->set_closure(*function);
|
|
|
|
context->set_previous(*previous);
|
|
|
|
context->set_extension(*scope_info);
|
|
|
|
context->set_global_object(previous->global_object());
|
|
|
|
return context;
|
2011-08-11 16:29:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
Handle<Struct> Factory::NewStruct(InstanceType type) {
|
2011-03-18 20:35:07 +00:00
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate(),
|
|
|
|
isolate()->heap()->AllocateStruct(type),
|
|
|
|
Struct);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-16 12:10:56 +00:00
|
|
|
Handle<CodeCache> Factory::NewCodeCache() {
|
2014-04-16 14:04:54 +00:00
|
|
|
Handle<CodeCache> code_cache =
|
|
|
|
Handle<CodeCache>::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;
|
2014-04-16 12:10:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-14 17:30:48 +00:00
|
|
|
Handle<AliasedArgumentsEntry> Factory::NewAliasedArgumentsEntry(
|
|
|
|
int aliased_context_slot) {
|
|
|
|
Handle<AliasedArgumentsEntry> entry = Handle<AliasedArgumentsEntry>::cast(
|
|
|
|
NewStruct(ALIASED_ARGUMENTS_ENTRY_TYPE));
|
|
|
|
entry->set_aliased_context_slot(aliased_context_slot);
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-12 14:33:08 +00:00
|
|
|
Handle<ExecutableAccessorInfo> Factory::NewExecutableAccessorInfo() {
|
|
|
|
Handle<ExecutableAccessorInfo> info =
|
|
|
|
Handle<ExecutableAccessorInfo>::cast(
|
|
|
|
NewStruct(EXECUTABLE_ACCESSOR_INFO_TYPE));
|
2008-07-03 15:10:15 +00:00
|
|
|
info->set_flag(0); // Must clear the flag, it was initialized as undefined.
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Script> Factory::NewScript(Handle<String> source) {
|
2009-03-10 12:05:20 +00:00
|
|
|
// Create and initialize script object.
|
2015-03-26 09:50:34 +00:00
|
|
|
Heap* heap = isolate()->heap();
|
2008-07-03 15:10:15 +00:00
|
|
|
Handle<Script> script = Handle<Script>::cast(NewStruct(SCRIPT_TYPE));
|
|
|
|
script->set_source(*source);
|
2011-03-18 20:35:07 +00:00
|
|
|
script->set_name(heap->undefined_value());
|
2015-03-26 09:50:34 +00:00
|
|
|
script->set_id(isolate()->heap()->NextScriptId());
|
2008-07-03 15:10:15 +00:00
|
|
|
script->set_line_offset(Smi::FromInt(0));
|
|
|
|
script->set_column_offset(Smi::FromInt(0));
|
2011-03-18 20:35:07 +00:00
|
|
|
script->set_context_data(heap->undefined_value());
|
2009-06-08 10:47:49 +00:00
|
|
|
script->set_type(Smi::FromInt(Script::TYPE_NORMAL));
|
2014-10-15 10:11:08 +00:00
|
|
|
script->set_wrapper(heap->undefined_value());
|
2011-03-18 20:35:07 +00:00
|
|
|
script->set_line_ends(heap->undefined_value());
|
|
|
|
script->set_eval_from_shared(heap->undefined_value());
|
2009-06-08 10:47:49 +00:00
|
|
|
script->set_eval_from_instructions_offset(Smi::FromInt(0));
|
2015-06-25 12:19:55 +00:00
|
|
|
script->set_shared_function_infos(Smi::FromInt(0));
|
2013-07-30 17:00:05 +00:00
|
|
|
script->set_flags(Smi::FromInt(0));
|
2009-03-10 12:05:20 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
return script;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-19 11:47:34 +00:00
|
|
|
Handle<Foreign> Factory::NewForeign(Address addr, PretenureFlag pretenure) {
|
2011-03-18 20:35:07 +00:00
|
|
|
CALL_HEAP_FUNCTION(isolate(),
|
2011-05-19 11:47:34 +00:00
|
|
|
isolate()->heap()->AllocateForeign(addr, pretenure),
|
|
|
|
Foreign);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-19 11:47:34 +00:00
|
|
|
Handle<Foreign> Factory::NewForeign(const AccessorDescriptor* desc) {
|
|
|
|
return NewForeign((Address) desc, TENURED);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-25 11:07:48 +00:00
|
|
|
Handle<ByteArray> Factory::NewByteArray(int length, PretenureFlag pretenure) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(0 <= length);
|
2011-03-18 20:35:07 +00:00
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate(),
|
|
|
|
isolate()->heap()->AllocateByteArray(length, pretenure),
|
|
|
|
ByteArray);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-07-24 12:02:41 +00:00
|
|
|
Handle<BytecodeArray> Factory::NewBytecodeArray(int length,
|
2015-07-24 14:56:26 +00:00
|
|
|
const byte* raw_bytecodes,
|
|
|
|
int frame_size) {
|
2015-07-24 12:02:41 +00:00
|
|
|
DCHECK(0 <= length);
|
|
|
|
CALL_HEAP_FUNCTION(isolate(), isolate()->heap()->AllocateBytecodeArray(
|
2015-07-24 14:56:26 +00:00
|
|
|
length, raw_bytecodes, frame_size),
|
2015-07-24 12:02:41 +00:00
|
|
|
BytecodeArray);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-07-28 09:29:34 +00:00
|
|
|
Handle<FixedTypedArrayBase> Factory::NewFixedTypedArrayWithExternalPointer(
|
|
|
|
int length, ExternalArrayType array_type, void* external_pointer,
|
|
|
|
PretenureFlag pretenure) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(0 <= length && length <= Smi::kMaxValue);
|
2011-03-18 20:35:07 +00:00
|
|
|
CALL_HEAP_FUNCTION(
|
2015-07-28 09:29:34 +00:00
|
|
|
isolate(), isolate()->heap()->AllocateFixedTypedArrayWithExternalPointer(
|
|
|
|
length, array_type, external_pointer, pretenure),
|
|
|
|
FixedTypedArrayBase);
|
2009-10-20 15:26:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-16 17:08:45 +00:00
|
|
|
Handle<FixedTypedArrayBase> Factory::NewFixedTypedArray(
|
2015-06-03 07:41:28 +00:00
|
|
|
int length, ExternalArrayType array_type, bool initialize,
|
2014-01-16 17:08:45 +00:00
|
|
|
PretenureFlag pretenure) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(0 <= length && length <= Smi::kMaxValue);
|
2015-06-03 07:41:28 +00:00
|
|
|
CALL_HEAP_FUNCTION(isolate(), isolate()->heap()->AllocateFixedTypedArray(
|
|
|
|
length, array_type, initialize, pretenure),
|
|
|
|
FixedTypedArrayBase);
|
2014-01-16 17:08:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-12 15:03:44 +00:00
|
|
|
Handle<Cell> Factory::NewCell(Handle<Object> value) {
|
|
|
|
AllowDeferredHandleDereference convert_to_cell;
|
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate(),
|
|
|
|
isolate()->heap()->AllocateCell(*value),
|
|
|
|
Cell);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-17 13:27:25 +00:00
|
|
|
Handle<PropertyCell> Factory::NewPropertyCell() {
|
2011-03-18 20:35:07 +00:00
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate(),
|
2013-10-21 13:55:24 +00:00
|
|
|
isolate()->heap()->AllocatePropertyCell(),
|
2013-06-14 16:06:12 +00:00
|
|
|
PropertyCell);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-14 14:43:45 +00:00
|
|
|
Handle<WeakCell> Factory::NewWeakCell(Handle<HeapObject> value) {
|
2015-04-29 08:36:05 +00:00
|
|
|
// It is safe to dereference the value because we are embedding it
|
|
|
|
// in cell and not inspecting its fields.
|
2014-10-14 14:43:45 +00:00
|
|
|
AllowDeferredHandleDereference convert_to_cell;
|
|
|
|
CALL_HEAP_FUNCTION(isolate(), isolate()->heap()->AllocateWeakCell(*value),
|
|
|
|
WeakCell);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-08 10:02:16 +00:00
|
|
|
Handle<AllocationSite> Factory::NewAllocationSite() {
|
2014-04-16 12:54:29 +00:00
|
|
|
Handle<Map> map = allocation_site_map();
|
2015-04-07 11:31:57 +00:00
|
|
|
Handle<AllocationSite> site = New<AllocationSite>(map, OLD_SPACE);
|
2014-04-16 12:54:29 +00:00
|
|
|
site->Initialize();
|
|
|
|
|
|
|
|
// Link the site
|
|
|
|
site->set_weak_next(isolate()->heap()->allocation_sites_list());
|
|
|
|
isolate()->heap()->set_allocation_sites_list(*site);
|
|
|
|
return site;
|
2013-07-08 10:02:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-22 11:30:04 +00:00
|
|
|
Handle<Map> Factory::NewMap(InstanceType type,
|
|
|
|
int instance_size,
|
|
|
|
ElementsKind elements_kind) {
|
2011-03-18 20:35:07 +00:00
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate(),
|
2011-09-22 11:30:04 +00:00
|
|
|
isolate()->heap()->AllocateMap(type, instance_size, elements_kind),
|
2011-03-18 20:35:07 +00:00
|
|
|
Map);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-29 07:02:11 +00:00
|
|
|
Handle<JSObject> Factory::CopyJSObject(Handle<JSObject> object) {
|
|
|
|
CALL_HEAP_FUNCTION(isolate(),
|
|
|
|
isolate()->heap()->CopyJSObject(*object, NULL),
|
|
|
|
JSObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<JSObject> Factory::CopyJSObjectWithAllocationSite(
|
|
|
|
Handle<JSObject> object,
|
|
|
|
Handle<AllocationSite> site) {
|
|
|
|
CALL_HEAP_FUNCTION(isolate(),
|
|
|
|
isolate()->heap()->CopyJSObject(
|
|
|
|
*object,
|
|
|
|
site.is_null() ? NULL : *site),
|
|
|
|
JSObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-28 15:33:16 +00:00
|
|
|
Handle<FixedArray> Factory::CopyFixedArrayWithMap(Handle<FixedArray> array,
|
|
|
|
Handle<Map> map) {
|
|
|
|
CALL_HEAP_FUNCTION(isolate(),
|
|
|
|
isolate()->heap()->CopyFixedArrayWithMap(*array, *map),
|
|
|
|
FixedArray);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-08-04 17:48:42 +00:00
|
|
|
Handle<FixedArray> Factory::CopyFixedArrayAndGrow(Handle<FixedArray> array,
|
2015-08-05 08:53:17 +00:00
|
|
|
int grow_by,
|
|
|
|
PretenureFlag pretenure) {
|
|
|
|
CALL_HEAP_FUNCTION(isolate(), isolate()->heap()->CopyFixedArrayAndGrow(
|
|
|
|
*array, grow_by, pretenure),
|
2015-08-04 17:48:42 +00:00
|
|
|
FixedArray);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-28 15:33:16 +00:00
|
|
|
Handle<FixedArray> Factory::CopyFixedArray(Handle<FixedArray> array) {
|
2014-03-17 13:42:37 +00:00
|
|
|
CALL_HEAP_FUNCTION(isolate(),
|
2014-04-28 15:33:16 +00:00
|
|
|
isolate()->heap()->CopyFixedArray(*array),
|
2014-03-17 13:42:37 +00:00
|
|
|
FixedArray);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-28 15:33:16 +00:00
|
|
|
Handle<FixedArray> Factory::CopyAndTenureFixedCOWArray(
|
|
|
|
Handle<FixedArray> array) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(isolate()->heap()->InNewSpace(*array));
|
2013-10-04 07:25:24 +00:00
|
|
|
CALL_HEAP_FUNCTION(isolate(),
|
2014-04-28 15:33:16 +00:00
|
|
|
isolate()->heap()->CopyAndTenureFixedCOWArray(*array),
|
2013-10-04 07:25:24 +00:00
|
|
|
FixedArray);
|
2012-11-13 12:27:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-19 11:36:55 +00:00
|
|
|
Handle<FixedDoubleArray> Factory::CopyFixedDoubleArray(
|
|
|
|
Handle<FixedDoubleArray> array) {
|
2014-04-28 15:33:16 +00:00
|
|
|
CALL_HEAP_FUNCTION(isolate(),
|
|
|
|
isolate()->heap()->CopyFixedDoubleArray(*array),
|
|
|
|
FixedDoubleArray);
|
2011-10-19 11:36:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
Handle<Object> Factory::NewNumber(double value,
|
|
|
|
PretenureFlag pretenure) {
|
2014-04-16 14:04:54 +00:00
|
|
|
// 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.
|
2015-02-05 04:58:25 +00:00
|
|
|
if (IsMinusZero(value)) return NewHeapNumber(-0.0, IMMUTABLE, pretenure);
|
2014-04-16 14:04:54 +00:00
|
|
|
|
2014-12-18 11:12:57 +00:00
|
|
|
int int_value = FastD2IChecked(value);
|
2014-04-16 14:04:54 +00:00
|
|
|
if (value == int_value && Smi::IsValid(int_value)) {
|
|
|
|
return handle(Smi::FromInt(int_value), isolate());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Materialize the value in the heap.
|
2014-07-01 15:02:31 +00:00
|
|
|
return NewHeapNumber(value, IMMUTABLE, pretenure);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-21 10:18:47 +00:00
|
|
|
Handle<Object> Factory::NewNumberFromInt(int32_t value,
|
|
|
|
PretenureFlag pretenure) {
|
2014-04-16 14:04:54 +00:00
|
|
|
if (Smi::IsValid(value)) return handle(Smi::FromInt(value), isolate());
|
2014-07-01 15:02:31 +00:00
|
|
|
// Bypass NewNumber to avoid various redundant checks.
|
|
|
|
return NewHeapNumber(FastI2D(value), IMMUTABLE, pretenure);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-21 10:18:47 +00:00
|
|
|
Handle<Object> Factory::NewNumberFromUint(uint32_t value,
|
2014-04-30 12:25:18 +00:00
|
|
|
PretenureFlag pretenure) {
|
|
|
|
int32_t int32v = static_cast<int32_t>(value);
|
|
|
|
if (int32v >= 0 && Smi::IsValid(int32v)) {
|
|
|
|
return handle(Smi::FromInt(int32v), isolate());
|
|
|
|
}
|
2014-07-01 15:02:31 +00:00
|
|
|
return NewHeapNumber(FastUI2D(value), IMMUTABLE, pretenure);
|
2009-03-10 08:10:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-08 15:02:08 +00:00
|
|
|
Handle<HeapNumber> Factory::NewHeapNumber(double value,
|
2014-07-01 15:02:31 +00:00
|
|
|
MutableMode mode,
|
2013-05-08 15:02:08 +00:00
|
|
|
PretenureFlag pretenure) {
|
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate(),
|
2014-07-01 15:02:31 +00:00
|
|
|
isolate()->heap()->AllocateHeapNumber(value, mode, pretenure),
|
|
|
|
HeapNumber);
|
2013-05-08 15:02:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-08-03 13:02:39 +00:00
|
|
|
Handle<Float32x4> Factory::NewFloat32x4(float lanes[4],
|
2015-06-03 23:56:21 +00:00
|
|
|
PretenureFlag pretenure) {
|
2015-08-03 13:02:39 +00:00
|
|
|
CALL_HEAP_FUNCTION(isolate(),
|
|
|
|
isolate()->heap()->AllocateFloat32x4(lanes, pretenure),
|
|
|
|
Float32x4);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Int32x4> Factory::NewInt32x4(int32_t lanes[4], PretenureFlag pretenure) {
|
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate(), isolate()->heap()->AllocateInt32x4(lanes, pretenure), Int32x4);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Bool32x4> Factory::NewBool32x4(bool lanes[4], PretenureFlag pretenure) {
|
|
|
|
CALL_HEAP_FUNCTION(isolate(),
|
|
|
|
isolate()->heap()->AllocateBool32x4(lanes, pretenure),
|
|
|
|
Bool32x4);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Int16x8> Factory::NewInt16x8(int16_t lanes[8], PretenureFlag pretenure) {
|
2015-06-03 23:56:21 +00:00
|
|
|
CALL_HEAP_FUNCTION(
|
2015-08-03 13:02:39 +00:00
|
|
|
isolate(), isolate()->heap()->AllocateInt16x8(lanes, pretenure), Int16x8);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Bool16x8> Factory::NewBool16x8(bool lanes[8], PretenureFlag pretenure) {
|
|
|
|
CALL_HEAP_FUNCTION(isolate(),
|
|
|
|
isolate()->heap()->AllocateBool16x8(lanes, pretenure),
|
|
|
|
Bool16x8);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Int8x16> Factory::NewInt8x16(int8_t lanes[16], PretenureFlag pretenure) {
|
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate(), isolate()->heap()->AllocateInt8x16(lanes, pretenure), Int8x16);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Bool8x16> Factory::NewBool8x16(bool lanes[16], PretenureFlag pretenure) {
|
|
|
|
CALL_HEAP_FUNCTION(isolate(),
|
|
|
|
isolate()->heap()->AllocateBool8x16(lanes, pretenure),
|
|
|
|
Bool8x16);
|
2015-06-03 23:56:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-16 07:01:20 +00:00
|
|
|
Handle<Object> Factory::NewError(const char* maker,
|
|
|
|
MessageTemplate::Template template_index,
|
|
|
|
Handle<Object> arg0, Handle<Object> arg1,
|
|
|
|
Handle<Object> arg2) {
|
|
|
|
HandleScope scope(isolate());
|
|
|
|
Handle<String> error_maker = InternalizeUtf8String(maker);
|
2015-06-10 17:42:01 +00:00
|
|
|
if (isolate()->bootstrapper()->IsActive()) {
|
|
|
|
// If this exception is being thrown during bootstrapping,
|
|
|
|
// js_builtins_object is unavailable. We return the error maker
|
|
|
|
// name's string as the exception since we have nothing better
|
|
|
|
// to do.
|
|
|
|
return scope.CloseAndEscape(error_maker);
|
|
|
|
}
|
2015-04-16 07:01:20 +00:00
|
|
|
Handle<Object> fun_obj = Object::GetProperty(isolate()->js_builtins_object(),
|
|
|
|
error_maker).ToHandleChecked();
|
|
|
|
|
|
|
|
Handle<JSFunction> fun = Handle<JSFunction>::cast(fun_obj);
|
|
|
|
Handle<Object> message_type(Smi::FromInt(template_index), isolate());
|
|
|
|
if (arg0.is_null()) arg0 = undefined_value();
|
|
|
|
if (arg1.is_null()) arg1 = undefined_value();
|
|
|
|
if (arg2.is_null()) arg2 = undefined_value();
|
|
|
|
Handle<Object> argv[] = {message_type, arg0, arg1, arg2};
|
|
|
|
|
|
|
|
// Invoke the JavaScript factory method. If an exception is thrown while
|
|
|
|
// running the factory method, use the exception as the result.
|
|
|
|
Handle<Object> result;
|
|
|
|
MaybeHandle<Object> exception;
|
|
|
|
if (!Execution::TryCall(fun, isolate()->js_builtins_object(), arraysize(argv),
|
|
|
|
argv, &exception).ToHandle(&result)) {
|
|
|
|
Handle<Object> exception_obj;
|
|
|
|
if (exception.ToHandle(&exception_obj)) {
|
|
|
|
result = exception_obj;
|
|
|
|
} else {
|
|
|
|
result = undefined_value();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return scope.CloseAndEscape(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-17 08:35:59 +00:00
|
|
|
Handle<Object> Factory::NewError(MessageTemplate::Template template_index,
|
|
|
|
Handle<Object> arg0, Handle<Object> arg1,
|
|
|
|
Handle<Object> arg2) {
|
|
|
|
return NewError("MakeError", template_index, arg0, arg1, arg2);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Object> Factory::NewTypeError(MessageTemplate::Template template_index,
|
|
|
|
Handle<Object> arg0, Handle<Object> arg1,
|
|
|
|
Handle<Object> arg2) {
|
|
|
|
return NewError("MakeTypeError", template_index, arg0, arg1, arg2);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-15 13:32:32 +00:00
|
|
|
Handle<Object> Factory::NewSyntaxError(MessageTemplate::Template template_index,
|
|
|
|
Handle<Object> arg0, Handle<Object> arg1,
|
|
|
|
Handle<Object> arg2) {
|
|
|
|
return NewError("MakeSyntaxError", template_index, arg0, arg1, arg2);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-07 10:00:21 +00:00
|
|
|
Handle<Object> Factory::NewReferenceError(
|
|
|
|
MessageTemplate::Template template_index, Handle<Object> arg0,
|
|
|
|
Handle<Object> arg1, Handle<Object> arg2) {
|
|
|
|
return NewError("MakeReferenceError", template_index, arg0, arg1, arg2);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-06 07:51:56 +00:00
|
|
|
Handle<Object> Factory::NewRangeError(MessageTemplate::Template template_index,
|
|
|
|
Handle<Object> arg0, Handle<Object> arg1,
|
|
|
|
Handle<Object> arg2) {
|
|
|
|
return NewError("MakeRangeError", template_index, arg0, arg1, arg2);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-17 08:35:59 +00:00
|
|
|
Handle<Object> Factory::NewEvalError(MessageTemplate::Template template_index,
|
|
|
|
Handle<Object> arg0, Handle<Object> arg1,
|
|
|
|
Handle<Object> arg2) {
|
|
|
|
return NewError("MakeEvalError", template_index, arg0, arg1, arg2);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-06 13:28:22 +00:00
|
|
|
Handle<String> Factory::EmergencyNewError(const char* message,
|
2012-05-31 12:26:36 +00:00
|
|
|
Handle<JSArray> args) {
|
|
|
|
const int kBufferSize = 1000;
|
|
|
|
char buffer[kBufferSize];
|
|
|
|
size_t space = kBufferSize;
|
|
|
|
char* p = &buffer[0];
|
|
|
|
|
|
|
|
Vector<char> v(buffer, kBufferSize);
|
2014-06-13 16:43:27 +00:00
|
|
|
StrNCpy(v, message, space);
|
2013-06-06 13:28:22 +00:00
|
|
|
space -= Min(space, strlen(message));
|
2012-05-31 12:26:36 +00:00
|
|
|
p = &buffer[kBufferSize] - space;
|
|
|
|
|
2014-08-26 09:19:24 +00:00
|
|
|
for (int i = 0; i < Smi::cast(args->length())->value(); i++) {
|
2012-05-31 12:26:36 +00:00
|
|
|
if (space > 0) {
|
|
|
|
*p++ = ' ';
|
|
|
|
space--;
|
|
|
|
if (space > 0) {
|
2014-03-18 12:34:02 +00:00
|
|
|
Handle<String> arg_str = Handle<String>::cast(
|
2014-04-11 12:47:34 +00:00
|
|
|
Object::GetElement(isolate(), args, i).ToHandleChecked());
|
2015-07-13 12:38:06 +00:00
|
|
|
base::SmartArrayPointer<char> arg = arg_str->ToCString();
|
2012-06-19 13:45:30 +00:00
|
|
|
Vector<char> v2(p, static_cast<int>(space));
|
2014-06-13 16:43:27 +00:00
|
|
|
StrNCpy(v2, arg.get(), space);
|
2013-12-09 07:41:20 +00:00
|
|
|
space -= Min(space, strlen(arg.get()));
|
2012-05-31 12:26:36 +00:00
|
|
|
p = &buffer[kBufferSize] - space;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (space > 0) {
|
|
|
|
*p = '\0';
|
|
|
|
} else {
|
|
|
|
buffer[kBufferSize - 1] = '\0';
|
|
|
|
}
|
2014-04-17 13:27:02 +00:00
|
|
|
return NewStringFromUtf8(CStrVector(buffer), TENURED).ToHandleChecked();
|
2012-05-31 12:26:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-24 09:01:33 +00:00
|
|
|
Handle<Object> Factory::NewError(const char* maker, const char* message,
|
|
|
|
Handle<JSArray> args) {
|
2013-02-28 17:03:34 +00:00
|
|
|
Handle<String> make_str = InternalizeUtf8String(maker);
|
2014-04-11 12:47:34 +00:00
|
|
|
Handle<Object> fun_obj = Object::GetProperty(
|
|
|
|
isolate()->js_builtins_object(), make_str).ToHandleChecked();
|
2009-09-10 06:52:46 +00:00
|
|
|
// If the builtins haven't been properly configured yet this error
|
|
|
|
// constructor may not have been defined. Bail out.
|
2012-05-31 12:26:36 +00:00
|
|
|
if (!fun_obj->IsJSFunction()) {
|
2013-06-06 13:28:22 +00:00
|
|
|
return EmergencyNewError(message, args);
|
2012-05-31 12:26:36 +00:00
|
|
|
}
|
2009-09-10 06:52:46 +00:00
|
|
|
Handle<JSFunction> fun = Handle<JSFunction>::cast(fun_obj);
|
2013-06-06 13:28:22 +00:00
|
|
|
Handle<Object> message_obj = InternalizeUtf8String(message);
|
|
|
|
Handle<Object> argv[] = { message_obj, args };
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Invoke the JavaScript factory method. If an exception is thrown while
|
|
|
|
// running the factory method, use the exception as the result.
|
2014-04-11 10:41:09 +00:00
|
|
|
Handle<Object> result;
|
2014-09-01 09:11:44 +00:00
|
|
|
MaybeHandle<Object> exception;
|
2014-04-11 10:41:09 +00:00
|
|
|
if (!Execution::TryCall(fun,
|
|
|
|
isolate()->js_builtins_object(),
|
2014-08-26 09:19:24 +00:00
|
|
|
arraysize(argv),
|
2014-04-11 10:41:09 +00:00
|
|
|
argv,
|
|
|
|
&exception).ToHandle(&result)) {
|
2015-02-24 08:30:22 +00:00
|
|
|
Handle<Object> exception_obj;
|
|
|
|
if (exception.ToHandle(&exception_obj)) return exception_obj;
|
|
|
|
return undefined_value();
|
2014-04-11 10:41:09 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-24 09:01:33 +00:00
|
|
|
Handle<Object> Factory::NewError(const char* constructor,
|
|
|
|
Handle<String> message) {
|
2013-02-28 17:03:34 +00:00
|
|
|
Handle<String> constr = InternalizeUtf8String(constructor);
|
2014-04-11 12:47:34 +00:00
|
|
|
Handle<JSFunction> fun = Handle<JSFunction>::cast(Object::GetProperty(
|
|
|
|
isolate()->js_builtins_object(), constr).ToHandleChecked());
|
2011-10-06 09:31:38 +00:00
|
|
|
Handle<Object> argv[] = { message };
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Invoke the JavaScript factory method. If an exception is thrown while
|
|
|
|
// running the factory method, use the exception as the result.
|
2014-04-11 10:41:09 +00:00
|
|
|
Handle<Object> result;
|
2014-09-01 09:11:44 +00:00
|
|
|
MaybeHandle<Object> exception;
|
2014-04-11 10:41:09 +00:00
|
|
|
if (!Execution::TryCall(fun,
|
|
|
|
isolate()->js_builtins_object(),
|
2014-08-26 09:19:24 +00:00
|
|
|
arraysize(argv),
|
2014-04-11 10:41:09 +00:00
|
|
|
argv,
|
|
|
|
&exception).ToHandle(&result)) {
|
2015-02-24 08:30:22 +00:00
|
|
|
Handle<Object> exception_obj;
|
|
|
|
if (exception.ToHandle(&exception_obj)) return exception_obj;
|
|
|
|
return undefined_value();
|
2014-04-11 10:41:09 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-06 11:26:35 +00:00
|
|
|
void Factory::InitializeFunction(Handle<JSFunction> function,
|
|
|
|
Handle<SharedFunctionInfo> info,
|
|
|
|
Handle<Context> context) {
|
|
|
|
function->initialize_properties();
|
|
|
|
function->initialize_elements();
|
|
|
|
function->set_shared(*info);
|
|
|
|
function->set_code(info->code());
|
|
|
|
function->set_context(*context);
|
|
|
|
function->set_prototype_or_initial_map(*the_hole_value());
|
|
|
|
function->set_literals_or_bindings(*empty_fixed_array());
|
2015-05-29 08:06:19 +00:00
|
|
|
function->set_next_function_link(*undefined_value(), SKIP_WRITE_BARRIER);
|
2014-05-06 11:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<JSFunction> Factory::NewFunction(Handle<Map> map,
|
|
|
|
Handle<SharedFunctionInfo> info,
|
|
|
|
Handle<Context> context,
|
|
|
|
PretenureFlag pretenure) {
|
2015-04-07 11:31:57 +00:00
|
|
|
AllocationSpace space = pretenure == TENURED ? OLD_SPACE : NEW_SPACE;
|
2014-05-06 11:26:35 +00:00
|
|
|
Handle<JSFunction> result = New<JSFunction>(map, space);
|
|
|
|
InitializeFunction(result, info, context);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-09 17:39:54 +00:00
|
|
|
Handle<JSFunction> Factory::NewFunction(Handle<Map> map,
|
|
|
|
Handle<String> name,
|
|
|
|
MaybeHandle<Code> code) {
|
2014-07-01 12:12:34 +00:00
|
|
|
Handle<Context> context(isolate()->native_context());
|
2014-05-09 17:39:54 +00:00
|
|
|
Handle<SharedFunctionInfo> info = NewSharedFunctionInfo(name, code);
|
2015-02-04 09:34:05 +00:00
|
|
|
DCHECK(is_sloppy(info->language_mode()) &&
|
2014-05-09 17:39:54 +00:00
|
|
|
(map.is_identical_to(isolate()->sloppy_function_map()) ||
|
|
|
|
map.is_identical_to(
|
2014-05-09 17:59:15 +00:00
|
|
|
isolate()->sloppy_function_without_prototype_map()) ||
|
|
|
|
map.is_identical_to(
|
2015-04-09 22:40:16 +00:00
|
|
|
isolate()->sloppy_function_with_readonly_prototype_map()) ||
|
|
|
|
map.is_identical_to(isolate()->strict_function_map())));
|
2014-05-09 17:39:54 +00:00
|
|
|
return NewFunction(map, info, context);
|
2014-05-06 11:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-09 16:39:33 +00:00
|
|
|
Handle<JSFunction> Factory::NewFunction(Handle<String> name) {
|
2014-05-09 17:39:54 +00:00
|
|
|
return NewFunction(
|
|
|
|
isolate()->sloppy_function_map(), name, MaybeHandle<Code>());
|
2014-05-06 11:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-09 17:39:54 +00:00
|
|
|
Handle<JSFunction> Factory::NewFunctionWithoutPrototype(Handle<String> name,
|
2015-04-09 22:40:16 +00:00
|
|
|
Handle<Code> code,
|
|
|
|
bool is_strict) {
|
|
|
|
Handle<Map> map = is_strict
|
|
|
|
? isolate()->strict_function_without_prototype_map()
|
|
|
|
: isolate()->sloppy_function_without_prototype_map();
|
|
|
|
return NewFunction(map, name, code);
|
2014-05-09 17:39:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-09 22:40:16 +00:00
|
|
|
Handle<JSFunction> Factory::NewFunction(Handle<String> name, Handle<Code> code,
|
2014-05-09 17:59:15 +00:00
|
|
|
Handle<Object> prototype,
|
2015-04-09 22:40:16 +00:00
|
|
|
bool read_only_prototype,
|
|
|
|
bool is_strict) {
|
|
|
|
// In strict mode, readonly strict map is only available during bootstrap
|
|
|
|
DCHECK(!is_strict || !read_only_prototype ||
|
|
|
|
isolate()->bootstrapper()->IsActive());
|
|
|
|
Handle<Map> map =
|
|
|
|
is_strict ? isolate()->strict_function_map()
|
|
|
|
: read_only_prototype
|
|
|
|
? isolate()->sloppy_function_with_readonly_prototype_map()
|
|
|
|
: isolate()->sloppy_function_map();
|
2014-05-09 17:59:15 +00:00
|
|
|
Handle<JSFunction> result = NewFunction(map, name, code);
|
2014-05-09 17:39:54 +00:00
|
|
|
result->set_prototype_or_initial_map(*prototype);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-11-13 14:12:03 +00:00
|
|
|
Handle<JSFunction> Factory::NewFunction(Handle<String> name, Handle<Code> code,
|
2014-05-09 17:39:54 +00:00
|
|
|
Handle<Object> prototype,
|
2014-11-13 14:12:03 +00:00
|
|
|
InstanceType type, int instance_size,
|
|
|
|
bool read_only_prototype,
|
2015-04-09 22:40:16 +00:00
|
|
|
bool install_constructor,
|
|
|
|
bool is_strict) {
|
2008-07-03 15:10:15 +00:00
|
|
|
// Allocate the function
|
2015-04-09 22:40:16 +00:00
|
|
|
Handle<JSFunction> function =
|
|
|
|
NewFunction(name, code, prototype, read_only_prototype, is_strict);
|
2014-05-09 16:59:03 +00:00
|
|
|
|
2014-09-25 08:25:25 +00:00
|
|
|
ElementsKind elements_kind =
|
|
|
|
type == JS_ARRAY_TYPE ? FAST_SMI_ELEMENTS : FAST_HOLEY_SMI_ELEMENTS;
|
|
|
|
Handle<Map> initial_map = NewMap(type, instance_size, elements_kind);
|
2014-11-13 14:12:03 +00:00
|
|
|
if (!function->shared()->is_generator()) {
|
|
|
|
if (prototype->IsTheHole()) {
|
|
|
|
prototype = NewFunctionPrototype(function);
|
|
|
|
} else if (install_constructor) {
|
|
|
|
JSObject::AddProperty(Handle<JSObject>::cast(prototype),
|
|
|
|
constructor_string(), function, DONT_ENUM);
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2014-08-07 16:14:22 +00:00
|
|
|
|
2014-08-11 14:00:58 +00:00
|
|
|
JSFunction::SetInitialMap(function, initial_map,
|
|
|
|
Handle<JSReceiver>::cast(prototype));
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
return function;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-29 17:48:07 +00:00
|
|
|
Handle<JSFunction> Factory::NewFunction(Handle<String> name,
|
2014-05-09 17:39:54 +00:00
|
|
|
Handle<Code> code,
|
2014-04-29 17:48:07 +00:00
|
|
|
InstanceType type,
|
2014-05-09 17:39:54 +00:00
|
|
|
int instance_size) {
|
|
|
|
return NewFunction(name, code, the_hole_value(), type, instance_size);
|
2014-04-29 17:48:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-06 11:26:35 +00:00
|
|
|
Handle<JSObject> Factory::NewFunctionPrototype(Handle<JSFunction> function) {
|
|
|
|
// Make sure to use globals from the function's context, since the function
|
|
|
|
// can be from a different context.
|
|
|
|
Handle<Context> native_context(function->context()->native_context());
|
|
|
|
Handle<Map> new_map;
|
|
|
|
if (function->shared()->is_generator()) {
|
|
|
|
// Generator prototypes can share maps since they don't have "constructor"
|
|
|
|
// properties.
|
|
|
|
new_map = handle(native_context->generator_object_prototype_map());
|
|
|
|
} else {
|
|
|
|
// Each function prototype gets a fresh map to avoid unwanted sharing of
|
|
|
|
// maps between prototypes of different constructors.
|
|
|
|
Handle<JSFunction> object_function(native_context->object_function());
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(object_function->has_initial_map());
|
2014-08-07 16:14:22 +00:00
|
|
|
new_map = handle(object_function->initial_map());
|
2014-05-06 11:26:35 +00:00
|
|
|
}
|
|
|
|
|
2014-08-11 14:00:58 +00:00
|
|
|
DCHECK(!new_map->is_prototype_map());
|
2014-05-06 11:26:35 +00:00
|
|
|
Handle<JSObject> prototype = NewJSObjectFromMap(new_map);
|
|
|
|
|
|
|
|
if (!function->shared()->is_generator()) {
|
2014-06-30 13:48:57 +00:00
|
|
|
JSObject::AddProperty(prototype, constructor_string(), function, DONT_ENUM);
|
2014-05-06 11:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return prototype;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<JSFunction> Factory::NewFunctionFromSharedFunctionInfo(
|
|
|
|
Handle<SharedFunctionInfo> info,
|
|
|
|
Handle<Context> context,
|
|
|
|
PretenureFlag pretenure) {
|
2015-02-04 09:34:05 +00:00
|
|
|
int map_index =
|
|
|
|
Context::FunctionMapIndex(info->language_mode(), info->kind());
|
2014-05-06 11:26:35 +00:00
|
|
|
Handle<Map> map(Map::cast(context->native_context()->get(map_index)));
|
|
|
|
Handle<JSFunction> result = NewFunction(map, info, context, pretenure);
|
|
|
|
|
|
|
|
if (info->ic_age() != isolate()->heap()->global_ic_age()) {
|
|
|
|
info->ResetForNewContext(isolate()->heap()->global_ic_age());
|
|
|
|
}
|
|
|
|
|
2015-04-07 15:44:16 +00:00
|
|
|
if (FLAG_always_opt && info->allows_lazy_compilation()) {
|
|
|
|
result->MarkForOptimization();
|
|
|
|
}
|
|
|
|
|
2015-06-25 08:28:19 +00:00
|
|
|
CodeAndLiterals cached = info->SearchOptimizedCodeMap(
|
|
|
|
context->native_context(), BailoutId::None());
|
|
|
|
if (cached.code != nullptr) {
|
|
|
|
// Caching of optimized code enabled and optimized code found.
|
|
|
|
if (cached.literals != nullptr) result->set_literals(cached.literals);
|
|
|
|
DCHECK(!cached.code->marked_for_deoptimization());
|
|
|
|
DCHECK(result->shared()->is_compiled());
|
|
|
|
result->ReplaceCode(cached.code);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cached.literals == nullptr && !info->bound()) {
|
2014-05-06 11:26:35 +00:00
|
|
|
int number_of_literals = info->num_literals();
|
2015-06-26 09:07:30 +00:00
|
|
|
// TODO(mstarzinger): Consider sharing the newly created literals array.
|
2014-05-06 11:26:35 +00:00
|
|
|
Handle<FixedArray> literals = NewFixedArray(number_of_literals, pretenure);
|
|
|
|
result->set_literals(*literals);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-03 10:36:55 +00:00
|
|
|
Handle<ScopeInfo> Factory::NewScopeInfo(int length) {
|
2014-04-07 10:12:54 +00:00
|
|
|
Handle<FixedArray> array = NewFixedArray(length, TENURED);
|
|
|
|
array->set_map_no_write_barrier(*scope_info_map());
|
|
|
|
Handle<ScopeInfo> scope_info = Handle<ScopeInfo>::cast(array);
|
|
|
|
return scope_info;
|
2011-08-11 16:29:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-13 12:27:03 +00:00
|
|
|
Handle<JSObject> Factory::NewExternal(void* value) {
|
2014-04-07 10:12:54 +00:00
|
|
|
Handle<Foreign> foreign = NewForeign(static_cast<Address>(value));
|
|
|
|
Handle<JSObject> external = NewJSObjectFromMap(external_map());
|
|
|
|
external->SetInternalField(0, *foreign);
|
|
|
|
return external;
|
2012-11-13 12:27:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-29 13:58:55 +00:00
|
|
|
Handle<Code> Factory::NewCodeRaw(int object_size, bool immovable) {
|
|
|
|
CALL_HEAP_FUNCTION(isolate(),
|
|
|
|
isolate()->heap()->AllocateCode(object_size, immovable),
|
2014-04-16 11:38:56 +00:00
|
|
|
Code);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-18 09:41:16 +00:00
|
|
|
Handle<Code> Factory::NewCode(const CodeDesc& desc,
|
|
|
|
Code::Flags flags,
|
2011-03-09 10:38:19 +00:00
|
|
|
Handle<Object> self_ref,
|
2013-04-18 09:50:46 +00:00
|
|
|
bool immovable,
|
2013-10-23 13:48:04 +00:00
|
|
|
bool crankshafted,
|
2014-05-12 13:47:01 +00:00
|
|
|
int prologue_offset,
|
|
|
|
bool is_debug) {
|
2014-04-16 11:38:56 +00:00
|
|
|
Handle<ByteArray> reloc_info = NewByteArray(desc.reloc_size, TENURED);
|
|
|
|
|
|
|
|
// Compute size.
|
|
|
|
int body_size = RoundUp(desc.instr_size, kObjectAlignment);
|
|
|
|
int obj_size = Code::SizeFor(body_size);
|
|
|
|
|
2014-04-29 13:58:55 +00:00
|
|
|
Handle<Code> code = NewCodeRaw(obj_size, immovable);
|
2015-06-12 11:42:06 +00:00
|
|
|
DCHECK(isolate()->code_range() == NULL || !isolate()->code_range()->valid() ||
|
|
|
|
isolate()->code_range()->contains(code->address()) ||
|
|
|
|
obj_size <= isolate()->heap()->code_space()->AreaSize());
|
2014-04-16 11:38:56 +00:00
|
|
|
|
|
|
|
// 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));
|
2015-02-19 09:56:06 +00:00
|
|
|
code->set_ic_age(isolate()->heap()->global_ic_age());
|
2014-04-16 11:38:56 +00:00
|
|
|
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);
|
2014-07-21 13:51:42 +00:00
|
|
|
code->set_raw_type_feedback_info(Smi::FromInt(0));
|
2014-04-16 11:38:56 +00:00
|
|
|
code->set_next_code_link(*undefined_value());
|
|
|
|
code->set_handler_table(*empty_fixed_array(), SKIP_WRITE_BARRIER);
|
|
|
|
code->set_prologue_offset(prologue_offset);
|
2015-06-04 14:44:00 +00:00
|
|
|
if (FLAG_enable_embedded_constant_pool) {
|
|
|
|
code->set_constant_pool_offset(desc.instr_size - desc.constant_pool_size);
|
|
|
|
}
|
2014-04-16 11:38:56 +00:00
|
|
|
if (code->kind() == Code::OPTIMIZED_FUNCTION) {
|
|
|
|
code->set_marked_for_deoptimization(false);
|
|
|
|
}
|
|
|
|
|
2014-05-12 13:47:01 +00:00
|
|
|
if (is_debug) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(code->kind() == Code::FUNCTION);
|
2014-05-12 13:47:01 +00:00
|
|
|
code->set_has_debug_break_slots(true);
|
|
|
|
}
|
|
|
|
|
2014-04-16 11:38:56 +00:00
|
|
|
// 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
|
2014-04-30 12:25:18 +00:00
|
|
|
if (FLAG_verify_heap) code->ObjectVerify();
|
2014-04-16 11:38:56 +00:00
|
|
|
#endif
|
|
|
|
return code;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Code> Factory::CopyCode(Handle<Code> code) {
|
2011-03-18 20:35:07 +00:00
|
|
|
CALL_HEAP_FUNCTION(isolate(),
|
|
|
|
isolate()->heap()->CopyCode(*code),
|
|
|
|
Code);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-15 21:06:51 +00:00
|
|
|
Handle<Code> Factory::CopyCode(Handle<Code> code, Vector<byte> reloc_info) {
|
2011-03-18 20:35:07 +00:00
|
|
|
CALL_HEAP_FUNCTION(isolate(),
|
|
|
|
isolate()->heap()->CopyCode(*code, reloc_info),
|
|
|
|
Code);
|
2010-03-15 21:06:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
Handle<JSObject> Factory::NewJSObject(Handle<JSFunction> constructor,
|
|
|
|
PretenureFlag pretenure) {
|
2013-11-05 12:11:27 +00:00
|
|
|
JSFunction::EnsureHasInitialMap(constructor);
|
2011-03-18 20:35:07 +00:00
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate(),
|
|
|
|
isolate()->heap()->AllocateJSObject(*constructor, pretenure), JSObject);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-19 13:39:09 +00:00
|
|
|
Handle<JSObject> Factory::NewJSObjectWithMemento(
|
|
|
|
Handle<JSFunction> constructor,
|
|
|
|
Handle<AllocationSite> site) {
|
|
|
|
JSFunction::EnsureHasInitialMap(constructor);
|
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate(),
|
|
|
|
isolate()->heap()->AllocateJSObject(*constructor, NOT_TENURED, *site),
|
|
|
|
JSObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-09 08:59:03 +00:00
|
|
|
Handle<JSModule> Factory::NewJSModule(Handle<Context> context,
|
|
|
|
Handle<ScopeInfo> scope_info) {
|
2014-04-07 12:43:35 +00:00
|
|
|
// Allocate a fresh map. Modules do not have a prototype.
|
|
|
|
Handle<Map> map = NewMap(JS_MODULE_TYPE, JSModule::kSize);
|
|
|
|
// Allocate the object based on the map.
|
|
|
|
Handle<JSModule> module =
|
|
|
|
Handle<JSModule>::cast(NewJSObjectFromMap(map, TENURED));
|
|
|
|
module->set_context(*context);
|
|
|
|
module->set_scope_info(*scope_info);
|
|
|
|
return module;
|
2012-04-16 14:43:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-21 13:55:24 +00:00
|
|
|
Handle<GlobalObject> Factory::NewGlobalObject(Handle<JSFunction> constructor) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(constructor->has_initial_map());
|
2013-10-21 13:55:24 +00:00
|
|
|
Handle<Map> map(constructor->initial_map());
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(map->is_dictionary_map());
|
2013-10-21 13:55:24 +00:00
|
|
|
|
|
|
|
// Make sure no field properties are described in the initial map.
|
|
|
|
// This guarantees us that normalizing the properties does not
|
|
|
|
// require us to change property values to PropertyCells.
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(map->NextFreePropertyIndex() == 0);
|
2013-10-21 13:55:24 +00:00
|
|
|
|
|
|
|
// Make sure we don't have a ton of pre-allocated slots in the
|
|
|
|
// global objects. They will be unused once we normalize the object.
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(map->unused_property_fields() == 0);
|
|
|
|
DCHECK(map->inobject_properties() == 0);
|
2013-10-21 13:55:24 +00:00
|
|
|
|
|
|
|
// Initial size of the backing store to avoid resize of the storage during
|
|
|
|
// bootstrapping. The size differs between the JS global object ad the
|
|
|
|
// builtins object.
|
|
|
|
int initial_size = map->instance_type() == JS_GLOBAL_OBJECT_TYPE ? 64 : 512;
|
|
|
|
|
|
|
|
// Allocate a dictionary object for backing storage.
|
|
|
|
int at_least_space_for = map->NumberOfOwnDescriptors() * 2 + initial_size;
|
2015-06-01 16:24:59 +00:00
|
|
|
Handle<GlobalDictionary> dictionary =
|
|
|
|
GlobalDictionary::New(isolate(), at_least_space_for);
|
2013-10-21 13:55:24 +00:00
|
|
|
|
|
|
|
// The global object might be created from an object template with accessors.
|
|
|
|
// Fill these accessors into the dictionary.
|
|
|
|
Handle<DescriptorArray> descs(map->instance_descriptors());
|
|
|
|
for (int i = 0; i < map->NumberOfOwnDescriptors(); i++) {
|
|
|
|
PropertyDetails details = descs->GetDetails(i);
|
2015-01-19 17:49:13 +00:00
|
|
|
// Only accessors are expected.
|
|
|
|
DCHECK_EQ(ACCESSOR_CONSTANT, details.type());
|
2015-03-17 13:27:25 +00:00
|
|
|
PropertyDetails d(details.attributes(), ACCESSOR_CONSTANT, i + 1,
|
|
|
|
PropertyCellType::kMutable);
|
2013-10-21 13:55:24 +00:00
|
|
|
Handle<Name> name(descs->GetKey(i));
|
2015-03-17 13:27:25 +00:00
|
|
|
Handle<PropertyCell> cell = NewPropertyCell();
|
|
|
|
cell->set_value(descs->GetCallbacksObject(i));
|
2014-04-24 15:45:44 +00:00
|
|
|
// |dictionary| already contains enough space for all properties.
|
2015-06-01 16:24:59 +00:00
|
|
|
USE(GlobalDictionary::Add(dictionary, name, cell, d));
|
2013-10-21 13:55:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Allocate the global object and initialize it with the backing store.
|
2015-04-07 11:31:57 +00:00
|
|
|
Handle<GlobalObject> global = New<GlobalObject>(map, OLD_SPACE);
|
2013-10-21 13:55:24 +00:00
|
|
|
isolate()->heap()->InitializeJSObjectFromMap(*global, *dictionary, *map);
|
|
|
|
|
|
|
|
// Create a new map for the global object.
|
|
|
|
Handle<Map> new_map = Map::CopyDropDescriptors(map);
|
|
|
|
new_map->set_dictionary_map(true);
|
|
|
|
|
|
|
|
// Set up the global object as a normalized object.
|
|
|
|
global->set_map(*new_map);
|
|
|
|
global->set_properties(*dictionary);
|
|
|
|
|
|
|
|
// Make sure result is a global object with properties in dictionary.
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(global->IsGlobalObject() && !global->HasFastProperties());
|
2013-10-21 13:55:24 +00:00
|
|
|
return global;
|
|
|
|
}
|
|
|
|
|
2009-06-30 10:05:36 +00:00
|
|
|
|
2014-03-17 15:01:45 +00:00
|
|
|
Handle<JSObject> Factory::NewJSObjectFromMap(
|
|
|
|
Handle<Map> map,
|
|
|
|
PretenureFlag pretenure,
|
|
|
|
Handle<AllocationSite> allocation_site) {
|
2011-03-18 20:35:07 +00:00
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate(),
|
2014-03-17 15:01:45 +00:00
|
|
|
isolate()->heap()->AllocateJSObjectFromMap(
|
|
|
|
*map,
|
|
|
|
pretenure,
|
|
|
|
allocation_site.is_null() ? NULL : *allocation_site),
|
2011-03-18 20:35:07 +00:00
|
|
|
JSObject);
|
2008-09-25 07:46:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-07 10:00:14 +00:00
|
|
|
Handle<JSArray> Factory::NewJSArray(ElementsKind elements_kind,
|
2015-06-08 12:17:58 +00:00
|
|
|
Strength strength,
|
2014-04-07 10:00:14 +00:00
|
|
|
PretenureFlag pretenure) {
|
2015-06-02 11:46:04 +00:00
|
|
|
Map* map = isolate()->get_initial_js_array_map(elements_kind, strength);
|
|
|
|
if (map == nullptr) {
|
2015-06-08 12:17:58 +00:00
|
|
|
DCHECK(strength == Strength::WEAK);
|
2015-06-02 11:46:04 +00:00
|
|
|
Context* native_context = isolate()->context()->native_context();
|
|
|
|
JSFunction* array_function = native_context->array_function();
|
|
|
|
map = array_function->initial_map();
|
|
|
|
}
|
2014-04-07 12:43:35 +00:00
|
|
|
return Handle<JSArray>::cast(NewJSObjectFromMap(handle(map), pretenure));
|
2014-04-07 10:00:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-02 11:46:04 +00:00
|
|
|
Handle<JSArray> Factory::NewJSArray(ElementsKind elements_kind, int length,
|
2015-06-08 12:17:58 +00:00
|
|
|
int capacity, Strength strength,
|
2014-03-27 16:41:09 +00:00
|
|
|
ArrayStorageAllocationMode mode,
|
2008-07-03 15:10:15 +00:00
|
|
|
PretenureFlag pretenure) {
|
2015-06-02 11:46:04 +00:00
|
|
|
Handle<JSArray> array = NewJSArray(elements_kind, strength, pretenure);
|
2014-04-07 12:43:35 +00:00
|
|
|
NewJSArrayStorage(array, length, capacity, mode);
|
|
|
|
return array;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-09 08:50:19 +00:00
|
|
|
Handle<JSArray> Factory::NewJSArrayWithElements(Handle<FixedArrayBase> elements,
|
2012-01-26 21:47:57 +00:00
|
|
|
ElementsKind elements_kind,
|
2015-06-08 12:17:58 +00:00
|
|
|
int length, Strength strength,
|
2008-07-03 15:10:15 +00:00
|
|
|
PretenureFlag pretenure) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(length <= elements->length());
|
2015-06-02 11:46:04 +00:00
|
|
|
Handle<JSArray> array = NewJSArray(elements_kind, strength, pretenure);
|
2014-04-07 10:00:14 +00:00
|
|
|
|
|
|
|
array->set_elements(*elements);
|
|
|
|
array->set_length(Smi::FromInt(length));
|
|
|
|
JSObject::ValidateElements(array);
|
|
|
|
return array;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-17 15:01:45 +00:00
|
|
|
void Factory::NewJSArrayStorage(Handle<JSArray> array,
|
2014-04-14 16:05:19 +00:00
|
|
|
int length,
|
|
|
|
int capacity,
|
|
|
|
ArrayStorageAllocationMode mode) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(capacity >= length);
|
2014-04-14 16:05:19 +00:00
|
|
|
|
|
|
|
if (capacity == 0) {
|
|
|
|
array->set_length(Smi::FromInt(0));
|
|
|
|
array->set_elements(*empty_fixed_array());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-12-18 12:50:02 +00:00
|
|
|
HandleScope inner_scope(isolate());
|
2014-04-14 16:05:19 +00:00
|
|
|
Handle<FixedArrayBase> elms;
|
|
|
|
ElementsKind elements_kind = array->GetElementsKind();
|
|
|
|
if (IsFastDoubleElementsKind(elements_kind)) {
|
|
|
|
if (mode == DONT_INITIALIZE_ARRAY_ELEMENTS) {
|
|
|
|
elms = NewFixedDoubleArray(capacity);
|
|
|
|
} else {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(mode == INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE);
|
2014-04-14 16:05:19 +00:00
|
|
|
elms = NewFixedDoubleArrayWithHoles(capacity);
|
|
|
|
}
|
|
|
|
} else {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(IsFastSmiOrObjectElementsKind(elements_kind));
|
2014-04-14 16:05:19 +00:00
|
|
|
if (mode == DONT_INITIALIZE_ARRAY_ELEMENTS) {
|
|
|
|
elms = NewUninitializedFixedArray(capacity);
|
|
|
|
} else {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(mode == INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE);
|
2014-04-14 16:05:19 +00:00
|
|
|
elms = NewFixedArrayWithHoles(capacity);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
array->set_elements(*elms);
|
|
|
|
array->set_length(Smi::FromInt(length));
|
2014-03-17 15:01:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-05 12:11:27 +00:00
|
|
|
Handle<JSGeneratorObject> Factory::NewJSGeneratorObject(
|
|
|
|
Handle<JSFunction> function) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(function->shared()->is_generator());
|
2013-11-05 12:11:27 +00:00
|
|
|
JSFunction::EnsureHasInitialMap(function);
|
|
|
|
Handle<Map> map(function->initial_map());
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(map->instance_type() == JS_GENERATOR_OBJECT_TYPE);
|
2014-04-08 06:15:20 +00:00
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate(),
|
|
|
|
isolate()->heap()->AllocateJSObjectFromMap(*map),
|
|
|
|
JSGeneratorObject);
|
2013-11-05 12:11:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-22 13:43:38 +00:00
|
|
|
Handle<JSArrayBuffer> Factory::NewJSArrayBuffer(SharedFlag shared) {
|
2013-08-06 19:14:51 +00:00
|
|
|
Handle<JSFunction> array_buffer_fun(
|
2015-05-22 13:43:38 +00:00
|
|
|
shared == SharedFlag::kShared
|
|
|
|
? isolate()->native_context()->shared_array_buffer_fun()
|
|
|
|
: isolate()->native_context()->array_buffer_fun());
|
2014-04-08 06:15:20 +00:00
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate(),
|
|
|
|
isolate()->heap()->AllocateJSObject(*array_buffer_fun),
|
|
|
|
JSArrayBuffer);
|
2013-04-25 12:02:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-21 13:02:38 +00:00
|
|
|
Handle<JSDataView> Factory::NewJSDataView() {
|
2013-08-06 19:14:51 +00:00
|
|
|
Handle<JSFunction> data_view_fun(
|
2014-07-01 12:12:34 +00:00
|
|
|
isolate()->native_context()->data_view_fun());
|
2014-04-08 06:15:20 +00:00
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate(),
|
|
|
|
isolate()->heap()->AllocateJSObject(*data_view_fun),
|
|
|
|
JSDataView);
|
2013-06-21 13:02:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-26 17:36:48 +00:00
|
|
|
Handle<JSMap> Factory::NewJSMap() {
|
|
|
|
Handle<Map> map(isolate()->native_context()->js_map_map());
|
|
|
|
Handle<JSMap> js_map = Handle<JSMap>::cast(NewJSObjectFromMap(map));
|
|
|
|
Runtime::JSMapInitialize(isolate(), js_map);
|
|
|
|
return js_map;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<JSSet> Factory::NewJSSet() {
|
|
|
|
Handle<Map> map(isolate()->native_context()->js_set_map());
|
|
|
|
Handle<JSSet> js_set = Handle<JSSet>::cast(NewJSObjectFromMap(map));
|
|
|
|
Runtime::JSSetInitialize(isolate(), js_set);
|
|
|
|
return js_set;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-11-04 10:02:25 +00:00
|
|
|
Handle<JSMapIterator> Factory::NewJSMapIterator() {
|
|
|
|
Handle<Map> map(isolate()->native_context()->map_iterator_map());
|
|
|
|
CALL_HEAP_FUNCTION(isolate(),
|
|
|
|
isolate()->heap()->AllocateJSObjectFromMap(*map),
|
|
|
|
JSMapIterator);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<JSSetIterator> Factory::NewJSSetIterator() {
|
|
|
|
Handle<Map> map(isolate()->native_context()->set_iterator_map());
|
|
|
|
CALL_HEAP_FUNCTION(isolate(),
|
|
|
|
isolate()->heap()->AllocateJSObjectFromMap(*map),
|
|
|
|
JSSetIterator);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-07 07:36:21 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
ElementsKind GetExternalArrayElementsKind(ExternalArrayType type) {
|
|
|
|
switch (type) {
|
|
|
|
#define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \
|
|
|
|
case kExternal##Type##Array: \
|
2015-07-28 09:29:34 +00:00
|
|
|
return TYPE##_ELEMENTS;
|
2014-10-07 07:36:21 +00:00
|
|
|
TYPED_ARRAYS(TYPED_ARRAY_CASE)
|
|
|
|
}
|
|
|
|
UNREACHABLE();
|
2015-07-28 09:29:34 +00:00
|
|
|
return FIRST_FIXED_TYPED_ARRAY_ELEMENTS_KIND;
|
2014-10-07 07:36:21 +00:00
|
|
|
#undef TYPED_ARRAY_CASE
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-10 08:10:29 +00:00
|
|
|
size_t GetExternalArrayElementSize(ExternalArrayType type) {
|
|
|
|
switch (type) {
|
|
|
|
#define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \
|
|
|
|
case kExternal##Type##Array: \
|
|
|
|
return size;
|
|
|
|
TYPED_ARRAYS(TYPED_ARRAY_CASE)
|
2015-04-27 09:28:16 +00:00
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#undef TYPED_ARRAY_CASE
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
size_t GetFixedTypedArraysElementSize(ElementsKind kind) {
|
|
|
|
switch (kind) {
|
|
|
|
#define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \
|
|
|
|
case TYPE##_ELEMENTS: \
|
|
|
|
return size;
|
|
|
|
TYPED_ARRAYS(TYPED_ARRAY_CASE)
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#undef TYPED_ARRAY_CASE
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ExternalArrayType GetArrayTypeFromElementsKind(ElementsKind kind) {
|
|
|
|
switch (kind) {
|
|
|
|
#define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \
|
|
|
|
case TYPE##_ELEMENTS: \
|
|
|
|
return kExternal##Type##Array;
|
|
|
|
TYPED_ARRAYS(TYPED_ARRAY_CASE)
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
return kExternalInt8Array;
|
2014-10-10 08:10:29 +00:00
|
|
|
}
|
|
|
|
#undef TYPED_ARRAY_CASE
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-07 07:36:21 +00:00
|
|
|
JSFunction* GetTypedArrayFun(ExternalArrayType type, Isolate* isolate) {
|
2013-08-06 19:14:51 +00:00
|
|
|
Context* native_context = isolate->context()->native_context();
|
2013-04-29 11:09:03 +00:00
|
|
|
switch (type) {
|
2014-01-24 16:01:15 +00:00
|
|
|
#define TYPED_ARRAY_FUN(Type, type, TYPE, ctype, size) \
|
|
|
|
case kExternal##Type##Array: \
|
|
|
|
return native_context->type##_array_fun();
|
2013-04-29 11:09:03 +00:00
|
|
|
|
2014-01-24 16:01:15 +00:00
|
|
|
TYPED_ARRAYS(TYPED_ARRAY_FUN)
|
|
|
|
#undef TYPED_ARRAY_FUN
|
2013-05-02 11:36:48 +00:00
|
|
|
|
2013-04-29 11:09:03 +00:00
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
2013-08-06 19:14:51 +00:00
|
|
|
return NULL;
|
2013-04-29 11:09:03 +00:00
|
|
|
}
|
2013-08-06 19:14:51 +00:00
|
|
|
}
|
|
|
|
|
2014-10-17 09:04:58 +00:00
|
|
|
|
2015-04-27 09:28:16 +00:00
|
|
|
JSFunction* GetTypedArrayFun(ElementsKind elements_kind, Isolate* isolate) {
|
|
|
|
Context* native_context = isolate->context()->native_context();
|
|
|
|
switch (elements_kind) {
|
|
|
|
#define TYPED_ARRAY_FUN(Type, type, TYPE, ctype, size) \
|
|
|
|
case TYPE##_ELEMENTS: \
|
|
|
|
return native_context->type##_array_fun();
|
|
|
|
|
|
|
|
TYPED_ARRAYS(TYPED_ARRAY_FUN)
|
|
|
|
#undef TYPED_ARRAY_FUN
|
|
|
|
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-17 09:04:58 +00:00
|
|
|
void SetupArrayBufferView(i::Isolate* isolate,
|
|
|
|
i::Handle<i::JSArrayBufferView> obj,
|
|
|
|
i::Handle<i::JSArrayBuffer> buffer,
|
|
|
|
size_t byte_offset, size_t byte_length) {
|
|
|
|
DCHECK(byte_offset + byte_length <=
|
|
|
|
static_cast<size_t>(buffer->byte_length()->Number()));
|
|
|
|
|
|
|
|
obj->set_buffer(*buffer);
|
|
|
|
|
|
|
|
i::Handle<i::Object> byte_offset_object =
|
|
|
|
isolate->factory()->NewNumberFromSize(byte_offset);
|
|
|
|
obj->set_byte_offset(*byte_offset_object);
|
|
|
|
|
|
|
|
i::Handle<i::Object> byte_length_object =
|
|
|
|
isolate->factory()->NewNumberFromSize(byte_length);
|
|
|
|
obj->set_byte_length(*byte_length_object);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-07 07:36:21 +00:00
|
|
|
} // namespace
|
|
|
|
|
2013-08-06 19:14:51 +00:00
|
|
|
|
|
|
|
Handle<JSTypedArray> Factory::NewJSTypedArray(ExternalArrayType type) {
|
|
|
|
Handle<JSFunction> typed_array_fun_handle(GetTypedArrayFun(type, isolate()));
|
2014-04-08 06:15:20 +00:00
|
|
|
|
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate(),
|
|
|
|
isolate()->heap()->AllocateJSObject(*typed_array_fun_handle),
|
|
|
|
JSTypedArray);
|
2013-04-29 11:09:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-27 09:28:16 +00:00
|
|
|
Handle<JSTypedArray> Factory::NewJSTypedArray(ElementsKind elements_kind) {
|
|
|
|
Handle<JSFunction> typed_array_fun_handle(
|
|
|
|
GetTypedArrayFun(elements_kind, isolate()));
|
|
|
|
|
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate(), isolate()->heap()->AllocateJSObject(*typed_array_fun_handle),
|
|
|
|
JSTypedArray);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-07 07:36:21 +00:00
|
|
|
Handle<JSTypedArray> Factory::NewJSTypedArray(ExternalArrayType type,
|
|
|
|
Handle<JSArrayBuffer> buffer,
|
2014-10-17 09:04:58 +00:00
|
|
|
size_t byte_offset,
|
2014-10-07 07:36:21 +00:00
|
|
|
size_t length) {
|
2014-10-17 09:04:58 +00:00
|
|
|
Handle<JSTypedArray> obj = NewJSTypedArray(type);
|
|
|
|
|
|
|
|
size_t element_size = GetExternalArrayElementSize(type);
|
|
|
|
ElementsKind elements_kind = GetExternalArrayElementsKind(type);
|
|
|
|
|
|
|
|
CHECK(byte_offset % element_size == 0);
|
|
|
|
|
|
|
|
CHECK(length <= (std::numeric_limits<size_t>::max() / element_size));
|
|
|
|
CHECK(length <= static_cast<size_t>(Smi::kMaxValue));
|
|
|
|
size_t byte_length = length * element_size;
|
|
|
|
SetupArrayBufferView(isolate(), obj, buffer, byte_offset, byte_length);
|
|
|
|
|
|
|
|
Handle<Object> length_object = NewNumberFromSize(length);
|
|
|
|
obj->set_length(*length_object);
|
|
|
|
|
2015-07-28 09:29:34 +00:00
|
|
|
Handle<FixedTypedArrayBase> elements = NewFixedTypedArrayWithExternalPointer(
|
2014-10-17 09:04:58 +00:00
|
|
|
static_cast<int>(length), type,
|
|
|
|
static_cast<uint8_t*>(buffer->backing_store()) + byte_offset);
|
|
|
|
Handle<Map> map = JSObject::GetElementsTransitionMap(obj, elements_kind);
|
|
|
|
JSObject::SetMapAndElements(obj, map, elements);
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-27 09:28:16 +00:00
|
|
|
Handle<JSTypedArray> Factory::NewJSTypedArray(ElementsKind elements_kind,
|
|
|
|
size_t number_of_elements) {
|
|
|
|
Handle<JSTypedArray> obj = NewJSTypedArray(elements_kind);
|
|
|
|
|
|
|
|
size_t element_size = GetFixedTypedArraysElementSize(elements_kind);
|
|
|
|
ExternalArrayType array_type = GetArrayTypeFromElementsKind(elements_kind);
|
|
|
|
|
|
|
|
CHECK(number_of_elements <=
|
|
|
|
(std::numeric_limits<size_t>::max() / element_size));
|
|
|
|
CHECK(number_of_elements <= static_cast<size_t>(Smi::kMaxValue));
|
|
|
|
size_t byte_length = number_of_elements * element_size;
|
|
|
|
|
|
|
|
obj->set_byte_offset(Smi::FromInt(0));
|
|
|
|
i::Handle<i::Object> byte_length_object =
|
|
|
|
isolate()->factory()->NewNumberFromSize(byte_length);
|
|
|
|
obj->set_byte_length(*byte_length_object);
|
|
|
|
Handle<Object> length_object = NewNumberFromSize(number_of_elements);
|
|
|
|
obj->set_length(*length_object);
|
|
|
|
|
2015-04-30 13:46:27 +00:00
|
|
|
Handle<JSArrayBuffer> buffer = isolate()->factory()->NewJSArrayBuffer();
|
2015-05-22 13:43:38 +00:00
|
|
|
Runtime::SetupArrayBuffer(isolate(), buffer, true, NULL, byte_length,
|
|
|
|
SharedFlag::kNotShared);
|
2015-04-30 13:46:27 +00:00
|
|
|
obj->set_buffer(*buffer);
|
2015-04-27 09:28:16 +00:00
|
|
|
Handle<FixedTypedArrayBase> elements =
|
|
|
|
isolate()->factory()->NewFixedTypedArray(
|
2015-06-03 07:41:28 +00:00
|
|
|
static_cast<int>(number_of_elements), array_type, true);
|
2015-04-27 09:28:16 +00:00
|
|
|
obj->set_elements(*elements);
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-17 09:04:58 +00:00
|
|
|
Handle<JSDataView> Factory::NewJSDataView(Handle<JSArrayBuffer> buffer,
|
|
|
|
size_t byte_offset,
|
|
|
|
size_t byte_length) {
|
|
|
|
Handle<JSDataView> obj = NewJSDataView();
|
|
|
|
SetupArrayBufferView(isolate(), obj, buffer, byte_offset, byte_length);
|
|
|
|
return obj;
|
2014-10-07 07:36:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-13 10:58:25 +00:00
|
|
|
Handle<JSProxy> Factory::NewJSProxy(Handle<Object> handler,
|
|
|
|
Handle<Object> prototype) {
|
2014-04-16 13:35:36 +00:00
|
|
|
// 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> map = NewMap(JS_PROXY_TYPE, JSProxy::kSize);
|
2015-04-10 12:13:18 +00:00
|
|
|
Map::SetPrototype(map, prototype);
|
2014-04-16 13:35:36 +00:00
|
|
|
|
|
|
|
// Allocate the proxy object.
|
|
|
|
Handle<JSProxy> result = New<JSProxy>(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;
|
2011-05-13 10:58:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-15 10:59:38 +00:00
|
|
|
Handle<JSProxy> Factory::NewJSFunctionProxy(Handle<Object> handler,
|
|
|
|
Handle<Object> call_trap,
|
|
|
|
Handle<Object> construct_trap,
|
|
|
|
Handle<Object> prototype) {
|
2014-04-16 13:35:36 +00:00
|
|
|
// 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> map = NewMap(JS_FUNCTION_PROXY_TYPE, JSFunctionProxy::kSize);
|
2015-04-10 12:13:18 +00:00
|
|
|
Map::SetPrototype(map, prototype);
|
2014-04-16 13:35:36 +00:00
|
|
|
|
|
|
|
// Allocate the proxy object.
|
|
|
|
Handle<JSFunctionProxy> result = New<JSFunctionProxy>(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;
|
2014-04-15 10:59:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-27 15:54:23 +00:00
|
|
|
void Factory::ReinitializeJSProxy(Handle<JSProxy> proxy, InstanceType type,
|
|
|
|
int size) {
|
|
|
|
DCHECK(type == JS_OBJECT_TYPE || type == JS_FUNCTION_TYPE);
|
2014-04-15 11:51:34 +00:00
|
|
|
|
2015-06-02 11:29:22 +00:00
|
|
|
Handle<Map> proxy_map(proxy->map());
|
|
|
|
Handle<Map> map = Map::FixProxy(proxy_map, type, size);
|
2014-04-15 11:51:34 +00:00
|
|
|
|
|
|
|
// Check that the receiver has at least the size of the fresh object.
|
2015-06-02 11:29:22 +00:00
|
|
|
int size_difference = proxy_map->instance_size() - map->instance_size();
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(size_difference >= 0);
|
2014-04-15 11:51:34 +00:00
|
|
|
|
|
|
|
// Allocate the backing storage for the properties.
|
2015-07-13 08:26:21 +00:00
|
|
|
Handle<FixedArray> properties = empty_fixed_array();
|
2014-04-15 11:51:34 +00:00
|
|
|
|
|
|
|
Heap* heap = isolate()->heap();
|
|
|
|
MaybeHandle<SharedFunctionInfo> shared;
|
|
|
|
if (type == JS_FUNCTION_TYPE) {
|
2014-09-10 12:38:12 +00:00
|
|
|
OneByteStringKey key(STATIC_CHAR_VECTOR("<freezing call trap>"),
|
2014-04-15 11:51:34 +00:00
|
|
|
heap->HashSeed());
|
|
|
|
Handle<String> name = InternalizeStringWithKey(&key);
|
2014-05-09 17:39:54 +00:00
|
|
|
shared = NewSharedFunctionInfo(name, MaybeHandle<Code>());
|
2014-04-15 11:51:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
2014-06-24 14:53:48 +00:00
|
|
|
// Put in filler if the new object is smaller than the old.
|
|
|
|
if (size_difference > 0) {
|
2014-08-27 15:54:23 +00:00
|
|
|
Address address = proxy->address();
|
2014-07-28 18:15:35 +00:00
|
|
|
heap->CreateFillerObjectAt(address + map->instance_size(), size_difference);
|
2015-08-04 07:02:42 +00:00
|
|
|
heap->AdjustLiveBytes(*proxy, -size_difference,
|
2015-04-16 08:39:19 +00:00
|
|
|
Heap::CONCURRENT_TO_SWEEPER);
|
2014-06-24 14:53:48 +00:00
|
|
|
}
|
|
|
|
|
2014-04-15 11:51:34 +00:00
|
|
|
// Reset the map for the object.
|
2014-08-27 15:54:23 +00:00
|
|
|
proxy->synchronized_set_map(*map);
|
|
|
|
Handle<JSObject> jsobj = Handle<JSObject>::cast(proxy);
|
2014-04-15 11:51:34 +00:00
|
|
|
|
|
|
|
// Reinitialize the object from the constructor map.
|
|
|
|
heap->InitializeJSObjectFromMap(*jsobj, *properties, *map);
|
|
|
|
|
2014-08-27 15:54:23 +00:00
|
|
|
// The current native context is used to set up certain bits.
|
|
|
|
// TODO(adamk): Using the current context seems wrong, it should be whatever
|
|
|
|
// context the JSProxy originated in. But that context isn't stored anywhere.
|
|
|
|
Handle<Context> context(isolate()->native_context());
|
|
|
|
|
2014-04-15 11:51:34 +00:00
|
|
|
// Functions require some minimal initialization.
|
|
|
|
if (type == JS_FUNCTION_TYPE) {
|
|
|
|
map->set_function_with_prototype(true);
|
2014-08-27 15:54:23 +00:00
|
|
|
Handle<JSFunction> js_function = Handle<JSFunction>::cast(proxy);
|
2014-05-06 11:26:35 +00:00
|
|
|
InitializeFunction(js_function, shared.ToHandleChecked(), context);
|
2014-08-27 15:54:23 +00:00
|
|
|
} else {
|
|
|
|
// Provide JSObjects with a constructor.
|
2015-02-24 20:50:06 +00:00
|
|
|
map->SetConstructor(context->object_function());
|
2014-04-15 11:51:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-14 16:42:15 +00:00
|
|
|
Handle<JSGlobalProxy> Factory::NewUninitializedJSGlobalProxy() {
|
|
|
|
// Create an empty shell of a JSGlobalProxy that needs to be reinitialized
|
|
|
|
// via ReinitializeJSGlobalProxy later.
|
|
|
|
Handle<Map> map = NewMap(JS_GLOBAL_PROXY_TYPE, JSGlobalProxy::kSize);
|
|
|
|
// Maintain invariant expected from any JSGlobalProxy.
|
|
|
|
map->set_is_access_check_needed(true);
|
2015-07-13 08:26:21 +00:00
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate(), isolate()->heap()->AllocateJSObjectFromMap(*map, NOT_TENURED),
|
|
|
|
JSGlobalProxy);
|
2015-01-14 16:42:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-15 11:51:34 +00:00
|
|
|
void Factory::ReinitializeJSGlobalProxy(Handle<JSGlobalProxy> object,
|
|
|
|
Handle<JSFunction> constructor) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(constructor->has_initial_map());
|
2014-04-15 11:51:34 +00:00
|
|
|
Handle<Map> map(constructor->initial_map(), isolate());
|
|
|
|
|
2014-05-05 18:27:57 +00:00
|
|
|
// The proxy's hash should be retained across reinitialization.
|
|
|
|
Handle<Object> hash(object->hash(), isolate());
|
|
|
|
|
2014-04-15 11:51:34 +00:00
|
|
|
// Check that the already allocated object has the same size and type as
|
|
|
|
// objects allocated using the constructor.
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(map->instance_size() == object->map()->instance_size());
|
|
|
|
DCHECK(map->instance_type() == object->map()->instance_type());
|
2014-04-15 11:51:34 +00:00
|
|
|
|
|
|
|
// Allocate the backing storage for the properties.
|
2015-07-13 08:26:21 +00:00
|
|
|
Handle<FixedArray> properties = empty_fixed_array();
|
2014-04-15 11:51:34 +00:00
|
|
|
|
|
|
|
// 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.
|
2014-06-24 14:53:48 +00:00
|
|
|
object->synchronized_set_map(*map);
|
2014-04-15 11:51:34 +00:00
|
|
|
|
|
|
|
Heap* heap = isolate()->heap();
|
|
|
|
// Reinitialize the object from the constructor map.
|
|
|
|
heap->InitializeJSObjectFromMap(*object, *properties, *map);
|
2014-05-05 18:27:57 +00:00
|
|
|
|
|
|
|
// Restore the saved hash.
|
|
|
|
object->set_hash(*hash);
|
2014-04-15 11:51:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-27 15:54:23 +00:00
|
|
|
void Factory::BecomeJSObject(Handle<JSProxy> proxy) {
|
|
|
|
ReinitializeJSProxy(proxy, JS_OBJECT_TYPE, JSObject::kHeaderSize);
|
2011-09-13 11:42:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-27 15:54:23 +00:00
|
|
|
void Factory::BecomeJSFunction(Handle<JSProxy> proxy) {
|
|
|
|
ReinitializeJSProxy(proxy, JS_FUNCTION_TYPE, JSFunction::kSize);
|
2011-07-18 13:04:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-17 15:16:21 +00:00
|
|
|
template Handle<TypeFeedbackVector> Factory::NewTypeFeedbackVector(
|
|
|
|
const ZoneFeedbackVectorSpec* spec);
|
|
|
|
template Handle<TypeFeedbackVector> Factory::NewTypeFeedbackVector(
|
|
|
|
const FeedbackVectorSpec* spec);
|
|
|
|
|
|
|
|
template <typename Spec>
|
|
|
|
Handle<TypeFeedbackVector> Factory::NewTypeFeedbackVector(const Spec* spec) {
|
|
|
|
return TypeFeedbackVector::Allocate<Spec>(isolate(), spec);
|
2014-04-30 10:51:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-23 06:04:44 +00:00
|
|
|
Handle<SharedFunctionInfo> Factory::NewSharedFunctionInfo(
|
2014-09-10 16:39:42 +00:00
|
|
|
Handle<String> name, int number_of_literals, FunctionKind kind,
|
|
|
|
Handle<Code> code, Handle<ScopeInfo> scope_info,
|
2014-09-18 09:59:53 +00:00
|
|
|
Handle<TypeFeedbackVector> feedback_vector) {
|
2014-09-10 16:39:42 +00:00
|
|
|
DCHECK(IsValidFunctionKind(kind));
|
2014-05-09 17:39:54 +00:00
|
|
|
Handle<SharedFunctionInfo> shared = NewSharedFunctionInfo(name, code);
|
2010-07-13 13:06:33 +00:00
|
|
|
shared->set_scope_info(*scope_info);
|
2014-04-30 10:51:01 +00:00
|
|
|
shared->set_feedback_vector(*feedback_vector);
|
2014-09-10 16:39:42 +00:00
|
|
|
shared->set_kind(kind);
|
2015-02-25 22:41:40 +00:00
|
|
|
shared->set_num_literals(number_of_literals);
|
2014-09-10 16:39:42 +00:00
|
|
|
if (IsGeneratorFunction(kind)) {
|
2013-04-17 15:01:25 +00:00
|
|
|
shared->set_instance_class_name(isolate()->heap()->Generator_string());
|
2013-08-07 09:33:09 +00:00
|
|
|
shared->DisableOptimization(kGenerator);
|
2013-04-17 15:01:25 +00:00
|
|
|
}
|
2010-03-23 06:04:44 +00:00
|
|
|
return shared;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-02 13:31:52 +00:00
|
|
|
Handle<JSMessageObject> Factory::NewJSMessageObject(
|
2015-05-18 08:34:05 +00:00
|
|
|
MessageTemplate::Template message, Handle<Object> argument,
|
|
|
|
int start_position, int end_position, Handle<Object> script,
|
2011-02-02 13:31:52 +00:00
|
|
|
Handle<Object> stack_frames) {
|
2014-04-16 13:35:36 +00:00
|
|
|
Handle<Map> map = message_object_map();
|
2015-05-18 08:34:05 +00:00
|
|
|
Handle<JSMessageObject> message_obj = New<JSMessageObject>(map, NEW_SPACE);
|
|
|
|
message_obj->set_properties(*empty_fixed_array(), SKIP_WRITE_BARRIER);
|
|
|
|
message_obj->initialize_elements();
|
|
|
|
message_obj->set_elements(*empty_fixed_array(), SKIP_WRITE_BARRIER);
|
|
|
|
message_obj->set_type(message);
|
|
|
|
message_obj->set_argument(*argument);
|
|
|
|
message_obj->set_start_position(start_position);
|
|
|
|
message_obj->set_end_position(end_position);
|
|
|
|
message_obj->set_script(*script);
|
|
|
|
message_obj->set_stack_frames(*stack_frames);
|
|
|
|
return message_obj;
|
2011-02-02 13:31:52 +00:00
|
|
|
}
|
|
|
|
|
2013-07-05 09:52:11 +00:00
|
|
|
|
2014-05-09 17:39:54 +00:00
|
|
|
Handle<SharedFunctionInfo> Factory::NewSharedFunctionInfo(
|
|
|
|
Handle<String> name,
|
|
|
|
MaybeHandle<Code> maybe_code) {
|
2014-04-16 13:35:36 +00:00
|
|
|
Handle<Map> map = shared_function_info_map();
|
2015-04-07 11:31:57 +00:00
|
|
|
Handle<SharedFunctionInfo> share = New<SharedFunctionInfo>(map, OLD_SPACE);
|
2014-04-16 13:35:36 +00:00
|
|
|
|
|
|
|
// Set pointer fields.
|
|
|
|
share->set_name(*name);
|
2014-05-09 17:39:54 +00:00
|
|
|
Handle<Code> code;
|
|
|
|
if (!maybe_code.ToHandle(&code)) {
|
|
|
|
code = handle(isolate()->builtins()->builtin(Builtins::kIllegal));
|
|
|
|
}
|
|
|
|
share->set_code(*code);
|
2014-04-16 13:35:36 +00:00
|
|
|
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);
|
2015-03-17 15:16:21 +00:00
|
|
|
FeedbackVectorSpec empty_spec(0);
|
2014-11-27 16:36:18 +00:00
|
|
|
Handle<TypeFeedbackVector> feedback_vector =
|
2015-03-17 15:16:21 +00:00
|
|
|
NewTypeFeedbackVector(&empty_spec);
|
2014-09-18 13:24:02 +00:00
|
|
|
share->set_feedback_vector(*feedback_vector, SKIP_WRITE_BARRIER);
|
2014-11-07 16:03:11 +00:00
|
|
|
#if TRACE_MAPS
|
|
|
|
share->set_unique_id(isolate()->GetNextUniqueSharedFunctionInfoId());
|
|
|
|
#endif
|
2014-04-23 07:07:54 +00:00
|
|
|
share->set_profiler_ticks(0);
|
2014-04-16 13:35:36 +00:00
|
|
|
share->set_ast_node_count(0);
|
|
|
|
share->set_counters(0);
|
|
|
|
|
|
|
|
// Set integer fields (smi or int, depending on the architecture).
|
|
|
|
share->set_length(0);
|
2015-02-11 09:47:32 +00:00
|
|
|
share->set_internal_formal_parameter_count(0);
|
2014-04-16 13:35:36 +00:00
|
|
|
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;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-16 14:04:54 +00:00
|
|
|
static inline int NumberCacheHash(Handle<FixedArray> cache,
|
|
|
|
Handle<Object> number) {
|
|
|
|
int mask = (cache->length() >> 1) - 1;
|
|
|
|
if (number->IsSmi()) {
|
|
|
|
return Handle<Smi>::cast(number)->value() & mask;
|
|
|
|
} else {
|
|
|
|
DoubleRepresentation rep(number->Number());
|
|
|
|
return
|
|
|
|
(static_cast<int>(rep.bits) ^ static_cast<int>(rep.bits >> 32)) & mask;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Object> Factory::GetNumberStringCache(Handle<Object> 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>(
|
|
|
|
String::cast(number_string_cache()->get(hash * 2 + 1)), isolate());
|
|
|
|
}
|
|
|
|
return undefined_value();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Factory::SetNumberStringCache(Handle<Object> number,
|
|
|
|
Handle<String> 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) {
|
|
|
|
Handle<FixedArray> 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-15 11:16:02 +00:00
|
|
|
Handle<String> Factory::NumberToString(Handle<Object> number,
|
|
|
|
bool check_number_string_cache) {
|
2014-04-16 14:04:54 +00:00
|
|
|
isolate()->counters()->number_to_string_runtime()->Increment();
|
|
|
|
if (check_number_string_cache) {
|
|
|
|
Handle<Object> cached = GetNumberStringCache(number);
|
|
|
|
if (!cached->IsUndefined()) return Handle<String>::cast(cached);
|
|
|
|
}
|
2009-10-02 13:43:16 +00:00
|
|
|
|
2014-04-16 14:04:54 +00:00
|
|
|
char arr[100];
|
2014-08-26 09:19:24 +00:00
|
|
|
Vector<char> buffer(arr, arraysize(arr));
|
2014-04-16 14:04:54 +00:00
|
|
|
const char* str;
|
|
|
|
if (number->IsSmi()) {
|
|
|
|
int num = Handle<Smi>::cast(number)->value();
|
|
|
|
str = IntToCString(num, buffer);
|
|
|
|
} else {
|
|
|
|
double num = Handle<HeapNumber>::cast(number)->value();
|
|
|
|
str = DoubleToCString(num, buffer);
|
|
|
|
}
|
2009-10-02 13:43:16 +00:00
|
|
|
|
2014-04-16 14:04:54 +00:00
|
|
|
// We tenure the allocated string since it is referenced from the
|
|
|
|
// number-string cache which lives in the old space.
|
2014-04-17 13:27:02 +00:00
|
|
|
Handle<String> js_string = NewStringFromAsciiChecked(str, TENURED);
|
2014-04-16 14:04:54 +00:00
|
|
|
SetNumberStringCache(number, js_string);
|
|
|
|
return js_string;
|
2011-09-22 10:45:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-01 10:15:45 +00:00
|
|
|
Handle<DebugInfo> Factory::NewDebugInfo(Handle<SharedFunctionInfo> shared) {
|
|
|
|
// Allocate initial fixed array for active break points before allocating the
|
|
|
|
// debug info object to avoid allocation while setting up the debug info
|
|
|
|
// object.
|
|
|
|
Handle<FixedArray> break_points(
|
2014-06-02 12:51:19 +00:00
|
|
|
NewFixedArray(DebugInfo::kEstimatedNofBreakPointsInFunction));
|
2008-09-01 10:15:45 +00:00
|
|
|
|
|
|
|
// Create and set up the debug info object. Debug info contains function, a
|
|
|
|
// copy of the original code, the executing code and initial fixed array for
|
|
|
|
// active break points.
|
|
|
|
Handle<DebugInfo> debug_info =
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<DebugInfo>::cast(NewStruct(DEBUG_INFO_TYPE));
|
2008-09-01 10:15:45 +00:00
|
|
|
debug_info->set_shared(*shared);
|
2015-07-15 09:22:33 +00:00
|
|
|
debug_info->set_code(shared->code());
|
2008-09-01 10:15:45 +00:00
|
|
|
debug_info->set_break_points(*break_points);
|
|
|
|
|
|
|
|
// Link debug info to function.
|
|
|
|
shared->set_debug_info(*debug_info);
|
|
|
|
|
|
|
|
return debug_info;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-07 13:27:37 +00:00
|
|
|
Handle<JSObject> Factory::NewArgumentsObject(Handle<JSFunction> callee,
|
2008-07-03 15:10:15 +00:00
|
|
|
int length) {
|
2015-02-14 00:14:46 +00:00
|
|
|
bool strict_mode_callee = is_strict(callee->shared()->language_mode()) ||
|
2015-08-07 11:38:20 +00:00
|
|
|
!callee->has_simple_parameters();
|
2014-07-07 13:27:37 +00:00
|
|
|
Handle<Map> map = strict_mode_callee ? isolate()->strict_arguments_map()
|
|
|
|
: isolate()->sloppy_arguments_map();
|
|
|
|
AllocationSiteUsageContext context(isolate(), Handle<AllocationSite>(),
|
|
|
|
false);
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(!isolate()->has_pending_exception());
|
2014-07-07 13:27:37 +00:00
|
|
|
Handle<JSObject> result = NewJSObjectFromMap(map);
|
|
|
|
Handle<Smi> value(Smi::FromInt(length), isolate());
|
2014-07-22 08:28:49 +00:00
|
|
|
Object::SetProperty(result, length_string(), value, STRICT).Assert();
|
2014-07-07 13:27:37 +00:00
|
|
|
if (!strict_mode_callee) {
|
2014-07-22 08:28:49 +00:00
|
|
|
Object::SetProperty(result, callee_string(), callee, STRICT).Assert();
|
2014-07-07 13:27:37 +00:00
|
|
|
}
|
|
|
|
return result;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-05 09:40:13 +00:00
|
|
|
Handle<JSWeakMap> Factory::NewJSWeakMap() {
|
|
|
|
// TODO(adamk): Currently the map is only created three times per
|
|
|
|
// isolate. If it's created more often, the map should be moved into the
|
|
|
|
// strong root list.
|
|
|
|
Handle<Map> map = NewMap(JS_WEAK_MAP_TYPE, JSWeakMap::kSize);
|
|
|
|
return Handle<JSWeakMap>::cast(NewJSObjectFromMap(map));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-25 07:46:07 +00:00
|
|
|
Handle<Map> Factory::ObjectLiteralMapFromCache(Handle<Context> context,
|
2014-11-10 18:03:50 +00:00
|
|
|
int number_of_properties,
|
2015-05-20 07:07:54 +00:00
|
|
|
bool is_strong,
|
2014-11-10 18:03:50 +00:00
|
|
|
bool* is_result_from_cache) {
|
|
|
|
const int kMapCacheSize = 128;
|
|
|
|
|
2015-05-05 13:59:08 +00:00
|
|
|
// We do not cache maps for too many properties or when running builtin code.
|
2015-05-22 10:51:49 +00:00
|
|
|
if (number_of_properties > kMapCacheSize ||
|
2015-05-05 13:59:08 +00:00
|
|
|
isolate()->bootstrapper()->IsActive()) {
|
2014-11-10 18:03:50 +00:00
|
|
|
*is_result_from_cache = false;
|
2015-05-20 07:07:54 +00:00
|
|
|
Handle<Map> map = Map::Create(isolate(), number_of_properties);
|
2015-05-22 10:51:49 +00:00
|
|
|
if (is_strong) map->set_is_strong();
|
2015-05-20 07:07:54 +00:00
|
|
|
return map;
|
2014-11-10 18:03:50 +00:00
|
|
|
}
|
|
|
|
*is_result_from_cache = true;
|
|
|
|
if (number_of_properties == 0) {
|
|
|
|
// Reuse the initial map of the Object function if the literal has no
|
2015-05-22 10:51:49 +00:00
|
|
|
// predeclared properties, or the strong map if strong.
|
|
|
|
return handle(is_strong
|
|
|
|
? context->js_object_strong_map()
|
|
|
|
: context->object_function()->initial_map(), isolate());
|
2014-11-10 18:03:50 +00:00
|
|
|
}
|
2015-05-22 10:51:49 +00:00
|
|
|
|
2014-11-10 18:03:50 +00:00
|
|
|
int cache_index = number_of_properties - 1;
|
2015-06-02 10:15:06 +00:00
|
|
|
Handle<Object> maybe_cache(is_strong ? context->strong_map_cache()
|
|
|
|
: context->map_cache(), isolate());
|
|
|
|
if (maybe_cache->IsUndefined()) {
|
|
|
|
// Allocate the new map cache for the native context.
|
|
|
|
maybe_cache = NewFixedArray(kMapCacheSize, TENURED);
|
|
|
|
if (is_strong) {
|
|
|
|
context->set_strong_map_cache(*maybe_cache);
|
|
|
|
} else {
|
|
|
|
context->set_map_cache(*maybe_cache);
|
2015-05-22 10:51:49 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Check to see whether there is a matching element in the cache.
|
2015-06-02 10:15:06 +00:00
|
|
|
Handle<FixedArray> cache = Handle<FixedArray>::cast(maybe_cache);
|
2014-11-10 18:03:50 +00:00
|
|
|
Object* result = cache->get(cache_index);
|
|
|
|
if (result->IsWeakCell()) {
|
|
|
|
WeakCell* cell = WeakCell::cast(result);
|
|
|
|
if (!cell->cleared()) {
|
|
|
|
return handle(Map::cast(cell->value()), isolate());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-06-02 10:15:06 +00:00
|
|
|
// Create a new map and add it to the cache.
|
|
|
|
Handle<FixedArray> cache = Handle<FixedArray>::cast(maybe_cache);
|
|
|
|
Handle<Map> map = Map::Create(isolate(), number_of_properties);
|
|
|
|
if (is_strong) map->set_is_strong();
|
2014-11-10 18:03:50 +00:00
|
|
|
Handle<WeakCell> cell = NewWeakCell(map);
|
|
|
|
cache->set(cache_index, *cell);
|
2014-04-02 13:30:36 +00:00
|
|
|
return map;
|
2008-09-25 07:46:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-03-11 14:00:55 +00:00
|
|
|
void Factory::SetRegExpAtomData(Handle<JSRegExp> regexp,
|
|
|
|
JSRegExp::Type type,
|
|
|
|
Handle<String> source,
|
|
|
|
JSRegExp::Flags flags,
|
|
|
|
Handle<Object> data) {
|
|
|
|
Handle<FixedArray> store = NewFixedArray(JSRegExp::kAtomDataSize);
|
|
|
|
|
2008-10-24 08:40:02 +00:00
|
|
|
store->set(JSRegExp::kTagIndex, Smi::FromInt(type));
|
|
|
|
store->set(JSRegExp::kSourceIndex, *source);
|
|
|
|
store->set(JSRegExp::kFlagsIndex, Smi::FromInt(flags.value()));
|
|
|
|
store->set(JSRegExp::kAtomPatternIndex, *data);
|
|
|
|
regexp->set_data(*store);
|
|
|
|
}
|
|
|
|
|
2014-11-10 18:03:50 +00:00
|
|
|
|
2009-03-11 14:00:55 +00:00
|
|
|
void Factory::SetRegExpIrregexpData(Handle<JSRegExp> regexp,
|
|
|
|
JSRegExp::Type type,
|
|
|
|
Handle<String> source,
|
|
|
|
JSRegExp::Flags flags,
|
|
|
|
int capture_count) {
|
|
|
|
Handle<FixedArray> store = NewFixedArray(JSRegExp::kIrregexpDataSize);
|
2011-07-05 06:19:53 +00:00
|
|
|
Smi* uninitialized = Smi::FromInt(JSRegExp::kUninitializedValue);
|
2009-03-11 14:00:55 +00:00
|
|
|
store->set(JSRegExp::kTagIndex, Smi::FromInt(type));
|
|
|
|
store->set(JSRegExp::kSourceIndex, *source);
|
|
|
|
store->set(JSRegExp::kFlagsIndex, Smi::FromInt(flags.value()));
|
2014-09-10 12:38:12 +00:00
|
|
|
store->set(JSRegExp::kIrregexpLatin1CodeIndex, uninitialized);
|
2011-07-05 06:19:53 +00:00
|
|
|
store->set(JSRegExp::kIrregexpUC16CodeIndex, uninitialized);
|
2014-09-10 12:38:12 +00:00
|
|
|
store->set(JSRegExp::kIrregexpLatin1CodeSavedIndex, uninitialized);
|
2011-07-05 06:19:53 +00:00
|
|
|
store->set(JSRegExp::kIrregexpUC16CodeSavedIndex, uninitialized);
|
2009-03-11 14:00:55 +00:00
|
|
|
store->set(JSRegExp::kIrregexpMaxRegisterCountIndex, Smi::FromInt(0));
|
|
|
|
store->set(JSRegExp::kIrregexpCaptureCountIndex,
|
|
|
|
Smi::FromInt(capture_count));
|
|
|
|
regexp->set_data(*store);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-13 16:22:11 +00:00
|
|
|
Handle<Object> Factory::GlobalConstantFor(Handle<Name> name) {
|
|
|
|
if (Name::Equals(name, undefined_string())) return undefined_value();
|
|
|
|
if (Name::Equals(name, nan_string())) return nan_value();
|
|
|
|
if (Name::Equals(name, infinity_string())) return infinity_value();
|
2011-09-23 08:00:06 +00:00
|
|
|
return Handle<Object>::null();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-10 09:21:48 +00:00
|
|
|
Handle<Object> Factory::ToBoolean(bool value) {
|
2013-02-25 14:46:09 +00:00
|
|
|
return value ? true_value() : false_value();
|
2011-10-10 09:21:48 +00:00
|
|
|
}
|
|
|
|
|
2014-04-17 17:45:32 +00:00
|
|
|
|
2015-06-01 22:46:54 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|