2013-04-18 09:50:46 +00:00
|
|
|
// Copyright 2013 the V8 project authors. All rights reserved.
|
2008-07-03 15:10:15 +00:00
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are
|
|
|
|
// met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright
|
|
|
|
// notice, this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above
|
|
|
|
// copyright notice, this list of conditions and the following
|
|
|
|
// disclaimer in the documentation and/or other materials provided
|
|
|
|
// with the distribution.
|
|
|
|
// * Neither the name of Google Inc. nor the names of its
|
|
|
|
// contributors may be used to endorse or promote products derived
|
|
|
|
// from this software without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
#include "v8.h"
|
|
|
|
|
|
|
|
#include "api.h"
|
2008-09-01 10:15:45 +00:00
|
|
|
#include "debug.h"
|
2008-07-03 15:10:15 +00:00
|
|
|
#include "execution.h"
|
|
|
|
#include "factory.h"
|
2013-07-02 15:30:33 +00:00
|
|
|
#include "isolate-inl.h"
|
2008-07-03 15:10:15 +00:00
|
|
|
#include "macro-assembler.h"
|
2010-12-07 11:31:57 +00:00
|
|
|
#include "objects.h"
|
2010-08-11 14:30:14 +00:00
|
|
|
#include "objects-visiting.h"
|
2012-05-31 12:26:36 +00:00
|
|
|
#include "platform.h"
|
2011-08-11 16:29:28 +00:00
|
|
|
#include "scopeinfo.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
|
|
|
|
|
|
|
|
2013-06-06 15:40:28 +00:00
|
|
|
Handle<Box> Factory::NewBox(Handle<Object> value, PretenureFlag pretenure) {
|
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate(),
|
|
|
|
isolate()->heap()->AllocateBox(*value, pretenure),
|
|
|
|
Box);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
Handle<FixedArray> Factory::NewFixedArray(int size, PretenureFlag pretenure) {
|
|
|
|
ASSERT(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) {
|
2008-10-29 10:02:09 +00:00
|
|
|
ASSERT(0 <= size);
|
2011-03-18 20:35:07 +00:00
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate(),
|
|
|
|
isolate()->heap()->AllocateFixedArrayWithHoles(size, pretenure),
|
|
|
|
FixedArray);
|
2008-10-29 10:02:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-19 11:36:55 +00:00
|
|
|
Handle<FixedDoubleArray> Factory::NewFixedDoubleArray(int size,
|
|
|
|
PretenureFlag pretenure) {
|
2011-06-09 10:03:35 +00:00
|
|
|
ASSERT(0 <= size);
|
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate(),
|
|
|
|
isolate()->heap()->AllocateUninitializedFixedDoubleArray(size, pretenure),
|
2011-10-19 11:36:55 +00:00
|
|
|
FixedDoubleArray);
|
2011-06-09 10:03:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-14 13:35:06 +00:00
|
|
|
Handle<ConstantPoolArray> Factory::NewConstantPoolArray(
|
|
|
|
int number_of_int64_entries,
|
|
|
|
int number_of_ptr_entries,
|
|
|
|
int number_of_int32_entries) {
|
|
|
|
ASSERT(number_of_int64_entries > 0 || number_of_ptr_entries > 0 ||
|
|
|
|
number_of_int32_entries > 0);
|
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate(),
|
|
|
|
isolate()->heap()->AllocateConstantPoolArray(number_of_int64_entries,
|
|
|
|
number_of_ptr_entries,
|
|
|
|
number_of_int32_entries),
|
|
|
|
ConstantPoolArray);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-04 15:00:57 +00:00
|
|
|
Handle<NameDictionary> Factory::NewNameDictionary(int at_least_space_for) {
|
2008-10-28 14:47:50 +00:00
|
|
|
ASSERT(0 <= at_least_space_for);
|
2011-03-18 20:35:07 +00:00
|
|
|
CALL_HEAP_FUNCTION(isolate(),
|
2013-03-12 07:06:36 +00:00
|
|
|
NameDictionary::Allocate(isolate()->heap(),
|
|
|
|
at_least_space_for),
|
2013-03-04 15:00:57 +00:00
|
|
|
NameDictionary);
|
2009-07-02 06:50:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-16 09:44:35 +00:00
|
|
|
Handle<SeededNumberDictionary> Factory::NewSeededNumberDictionary(
|
|
|
|
int at_least_space_for) {
|
2009-07-02 06:50:43 +00:00
|
|
|
ASSERT(0 <= at_least_space_for);
|
2011-03-18 20:35:07 +00:00
|
|
|
CALL_HEAP_FUNCTION(isolate(),
|
2013-03-12 07:06:36 +00:00
|
|
|
SeededNumberDictionary::Allocate(isolate()->heap(),
|
|
|
|
at_least_space_for),
|
2012-01-16 09:44:35 +00:00
|
|
|
SeededNumberDictionary);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<UnseededNumberDictionary> Factory::NewUnseededNumberDictionary(
|
|
|
|
int at_least_space_for) {
|
|
|
|
ASSERT(0 <= at_least_space_for);
|
|
|
|
CALL_HEAP_FUNCTION(isolate(),
|
2013-03-12 07:06:36 +00:00
|
|
|
UnseededNumberDictionary::Allocate(isolate()->heap(),
|
|
|
|
at_least_space_for),
|
2012-01-16 09:44:35 +00:00
|
|
|
UnseededNumberDictionary);
|
2008-10-28 14:47:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-25 14:14:56 +00:00
|
|
|
Handle<ObjectHashSet> Factory::NewObjectHashSet(int at_least_space_for) {
|
|
|
|
ASSERT(0 <= at_least_space_for);
|
|
|
|
CALL_HEAP_FUNCTION(isolate(),
|
2013-03-12 07:06:36 +00:00
|
|
|
ObjectHashSet::Allocate(isolate()->heap(),
|
|
|
|
at_least_space_for),
|
2011-10-25 14:14:56 +00:00
|
|
|
ObjectHashSet);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-05 11:47:11 +00:00
|
|
|
Handle<ObjectHashTable> Factory::NewObjectHashTable(
|
|
|
|
int at_least_space_for,
|
|
|
|
MinimumCapacity capacity_option) {
|
2011-07-28 17:21:22 +00:00
|
|
|
ASSERT(0 <= at_least_space_for);
|
|
|
|
CALL_HEAP_FUNCTION(isolate(),
|
2013-03-12 07:06:36 +00:00
|
|
|
ObjectHashTable::Allocate(isolate()->heap(),
|
2013-11-05 11:47:11 +00:00
|
|
|
at_least_space_for,
|
|
|
|
capacity_option),
|
2011-07-28 17:21:22 +00:00
|
|
|
ObjectHashTable);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-04 07:25:24 +00:00
|
|
|
Handle<WeakHashTable> Factory::NewWeakHashTable(int at_least_space_for) {
|
|
|
|
ASSERT(0 <= at_least_space_for);
|
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate(),
|
|
|
|
WeakHashTable::Allocate(isolate()->heap(),
|
|
|
|
at_least_space_for,
|
2013-11-05 11:47:11 +00:00
|
|
|
USE_DEFAULT_MINIMUM_CAPACITY,
|
2013-10-04 07:25:24 +00:00
|
|
|
TENURED),
|
|
|
|
WeakHashTable);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-18 13:25:12 +00:00
|
|
|
Handle<DescriptorArray> Factory::NewDescriptorArray(int number_of_descriptors,
|
|
|
|
int slack) {
|
2008-07-03 15:10:15 +00:00
|
|
|
ASSERT(0 <= number_of_descriptors);
|
2011-03-18 20:35:07 +00:00
|
|
|
CALL_HEAP_FUNCTION(isolate(),
|
2013-09-04 10:34:42 +00:00
|
|
|
DescriptorArray::Allocate(
|
|
|
|
isolate(), number_of_descriptors, slack),
|
2008-07-03 15:10:15 +00:00
|
|
|
DescriptorArray);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
Handle<DeoptimizationInputData> Factory::NewDeoptimizationInputData(
|
|
|
|
int deopt_entry_count,
|
|
|
|
PretenureFlag pretenure) {
|
|
|
|
ASSERT(deopt_entry_count > 0);
|
2011-03-18 20:35:07 +00:00
|
|
|
CALL_HEAP_FUNCTION(isolate(),
|
2013-09-11 07:14:41 +00:00
|
|
|
DeoptimizationInputData::Allocate(isolate(),
|
|
|
|
deopt_entry_count,
|
2010-12-07 11:31:57 +00:00
|
|
|
pretenure),
|
|
|
|
DeoptimizationInputData);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<DeoptimizationOutputData> Factory::NewDeoptimizationOutputData(
|
|
|
|
int deopt_entry_count,
|
|
|
|
PretenureFlag pretenure) {
|
|
|
|
ASSERT(deopt_entry_count > 0);
|
2011-03-18 20:35:07 +00:00
|
|
|
CALL_HEAP_FUNCTION(isolate(),
|
2013-09-11 07:14:41 +00:00
|
|
|
DeoptimizationOutputData::Allocate(isolate(),
|
|
|
|
deopt_entry_count,
|
2010-12-07 11:31:57 +00:00
|
|
|
pretenure),
|
|
|
|
DeoptimizationOutputData);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-10 16:11:33 +00:00
|
|
|
Handle<AccessorPair> Factory::NewAccessorPair() {
|
|
|
|
CALL_HEAP_FUNCTION(isolate(),
|
|
|
|
isolate()->heap()->AllocateAccessorPair(),
|
|
|
|
AccessorPair);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-20 12:57:23 +00:00
|
|
|
Handle<TypeFeedbackInfo> Factory::NewTypeFeedbackInfo() {
|
|
|
|
CALL_HEAP_FUNCTION(isolate(),
|
|
|
|
isolate()->heap()->AllocateTypeFeedbackInfo(),
|
|
|
|
TypeFeedbackInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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) {
|
2011-03-18 20:35:07 +00:00
|
|
|
CALL_HEAP_FUNCTION(isolate(),
|
2013-02-28 17:03:34 +00:00
|
|
|
isolate()->heap()->InternalizeUtf8String(string),
|
2011-03-18 20:35:07 +00:00
|
|
|
String);
|
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) {
|
2011-05-24 12:16:23 +00:00
|
|
|
CALL_HEAP_FUNCTION(isolate(),
|
2013-02-28 17:03:34 +00:00
|
|
|
isolate()->heap()->InternalizeString(*string),
|
2011-05-24 12:16:23 +00:00
|
|
|
String);
|
|
|
|
}
|
|
|
|
|
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) {
|
2011-03-18 20:35:07 +00:00
|
|
|
CALL_HEAP_FUNCTION(isolate(),
|
2013-02-28 17:03:34 +00:00
|
|
|
isolate()->heap()->InternalizeOneByteString(string),
|
2011-03-18 20:35:07 +00:00
|
|
|
String);
|
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) {
|
2011-05-24 12:16:23 +00:00
|
|
|
CALL_HEAP_FUNCTION(isolate(),
|
2013-02-28 17:03:34 +00:00
|
|
|
isolate()->heap()->InternalizeOneByteString(
|
|
|
|
string, from, length),
|
2011-05-24 12:16:23 +00:00
|
|
|
String);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-28 17:03:34 +00:00
|
|
|
Handle<String> Factory::InternalizeTwoByteString(Vector<const uc16> string) {
|
2011-03-18 20:35:07 +00:00
|
|
|
CALL_HEAP_FUNCTION(isolate(),
|
2013-02-28 17:03:34 +00:00
|
|
|
isolate()->heap()->InternalizeTwoByteString(string),
|
2011-03-18 20:35:07 +00:00
|
|
|
String);
|
2010-12-22 20:14:19 +00:00
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2013-01-09 10:30:54 +00:00
|
|
|
Handle<String> Factory::NewStringFromOneByte(Vector<const uint8_t> string,
|
|
|
|
PretenureFlag pretenure) {
|
2011-03-18 20:35:07 +00:00
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate(),
|
2012-11-21 10:01:05 +00:00
|
|
|
isolate()->heap()->AllocateStringFromOneByte(string, pretenure),
|
2011-03-18 20:35:07 +00:00
|
|
|
String);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Handle<String> Factory::NewStringFromUtf8(Vector<const char> string,
|
2012-09-04 12:23:22 +00:00
|
|
|
PretenureFlag pretenure) {
|
2011-03-18 20:35:07 +00:00
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate(),
|
2012-09-04 12:23:22 +00:00
|
|
|
isolate()->heap()->AllocateStringFromUtf8(string, pretenure),
|
2011-03-18 20:35:07 +00:00
|
|
|
String);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-18 07:14:02 +00:00
|
|
|
Handle<String> Factory::NewStringFromTwoByte(Vector<const uc16> string,
|
|
|
|
PretenureFlag pretenure) {
|
2011-03-18 20:35:07 +00:00
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate(),
|
|
|
|
isolate()->heap()->AllocateStringFromTwoByte(string, pretenure),
|
|
|
|
String);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-15 13:31:27 +00:00
|
|
|
Handle<SeqOneByteString> Factory::NewRawOneByteString(int length,
|
2011-06-27 09:02:34 +00:00
|
|
|
PretenureFlag pretenure) {
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-27 09:02:34 +00:00
|
|
|
Handle<SeqTwoByteString> Factory::NewRawTwoByteString(int length,
|
|
|
|
PretenureFlag pretenure) {
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-05 15:36:15 +00:00
|
|
|
Handle<String> Factory::NewConsString(Handle<String> first,
|
|
|
|
Handle<String> second) {
|
|
|
|
CALL_HEAP_FUNCTION(isolate(),
|
|
|
|
isolate()->heap()->AllocateConsString(*first, *second),
|
|
|
|
String);
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<String> Factory::NewFlatConcatString(Handle<String> first,
|
|
|
|
Handle<String> second) {
|
|
|
|
int total_length = first->length() + second->length();
|
2013-11-11 15:28:47 +00:00
|
|
|
if (first->IsOneByteRepresentation() && second->IsOneByteRepresentation()) {
|
2013-06-21 09:24:30 +00:00
|
|
|
return ConcatStringContent<uint8_t>(
|
|
|
|
NewRawOneByteString(total_length), first, second);
|
|
|
|
} else {
|
|
|
|
return ConcatStringContent<uc16>(
|
|
|
|
NewRawTwoByteString(total_length), first, second);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-05 15:36:15 +00:00
|
|
|
Handle<String> Factory::NewSubString(Handle<String> str,
|
|
|
|
int begin,
|
|
|
|
int end) {
|
2011-03-18 20:35:07 +00:00
|
|
|
CALL_HEAP_FUNCTION(isolate(),
|
2013-11-05 15:36:15 +00:00
|
|
|
str->SubString(begin, end),
|
|
|
|
String);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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) {
|
|
|
|
ASSERT(begin > 0 || end < str->length());
|
2013-11-05 15:36:15 +00:00
|
|
|
CALL_HEAP_FUNCTION(isolate(),
|
|
|
|
isolate()->heap()->AllocateSubString(*str, begin, end),
|
|
|
|
String);
|
2011-06-22 14:20:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
Handle<String> Factory::NewExternalStringFromAscii(
|
2011-09-21 13:28:09 +00:00
|
|
|
const ExternalAsciiString::Resource* resource) {
|
2011-03-18 20:35:07 +00:00
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate(),
|
|
|
|
isolate()->heap()->AllocateExternalStringFromAscii(resource),
|
|
|
|
String);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<String> Factory::NewExternalStringFromTwoByte(
|
2011-09-21 13:28:09 +00:00
|
|
|
const ExternalTwoByteString::Resource* resource) {
|
2011-03-18 20:35:07 +00:00
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate(),
|
|
|
|
isolate()->heap()->AllocateExternalStringFromTwoByte(resource),
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Provide private symbols through internal APIs
Adds a notion of private symbols, mainly intended for internal use, especially, self-hosting of built-in types that would otherwise require new C++ classes.
On the JS side (i.e., in built-ins), private properties can be created and accessed through a set of macros:
NEW_PRIVATE(print_name)
HAS_PRIVATE(obj, sym)
GET_PRIVATE(obj, sym)
SET_PRIVATE(obj, sym, val)
DELETE_PRIVATE(obj, sym)
In the V8 API, they are accessible via a new class Private, and respective HasPrivate/Get/Private/SetPrivate/DeletePrivate methods on calss Object.
These APIs are designed and restricted such that their implementation can later be replaced by whatever ES7+ will officially provide.
R=yangguo@chromium.org
BUG=
Review URL: https://codereview.chromium.org/48923002
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@17683 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2013-11-13 10:34:06 +00:00
|
|
|
Handle<Symbol> Factory::NewPrivateSymbol() {
|
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate(),
|
|
|
|
isolate()->heap()->AllocatePrivateSymbol(),
|
|
|
|
Symbol);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-17 09:03:08 +00:00
|
|
|
Handle<Context> Factory::NewNativeContext() {
|
2011-03-18 20:35:07 +00:00
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate(),
|
2012-08-17 09:03:08 +00:00
|
|
|
isolate()->heap()->AllocateNativeContext(),
|
2011-03-18 20:35:07 +00:00
|
|
|
Context);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-27 09:40:26 +00:00
|
|
|
Handle<Context> Factory::NewGlobalContext(Handle<JSFunction> function,
|
|
|
|
Handle<ScopeInfo> scope_info) {
|
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate(),
|
|
|
|
isolate()->heap()->AllocateGlobalContext(*function, *scope_info),
|
|
|
|
Context);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-09 08:59:03 +00:00
|
|
|
Handle<Context> Factory::NewModuleContext(Handle<ScopeInfo> scope_info) {
|
2012-04-16 14:43:27 +00:00
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate(),
|
2012-07-09 08:59:03 +00:00
|
|
|
isolate()->heap()->AllocateModuleContext(*scope_info),
|
2012-04-16 14:43:27 +00:00
|
|
|
Context);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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) {
|
2011-03-18 20:35:07 +00:00
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate(),
|
2011-06-29 07:41:42 +00:00
|
|
|
isolate()->heap()->AllocateFunctionContext(length, *function),
|
2011-03-18 20:35:07 +00:00
|
|
|
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) {
|
2011-06-09 11:26:01 +00:00
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate(),
|
2011-06-29 07:41:42 +00:00
|
|
|
isolate()->heap()->AllocateCatchContext(*function,
|
|
|
|
*previous,
|
|
|
|
*name,
|
|
|
|
*thrown_object),
|
2011-06-09 11:26:01 +00:00
|
|
|
Context);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-29 07:41:42 +00:00
|
|
|
Handle<Context> Factory::NewWithContext(Handle<JSFunction> function,
|
|
|
|
Handle<Context> previous,
|
2011-06-09 11:26:01 +00:00
|
|
|
Handle<JSObject> extension) {
|
2011-03-18 20:35:07 +00:00
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate(),
|
2011-06-29 07:41:42 +00:00
|
|
|
isolate()->heap()->AllocateWithContext(*function, *previous, *extension),
|
2011-03-18 20:35:07 +00:00
|
|
|
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) {
|
2011-08-11 16:29:28 +00:00
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate(),
|
|
|
|
isolate()->heap()->AllocateBlockContext(*function,
|
|
|
|
*previous,
|
|
|
|
*scope_info),
|
|
|
|
Context);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
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-03-07 11:42:58 +00:00
|
|
|
Handle<DeclaredAccessorDescriptor> Factory::NewDeclaredAccessorDescriptor() {
|
|
|
|
return Handle<DeclaredAccessorDescriptor>::cast(
|
|
|
|
NewStruct(DECLARED_ACCESSOR_DESCRIPTOR_TYPE));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-12 14:33:08 +00:00
|
|
|
Handle<DeclaredAccessorInfo> Factory::NewDeclaredAccessorInfo() {
|
|
|
|
Handle<DeclaredAccessorInfo> info =
|
|
|
|
Handle<DeclaredAccessorInfo>::cast(
|
|
|
|
NewStruct(DECLARED_ACCESSOR_INFO_TYPE));
|
|
|
|
info->set_flag(0); // Must clear the flag, it was initialized as undefined.
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
// Generate id for this script.
|
2011-03-18 20:35:07 +00:00
|
|
|
Heap* heap = isolate()->heap();
|
2013-06-25 14:57:47 +00:00
|
|
|
int id = heap->last_script_id()->value() + 1;
|
|
|
|
if (!Smi::IsValid(id) || id < 0) id = 1;
|
|
|
|
heap->set_last_script_id(Smi::FromInt(id));
|
2009-03-10 12:41:11 +00:00
|
|
|
|
2009-03-10 12:05:20 +00:00
|
|
|
// Create and initialize script object.
|
2011-05-19 11:47:34 +00:00
|
|
|
Handle<Foreign> wrapper = NewForeign(0, TENURED);
|
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());
|
2013-06-25 14:57:47 +00:00
|
|
|
script->set_id(Smi::FromInt(id));
|
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_data(heap->undefined_value());
|
|
|
|
script->set_context_data(heap->undefined_value());
|
2009-06-08 10:47:49 +00:00
|
|
|
script->set_type(Smi::FromInt(Script::TYPE_NORMAL));
|
2009-05-07 12:25:46 +00:00
|
|
|
script->set_wrapper(*wrapper);
|
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));
|
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) {
|
2008-07-03 15:10:15 +00:00
|
|
|
ASSERT(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
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-20 15:26:17 +00:00
|
|
|
Handle<ExternalArray> Factory::NewExternalArray(int length,
|
|
|
|
ExternalArrayType array_type,
|
|
|
|
void* external_pointer,
|
|
|
|
PretenureFlag pretenure) {
|
|
|
|
ASSERT(0 <= length);
|
2011-03-18 20:35:07 +00:00
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate(),
|
|
|
|
isolate()->heap()->AllocateExternalArray(length,
|
|
|
|
array_type,
|
|
|
|
external_pointer,
|
|
|
|
pretenure),
|
|
|
|
ExternalArray);
|
2009-10-20 15:26:17 +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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-21 13:55:24 +00:00
|
|
|
Handle<PropertyCell> Factory::NewPropertyCellWithHole() {
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-21 13:55:24 +00:00
|
|
|
Handle<PropertyCell> Factory::NewPropertyCell(Handle<Object> value) {
|
|
|
|
AllowDeferredHandleDereference convert_to_cell;
|
|
|
|
Handle<PropertyCell> cell = NewPropertyCellWithHole();
|
|
|
|
PropertyCell::SetValueInferType(cell, value);
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-08 10:02:16 +00:00
|
|
|
Handle<AllocationSite> Factory::NewAllocationSite() {
|
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate(),
|
|
|
|
isolate()->heap()->AllocateAllocationSite(),
|
|
|
|
AllocationSite);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<JSObject> Factory::NewFunctionPrototype(Handle<JSFunction> function) {
|
2013-11-05 13:34:14 +00:00
|
|
|
// 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());
|
|
|
|
ASSERT(object_function->has_initial_map());
|
|
|
|
new_map = Map::Copy(handle(object_function->initial_map()));
|
|
|
|
}
|
|
|
|
|
|
|
|
Handle<JSObject> prototype = NewJSObjectFromMap(new_map);
|
|
|
|
|
|
|
|
if (!function->shared()->is_generator()) {
|
|
|
|
JSObject::SetLocalPropertyIgnoreAttributes(prototype,
|
|
|
|
constructor_string(),
|
|
|
|
function,
|
|
|
|
DONT_ENUM);
|
|
|
|
}
|
|
|
|
|
|
|
|
return prototype;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-11 14:29:16 +00:00
|
|
|
Handle<Map> Factory::CopyWithPreallocatedFieldDescriptors(Handle<Map> src) {
|
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate(), src->CopyWithPreallocatedFieldDescriptors(), Map);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-12 10:59:58 +00:00
|
|
|
Handle<Map> Factory::CopyMap(Handle<Map> src,
|
|
|
|
int extra_inobject_properties) {
|
2012-07-11 14:29:16 +00:00
|
|
|
Handle<Map> copy = CopyWithPreallocatedFieldDescriptors(src);
|
2009-01-12 10:59:58 +00:00
|
|
|
// Check that we do not overflow the instance size when adding the
|
|
|
|
// extra inobject properties.
|
|
|
|
int instance_size_delta = extra_inobject_properties * kPointerSize;
|
|
|
|
int max_instance_size_delta =
|
|
|
|
JSObject::kMaxInstanceSize - copy->instance_size();
|
2013-11-14 11:56:03 +00:00
|
|
|
int max_extra_properties = max_instance_size_delta >> kPointerSizeLog2;
|
|
|
|
if (extra_inobject_properties > max_extra_properties) {
|
2009-01-12 10:59:58 +00:00
|
|
|
// If the instance size overflows, we allocate as many properties
|
|
|
|
// as we can as inobject properties.
|
|
|
|
instance_size_delta = max_instance_size_delta;
|
2013-11-14 11:56:03 +00:00
|
|
|
extra_inobject_properties = max_extra_properties;
|
2009-01-12 10:59:58 +00:00
|
|
|
}
|
|
|
|
// Adjust the map with the extra inobject properties.
|
|
|
|
int inobject_properties =
|
|
|
|
copy->inobject_properties() + extra_inobject_properties;
|
|
|
|
copy->set_inobject_properties(inobject_properties);
|
|
|
|
copy->set_unused_property_fields(inobject_properties);
|
|
|
|
copy->set_instance_size(copy->instance_size() + instance_size_delta);
|
2010-08-11 14:30:14 +00:00
|
|
|
copy->set_visitor_id(StaticVisitorBase::GetVisitorId(*copy));
|
2009-01-12 10:59:58 +00:00
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
2010-06-24 13:56:35 +00:00
|
|
|
|
2012-07-17 13:50:19 +00:00
|
|
|
Handle<Map> Factory::CopyMap(Handle<Map> src) {
|
2012-08-13 08:43:16 +00:00
|
|
|
CALL_HEAP_FUNCTION(isolate(), src->Copy(), Map);
|
2008-08-27 13:47:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-09 14:47:37 +00:00
|
|
|
Handle<Map> Factory::GetElementsTransitionMap(
|
2011-09-15 16:38:47 +00:00
|
|
|
Handle<JSObject> src,
|
|
|
|
ElementsKind elements_kind) {
|
2012-01-26 21:47:57 +00:00
|
|
|
Isolate* i = isolate();
|
|
|
|
CALL_HEAP_FUNCTION(i,
|
|
|
|
src->GetElementsTransitionMap(i, elements_kind),
|
2011-03-23 09:57:12 +00:00
|
|
|
Map);
|
2011-02-10 12:02:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
Handle<FixedArray> Factory::CopyFixedArray(Handle<FixedArray> array) {
|
2011-03-18 20:35:07 +00:00
|
|
|
CALL_HEAP_FUNCTION(isolate(), array->Copy(), FixedArray);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-13 12:27:03 +00:00
|
|
|
Handle<FixedArray> Factory::CopySizeFixedArray(Handle<FixedArray> array,
|
2013-10-04 07:25:24 +00:00
|
|
|
int new_length,
|
|
|
|
PretenureFlag pretenure) {
|
|
|
|
CALL_HEAP_FUNCTION(isolate(),
|
|
|
|
array->CopySize(new_length, pretenure),
|
|
|
|
FixedArray);
|
2012-11-13 12:27:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-19 11:36:55 +00:00
|
|
|
Handle<FixedDoubleArray> Factory::CopyFixedDoubleArray(
|
|
|
|
Handle<FixedDoubleArray> array) {
|
|
|
|
CALL_HEAP_FUNCTION(isolate(), array->Copy(), FixedDoubleArray);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-14 13:35:06 +00:00
|
|
|
Handle<ConstantPoolArray> Factory::CopyConstantPoolArray(
|
|
|
|
Handle<ConstantPoolArray> array) {
|
|
|
|
CALL_HEAP_FUNCTION(isolate(), array->Copy(), ConstantPoolArray);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-23 06:04:44 +00:00
|
|
|
Handle<JSFunction> Factory::BaseNewFunctionFromSharedFunctionInfo(
|
|
|
|
Handle<SharedFunctionInfo> function_info,
|
2009-12-16 15:43:20 +00:00
|
|
|
Handle<Map> function_map,
|
|
|
|
PretenureFlag pretenure) {
|
2011-03-18 20:35:07 +00:00
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate(),
|
|
|
|
isolate()->heap()->AllocateFunction(*function_map,
|
|
|
|
*function_info,
|
|
|
|
isolate()->heap()->the_hole_value(),
|
|
|
|
pretenure),
|
2008-07-03 15:10:15 +00:00
|
|
|
JSFunction);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-11 16:28:19 +00:00
|
|
|
static Handle<Map> MapForNewFunction(Isolate *isolate,
|
|
|
|
Handle<SharedFunctionInfo> function_info) {
|
|
|
|
Context *context = isolate->context()->native_context();
|
|
|
|
int map_index = Context::FunctionMapIndex(function_info->language_mode(),
|
|
|
|
function_info->is_generator());
|
|
|
|
return Handle<Map>(Map::cast(context->get(map_index)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-23 06:04:44 +00:00
|
|
|
Handle<JSFunction> Factory::NewFunctionFromSharedFunctionInfo(
|
|
|
|
Handle<SharedFunctionInfo> function_info,
|
2009-12-16 15:43:20 +00:00
|
|
|
Handle<Context> context,
|
|
|
|
PretenureFlag pretenure) {
|
2010-03-23 06:04:44 +00:00
|
|
|
Handle<JSFunction> result = BaseNewFunctionFromSharedFunctionInfo(
|
2011-03-17 20:28:17 +00:00
|
|
|
function_info,
|
2013-04-11 16:28:19 +00:00
|
|
|
MapForNewFunction(isolate(), function_info),
|
2011-03-17 20:28:17 +00:00
|
|
|
pretenure);
|
|
|
|
|
2012-03-26 13:08:08 +00:00
|
|
|
if (function_info->ic_age() != isolate()->heap()->global_ic_age()) {
|
|
|
|
function_info->ResetForNewContext(isolate()->heap()->global_ic_age());
|
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
result->set_context(*context);
|
2012-06-14 14:06:22 +00:00
|
|
|
|
2012-08-17 09:03:08 +00:00
|
|
|
int index = function_info->SearchOptimizedCodeMap(context->native_context());
|
2012-06-22 13:55:15 +00:00
|
|
|
if (!function_info->bound() && index < 0) {
|
|
|
|
int number_of_literals = function_info->num_literals();
|
|
|
|
Handle<FixedArray> literals = NewFixedArray(number_of_literals, pretenure);
|
|
|
|
if (number_of_literals > 0) {
|
2012-08-17 09:03:08 +00:00
|
|
|
// Store the native context in the literals array prefix. This
|
2012-06-22 13:55:15 +00:00
|
|
|
// context will be used when creating object, regexp and array
|
|
|
|
// literals in this function.
|
2012-08-17 09:03:08 +00:00
|
|
|
literals->set(JSFunction::kLiteralNativeContextIndex,
|
|
|
|
context->native_context());
|
2011-10-17 12:44:16 +00:00
|
|
|
}
|
2012-06-22 13:55:15 +00:00
|
|
|
result->set_literals(*literals);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2012-06-14 14:06:22 +00:00
|
|
|
|
|
|
|
if (index > 0) {
|
|
|
|
// Caching of optimized code enabled and optimized code found.
|
2012-06-22 13:55:15 +00:00
|
|
|
function_info->InstallFromOptimizedCodeMap(*result, index);
|
2012-06-14 14:06:22 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-09-03 08:49:44 +00:00
|
|
|
if (isolate()->use_crankshaft() &&
|
2010-12-07 11:31:57 +00:00
|
|
|
FLAG_always_opt &&
|
|
|
|
result->is_compiled() &&
|
|
|
|
!function_info->is_toplevel() &&
|
2012-03-19 10:16:38 +00:00
|
|
|
function_info->allows_lazy_compilation() &&
|
2013-07-02 15:30:33 +00:00
|
|
|
!function_info->optimization_disabled() &&
|
|
|
|
!isolate()->DebuggerHasBreakPoints()) {
|
2013-07-24 07:45:54 +00:00
|
|
|
result->MarkForLazyRecompilation();
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Object> Factory::NewNumber(double value,
|
|
|
|
PretenureFlag pretenure) {
|
2011-03-18 20:35:07 +00:00
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate(),
|
|
|
|
isolate()->heap()->NumberFromDouble(value, pretenure), Object);
|
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) {
|
2011-03-18 20:35:07 +00:00
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate(),
|
2011-11-21 10:18:47 +00:00
|
|
|
isolate()->heap()->NumberFromInt32(value, pretenure), Object);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-21 10:18:47 +00:00
|
|
|
Handle<Object> Factory::NewNumberFromUint(uint32_t value,
|
|
|
|
PretenureFlag pretenure) {
|
2011-03-18 20:35:07 +00:00
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate(),
|
2011-11-21 10:18:47 +00:00
|
|
|
isolate()->heap()->NumberFromUint32(value, pretenure), Object);
|
2009-03-10 08:10:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-08 15:02:08 +00:00
|
|
|
Handle<HeapNumber> Factory::NewHeapNumber(double value,
|
|
|
|
PretenureFlag pretenure) {
|
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate(),
|
|
|
|
isolate()->heap()->AllocateHeapNumber(value, pretenure), HeapNumber);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
Handle<JSObject> Factory::NewNeanderObject() {
|
2011-03-18 20:35:07 +00:00
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate(),
|
|
|
|
isolate()->heap()->AllocateJSObjectFromMap(
|
|
|
|
isolate()->heap()->neander_map()),
|
|
|
|
JSObject);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-06 13:28:22 +00:00
|
|
|
Handle<Object> Factory::NewTypeError(const char* message,
|
2008-07-03 15:10:15 +00:00
|
|
|
Vector< Handle<Object> > args) {
|
2013-06-06 13:28:22 +00:00
|
|
|
return NewError("MakeTypeError", message, args);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Object> Factory::NewTypeError(Handle<String> message) {
|
|
|
|
return NewError("$TypeError", message);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-06 13:28:22 +00:00
|
|
|
Handle<Object> Factory::NewRangeError(const char* message,
|
2008-07-03 15:10:15 +00:00
|
|
|
Vector< Handle<Object> > args) {
|
2013-06-06 13:28:22 +00:00
|
|
|
return NewError("MakeRangeError", message, args);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Object> Factory::NewRangeError(Handle<String> message) {
|
|
|
|
return NewError("$RangeError", message);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-06 13:28:22 +00:00
|
|
|
Handle<Object> Factory::NewSyntaxError(const char* message,
|
|
|
|
Handle<JSArray> args) {
|
|
|
|
return NewError("MakeSyntaxError", message, args);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Object> Factory::NewSyntaxError(Handle<String> message) {
|
|
|
|
return NewError("$SyntaxError", message);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-06 13:28:22 +00:00
|
|
|
Handle<Object> Factory::NewReferenceError(const char* message,
|
2008-07-03 15:10:15 +00:00
|
|
|
Vector< Handle<Object> > args) {
|
2013-06-06 13:28:22 +00:00
|
|
|
return NewError("MakeReferenceError", message, args);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Object> Factory::NewReferenceError(Handle<String> message) {
|
|
|
|
return NewError("$ReferenceError", message);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-15 12:06:53 +00:00
|
|
|
Handle<Object> Factory::NewError(const char* maker,
|
2013-06-06 13:28:22 +00:00
|
|
|
const char* message,
|
2013-03-15 12:06:53 +00:00
|
|
|
Vector< Handle<Object> > args) {
|
|
|
|
// Instantiate a closeable HandleScope for EscapeFrom.
|
2013-12-02 18:12:01 +00:00
|
|
|
v8::EscapableHandleScope scope(reinterpret_cast<v8::Isolate*>(isolate()));
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<FixedArray> array = NewFixedArray(args.length());
|
2008-10-09 13:34:17 +00:00
|
|
|
for (int i = 0; i < args.length(); i++) {
|
|
|
|
array->set(i, *args[i]);
|
|
|
|
}
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<JSArray> object = NewJSArrayWithElements(array);
|
2013-06-06 13:28:22 +00:00
|
|
|
Handle<Object> result = NewError(maker, message, object);
|
2008-07-03 15:10:15 +00:00
|
|
|
return result.EscapeFrom(&scope);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-06 13:28:22 +00:00
|
|
|
Handle<Object> Factory::NewEvalError(const char* message,
|
2008-07-03 15:10:15 +00:00
|
|
|
Vector< Handle<Object> > args) {
|
2013-06-06 13:28:22 +00:00
|
|
|
return NewError("MakeEvalError", message, args);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-06 13:28:22 +00:00
|
|
|
Handle<Object> Factory::NewError(const char* message,
|
2008-07-03 15:10:15 +00:00
|
|
|
Vector< Handle<Object> > args) {
|
2013-06-06 13:28:22 +00:00
|
|
|
return NewError("MakeError", message, args);
|
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);
|
2013-06-06 13:28:22 +00:00
|
|
|
OS::StrNCpy(v, message, space);
|
|
|
|
space -= Min(space, strlen(message));
|
2012-05-31 12:26:36 +00:00
|
|
|
p = &buffer[kBufferSize] - space;
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < ARRAY_SIZE(args); i++) {
|
|
|
|
if (space > 0) {
|
|
|
|
*p++ = ' ';
|
|
|
|
space--;
|
|
|
|
if (space > 0) {
|
2013-09-04 07:05:11 +00:00
|
|
|
MaybeObject* maybe_arg = args->GetElement(isolate(), i);
|
2012-05-31 12:26:36 +00:00
|
|
|
Handle<String> arg_str(reinterpret_cast<String*>(maybe_arg));
|
2013-12-09 07:41:20 +00:00
|
|
|
SmartArrayPointer<char> arg = arg_str->ToCString();
|
2012-06-19 13:45:30 +00:00
|
|
|
Vector<char> v2(p, static_cast<int>(space));
|
2013-12-09 07:41:20 +00:00
|
|
|
OS::StrNCpy(v2, arg.get(), space);
|
|
|
|
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';
|
|
|
|
}
|
|
|
|
Handle<String> error_string = NewStringFromUtf8(CStrVector(buffer), TENURED);
|
|
|
|
return error_string;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
Handle<Object> Factory::NewError(const char* maker,
|
2013-06-06 13:28:22 +00:00
|
|
|
const char* message,
|
2008-07-03 15:10:15 +00:00
|
|
|
Handle<JSArray> args) {
|
2013-02-28 17:03:34 +00:00
|
|
|
Handle<String> make_str = InternalizeUtf8String(maker);
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<Object> fun_obj(
|
2013-02-25 14:46:09 +00:00
|
|
|
isolate()->js_builtins_object()->GetPropertyNoExceptionThrown(*make_str),
|
|
|
|
isolate());
|
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.
|
|
|
|
bool caught_exception;
|
|
|
|
Handle<Object> result = Execution::TryCall(fun,
|
2011-10-06 09:31:38 +00:00
|
|
|
isolate()->js_builtins_object(),
|
|
|
|
ARRAY_SIZE(argv),
|
|
|
|
argv,
|
|
|
|
&caught_exception);
|
2008-07-03 15:10:15 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Object> Factory::NewError(Handle<String> message) {
|
|
|
|
return NewError("$Error", message);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Object> Factory::NewError(const char* constructor,
|
|
|
|
Handle<String> message) {
|
2013-02-28 17:03:34 +00:00
|
|
|
Handle<String> constr = InternalizeUtf8String(constructor);
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<JSFunction> fun = Handle<JSFunction>(
|
|
|
|
JSFunction::cast(isolate()->js_builtins_object()->
|
|
|
|
GetPropertyNoExceptionThrown(*constr)));
|
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.
|
|
|
|
bool caught_exception;
|
|
|
|
Handle<Object> result = Execution::TryCall(fun,
|
2011-10-06 09:31:38 +00:00
|
|
|
isolate()->js_builtins_object(),
|
|
|
|
ARRAY_SIZE(argv),
|
|
|
|
argv,
|
|
|
|
&caught_exception);
|
2008-07-03 15:10:15 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<JSFunction> Factory::NewFunction(Handle<String> name,
|
|
|
|
InstanceType type,
|
|
|
|
int instance_size,
|
|
|
|
Handle<Code> code,
|
|
|
|
bool force_initial_map) {
|
|
|
|
// Allocate the function
|
|
|
|
Handle<JSFunction> function = NewFunction(name, the_hole_value());
|
2010-08-11 08:12:53 +00:00
|
|
|
|
2012-01-13 13:09:52 +00:00
|
|
|
// Set up the code pointer in both the shared function info and in
|
2010-08-11 08:12:53 +00:00
|
|
|
// the function itself.
|
|
|
|
function->shared()->set_code(*code);
|
2008-07-03 15:10:15 +00:00
|
|
|
function->set_code(*code);
|
|
|
|
|
|
|
|
if (force_initial_map ||
|
|
|
|
type != JS_OBJECT_TYPE ||
|
|
|
|
instance_size != JSObject::kHeaderSize) {
|
|
|
|
Handle<Map> initial_map = NewMap(type, instance_size);
|
|
|
|
Handle<JSObject> prototype = NewFunctionPrototype(function);
|
|
|
|
initial_map->set_prototype(*prototype);
|
|
|
|
function->set_initial_map(*initial_map);
|
|
|
|
initial_map->set_constructor(*function);
|
|
|
|
} else {
|
|
|
|
ASSERT(!function->has_initial_map());
|
|
|
|
ASSERT(!function->has_prototype());
|
|
|
|
}
|
|
|
|
|
|
|
|
return function;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<JSFunction> Factory::NewFunctionWithPrototype(Handle<String> name,
|
|
|
|
InstanceType type,
|
|
|
|
int instance_size,
|
|
|
|
Handle<JSObject> prototype,
|
|
|
|
Handle<Code> code,
|
|
|
|
bool force_initial_map) {
|
2010-08-11 08:12:53 +00:00
|
|
|
// Allocate the function.
|
2008-07-03 15:10:15 +00:00
|
|
|
Handle<JSFunction> function = NewFunction(name, prototype);
|
|
|
|
|
2012-01-13 13:09:52 +00:00
|
|
|
// Set up the code pointer in both the shared function info and in
|
2010-08-11 08:12:53 +00:00
|
|
|
// the function itself.
|
|
|
|
function->shared()->set_code(*code);
|
2008-07-03 15:10:15 +00:00
|
|
|
function->set_code(*code);
|
|
|
|
|
|
|
|
if (force_initial_map ||
|
|
|
|
type != JS_OBJECT_TYPE ||
|
|
|
|
instance_size != JSObject::kHeaderSize) {
|
2011-09-22 11:30:04 +00:00
|
|
|
Handle<Map> initial_map = NewMap(type,
|
|
|
|
instance_size,
|
2012-05-23 14:24:29 +00:00
|
|
|
GetInitialFastElementsKind());
|
2008-07-03 15:10:15 +00:00
|
|
|
function->set_initial_map(*initial_map);
|
|
|
|
initial_map->set_constructor(*function);
|
|
|
|
}
|
|
|
|
|
2013-07-18 07:59:48 +00:00
|
|
|
JSFunction::SetPrototype(function, prototype);
|
2008-07-03 15:10:15 +00:00
|
|
|
return function;
|
|
|
|
}
|
|
|
|
|
2008-10-30 11:12:08 +00:00
|
|
|
|
2010-04-28 12:05:40 +00:00
|
|
|
Handle<JSFunction> Factory::NewFunctionWithoutPrototype(Handle<String> name,
|
|
|
|
Handle<Code> code) {
|
2011-03-17 20:28:17 +00:00
|
|
|
Handle<JSFunction> function = NewFunctionWithoutPrototype(name,
|
2011-11-24 15:17:04 +00:00
|
|
|
CLASSIC_MODE);
|
2010-08-11 08:12:53 +00:00
|
|
|
function->shared()->set_code(*code);
|
2010-04-28 12:05:40 +00:00
|
|
|
function->set_code(*code);
|
|
|
|
ASSERT(!function->has_initial_map());
|
|
|
|
ASSERT(!function->has_prototype());
|
|
|
|
return function;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-03 10:36:55 +00:00
|
|
|
Handle<ScopeInfo> Factory::NewScopeInfo(int length) {
|
2011-08-11 16:29:28 +00:00
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate(),
|
2011-11-03 10:36:55 +00:00
|
|
|
isolate()->heap()->AllocateScopeInfo(length),
|
|
|
|
ScopeInfo);
|
2011-08-11 16:29:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-13 12:27:03 +00:00
|
|
|
Handle<JSObject> Factory::NewExternal(void* value) {
|
|
|
|
CALL_HEAP_FUNCTION(isolate(),
|
|
|
|
isolate()->heap()->AllocateExternal(value),
|
|
|
|
JSObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
int prologue_offset) {
|
2011-03-18 20:35:07 +00:00
|
|
|
CALL_HEAP_FUNCTION(isolate(),
|
|
|
|
isolate()->heap()->CreateCode(
|
2013-10-23 13:48:04 +00:00
|
|
|
desc, flags, self_ref, immovable, crankshafted,
|
|
|
|
prologue_offset),
|
2011-03-18 20:35:07 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-28 17:03:34 +00:00
|
|
|
Handle<String> Factory::InternalizedStringFromString(Handle<String> value) {
|
2011-03-18 20:35:07 +00:00
|
|
|
CALL_HEAP_FUNCTION(isolate(),
|
2013-02-28 17:03:34 +00:00
|
|
|
isolate()->heap()->InternalizeString(*value), String);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-09 08:59:03 +00:00
|
|
|
Handle<JSModule> Factory::NewJSModule(Handle<Context> context,
|
|
|
|
Handle<ScopeInfo> scope_info) {
|
2012-04-16 14:43:27 +00:00
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate(),
|
2012-07-09 08:59:03 +00:00
|
|
|
isolate()->heap()->AllocateJSModule(*context, *scope_info), JSModule);
|
2012-04-16 14:43:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-21 13:55:24 +00:00
|
|
|
// TODO(mstarzinger): Temporary wrapper until handlified.
|
|
|
|
static Handle<NameDictionary> NameDictionaryAdd(Handle<NameDictionary> dict,
|
|
|
|
Handle<Name> name,
|
|
|
|
Handle<Object> value,
|
|
|
|
PropertyDetails details) {
|
|
|
|
CALL_HEAP_FUNCTION(dict->GetIsolate(),
|
|
|
|
dict->Add(*name, *value, details),
|
|
|
|
NameDictionary);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static Handle<GlobalObject> NewGlobalObjectFromMap(Isolate* isolate,
|
|
|
|
Handle<Map> map) {
|
|
|
|
CALL_HEAP_FUNCTION(isolate,
|
|
|
|
isolate->heap()->Allocate(*map, OLD_POINTER_SPACE),
|
2009-07-01 11:44:37 +00:00
|
|
|
GlobalObject);
|
2009-06-30 10:05:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-21 13:55:24 +00:00
|
|
|
Handle<GlobalObject> Factory::NewGlobalObject(Handle<JSFunction> constructor) {
|
|
|
|
ASSERT(constructor->has_initial_map());
|
|
|
|
Handle<Map> map(constructor->initial_map());
|
|
|
|
ASSERT(map->is_dictionary_map());
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
ASSERT(map->NextFreePropertyIndex() == 0);
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
ASSERT(map->unused_property_fields() == 0);
|
|
|
|
ASSERT(map->inobject_properties() == 0);
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
Handle<NameDictionary> dictionary = NewNameDictionary(at_least_space_for);
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
ASSERT(details.type() == CALLBACKS); // Only accessors are expected.
|
|
|
|
PropertyDetails d = PropertyDetails(details.attributes(), CALLBACKS, i + 1);
|
|
|
|
Handle<Name> name(descs->GetKey(i));
|
|
|
|
Handle<Object> value(descs->GetCallbacksObject(i), isolate());
|
|
|
|
Handle<PropertyCell> cell = NewPropertyCell(value);
|
|
|
|
NameDictionaryAdd(dictionary, name, cell, d);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Allocate the global object and initialize it with the backing store.
|
|
|
|
Handle<GlobalObject> global = NewGlobalObjectFromMap(isolate(), map);
|
|
|
|
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.
|
|
|
|
ASSERT(global->IsGlobalObject() && !global->HasFastProperties());
|
|
|
|
return global;
|
|
|
|
}
|
|
|
|
|
2009-06-30 10:05:36 +00:00
|
|
|
|
2013-02-26 10:46:00 +00:00
|
|
|
Handle<JSObject> Factory::NewJSObjectFromMap(Handle<Map> map,
|
2013-08-07 11:24:14 +00:00
|
|
|
PretenureFlag pretenure,
|
|
|
|
bool alloc_props) {
|
2011-03-18 20:35:07 +00:00
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate(),
|
2013-08-07 11:24:14 +00:00
|
|
|
isolate()->heap()->AllocateJSObjectFromMap(*map, pretenure, alloc_props),
|
2011-03-18 20:35:07 +00:00
|
|
|
JSObject);
|
2008-09-25 07:46:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-16 19:55:31 +00:00
|
|
|
Handle<JSArray> Factory::NewJSArray(int capacity,
|
2012-01-26 21:47:57 +00:00
|
|
|
ElementsKind elements_kind,
|
2008-07-03 15:10:15 +00:00
|
|
|
PretenureFlag pretenure) {
|
2012-11-22 16:22:57 +00:00
|
|
|
if (capacity != 0) {
|
|
|
|
elements_kind = GetHoleyElementsKind(elements_kind);
|
|
|
|
}
|
2011-03-18 20:35:07 +00:00
|
|
|
CALL_HEAP_FUNCTION(isolate(),
|
2012-01-26 21:47:57 +00:00
|
|
|
isolate()->heap()->AllocateJSArrayAndStorage(
|
|
|
|
elements_kind,
|
|
|
|
0,
|
|
|
|
capacity,
|
|
|
|
INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE,
|
|
|
|
pretenure),
|
2011-03-18 20:35:07 +00:00
|
|
|
JSArray);
|
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,
|
2008-07-03 15:10:15 +00:00
|
|
|
PretenureFlag pretenure) {
|
2012-01-26 21:47:57 +00:00
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate(),
|
|
|
|
isolate()->heap()->AllocateJSArrayWithElements(*elements,
|
|
|
|
elements_kind,
|
2012-11-15 12:19:14 +00:00
|
|
|
elements->length(),
|
2012-01-26 21:47:57 +00:00
|
|
|
pretenure),
|
|
|
|
JSArray);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-09 08:50:19 +00:00
|
|
|
void Factory::SetElementsCapacityAndLength(Handle<JSArray> array,
|
|
|
|
int capacity,
|
|
|
|
int length) {
|
|
|
|
ElementsAccessor* accessor = array->GetElementsAccessor();
|
|
|
|
CALL_HEAP_FUNCTION_VOID(
|
|
|
|
isolate(),
|
|
|
|
accessor->SetCapacityAndLength(*array, capacity, length));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-22 11:30:04 +00:00
|
|
|
void Factory::SetContent(Handle<JSArray> array,
|
2011-12-09 08:50:19 +00:00
|
|
|
Handle<FixedArrayBase> elements) {
|
2011-09-22 11:30:04 +00:00
|
|
|
CALL_HEAP_FUNCTION_VOID(
|
|
|
|
isolate(),
|
|
|
|
array->SetContent(*elements));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-05 12:11:27 +00:00
|
|
|
Handle<JSGeneratorObject> Factory::NewJSGeneratorObject(
|
|
|
|
Handle<JSFunction> function) {
|
|
|
|
ASSERT(function->shared()->is_generator());
|
|
|
|
JSFunction::EnsureHasInitialMap(function);
|
|
|
|
Handle<Map> map(function->initial_map());
|
|
|
|
ASSERT(map->instance_type() == JS_GENERATOR_OBJECT_TYPE);
|
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate(),
|
|
|
|
isolate()->heap()->AllocateJSObjectFromMap(*map),
|
|
|
|
JSGeneratorObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-25 12:02:23 +00:00
|
|
|
Handle<JSArrayBuffer> Factory::NewJSArrayBuffer() {
|
2013-08-06 19:14:51 +00:00
|
|
|
Handle<JSFunction> array_buffer_fun(
|
|
|
|
isolate()->context()->native_context()->array_buffer_fun());
|
2013-04-25 12:02:23 +00:00
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate(),
|
2013-08-06 19:14:51 +00:00
|
|
|
isolate()->heap()->AllocateJSObject(*array_buffer_fun),
|
2013-04-25 12:02:23 +00:00
|
|
|
JSArrayBuffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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(
|
|
|
|
isolate()->context()->native_context()->data_view_fun());
|
2013-06-21 13:02:38 +00:00
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate(),
|
2013-08-06 19:14:51 +00:00
|
|
|
isolate()->heap()->AllocateJSObject(*data_view_fun),
|
2013-06-21 13:02:38 +00:00
|
|
|
JSDataView);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-06 19:14:51 +00:00
|
|
|
static JSFunction* GetTypedArrayFun(ExternalArrayType type,
|
|
|
|
Isolate* isolate) {
|
|
|
|
Context* native_context = isolate->context()->native_context();
|
2013-04-29 11:09:03 +00:00
|
|
|
switch (type) {
|
|
|
|
case kExternalUnsignedByteArray:
|
2013-08-06 19:14:51 +00:00
|
|
|
return native_context->uint8_array_fun();
|
2013-04-29 11:09:03 +00:00
|
|
|
|
|
|
|
case kExternalByteArray:
|
2013-08-06 19:14:51 +00:00
|
|
|
return native_context->int8_array_fun();
|
2013-04-29 11:09:03 +00:00
|
|
|
|
|
|
|
case kExternalUnsignedShortArray:
|
2013-08-06 19:14:51 +00:00
|
|
|
return native_context->uint16_array_fun();
|
2013-04-29 11:09:03 +00:00
|
|
|
|
|
|
|
case kExternalShortArray:
|
2013-08-06 19:14:51 +00:00
|
|
|
return native_context->int16_array_fun();
|
2013-04-29 11:09:03 +00:00
|
|
|
|
|
|
|
case kExternalUnsignedIntArray:
|
2013-08-06 19:14:51 +00:00
|
|
|
return native_context->uint32_array_fun();
|
2013-04-29 11:09:03 +00:00
|
|
|
|
|
|
|
case kExternalIntArray:
|
2013-08-06 19:14:51 +00:00
|
|
|
return native_context->int32_array_fun();
|
2013-04-29 11:09:03 +00:00
|
|
|
|
|
|
|
case kExternalFloatArray:
|
2013-08-06 19:14:51 +00:00
|
|
|
return native_context->float_array_fun();
|
2013-04-29 11:09:03 +00:00
|
|
|
|
|
|
|
case kExternalDoubleArray:
|
2013-08-06 19:14:51 +00:00
|
|
|
return native_context->double_array_fun();
|
2013-04-29 11:09:03 +00:00
|
|
|
|
2013-05-02 11:36:48 +00:00
|
|
|
case kExternalPixelArray:
|
2013-08-06 19:14:51 +00:00
|
|
|
return native_context->uint8c_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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<JSTypedArray> Factory::NewJSTypedArray(ExternalArrayType type) {
|
|
|
|
Handle<JSFunction> typed_array_fun_handle(GetTypedArrayFun(type, isolate()));
|
2013-04-29 11:09:03 +00:00
|
|
|
|
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate(),
|
2013-08-06 19:14:51 +00:00
|
|
|
isolate()->heap()->AllocateJSObject(*typed_array_fun_handle),
|
2013-04-29 11:09:03 +00:00
|
|
|
JSTypedArray);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-13 10:58:25 +00:00
|
|
|
Handle<JSProxy> Factory::NewJSProxy(Handle<Object> handler,
|
|
|
|
Handle<Object> prototype) {
|
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate(),
|
|
|
|
isolate()->heap()->AllocateJSProxy(*handler, *prototype),
|
|
|
|
JSProxy);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-13 11:42:57 +00:00
|
|
|
void Factory::BecomeJSObject(Handle<JSReceiver> object) {
|
2011-07-18 13:04:52 +00:00
|
|
|
CALL_HEAP_FUNCTION_VOID(
|
|
|
|
isolate(),
|
2011-09-13 11:42:57 +00:00
|
|
|
isolate()->heap()->ReinitializeJSReceiver(
|
|
|
|
*object, JS_OBJECT_TYPE, JSObject::kHeaderSize));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Factory::BecomeJSFunction(Handle<JSReceiver> object) {
|
|
|
|
CALL_HEAP_FUNCTION_VOID(
|
|
|
|
isolate(),
|
|
|
|
isolate()->heap()->ReinitializeJSReceiver(
|
|
|
|
*object, JS_FUNCTION_TYPE, JSFunction::kSize));
|
2011-07-18 13:04:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-23 06:04:44 +00:00
|
|
|
Handle<SharedFunctionInfo> Factory::NewSharedFunctionInfo(
|
2010-07-13 13:06:33 +00:00
|
|
|
Handle<String> name,
|
|
|
|
int number_of_literals,
|
2013-04-17 15:01:25 +00:00
|
|
|
bool is_generator,
|
2010-07-13 13:06:33 +00:00
|
|
|
Handle<Code> code,
|
2011-11-03 10:36:55 +00:00
|
|
|
Handle<ScopeInfo> scope_info) {
|
2010-03-23 06:04:44 +00:00
|
|
|
Handle<SharedFunctionInfo> shared = NewSharedFunctionInfo(name);
|
|
|
|
shared->set_code(*code);
|
2010-07-13 13:06:33 +00:00
|
|
|
shared->set_scope_info(*scope_info);
|
2010-03-23 06:04:44 +00:00
|
|
|
int literals_array_size = number_of_literals;
|
|
|
|
// If the function contains object, regexp or array literals,
|
|
|
|
// allocate extra space for a literals array prefix containing the
|
|
|
|
// context.
|
|
|
|
if (number_of_literals > 0) {
|
|
|
|
literals_array_size += JSFunction::kLiteralsPrefixSize;
|
|
|
|
}
|
|
|
|
shared->set_num_literals(literals_array_size);
|
2013-04-17 15:01:25 +00:00
|
|
|
if (is_generator) {
|
|
|
|
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(
|
|
|
|
Handle<String> type,
|
|
|
|
Handle<JSArray> arguments,
|
|
|
|
int start_position,
|
|
|
|
int end_position,
|
|
|
|
Handle<Object> script,
|
|
|
|
Handle<Object> stack_trace,
|
|
|
|
Handle<Object> stack_frames) {
|
2011-03-18 20:35:07 +00:00
|
|
|
CALL_HEAP_FUNCTION(isolate(),
|
|
|
|
isolate()->heap()->AllocateJSMessageObject(*type,
|
|
|
|
*arguments,
|
|
|
|
start_position,
|
|
|
|
end_position,
|
|
|
|
*script,
|
|
|
|
*stack_trace,
|
|
|
|
*stack_frames),
|
2011-02-02 13:31:52 +00:00
|
|
|
JSMessageObject);
|
|
|
|
}
|
|
|
|
|
2013-07-05 09:52:11 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
Handle<SharedFunctionInfo> Factory::NewSharedFunctionInfo(Handle<String> name) {
|
2011-03-18 20:35:07 +00:00
|
|
|
CALL_HEAP_FUNCTION(isolate(),
|
|
|
|
isolate()->heap()->AllocateSharedFunctionInfo(*name),
|
2008-07-03 15:10:15 +00:00
|
|
|
SharedFunctionInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-02 13:43:16 +00:00
|
|
|
Handle<String> Factory::NumberToString(Handle<Object> number) {
|
2011-03-18 20:35:07 +00:00
|
|
|
CALL_HEAP_FUNCTION(isolate(),
|
|
|
|
isolate()->heap()->NumberToString(*number), String);
|
2009-10-02 13:43:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-22 10:45:37 +00:00
|
|
|
Handle<String> Factory::Uint32ToString(uint32_t value) {
|
|
|
|
CALL_HEAP_FUNCTION(isolate(),
|
|
|
|
isolate()->heap()->Uint32ToString(value), String);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-16 09:44:35 +00:00
|
|
|
Handle<SeededNumberDictionary> Factory::DictionaryAtNumberPut(
|
|
|
|
Handle<SeededNumberDictionary> dictionary,
|
|
|
|
uint32_t key,
|
|
|
|
Handle<Object> value) {
|
|
|
|
CALL_HEAP_FUNCTION(isolate(),
|
|
|
|
dictionary->AtNumberPut(key, *value),
|
|
|
|
SeededNumberDictionary);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<UnseededNumberDictionary> Factory::DictionaryAtNumberPut(
|
|
|
|
Handle<UnseededNumberDictionary> dictionary,
|
2009-07-02 06:50:43 +00:00
|
|
|
uint32_t key,
|
|
|
|
Handle<Object> value) {
|
2011-03-18 20:35:07 +00:00
|
|
|
CALL_HEAP_FUNCTION(isolate(),
|
|
|
|
dictionary->AtNumberPut(key, *value),
|
2012-01-16 09:44:35 +00:00
|
|
|
UnseededNumberDictionary);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<JSFunction> Factory::NewFunctionHelper(Handle<String> name,
|
|
|
|
Handle<Object> prototype) {
|
|
|
|
Handle<SharedFunctionInfo> function_share = NewSharedFunctionInfo(name);
|
2011-03-18 20:35:07 +00:00
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate(),
|
|
|
|
isolate()->heap()->AllocateFunction(*isolate()->function_map(),
|
|
|
|
*function_share,
|
|
|
|
*prototype),
|
|
|
|
JSFunction);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<JSFunction> Factory::NewFunction(Handle<String> name,
|
|
|
|
Handle<Object> prototype) {
|
|
|
|
Handle<JSFunction> fun = NewFunctionHelper(name, prototype);
|
2012-08-17 09:03:08 +00:00
|
|
|
fun->set_context(isolate()->context()->native_context());
|
2008-07-03 15:10:15 +00:00
|
|
|
return fun;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-28 12:05:40 +00:00
|
|
|
Handle<JSFunction> Factory::NewFunctionWithoutPrototypeHelper(
|
2011-03-17 20:28:17 +00:00
|
|
|
Handle<String> name,
|
2011-11-24 15:17:04 +00:00
|
|
|
LanguageMode language_mode) {
|
2010-04-28 12:05:40 +00:00
|
|
|
Handle<SharedFunctionInfo> function_share = NewSharedFunctionInfo(name);
|
2011-11-24 15:17:04 +00:00
|
|
|
Handle<Map> map = (language_mode == CLASSIC_MODE)
|
|
|
|
? isolate()->function_without_prototype_map()
|
|
|
|
: isolate()->strict_mode_function_without_prototype_map();
|
2011-03-18 20:35:07 +00:00
|
|
|
CALL_HEAP_FUNCTION(isolate(),
|
|
|
|
isolate()->heap()->AllocateFunction(
|
2011-03-17 20:28:17 +00:00
|
|
|
*map,
|
2010-04-28 12:05:40 +00:00
|
|
|
*function_share,
|
|
|
|
*the_hole_value()),
|
|
|
|
JSFunction);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-17 20:28:17 +00:00
|
|
|
Handle<JSFunction> Factory::NewFunctionWithoutPrototype(
|
|
|
|
Handle<String> name,
|
2011-11-24 15:17:04 +00:00
|
|
|
LanguageMode language_mode) {
|
|
|
|
Handle<JSFunction> fun =
|
|
|
|
NewFunctionWithoutPrototypeHelper(name, language_mode);
|
2012-08-17 09:03:08 +00:00
|
|
|
fun->set_context(isolate()->context()->native_context());
|
2010-04-28 12:05:40 +00:00
|
|
|
return fun;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-18 14:13:58 +00:00
|
|
|
Handle<Object> Factory::ToObject(Handle<Object> object) {
|
2013-09-04 07:05:11 +00:00
|
|
|
CALL_HEAP_FUNCTION(isolate(), object->ToObject(isolate()), Object);
|
2010-01-18 14:13:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
Handle<Object> Factory::ToObject(Handle<Object> object,
|
2012-08-17 09:03:08 +00:00
|
|
|
Handle<Context> native_context) {
|
|
|
|
CALL_HEAP_FUNCTION(isolate(), object->ToObject(*native_context), Object);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-20 16:36:13 +00:00
|
|
|
#ifdef ENABLE_DEBUGGER_SUPPORT
|
2008-09-01 10:15:45 +00:00
|
|
|
Handle<DebugInfo> Factory::NewDebugInfo(Handle<SharedFunctionInfo> shared) {
|
|
|
|
// Get the original code of the function.
|
|
|
|
Handle<Code> code(shared->code());
|
|
|
|
|
|
|
|
// Create a copy of the code before allocating the debug info object to avoid
|
|
|
|
// allocation while setting up the debug info object.
|
|
|
|
Handle<Code> original_code(*Factory::CopyCode(code));
|
|
|
|
|
|
|
|
// 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(
|
2011-03-18 20:35:07 +00:00
|
|
|
NewFixedArray(Debug::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);
|
|
|
|
debug_info->set_original_code(*original_code);
|
|
|
|
debug_info->set_code(*code);
|
|
|
|
debug_info->set_break_points(*break_points);
|
|
|
|
|
|
|
|
// Link debug info to function.
|
|
|
|
shared->set_debug_info(*debug_info);
|
|
|
|
|
|
|
|
return debug_info;
|
|
|
|
}
|
2009-04-20 16:36:13 +00:00
|
|
|
#endif
|
2008-09-01 10:15:45 +00:00
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
Handle<JSObject> Factory::NewArgumentsObject(Handle<Object> callee,
|
|
|
|
int length) {
|
2011-03-18 20:35:07 +00:00
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate(),
|
|
|
|
isolate()->heap()->AllocateArgumentsObject(*callee, length), JSObject);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<JSFunction> Factory::CreateApiFunction(
|
Split window support from V8.
Here is a description of the background and design of split window in Chrome and V8:
https://docs.google.com/a/google.com/Doc?id=chhjkpg_47fwddxbfr
This change list splits the window object into two parts: 1) an inner window object used as the global object of contexts; 2) an outer window object exposed to JavaScript and accessible by the name 'window'. Firefox did it awhile ago, here are some discussions: https://wiki.mozilla.org/Gecko:SplitWindow. One additional benefit of splitting window in Chrome is that accessing global variables don't need security checks anymore, it can improve applications that use many global variables.
V8 support of split window:
There are a small number of changes on V8 api to support split window:
Security context is removed from V8, so does related API functions;
A global object can be detached from its context and reused by a new context;
Access checks on an object template can be turned on/off by default;
An object can turn on its access checks later;
V8 has a new object type, ApiGlobalObject, which is the outer window object type. The existing JSGlobalObject becomes the inner window object type. Security checks are moved from JSGlobalObject to ApiGlobalObject. ApiGlobalObject is the one exposed to JavaScript, it is accessible through Context::Global(). ApiGlobalObject's prototype is set to JSGlobalObject so that property lookups are forwarded to JSGlobalObject. ApiGlobalObject forwards all other property access requests to JSGlobalObject, such as SetProperty, DeleteProperty, etc.
Security token is moved to a global context, and ApiGlobalObject has a reference to its global context. JSGlobalObject has a reference to its global context as well. When accessing properties on a global object in JavaScript, the domain security check is performed by comparing the security token of the lexical context (Top::global_context()) to the token of global object's context. The check is only needed when the receiver is a window object, such as 'window.document'. Accessing global variables, such as 'var foo = 3; foo' does not need checks because the receiver is the inner window object.
When an outer window is detached from its global context (when a frame navigates away from a page), it is completely detached from the inner window. A new context is created for the new page, and the outer global object is reused. At this point, the access check on the DOMWindow wrapper of the old context is turned on. The code in old context is still able to access DOMWindow properties, but it has to go through domain security checks.
It is debatable on how to implement the outer window object. Currently each property access function has to check if the receiver is ApiGlobalObject type. This approach might be error-prone that one may forget to check the receiver when adding new functions. It is unlikely a performance issue because accessing global variables are more common than 'window.foo' style coding.
I am still working on the ARM port, and I'd like to hear comments and suggestions on the best way to support it in V8.
Review URL: http://codereview.chromium.org/7366
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@540 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2008-10-21 19:07:58 +00:00
|
|
|
Handle<FunctionTemplateInfo> obj, ApiInstanceType instance_type) {
|
2011-03-23 13:40:07 +00:00
|
|
|
Handle<Code> code = isolate()->builtins()->HandleApiCall();
|
|
|
|
Handle<Code> construct_stub = isolate()->builtins()->JSConstructStubApi();
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-07-16 07:07:30 +00:00
|
|
|
int internal_field_count = 0;
|
|
|
|
if (!obj->instance_template()->IsUndefined()) {
|
|
|
|
Handle<ObjectTemplateInfo> instance_template =
|
|
|
|
Handle<ObjectTemplateInfo>(
|
|
|
|
ObjectTemplateInfo::cast(obj->instance_template()));
|
|
|
|
internal_field_count =
|
|
|
|
Smi::cast(instance_template->internal_field_count())->value();
|
|
|
|
}
|
|
|
|
|
2013-08-09 08:22:46 +00:00
|
|
|
// TODO(svenpanne) Kill ApiInstanceType and refactor things by generalizing
|
|
|
|
// JSObject::GetHeaderSize.
|
2008-07-16 07:07:30 +00:00
|
|
|
int instance_size = kPointerSize * internal_field_count;
|
2013-08-09 08:22:46 +00:00
|
|
|
InstanceType type;
|
Split window support from V8.
Here is a description of the background and design of split window in Chrome and V8:
https://docs.google.com/a/google.com/Doc?id=chhjkpg_47fwddxbfr
This change list splits the window object into two parts: 1) an inner window object used as the global object of contexts; 2) an outer window object exposed to JavaScript and accessible by the name 'window'. Firefox did it awhile ago, here are some discussions: https://wiki.mozilla.org/Gecko:SplitWindow. One additional benefit of splitting window in Chrome is that accessing global variables don't need security checks anymore, it can improve applications that use many global variables.
V8 support of split window:
There are a small number of changes on V8 api to support split window:
Security context is removed from V8, so does related API functions;
A global object can be detached from its context and reused by a new context;
Access checks on an object template can be turned on/off by default;
An object can turn on its access checks later;
V8 has a new object type, ApiGlobalObject, which is the outer window object type. The existing JSGlobalObject becomes the inner window object type. Security checks are moved from JSGlobalObject to ApiGlobalObject. ApiGlobalObject is the one exposed to JavaScript, it is accessible through Context::Global(). ApiGlobalObject's prototype is set to JSGlobalObject so that property lookups are forwarded to JSGlobalObject. ApiGlobalObject forwards all other property access requests to JSGlobalObject, such as SetProperty, DeleteProperty, etc.
Security token is moved to a global context, and ApiGlobalObject has a reference to its global context. JSGlobalObject has a reference to its global context as well. When accessing properties on a global object in JavaScript, the domain security check is performed by comparing the security token of the lexical context (Top::global_context()) to the token of global object's context. The check is only needed when the receiver is a window object, such as 'window.document'. Accessing global variables, such as 'var foo = 3; foo' does not need checks because the receiver is the inner window object.
When an outer window is detached from its global context (when a frame navigates away from a page), it is completely detached from the inner window. A new context is created for the new page, and the outer global object is reused. At this point, the access check on the DOMWindow wrapper of the old context is turned on. The code in old context is still able to access DOMWindow properties, but it has to go through domain security checks.
It is debatable on how to implement the outer window object. Currently each property access function has to check if the receiver is ApiGlobalObject type. This approach might be error-prone that one may forget to check the receiver when adding new functions. It is unlikely a performance issue because accessing global variables are more common than 'window.foo' style coding.
I am still working on the ARM port, and I'd like to hear comments and suggestions on the best way to support it in V8.
Review URL: http://codereview.chromium.org/7366
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@540 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2008-10-21 19:07:58 +00:00
|
|
|
switch (instance_type) {
|
|
|
|
case JavaScriptObject:
|
|
|
|
type = JS_OBJECT_TYPE;
|
|
|
|
instance_size += JSObject::kHeaderSize;
|
|
|
|
break;
|
|
|
|
case InnerGlobalObject:
|
|
|
|
type = JS_GLOBAL_OBJECT_TYPE;
|
|
|
|
instance_size += JSGlobalObject::kSize;
|
|
|
|
break;
|
|
|
|
case OuterGlobalObject:
|
|
|
|
type = JS_GLOBAL_PROXY_TYPE;
|
|
|
|
instance_size += JSGlobalProxy::kSize;
|
|
|
|
break;
|
|
|
|
default:
|
2013-08-09 08:22:46 +00:00
|
|
|
UNREACHABLE();
|
|
|
|
type = JS_OBJECT_TYPE; // Keep the compiler happy.
|
Split window support from V8.
Here is a description of the background and design of split window in Chrome and V8:
https://docs.google.com/a/google.com/Doc?id=chhjkpg_47fwddxbfr
This change list splits the window object into two parts: 1) an inner window object used as the global object of contexts; 2) an outer window object exposed to JavaScript and accessible by the name 'window'. Firefox did it awhile ago, here are some discussions: https://wiki.mozilla.org/Gecko:SplitWindow. One additional benefit of splitting window in Chrome is that accessing global variables don't need security checks anymore, it can improve applications that use many global variables.
V8 support of split window:
There are a small number of changes on V8 api to support split window:
Security context is removed from V8, so does related API functions;
A global object can be detached from its context and reused by a new context;
Access checks on an object template can be turned on/off by default;
An object can turn on its access checks later;
V8 has a new object type, ApiGlobalObject, which is the outer window object type. The existing JSGlobalObject becomes the inner window object type. Security checks are moved from JSGlobalObject to ApiGlobalObject. ApiGlobalObject is the one exposed to JavaScript, it is accessible through Context::Global(). ApiGlobalObject's prototype is set to JSGlobalObject so that property lookups are forwarded to JSGlobalObject. ApiGlobalObject forwards all other property access requests to JSGlobalObject, such as SetProperty, DeleteProperty, etc.
Security token is moved to a global context, and ApiGlobalObject has a reference to its global context. JSGlobalObject has a reference to its global context as well. When accessing properties on a global object in JavaScript, the domain security check is performed by comparing the security token of the lexical context (Top::global_context()) to the token of global object's context. The check is only needed when the receiver is a window object, such as 'window.document'. Accessing global variables, such as 'var foo = 3; foo' does not need checks because the receiver is the inner window object.
When an outer window is detached from its global context (when a frame navigates away from a page), it is completely detached from the inner window. A new context is created for the new page, and the outer global object is reused. At this point, the access check on the DOMWindow wrapper of the old context is turned on. The code in old context is still able to access DOMWindow properties, but it has to go through domain security checks.
It is debatable on how to implement the outer window object. Currently each property access function has to check if the receiver is ApiGlobalObject type. This approach might be error-prone that one may forget to check the receiver when adding new functions. It is unlikely a performance issue because accessing global variables are more common than 'window.foo' style coding.
I am still working on the ARM port, and I'd like to hear comments and suggestions on the best way to support it in V8.
Review URL: http://codereview.chromium.org/7366
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@540 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2008-10-21 19:07:58 +00:00
|
|
|
break;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Handle<JSFunction> result =
|
2013-02-28 17:03:34 +00:00
|
|
|
NewFunction(Factory::empty_string(),
|
2011-03-18 20:35:07 +00:00
|
|
|
type,
|
|
|
|
instance_size,
|
|
|
|
code,
|
|
|
|
true);
|
2012-12-19 10:28:36 +00:00
|
|
|
|
|
|
|
// Set length.
|
|
|
|
result->shared()->set_length(obj->length());
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// Set class name.
|
2013-02-25 14:46:09 +00:00
|
|
|
Handle<Object> class_name = Handle<Object>(obj->class_name(), isolate());
|
2008-07-03 15:10:15 +00:00
|
|
|
if (class_name->IsString()) {
|
|
|
|
result->shared()->set_instance_class_name(*class_name);
|
|
|
|
result->shared()->set_name(*class_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
Handle<Map> map = Handle<Map>(result->initial_map());
|
|
|
|
|
|
|
|
// Mark as undetectable if needed.
|
|
|
|
if (obj->undetectable()) {
|
|
|
|
map->set_is_undetectable();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mark as hidden for the __proto__ accessor if needed.
|
|
|
|
if (obj->hidden_prototype()) {
|
|
|
|
map->set_is_hidden_prototype();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mark as needs_access_check if needed.
|
|
|
|
if (obj->needs_access_check()) {
|
2008-10-30 12:51:06 +00:00
|
|
|
map->set_is_access_check_needed(true);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set interceptor information in the map.
|
|
|
|
if (!obj->named_property_handler()->IsUndefined()) {
|
|
|
|
map->set_has_named_interceptor();
|
|
|
|
}
|
|
|
|
if (!obj->indexed_property_handler()->IsUndefined()) {
|
|
|
|
map->set_has_indexed_interceptor();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set instance call-as-function information in the map.
|
|
|
|
if (!obj->instance_call_handler()->IsUndefined()) {
|
|
|
|
map->set_has_instance_call_handler();
|
|
|
|
}
|
|
|
|
|
|
|
|
result->shared()->set_function_data(*obj);
|
2010-01-15 12:25:24 +00:00
|
|
|
result->shared()->set_construct_stub(*construct_stub);
|
2008-09-16 10:12:32 +00:00
|
|
|
result->shared()->DontAdaptArguments();
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2013-09-04 07:45:36 +00:00
|
|
|
// Recursively copy parent instance templates' accessors,
|
|
|
|
// 'data' may be modified.
|
2012-09-18 13:25:12 +00:00
|
|
|
int max_number_of_additional_properties = 0;
|
2013-09-04 07:45:36 +00:00
|
|
|
int max_number_of_static_properties = 0;
|
2012-09-18 13:25:12 +00:00
|
|
|
FunctionTemplateInfo* info = *obj;
|
|
|
|
while (true) {
|
2013-09-04 07:45:36 +00:00
|
|
|
if (!info->instance_template()->IsUndefined()) {
|
|
|
|
Object* props =
|
|
|
|
ObjectTemplateInfo::cast(
|
|
|
|
info->instance_template())->property_accessors();
|
|
|
|
if (!props->IsUndefined()) {
|
|
|
|
Handle<Object> props_handle(props, isolate());
|
|
|
|
NeanderArray props_array(props_handle);
|
|
|
|
max_number_of_additional_properties += props_array.length();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!info->property_accessors()->IsUndefined()) {
|
|
|
|
Object* props = info->property_accessors();
|
|
|
|
if (!props->IsUndefined()) {
|
|
|
|
Handle<Object> props_handle(props, isolate());
|
|
|
|
NeanderArray props_array(props_handle);
|
|
|
|
max_number_of_static_properties += props_array.length();
|
|
|
|
}
|
2012-09-18 13:25:12 +00:00
|
|
|
}
|
|
|
|
Object* parent = info->parent_template();
|
|
|
|
if (parent->IsUndefined()) break;
|
|
|
|
info = FunctionTemplateInfo::cast(parent);
|
|
|
|
}
|
|
|
|
|
|
|
|
Map::EnsureDescriptorSlack(map, max_number_of_additional_properties);
|
|
|
|
|
2013-09-04 07:45:36 +00:00
|
|
|
// Use a temporary FixedArray to acculumate static accessors
|
|
|
|
int valid_descriptors = 0;
|
|
|
|
Handle<FixedArray> array;
|
|
|
|
if (max_number_of_static_properties > 0) {
|
|
|
|
array = NewFixedArray(max_number_of_static_properties);
|
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
while (true) {
|
2013-09-04 07:45:36 +00:00
|
|
|
// Install instance descriptors
|
|
|
|
if (!obj->instance_template()->IsUndefined()) {
|
|
|
|
Handle<ObjectTemplateInfo> instance =
|
|
|
|
Handle<ObjectTemplateInfo>(
|
|
|
|
ObjectTemplateInfo::cast(obj->instance_template()), isolate());
|
|
|
|
Handle<Object> props = Handle<Object>(instance->property_accessors(),
|
|
|
|
isolate());
|
|
|
|
if (!props->IsUndefined()) {
|
|
|
|
Map::AppendCallbackDescriptors(map, props);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Accumulate static accessors
|
|
|
|
if (!obj->property_accessors()->IsUndefined()) {
|
|
|
|
Handle<Object> props = Handle<Object>(obj->property_accessors(),
|
|
|
|
isolate());
|
|
|
|
valid_descriptors =
|
|
|
|
AccessorInfo::AppendUnique(props, array, valid_descriptors);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2013-09-04 07:45:36 +00:00
|
|
|
// Climb parent chain
|
2013-02-25 14:46:09 +00:00
|
|
|
Handle<Object> parent = Handle<Object>(obj->parent_template(), isolate());
|
2008-07-03 15:10:15 +00:00
|
|
|
if (parent->IsUndefined()) break;
|
|
|
|
obj = Handle<FunctionTemplateInfo>::cast(parent);
|
|
|
|
}
|
|
|
|
|
2013-09-04 07:45:36 +00:00
|
|
|
// Install accumulated static accessors
|
|
|
|
for (int i = 0; i < valid_descriptors; i++) {
|
|
|
|
Handle<AccessorInfo> accessor(AccessorInfo::cast(array->get(i)));
|
|
|
|
JSObject::SetAccessor(result, accessor);
|
|
|
|
}
|
|
|
|
|
2010-03-11 16:24:31 +00:00
|
|
|
ASSERT(result->shared()->IsApiFunction());
|
2008-07-03 15:10:15 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-25 07:46:07 +00:00
|
|
|
Handle<MapCache> Factory::NewMapCache(int at_least_space_for) {
|
2011-03-18 20:35:07 +00:00
|
|
|
CALL_HEAP_FUNCTION(isolate(),
|
2013-03-12 07:06:36 +00:00
|
|
|
MapCache::Allocate(isolate()->heap(),
|
|
|
|
at_least_space_for),
|
|
|
|
MapCache);
|
2008-09-25 07:46:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-25 15:22:03 +00:00
|
|
|
MUST_USE_RESULT static MaybeObject* UpdateMapCacheWith(Context* context,
|
|
|
|
FixedArray* keys,
|
|
|
|
Map* map) {
|
|
|
|
Object* result;
|
|
|
|
{ MaybeObject* maybe_result =
|
|
|
|
MapCache::cast(context->map_cache())->Put(keys, map);
|
|
|
|
if (!maybe_result->ToObject(&result)) return maybe_result;
|
|
|
|
}
|
|
|
|
context->set_map_cache(MapCache::cast(result));
|
2008-09-25 07:46:07 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<MapCache> Factory::AddToMapCache(Handle<Context> context,
|
|
|
|
Handle<FixedArray> keys,
|
|
|
|
Handle<Map> map) {
|
2011-03-18 20:35:07 +00:00
|
|
|
CALL_HEAP_FUNCTION(isolate(),
|
|
|
|
UpdateMapCacheWith(*context, *keys, *map), MapCache);
|
2008-09-25 07:46:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Map> Factory::ObjectLiteralMapFromCache(Handle<Context> context,
|
|
|
|
Handle<FixedArray> keys) {
|
|
|
|
if (context->map_cache()->IsUndefined()) {
|
2012-08-17 09:03:08 +00:00
|
|
|
// Allocate the new map cache for the native context.
|
2008-09-25 07:46:07 +00:00
|
|
|
Handle<MapCache> new_cache = NewMapCache(24);
|
|
|
|
context->set_map_cache(*new_cache);
|
|
|
|
}
|
2009-01-15 19:08:34 +00:00
|
|
|
// Check to see whether there is a matching element in the cache.
|
2008-09-25 07:46:07 +00:00
|
|
|
Handle<MapCache> cache =
|
|
|
|
Handle<MapCache>(MapCache::cast(context->map_cache()));
|
2012-11-16 08:38:11 +00:00
|
|
|
Handle<Object> result = Handle<Object>(cache->Lookup(*keys), isolate());
|
2008-09-25 07:46:07 +00:00
|
|
|
if (result->IsMap()) return Handle<Map>::cast(result);
|
|
|
|
// Create a new map and add it to the cache.
|
|
|
|
Handle<Map> map =
|
2009-01-12 10:59:58 +00:00
|
|
|
CopyMap(Handle<Map>(context->object_function()->initial_map()),
|
|
|
|
keys->length());
|
2008-09-25 07:46:07 +00:00
|
|
|
AddToMapCache(context, keys, map);
|
|
|
|
return Handle<Map>(map);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
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()));
|
2011-07-05 06:19:53 +00:00
|
|
|
store->set(JSRegExp::kIrregexpASCIICodeIndex, uninitialized);
|
|
|
|
store->set(JSRegExp::kIrregexpUC16CodeIndex, uninitialized);
|
|
|
|
store->set(JSRegExp::kIrregexpASCIICodeSavedIndex, uninitialized);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-24 08:40:02 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
void Factory::ConfigureInstance(Handle<FunctionTemplateInfo> desc,
|
|
|
|
Handle<JSObject> instance,
|
|
|
|
bool* pending_exception) {
|
|
|
|
// Configure the instance by adding the properties specified by the
|
|
|
|
// instance template.
|
2012-11-16 08:38:11 +00:00
|
|
|
Handle<Object> instance_template(desc->instance_template(), isolate());
|
2008-07-03 15:10:15 +00:00
|
|
|
if (!instance_template->IsUndefined()) {
|
2013-09-03 06:59:01 +00:00
|
|
|
Execution::ConfigureInstance(isolate(),
|
|
|
|
instance,
|
2008-07-03 15:10:15 +00:00
|
|
|
instance_template,
|
|
|
|
pending_exception);
|
|
|
|
} else {
|
|
|
|
*pending_exception = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-23 08:00:06 +00:00
|
|
|
Handle<Object> Factory::GlobalConstantFor(Handle<String> name) {
|
|
|
|
Heap* h = isolate()->heap();
|
2013-02-28 17:03:34 +00:00
|
|
|
if (name->Equals(h->undefined_string())) return undefined_value();
|
|
|
|
if (name->Equals(h->nan_string())) return nan_value();
|
|
|
|
if (name->Equals(h->infinity_string())) return infinity_value();
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
} } // namespace v8::internal
|