Upgrade to 3.29
Update V8 to 3.29.88.17 and update makefiles to support building on
all the relevant platforms.
Bug: 17370214
Change-Id: Ia3407c157fd8d72a93e23d8318ccaf6ecf77fa4e
diff --git a/src/factory.h b/src/factory.h
index 786d4a9..24b490c 100644
--- a/src/factory.h
+++ b/src/factory.h
@@ -1,45 +1,25 @@
-// Copyright 2012 the V8 project authors. All rights reserved.
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following
-// disclaimer in the documentation and/or other materials provided
-// with the distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived
-// from this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+// 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.
#ifndef V8_FACTORY_H_
#define V8_FACTORY_H_
-#include "globals.h"
-#include "handles.h"
-#include "heap.h"
+#include "src/isolate.h"
namespace v8 {
namespace internal {
// Interface for handle based allocation.
-class Factory {
+class Factory FINAL {
public:
- // Allocate a new uninitialized fixed array.
+ Handle<Oddball> NewOddball(Handle<Map> map,
+ const char* to_string,
+ Handle<Object> to_number,
+ byte kind);
+
+ // Allocates a fixed array initialized with undefined values.
Handle<FixedArray> NewFixedArray(
int size,
PretenureFlag pretenure = NOT_TENURED);
@@ -49,45 +29,55 @@
int size,
PretenureFlag pretenure = NOT_TENURED);
+ // Allocates an uninitialized fixed array. It must be filled by the caller.
+ Handle<FixedArray> NewUninitializedFixedArray(int size);
+
// Allocate a new uninitialized fixed double array.
- Handle<FixedDoubleArray> NewFixedDoubleArray(
+ // The function returns a pre-allocated empty fixed array for capacity = 0,
+ // so the return type must be the general fixed array class.
+ Handle<FixedArrayBase> NewFixedDoubleArray(
int size,
PretenureFlag pretenure = NOT_TENURED);
- Handle<SeededNumberDictionary> NewSeededNumberDictionary(
- int at_least_space_for);
+ // Allocate a new fixed double array with hole values.
+ Handle<FixedArrayBase> NewFixedDoubleArrayWithHoles(
+ int size,
+ PretenureFlag pretenure = NOT_TENURED);
- Handle<UnseededNumberDictionary> NewUnseededNumberDictionary(
- int at_least_space_for);
+ Handle<ConstantPoolArray> NewConstantPoolArray(
+ const ConstantPoolArray::NumberOfEntries& small);
- Handle<StringDictionary> NewStringDictionary(int at_least_space_for);
+ Handle<ConstantPoolArray> NewExtendedConstantPoolArray(
+ const ConstantPoolArray::NumberOfEntries& small,
+ const ConstantPoolArray::NumberOfEntries& extended);
- Handle<ObjectHashSet> NewObjectHashSet(int at_least_space_for);
+ Handle<OrderedHashSet> NewOrderedHashSet();
+ Handle<OrderedHashMap> NewOrderedHashMap();
- Handle<ObjectHashTable> NewObjectHashTable(int at_least_space_for);
+ // Create a new boxed value.
+ Handle<Box> NewBox(Handle<Object> value);
- Handle<DescriptorArray> NewDescriptorArray(int number_of_descriptors);
- Handle<DeoptimizationInputData> NewDeoptimizationInputData(
- int deopt_entry_count,
- PretenureFlag pretenure);
- Handle<DeoptimizationOutputData> NewDeoptimizationOutputData(
- int deopt_entry_count,
- PretenureFlag pretenure);
- // Allocates a pre-tenured empty AccessorPair.
+ // Create a pre-tenured empty AccessorPair.
Handle<AccessorPair> NewAccessorPair();
+ // Create an empty TypeFeedbackInfo.
Handle<TypeFeedbackInfo> NewTypeFeedbackInfo();
- Handle<String> LookupSymbol(Vector<const char> str);
- Handle<String> LookupSymbol(Handle<String> str);
- Handle<String> LookupAsciiSymbol(Vector<const char> str);
- Handle<String> LookupAsciiSymbol(Handle<SeqAsciiString>,
- int from,
- int length);
- Handle<String> LookupTwoByteSymbol(Vector<const uc16> str);
- Handle<String> LookupAsciiSymbol(const char* str) {
- return LookupSymbol(CStrVector(str));
+ // Finds the internalized copy for string in the string table.
+ // If not found, a new string is added to the table and returned.
+ Handle<String> InternalizeUtf8String(Vector<const char> str);
+ Handle<String> InternalizeUtf8String(const char* str) {
+ return InternalizeUtf8String(CStrVector(str));
}
+ Handle<String> InternalizeString(Handle<String> str);
+ Handle<String> InternalizeOneByteString(Vector<const uint8_t> str);
+ Handle<String> InternalizeOneByteString(
+ Handle<SeqOneByteString>, int from, int length);
+
+ Handle<String> InternalizeTwoByteString(Vector<const uc16> str);
+
+ template<class StringTableKey>
+ Handle<String> InternalizeStringWithKey(StringTableKey* key);
// String creation functions. Most of the string creation functions take
@@ -95,76 +85,155 @@
// allocated in the old generation. The pretenure flag defaults to
// DONT_TENURE.
//
- // Creates a new String object. There are two String encodings: ASCII and
- // two byte. One should choose between the three string factory functions
+ // Creates a new String object. There are two String encodings: one-byte and
+ // two-byte. One should choose between the three string factory functions
// based on the encoding of the string buffer that the string is
// initialized from.
- // - ...FromAscii initializes the string from a buffer that is ASCII
- // encoded (it does not check that the buffer is ASCII encoded) and
- // the result will be ASCII encoded.
+ // - ...FromOneByte initializes the string from a buffer that is Latin1
+ // encoded (it does not check that the buffer is Latin1 encoded) and
+ // the result will be Latin1 encoded.
// - ...FromUtf8 initializes the string from a buffer that is UTF-8
- // encoded. If the characters are all single-byte characters, the
- // result will be ASCII encoded, otherwise it will converted to two
- // byte.
- // - ...FromTwoByte initializes the string from a buffer that is two
- // byte encoded. If the characters are all single-byte characters,
- // the result will be converted to ASCII, otherwise it will be left as
- // two byte.
+ // encoded. If the characters are all ASCII characters, the result
+ // will be Latin1 encoded, otherwise it will converted to two-byte.
+ // - ...FromTwoByte initializes the string from a buffer that is two-byte
+ // encoded. If the characters are all Latin1 characters, the result
+ // will be converted to Latin1, otherwise it will be left as two-byte.
//
- // ASCII strings are pretenured when used as keys in the SourceCodeCache.
- Handle<String> NewStringFromAscii(
- Vector<const char> str,
+ // One-byte strings are pretenured when used as keys in the SourceCodeCache.
+ MUST_USE_RESULT MaybeHandle<String> NewStringFromOneByte(
+ Vector<const uint8_t> str,
PretenureFlag pretenure = NOT_TENURED);
+ template <size_t N>
+ inline Handle<String> NewStringFromStaticChars(
+ const char (&str)[N], PretenureFlag pretenure = NOT_TENURED) {
+ DCHECK(N == StrLength(str) + 1);
+ return NewStringFromOneByte(STATIC_CHAR_VECTOR(str), pretenure)
+ .ToHandleChecked();
+ }
+
+ inline Handle<String> NewStringFromAsciiChecked(
+ const char* str,
+ PretenureFlag pretenure = NOT_TENURED) {
+ return NewStringFromOneByte(
+ OneByteVector(str), pretenure).ToHandleChecked();
+ }
+
+
+ // Allocates and fully initializes a String. There are two String encodings:
+ // one-byte and two-byte. One should choose between the threestring
+ // allocation functions based on the encoding of the string buffer used to
+ // initialized the string.
+ // - ...FromOneByte initializes the string from a buffer that is Latin1
+ // encoded (it does not check that the buffer is Latin1 encoded) and the
+ // result will be Latin1 encoded.
+ // - ...FromUTF8 initializes the string from a buffer that is UTF-8
+ // encoded. If the characters are all ASCII characters, the result
+ // will be Latin1 encoded, otherwise it will converted to two-byte.
+ // - ...FromTwoByte initializes the string from a buffer that is two-byte
+ // encoded. If the characters are all Latin1 characters, the
+ // result will be converted to Latin1, otherwise it will be left as
+ // two-byte.
+
+ // TODO(dcarney): remove this function.
+ MUST_USE_RESULT inline MaybeHandle<String> NewStringFromAscii(
+ Vector<const char> str,
+ PretenureFlag pretenure = NOT_TENURED) {
+ return NewStringFromOneByte(Vector<const uint8_t>::cast(str), pretenure);
+ }
+
// UTF8 strings are pretenured when used for regexp literal patterns and
// flags in the parser.
- Handle<String> NewStringFromUtf8(
+ MUST_USE_RESULT MaybeHandle<String> NewStringFromUtf8(
Vector<const char> str,
PretenureFlag pretenure = NOT_TENURED);
- Handle<String> NewStringFromTwoByte(
+ MUST_USE_RESULT MaybeHandle<String> NewStringFromTwoByte(
Vector<const uc16> str,
PretenureFlag pretenure = NOT_TENURED);
- // Allocates and partially initializes an ASCII or TwoByte String. The
+ // Allocates an internalized string in old space based on the character
+ // stream.
+ MUST_USE_RESULT Handle<String> NewInternalizedStringFromUtf8(
+ Vector<const char> str,
+ int chars,
+ uint32_t hash_field);
+
+ MUST_USE_RESULT Handle<String> NewOneByteInternalizedString(
+ Vector<const uint8_t> str, uint32_t hash_field);
+
+ MUST_USE_RESULT Handle<String> NewOneByteInternalizedSubString(
+ Handle<SeqOneByteString> string, int offset, int length,
+ uint32_t hash_field);
+
+ MUST_USE_RESULT Handle<String> NewTwoByteInternalizedString(
+ Vector<const uc16> str,
+ uint32_t hash_field);
+
+ MUST_USE_RESULT Handle<String> NewInternalizedStringImpl(
+ Handle<String> string, int chars, uint32_t hash_field);
+
+ // Compute the matching internalized string map for a string if possible.
+ // Empty handle is returned if string is in new space or not flattened.
+ MUST_USE_RESULT MaybeHandle<Map> InternalizedStringMapForString(
+ Handle<String> string);
+
+ // Allocates and partially initializes an one-byte or two-byte String. The
// characters of the string are uninitialized. Currently used in regexp code
// only, where they are pretenured.
- Handle<SeqAsciiString> NewRawAsciiString(
+ MUST_USE_RESULT MaybeHandle<SeqOneByteString> NewRawOneByteString(
int length,
PretenureFlag pretenure = NOT_TENURED);
- Handle<SeqTwoByteString> NewRawTwoByteString(
+ MUST_USE_RESULT MaybeHandle<SeqTwoByteString> NewRawTwoByteString(
int length,
PretenureFlag pretenure = NOT_TENURED);
+ // Creates a single character string where the character has given code.
+ // A cache is used for Latin1 codes.
+ Handle<String> LookupSingleCharacterStringFromCode(uint32_t code);
+
// Create a new cons string object which consists of a pair of strings.
- Handle<String> NewConsString(Handle<String> first,
- Handle<String> second);
-
- // Create a new string object which holds a substring of a string.
- Handle<String> NewSubString(Handle<String> str,
- int begin,
- int end);
+ MUST_USE_RESULT MaybeHandle<String> NewConsString(Handle<String> left,
+ Handle<String> right);
// Create a new string object which holds a proper substring of a string.
Handle<String> NewProperSubString(Handle<String> str,
int begin,
int end);
+ // Create a new string object which holds a substring of a string.
+ Handle<String> NewSubString(Handle<String> str, int begin, int end) {
+ if (begin == 0 && end == str->length()) return str;
+ return NewProperSubString(str, begin, end);
+ }
+
// Creates a new external String object. There are two String encodings
- // in the system: ASCII and two byte. Unlike other String types, it does
+ // in the system: one-byte and two-byte. Unlike other String types, it does
// not make sense to have a UTF-8 factory function for external strings,
- // because we cannot change the underlying buffer.
- Handle<String> NewExternalStringFromAscii(
- const ExternalAsciiString::Resource* resource);
- Handle<String> NewExternalStringFromTwoByte(
+ // because we cannot change the underlying buffer. Note that these strings
+ // are backed by a string resource that resides outside the V8 heap.
+ MUST_USE_RESULT MaybeHandle<String> NewExternalStringFromOneByte(
+ const ExternalOneByteString::Resource* resource);
+ MUST_USE_RESULT MaybeHandle<String> NewExternalStringFromTwoByte(
const ExternalTwoByteString::Resource* resource);
+ // Create a symbol.
+ Handle<Symbol> NewSymbol();
+ Handle<Symbol> NewPrivateSymbol();
+ Handle<Symbol> NewPrivateOwnSymbol();
+
// Create a global (but otherwise uninitialized) context.
- Handle<Context> NewGlobalContext();
+ Handle<Context> NewNativeContext();
+
+ // Create a global context.
+ Handle<Context> NewGlobalContext(Handle<JSFunction> function,
+ Handle<ScopeInfo> scope_info);
+
+ // Create a module context.
+ Handle<Context> NewModuleContext(Handle<ScopeInfo> scope_info);
// Create a function context.
- Handle<Context> NewFunctionContext(int length,
- Handle<JSFunction> function);
+ Handle<Context> NewFunctionContext(int length, Handle<JSFunction> function);
// Create a catch context.
Handle<Context> NewCatchContext(Handle<JSFunction> function,
@@ -175,21 +244,27 @@
// Create a 'with' context.
Handle<Context> NewWithContext(Handle<JSFunction> function,
Handle<Context> previous,
- Handle<JSObject> extension);
+ Handle<JSReceiver> extension);
- // Create a 'block' context.
+ // Create a block context.
Handle<Context> NewBlockContext(Handle<JSFunction> function,
Handle<Context> previous,
Handle<ScopeInfo> scope_info);
- // Return the Symbol matching the passed in string.
- Handle<String> SymbolFromString(Handle<String> value);
-
// Allocate a new struct. The struct is pretenured (allocated directly in
// the old generation).
Handle<Struct> NewStruct(InstanceType type);
- Handle<AccessorInfo> NewAccessorInfo();
+ Handle<CodeCache> NewCodeCache();
+
+ Handle<AliasedArgumentsEntry> NewAliasedArgumentsEntry(
+ int aliased_context_slot);
+
+ Handle<DeclaredAccessorDescriptor> NewDeclaredAccessorDescriptor();
+
+ Handle<DeclaredAccessorInfo> NewDeclaredAccessorInfo();
+
+ Handle<ExecutableAccessorInfo> NewExecutableAccessorInfo();
Handle<Script> NewScript(Handle<String> source);
@@ -210,32 +285,53 @@
void* external_pointer,
PretenureFlag pretenure = NOT_TENURED);
- Handle<JSGlobalPropertyCell> NewJSGlobalPropertyCell(
- Handle<Object> value);
+ Handle<FixedTypedArrayBase> NewFixedTypedArray(
+ int length,
+ ExternalArrayType array_type,
+ PretenureFlag pretenure = NOT_TENURED);
- Handle<Map> NewMap(InstanceType type,
- int instance_size,
- ElementsKind elements_kind = FAST_ELEMENTS);
+ Handle<Cell> NewCell(Handle<Object> value);
+
+ Handle<PropertyCell> NewPropertyCellWithHole();
+
+ Handle<PropertyCell> NewPropertyCell(Handle<Object> value);
+
+ // Allocate a tenured AllocationSite. It's payload is null.
+ Handle<AllocationSite> NewAllocationSite();
+
+ Handle<Map> NewMap(
+ InstanceType type,
+ int instance_size,
+ ElementsKind elements_kind = TERMINAL_FAST_ELEMENTS_KIND);
+
+ Handle<HeapObject> NewFillerObject(int size,
+ bool double_align,
+ AllocationSpace space);
Handle<JSObject> NewFunctionPrototype(Handle<JSFunction> function);
- Handle<Map> CopyMapDropDescriptors(Handle<Map> map);
+ Handle<JSObject> CopyJSObject(Handle<JSObject> object);
- // Copy the map adding more inobject properties if possible without
- // overflowing the instance size.
- Handle<Map> CopyMap(Handle<Map> map, int extra_inobject_props);
+ Handle<JSObject> CopyJSObjectWithAllocationSite(Handle<JSObject> object,
+ Handle<AllocationSite> site);
- Handle<Map> CopyMapDropTransitions(Handle<Map> map);
-
- Handle<Map> GetElementsTransitionMap(Handle<JSObject> object,
- ElementsKind elements_kind);
+ Handle<FixedArray> CopyFixedArrayWithMap(Handle<FixedArray> array,
+ Handle<Map> map);
Handle<FixedArray> CopyFixedArray(Handle<FixedArray> array);
+ // This method expects a COW array in new space, and creates a copy
+ // of it in old space.
+ Handle<FixedArray> CopyAndTenureFixedCOWArray(Handle<FixedArray> array);
+
Handle<FixedDoubleArray> CopyFixedDoubleArray(
Handle<FixedDoubleArray> array);
+ Handle<ConstantPoolArray> CopyConstantPoolArray(
+ Handle<ConstantPoolArray> array);
+
// Numbers (e.g. literals) are pretenured by the parser.
+ // The return value may be a smi or a heap number.
Handle<Object> NewNumber(double value,
PretenureFlag pretenure = NOT_TENURED);
@@ -243,218 +339,286 @@
PretenureFlag pretenure = NOT_TENURED);
Handle<Object> NewNumberFromUint(uint32_t value,
PretenureFlag pretenure = NOT_TENURED);
+ Handle<Object> NewNumberFromSize(size_t value,
+ PretenureFlag pretenure = NOT_TENURED) {
+ if (Smi::IsValid(static_cast<intptr_t>(value))) {
+ return Handle<Object>(Smi::FromIntptr(static_cast<intptr_t>(value)),
+ isolate());
+ }
+ return NewNumber(static_cast<double>(value), pretenure);
+ }
+ Handle<HeapNumber> NewHeapNumber(double value,
+ MutableMode mode = IMMUTABLE,
+ PretenureFlag pretenure = NOT_TENURED);
// These objects are used by the api to create env-independent data
// structures in the heap.
- Handle<JSObject> NewNeanderObject();
+ inline Handle<JSObject> NewNeanderObject() {
+ return NewJSObjectFromMap(neander_map());
+ }
- Handle<JSObject> NewArgumentsObject(Handle<Object> callee, int length);
+ Handle<JSObject> NewArgumentsObject(Handle<JSFunction> callee, int length);
// JS objects are pretenured when allocated by the bootstrapper and
// runtime.
Handle<JSObject> NewJSObject(Handle<JSFunction> constructor,
PretenureFlag pretenure = NOT_TENURED);
+ // JSObject that should have a memento pointing to the allocation site.
+ Handle<JSObject> NewJSObjectWithMemento(Handle<JSFunction> constructor,
+ Handle<AllocationSite> site);
- // Global objects are pretenured.
+ // Global objects are pretenured and initialized based on a constructor.
Handle<GlobalObject> NewGlobalObject(Handle<JSFunction> constructor);
// JS objects are pretenured when allocated by the bootstrapper and
// runtime.
- Handle<JSObject> NewJSObjectFromMap(Handle<Map> map);
+ Handle<JSObject> NewJSObjectFromMap(
+ Handle<Map> map,
+ PretenureFlag pretenure = NOT_TENURED,
+ bool allocate_properties = true,
+ Handle<AllocationSite> allocation_site = Handle<AllocationSite>::null());
+
+ // JS modules are pretenured.
+ Handle<JSModule> NewJSModule(Handle<Context> context,
+ Handle<ScopeInfo> scope_info);
// JS arrays are pretenured when allocated by the parser.
- Handle<JSArray> NewJSArray(int capacity,
- ElementsKind elements_kind = FAST_ELEMENTS,
- PretenureFlag pretenure = NOT_TENURED);
+
+ // Create a JSArray with no elements.
+ Handle<JSArray> NewJSArray(
+ ElementsKind elements_kind,
+ PretenureFlag pretenure = NOT_TENURED);
+
+ // Create a JSArray with a specified length and elements initialized
+ // according to the specified mode.
+ Handle<JSArray> NewJSArray(
+ ElementsKind elements_kind, int length, int capacity,
+ ArrayStorageAllocationMode mode = DONT_INITIALIZE_ARRAY_ELEMENTS,
+ PretenureFlag pretenure = NOT_TENURED);
+
+ Handle<JSArray> NewJSArray(
+ int capacity,
+ ElementsKind elements_kind = TERMINAL_FAST_ELEMENTS_KIND,
+ PretenureFlag pretenure = NOT_TENURED) {
+ if (capacity != 0) {
+ elements_kind = GetHoleyElementsKind(elements_kind);
+ }
+ return NewJSArray(elements_kind, 0, capacity,
+ INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE, pretenure);
+ }
+
+ // Create a JSArray with the given elements.
+ Handle<JSArray> NewJSArrayWithElements(
+ Handle<FixedArrayBase> elements,
+ ElementsKind elements_kind,
+ int length,
+ PretenureFlag pretenure = NOT_TENURED);
Handle<JSArray> NewJSArrayWithElements(
Handle<FixedArrayBase> elements,
- ElementsKind elements_kind = FAST_ELEMENTS,
- PretenureFlag pretenure = NOT_TENURED);
+ ElementsKind elements_kind = TERMINAL_FAST_ELEMENTS_KIND,
+ PretenureFlag pretenure = NOT_TENURED) {
+ return NewJSArrayWithElements(
+ elements, elements_kind, elements->length(), pretenure);
+ }
- void SetElementsCapacityAndLength(Handle<JSArray> array,
- int capacity,
- int length);
+ void NewJSArrayStorage(
+ Handle<JSArray> array,
+ int length,
+ int capacity,
+ ArrayStorageAllocationMode mode = DONT_INITIALIZE_ARRAY_ELEMENTS);
- void SetContent(Handle<JSArray> array, Handle<FixedArrayBase> elements);
+ Handle<JSGeneratorObject> NewJSGeneratorObject(Handle<JSFunction> function);
- void EnsureCanContainHeapObjectElements(Handle<JSArray> array);
- void EnsureCanContainElements(Handle<JSArray> array,
- Handle<FixedArrayBase> elements,
- EnsureElementsMode mode);
+ Handle<JSArrayBuffer> NewJSArrayBuffer();
+ Handle<JSTypedArray> NewJSTypedArray(ExternalArrayType type);
+
+ Handle<JSDataView> NewJSDataView();
+
+ // Allocates a Harmony proxy.
Handle<JSProxy> NewJSProxy(Handle<Object> handler, Handle<Object> prototype);
- // Change the type of the argument into a JS object/function and reinitialize.
- void BecomeJSObject(Handle<JSReceiver> object);
- void BecomeJSFunction(Handle<JSReceiver> object);
+ // Allocates a Harmony function proxy.
+ Handle<JSProxy> NewJSFunctionProxy(Handle<Object> handler,
+ Handle<Object> call_trap,
+ Handle<Object> construct_trap,
+ Handle<Object> prototype);
- void SetIdentityHash(Handle<JSObject> object, Object* hash);
+ // Reinitialize an JSGlobalProxy based on a constructor. The object
+ // must have the same size as objects allocated using the
+ // constructor. The object is reinitialized and behaves as an
+ // object that has been freshly allocated using the constructor.
+ void ReinitializeJSGlobalProxy(Handle<JSGlobalProxy> global,
+ Handle<JSFunction> constructor);
+
+ // Change the type of the argument into a JS object/function and reinitialize.
+ void BecomeJSObject(Handle<JSProxy> object);
+ void BecomeJSFunction(Handle<JSProxy> object);
Handle<JSFunction> NewFunction(Handle<String> name,
- Handle<Object> prototype);
-
- Handle<JSFunction> NewFunctionWithoutPrototype(
- Handle<String> name,
- LanguageMode language_mode);
-
- Handle<JSFunction> NewFunction(Handle<Object> super, bool is_global);
-
- Handle<JSFunction> BaseNewFunctionFromSharedFunctionInfo(
- Handle<SharedFunctionInfo> function_info,
- Handle<Map> function_map,
- PretenureFlag pretenure);
+ Handle<Code> code,
+ Handle<Object> prototype,
+ bool read_only_prototype = false);
+ Handle<JSFunction> NewFunction(Handle<String> name);
+ Handle<JSFunction> NewFunctionWithoutPrototype(Handle<String> name,
+ Handle<Code> code);
Handle<JSFunction> NewFunctionFromSharedFunctionInfo(
Handle<SharedFunctionInfo> function_info,
Handle<Context> context,
PretenureFlag pretenure = TENURED);
+ Handle<JSFunction> NewFunction(Handle<String> name,
+ Handle<Code> code,
+ Handle<Object> prototype,
+ InstanceType type,
+ int instance_size,
+ bool read_only_prototype = false);
+ Handle<JSFunction> NewFunction(Handle<String> name,
+ Handle<Code> code,
+ InstanceType type,
+ int instance_size);
+
+ // Create a serialized scope info.
Handle<ScopeInfo> NewScopeInfo(int length);
+ // Create an External object for V8's external API.
+ Handle<JSObject> NewExternal(void* value);
+
+ // The reference to the Code object is stored in self_reference.
+ // This allows generated code to reference its own Code object
+ // by containing this handle.
Handle<Code> NewCode(const CodeDesc& desc,
Code::Flags flags,
Handle<Object> self_reference,
- bool immovable = false);
+ bool immovable = false,
+ bool crankshafted = false,
+ int prologue_offset = Code::kPrologueOffsetNotSet,
+ bool is_debug = false);
Handle<Code> CopyCode(Handle<Code> code);
Handle<Code> CopyCode(Handle<Code> code, Vector<byte> reloc_info);
- Handle<Object> ToObject(Handle<Object> object);
- Handle<Object> ToObject(Handle<Object> object,
- Handle<Context> global_context);
-
// Interface for creating error objects.
- Handle<Object> NewError(const char* maker, const char* type,
- Handle<JSArray> args);
- Handle<Object> NewError(const char* maker, const char* type,
- Vector< Handle<Object> > args);
- Handle<Object> NewError(const char* type,
- Vector< Handle<Object> > args);
- Handle<Object> NewError(Handle<String> message);
- Handle<Object> NewError(const char* constructor,
- Handle<String> message);
+ MaybeHandle<Object> NewError(const char* maker, const char* message,
+ Handle<JSArray> args);
+ Handle<String> EmergencyNewError(const char* message, Handle<JSArray> args);
+ MaybeHandle<Object> NewError(const char* maker, const char* message,
+ Vector<Handle<Object> > args);
+ MaybeHandle<Object> NewError(const char* message,
+ Vector<Handle<Object> > args);
+ MaybeHandle<Object> NewError(Handle<String> message);
+ MaybeHandle<Object> NewError(const char* constructor, Handle<String> message);
- Handle<Object> NewTypeError(const char* type,
- Vector< Handle<Object> > args);
- Handle<Object> NewTypeError(Handle<String> message);
+ MaybeHandle<Object> NewTypeError(const char* message,
+ Vector<Handle<Object> > args);
+ MaybeHandle<Object> NewTypeError(Handle<String> message);
- Handle<Object> NewRangeError(const char* type,
- Vector< Handle<Object> > args);
- Handle<Object> NewRangeError(Handle<String> message);
+ MaybeHandle<Object> NewRangeError(const char* message,
+ Vector<Handle<Object> > args);
+ MaybeHandle<Object> NewRangeError(Handle<String> message);
- Handle<Object> NewSyntaxError(const char* type, Handle<JSArray> args);
- Handle<Object> NewSyntaxError(Handle<String> message);
+ MaybeHandle<Object> NewInvalidStringLengthError() {
+ return NewRangeError("invalid_string_length",
+ HandleVector<Object>(NULL, 0));
+ }
- Handle<Object> NewReferenceError(const char* type,
- Vector< Handle<Object> > args);
- Handle<Object> NewReferenceError(Handle<String> message);
+ MaybeHandle<Object> NewSyntaxError(const char* message, Handle<JSArray> args);
+ MaybeHandle<Object> NewSyntaxError(Handle<String> message);
- Handle<Object> NewEvalError(const char* type,
- Vector< Handle<Object> > args);
+ MaybeHandle<Object> NewReferenceError(const char* message,
+ Vector<Handle<Object> > args);
+ MaybeHandle<Object> NewReferenceError(const char* message,
+ Handle<JSArray> args);
+ MaybeHandle<Object> NewReferenceError(Handle<String> message);
+ MaybeHandle<Object> NewEvalError(const char* message,
+ Vector<Handle<Object> > args);
- Handle<JSFunction> NewFunction(Handle<String> name,
- InstanceType type,
- int instance_size,
- Handle<Code> code,
- bool force_initial_map);
+ Handle<String> NumberToString(Handle<Object> number,
+ bool check_number_string_cache = true);
- Handle<JSFunction> NewFunction(Handle<Map> function_map,
- Handle<SharedFunctionInfo> shared, Handle<Object> prototype);
-
-
- Handle<JSFunction> NewFunctionWithPrototype(Handle<String> name,
- InstanceType type,
- int instance_size,
- Handle<JSObject> prototype,
- Handle<Code> code,
- bool force_initial_map);
-
- Handle<JSFunction> NewFunctionWithoutPrototype(Handle<String> name,
- Handle<Code> code);
-
- Handle<DescriptorArray> CopyAppendForeignDescriptor(
- Handle<DescriptorArray> array,
- Handle<String> key,
- Handle<Object> value,
- PropertyAttributes attributes);
-
- Handle<String> NumberToString(Handle<Object> number);
- Handle<String> Uint32ToString(uint32_t value);
+ Handle<String> Uint32ToString(uint32_t value) {
+ return NumberToString(NewNumberFromUint(value));
+ }
enum ApiInstanceType {
- JavaScriptObject,
- InnerGlobalObject,
- OuterGlobalObject
+ JavaScriptObjectType,
+ GlobalObjectType,
+ GlobalProxyType
};
Handle<JSFunction> CreateApiFunction(
Handle<FunctionTemplateInfo> data,
- ApiInstanceType type = JavaScriptObject);
+ Handle<Object> prototype,
+ ApiInstanceType type = JavaScriptObjectType);
Handle<JSFunction> InstallMembers(Handle<JSFunction> function);
// Installs interceptors on the instance. 'desc' is a function template,
// and instance is an object instance created by the function of this
// function template.
- void ConfigureInstance(Handle<FunctionTemplateInfo> desc,
- Handle<JSObject> instance,
- bool* pending_exception);
+ MUST_USE_RESULT MaybeHandle<FunctionTemplateInfo> ConfigureInstance(
+ Handle<FunctionTemplateInfo> desc, Handle<JSObject> instance);
-#define ROOT_ACCESSOR(type, name, camel_name) \
- inline Handle<type> name() { \
- return Handle<type>(BitCast<type**>( \
- &isolate()->heap()->roots_[Heap::k##camel_name##RootIndex])); \
+#define ROOT_ACCESSOR(type, name, camel_name) \
+ inline Handle<type> name() { \
+ return Handle<type>(bit_cast<type**>( \
+ &isolate()->heap()->roots_[Heap::k##camel_name##RootIndex])); \
}
ROOT_LIST(ROOT_ACCESSOR)
-#undef ROOT_ACCESSOR_ACCESSOR
+#undef ROOT_ACCESSOR
-#define SYMBOL_ACCESSOR(name, str) \
- inline Handle<String> name() { \
- return Handle<String>(BitCast<String**>( \
- &isolate()->heap()->roots_[Heap::k##name##RootIndex])); \
+#define STRUCT_MAP_ACCESSOR(NAME, Name, name) \
+ inline Handle<Map> name##_map() { \
+ return Handle<Map>(bit_cast<Map**>( \
+ &isolate()->heap()->roots_[Heap::k##Name##MapRootIndex])); \
}
- SYMBOL_LIST(SYMBOL_ACCESSOR)
-#undef SYMBOL_ACCESSOR
+ STRUCT_LIST(STRUCT_MAP_ACCESSOR)
+#undef STRUCT_MAP_ACCESSOR
- Handle<String> hidden_symbol() {
- return Handle<String>(&isolate()->heap()->hidden_symbol_);
+#define STRING_ACCESSOR(name, str) \
+ inline Handle<String> name() { \
+ return Handle<String>(bit_cast<String**>( \
+ &isolate()->heap()->roots_[Heap::k##name##RootIndex])); \
+ }
+ INTERNALIZED_STRING_LIST(STRING_ACCESSOR)
+#undef STRING_ACCESSOR
+
+ inline void set_string_table(Handle<StringTable> table) {
+ isolate()->heap()->set_string_table(*table);
}
+ Handle<String> hidden_string() {
+ return Handle<String>(&isolate()->heap()->hidden_string_);
+ }
+
+ // Allocates a new SharedFunctionInfo object.
Handle<SharedFunctionInfo> NewSharedFunctionInfo(
- Handle<String> name,
- int number_of_literals,
- Handle<Code> code,
- Handle<ScopeInfo> scope_info);
- Handle<SharedFunctionInfo> NewSharedFunctionInfo(Handle<String> name);
+ Handle<String> name, int number_of_literals, FunctionKind kind,
+ Handle<Code> code, Handle<ScopeInfo> scope_info,
+ Handle<TypeFeedbackVector> feedback_vector);
+ Handle<SharedFunctionInfo> NewSharedFunctionInfo(Handle<String> name,
+ MaybeHandle<Code> code);
+ // Allocate a new type feedback vector
+ Handle<TypeFeedbackVector> NewTypeFeedbackVector(int slot_count);
+
+ // Allocates a new JSMessageObject object.
Handle<JSMessageObject> NewJSMessageObject(
Handle<String> type,
Handle<JSArray> arguments,
int start_position,
int end_position,
Handle<Object> script,
- Handle<Object> stack_trace,
Handle<Object> stack_frames);
- Handle<SeededNumberDictionary> DictionaryAtNumberPut(
- Handle<SeededNumberDictionary>,
- uint32_t key,
- Handle<Object> value);
-
- Handle<UnseededNumberDictionary> DictionaryAtNumberPut(
- Handle<UnseededNumberDictionary>,
- uint32_t key,
- Handle<Object> value);
-
-#ifdef ENABLE_DEBUGGER_SUPPORT
Handle<DebugInfo> NewDebugInfo(Handle<SharedFunctionInfo> shared);
-#endif
- // Return a map using the map cache in the global context.
+ // Return a map using the map cache in the native context.
// The key the an ordered set of property names.
Handle<Map> ObjectLiteralMapFromCache(Handle<Context> context,
Handle<FixedArray> keys);
@@ -486,26 +650,59 @@
private:
Isolate* isolate() { return reinterpret_cast<Isolate*>(this); }
- Handle<JSFunction> NewFunctionHelper(Handle<String> name,
- Handle<Object> prototype);
+ // Creates a heap object based on the map. The fields of the heap object are
+ // not initialized by New<>() functions. It's the responsibility of the caller
+ // to do that.
+ template<typename T>
+ Handle<T> New(Handle<Map> map, AllocationSpace space);
- Handle<JSFunction> NewFunctionWithoutPrototypeHelper(
- Handle<String> name,
- LanguageMode language_mode);
+ template<typename T>
+ Handle<T> New(Handle<Map> map,
+ AllocationSpace space,
+ Handle<AllocationSite> allocation_site);
- Handle<DescriptorArray> CopyAppendCallbackDescriptors(
- Handle<DescriptorArray> array,
- Handle<Object> descriptors);
+ // Creates a code object that is not yet fully initialized yet.
+ inline Handle<Code> NewCodeRaw(int object_size, bool immovable);
// Create a new map cache.
Handle<MapCache> NewMapCache(int at_least_space_for);
- // Update the map cache in the global context with (keys, map)
+ // Update the map cache in the native context with (keys, map)
Handle<MapCache> AddToMapCache(Handle<Context> context,
Handle<FixedArray> keys,
Handle<Map> map);
-};
+ // Attempt to find the number in a small cache. If we finds it, return
+ // the string representation of the number. Otherwise return undefined.
+ Handle<Object> GetNumberStringCache(Handle<Object> number);
+
+ // Update the cache with a new number-string pair.
+ void SetNumberStringCache(Handle<Object> number, Handle<String> string);
+
+ // Initializes a function with a shared part and prototype.
+ // Note: this code was factored out of NewFunction such that other parts of
+ // the VM could use it. Specifically, a function that creates instances of
+ // type JS_FUNCTION_TYPE benefit from the use of this function.
+ inline void InitializeFunction(Handle<JSFunction> function,
+ Handle<SharedFunctionInfo> info,
+ Handle<Context> context);
+
+ // Creates a function initialized with a shared part.
+ Handle<JSFunction> NewFunction(Handle<Map> map,
+ Handle<SharedFunctionInfo> info,
+ Handle<Context> context,
+ PretenureFlag pretenure = TENURED);
+
+ Handle<JSFunction> NewFunction(Handle<Map> map,
+ Handle<String> name,
+ MaybeHandle<Code> maybe_code);
+
+ // Reinitialize a JSProxy into an (empty) JS object of respective type and
+ // size, but keeping the original prototype. The receiver must have at least
+ // the size of the new object. The object is reinitialized and behaves as an
+ // object that has been freshly allocated.
+ void ReinitializeJSProxy(Handle<JSProxy> proxy, InstanceType type, int size);
+};
} } // namespace v8::internal