2012-01-26 21:47:57 +00:00
|
|
|
// Copyright 2012 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.
|
|
|
|
|
|
|
|
#ifndef V8_FACTORY_H_
|
|
|
|
#define V8_FACTORY_H_
|
|
|
|
|
2009-07-08 19:12:58 +00:00
|
|
|
#include "globals.h"
|
2011-03-18 20:35:07 +00:00
|
|
|
#include "handles.h"
|
2008-07-03 15:10:15 +00:00
|
|
|
#include "heap.h"
|
|
|
|
|
2009-05-25 10:05:56 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Interface for handle based allocation.
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
class Factory {
|
2008-07-03 15:10:15 +00:00
|
|
|
public:
|
2013-06-06 15:40:28 +00:00
|
|
|
// Allocate a new boxed value.
|
|
|
|
Handle<Box> NewBox(
|
|
|
|
Handle<Object> value,
|
|
|
|
PretenureFlag pretenure = NOT_TENURED);
|
|
|
|
|
2011-06-09 10:03:35 +00:00
|
|
|
// Allocate a new uninitialized fixed array.
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<FixedArray> NewFixedArray(
|
2008-07-03 15:10:15 +00:00
|
|
|
int size,
|
|
|
|
PretenureFlag pretenure = NOT_TENURED);
|
2008-10-29 10:02:09 +00:00
|
|
|
|
|
|
|
// Allocate a new fixed array with non-existing entries (the hole).
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<FixedArray> NewFixedArrayWithHoles(
|
2010-04-14 14:46:15 +00:00
|
|
|
int size,
|
|
|
|
PretenureFlag pretenure = NOT_TENURED);
|
2008-10-29 10:02:09 +00:00
|
|
|
|
2011-06-09 10:03:35 +00:00
|
|
|
// Allocate a new uninitialized fixed double array.
|
2011-10-19 11:36:55 +00:00
|
|
|
Handle<FixedDoubleArray> NewFixedDoubleArray(
|
2011-06-09 10:03:35 +00:00
|
|
|
int size,
|
|
|
|
PretenureFlag pretenure = NOT_TENURED);
|
|
|
|
|
2012-01-16 09:44:35 +00:00
|
|
|
Handle<SeededNumberDictionary> NewSeededNumberDictionary(
|
|
|
|
int at_least_space_for);
|
|
|
|
|
|
|
|
Handle<UnseededNumberDictionary> NewUnseededNumberDictionary(
|
|
|
|
int at_least_space_for);
|
2009-07-02 06:50:43 +00:00
|
|
|
|
2013-03-04 15:00:57 +00:00
|
|
|
Handle<NameDictionary> NewNameDictionary(int at_least_space_for);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-10-25 14:14:56 +00:00
|
|
|
Handle<ObjectHashSet> NewObjectHashSet(int at_least_space_for);
|
|
|
|
|
2011-07-28 17:21:22 +00:00
|
|
|
Handle<ObjectHashTable> NewObjectHashTable(int at_least_space_for);
|
|
|
|
|
2013-10-04 07:25:24 +00:00
|
|
|
Handle<WeakHashTable> NewWeakHashTable(int at_least_space_for);
|
|
|
|
|
2012-09-18 13:25:12 +00:00
|
|
|
Handle<DescriptorArray> NewDescriptorArray(int number_of_descriptors,
|
|
|
|
int slack = 0);
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<DeoptimizationInputData> NewDeoptimizationInputData(
|
2010-12-07 11:31:57 +00:00
|
|
|
int deopt_entry_count,
|
|
|
|
PretenureFlag pretenure);
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<DeoptimizationOutputData> NewDeoptimizationOutputData(
|
2010-12-07 11:31:57 +00:00
|
|
|
int deopt_entry_count,
|
|
|
|
PretenureFlag pretenure);
|
2012-01-10 16:12:24 +00:00
|
|
|
// Allocates a pre-tenured empty AccessorPair.
|
2012-01-10 16:11:33 +00:00
|
|
|
Handle<AccessorPair> NewAccessorPair();
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2012-02-20 12:57:23 +00:00
|
|
|
Handle<TypeFeedbackInfo> NewTypeFeedbackInfo();
|
|
|
|
|
2013-02-28 17:03:34 +00:00
|
|
|
Handle<String> InternalizeUtf8String(Vector<const char> str);
|
|
|
|
Handle<String> InternalizeUtf8String(const char* str) {
|
|
|
|
return InternalizeUtf8String(CStrVector(str));
|
2012-12-17 15:56:16 +00:00
|
|
|
}
|
2013-02-28 17:03:34 +00:00
|
|
|
Handle<String> InternalizeString(Handle<String> str);
|
|
|
|
Handle<String> InternalizeOneByteString(Vector<const uint8_t> str);
|
|
|
|
Handle<String> InternalizeOneByteString(Handle<SeqOneByteString>,
|
2011-05-24 12:16:23 +00:00
|
|
|
int from,
|
|
|
|
int length);
|
2013-02-28 17:03:34 +00:00
|
|
|
Handle<String> InternalizeTwoByteString(Vector<const uc16> str);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
// String creation functions. Most of the string creation functions take
|
|
|
|
// a Heap::PretenureFlag argument to optionally request that they be
|
|
|
|
// 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
|
|
|
|
// 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.
|
|
|
|
// - ...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.
|
|
|
|
//
|
|
|
|
// ASCII strings are pretenured when used as keys in the SourceCodeCache.
|
2013-01-09 10:30:54 +00:00
|
|
|
Handle<String> NewStringFromOneByte(
|
|
|
|
Vector<const uint8_t> str,
|
2008-07-03 15:10:15 +00:00
|
|
|
PretenureFlag pretenure = NOT_TENURED);
|
2013-01-09 10:30:54 +00:00
|
|
|
// TODO(dcarney): remove this function.
|
|
|
|
inline Handle<String> NewStringFromAscii(
|
|
|
|
Vector<const char> str,
|
|
|
|
PretenureFlag pretenure = NOT_TENURED) {
|
|
|
|
return NewStringFromOneByte(Vector<const uint8_t>::cast(str), pretenure);
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// UTF8 strings are pretenured when used for regexp literal patterns and
|
|
|
|
// flags in the parser.
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<String> NewStringFromUtf8(
|
2008-07-03 15:10:15 +00:00
|
|
|
Vector<const char> str,
|
2012-09-04 12:23:22 +00:00
|
|
|
PretenureFlag pretenure = NOT_TENURED);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<String> NewStringFromTwoByte(
|
2010-07-05 12:49:00 +00:00
|
|
|
Vector<const uc16> str,
|
2009-08-18 07:14:02 +00:00
|
|
|
PretenureFlag pretenure = NOT_TENURED);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-07-05 12:49:00 +00:00
|
|
|
// Allocates and partially initializes an ASCII or TwoByte String. The
|
|
|
|
// characters of the string are uninitialized. Currently used in regexp code
|
|
|
|
// only, where they are pretenured.
|
2012-11-15 13:31:27 +00:00
|
|
|
Handle<SeqOneByteString> NewRawOneByteString(
|
2010-07-05 12:49:00 +00:00
|
|
|
int length,
|
|
|
|
PretenureFlag pretenure = NOT_TENURED);
|
2011-06-27 09:02:34 +00:00
|
|
|
Handle<SeqTwoByteString> NewRawTwoByteString(
|
2008-07-03 15:10:15 +00:00
|
|
|
int length,
|
|
|
|
PretenureFlag pretenure = NOT_TENURED);
|
|
|
|
|
|
|
|
// Create a new cons string object which consists of a pair of strings.
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<String> NewConsString(Handle<String> first,
|
|
|
|
Handle<String> second);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2013-06-21 09:24:30 +00:00
|
|
|
// Create a new sequential string containing the concatenation of the inputs.
|
|
|
|
Handle<String> NewFlatConcatString(Handle<String> first,
|
|
|
|
Handle<String> second);
|
|
|
|
|
2009-11-10 13:23:05 +00:00
|
|
|
// Create a new string object which holds a substring of a string.
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<String> NewSubString(Handle<String> str,
|
|
|
|
int begin,
|
|
|
|
int end);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-06-27 09:02:34 +00:00
|
|
|
// Create a new string object which holds a proper substring of a string.
|
|
|
|
Handle<String> NewProperSubString(Handle<String> str,
|
2011-06-22 14:20:23 +00:00
|
|
|
int begin,
|
|
|
|
int end);
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// Creates a new external String object. There are two String encodings
|
|
|
|
// in the system: ASCII 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.
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<String> NewExternalStringFromAscii(
|
2011-09-21 13:28:09 +00:00
|
|
|
const ExternalAsciiString::Resource* resource);
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<String> NewExternalStringFromTwoByte(
|
2011-09-21 13:28:09 +00:00
|
|
|
const ExternalTwoByteString::Resource* resource);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2013-03-01 10:34:31 +00:00
|
|
|
// Create a symbol.
|
|
|
|
Handle<Symbol> NewSymbol();
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// Create a global (but otherwise uninitialized) context.
|
2012-08-17 09:03:08 +00:00
|
|
|
Handle<Context> NewNativeContext();
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2012-08-27 09:40:26 +00:00
|
|
|
// Create a global context.
|
|
|
|
Handle<Context> NewGlobalContext(Handle<JSFunction> function,
|
|
|
|
Handle<ScopeInfo> scope_info);
|
|
|
|
|
2012-04-16 14:43:27 +00:00
|
|
|
// Create a module context.
|
2012-07-09 08:59:03 +00:00
|
|
|
Handle<Context> NewModuleContext(Handle<ScopeInfo> scope_info);
|
2012-04-16 14:43:27 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// Create a function context.
|
2012-04-16 14:43:27 +00:00
|
|
|
Handle<Context> NewFunctionContext(int length, Handle<JSFunction> function);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-06-09 11:26:01 +00:00
|
|
|
// Create a catch context.
|
2011-06-29 07:41:42 +00:00
|
|
|
Handle<Context> 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
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// Create a 'with' context.
|
2011-06-29 07:41:42 +00:00
|
|
|
Handle<Context> NewWithContext(Handle<JSFunction> function,
|
|
|
|
Handle<Context> previous,
|
2011-06-09 11:26:01 +00:00
|
|
|
Handle<JSObject> extension);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2012-04-16 14:43:27 +00:00
|
|
|
// Create a block context.
|
2011-08-11 16:29:28 +00:00
|
|
|
Handle<Context> NewBlockContext(Handle<JSFunction> function,
|
|
|
|
Handle<Context> previous,
|
2011-11-03 10:36:55 +00:00
|
|
|
Handle<ScopeInfo> scope_info);
|
2011-08-11 16:29:28 +00:00
|
|
|
|
2013-02-28 17:03:34 +00:00
|
|
|
// Return the internalized version of the passed in string.
|
|
|
|
Handle<String> InternalizedStringFromString(Handle<String> value);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Allocate a new struct. The struct is pretenured (allocated directly in
|
|
|
|
// the old generation).
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<Struct> NewStruct(InstanceType type);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2013-03-07 11:42:58 +00:00
|
|
|
Handle<DeclaredAccessorDescriptor> NewDeclaredAccessorDescriptor();
|
|
|
|
|
2013-02-12 14:33:08 +00:00
|
|
|
Handle<DeclaredAccessorInfo> NewDeclaredAccessorInfo();
|
|
|
|
|
|
|
|
Handle<ExecutableAccessorInfo> NewExecutableAccessorInfo();
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<Script> NewScript(Handle<String> source);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-05-19 11:47:34 +00:00
|
|
|
// Foreign objects are pretenured when allocated by the bootstrapper.
|
|
|
|
Handle<Foreign> NewForeign(Address addr,
|
|
|
|
PretenureFlag pretenure = NOT_TENURED);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-05-19 11:47:34 +00:00
|
|
|
// Allocate a new foreign object. The foreign is pretenured (allocated
|
|
|
|
// directly in the old generation).
|
|
|
|
Handle<Foreign> NewForeign(const AccessorDescriptor* foreign);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<ByteArray> NewByteArray(int length,
|
|
|
|
PretenureFlag pretenure = NOT_TENURED);
|
2009-07-28 08:43:51 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<ExternalArray> NewExternalArray(
|
2009-10-20 15:26:17 +00:00
|
|
|
int length,
|
|
|
|
ExternalArrayType array_type,
|
|
|
|
void* external_pointer,
|
|
|
|
PretenureFlag pretenure = NOT_TENURED);
|
|
|
|
|
2013-06-12 15:03:44 +00:00
|
|
|
Handle<Cell> NewCell(Handle<Object> value);
|
|
|
|
|
2013-06-14 16:06:12 +00:00
|
|
|
Handle<PropertyCell> NewPropertyCell(Handle<Object> value);
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2013-07-08 10:02:16 +00:00
|
|
|
Handle<AllocationSite> NewAllocationSite();
|
|
|
|
|
2012-05-23 14:24:29 +00:00
|
|
|
Handle<Map> NewMap(
|
|
|
|
InstanceType type,
|
|
|
|
int instance_size,
|
|
|
|
ElementsKind elements_kind = TERMINAL_FAST_ELEMENTS_KIND);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<JSObject> NewFunctionPrototype(Handle<JSFunction> function);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2012-07-11 14:29:16 +00:00
|
|
|
Handle<Map> CopyWithPreallocatedFieldDescriptors(Handle<Map> map);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-01-12 10:59:58 +00:00
|
|
|
// Copy the map adding more inobject properties if possible without
|
|
|
|
// overflowing the instance size.
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<Map> CopyMap(Handle<Map> map, int extra_inobject_props);
|
2012-07-17 13:50:19 +00:00
|
|
|
Handle<Map> CopyMap(Handle<Map> map);
|
2008-08-27 13:47:52 +00:00
|
|
|
|
2011-09-15 16:38:47 +00:00
|
|
|
Handle<Map> GetElementsTransitionMap(Handle<JSObject> object,
|
|
|
|
ElementsKind elements_kind);
|
2011-02-10 12:02:36 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<FixedArray> CopyFixedArray(Handle<FixedArray> array);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2012-11-13 12:27:03 +00:00
|
|
|
Handle<FixedArray> CopySizeFixedArray(Handle<FixedArray> array,
|
2013-10-04 07:25:24 +00:00
|
|
|
int new_length,
|
|
|
|
PretenureFlag pretenure = NOT_TENURED);
|
2012-11-13 12:27:03 +00:00
|
|
|
|
2011-10-19 11:36:55 +00:00
|
|
|
Handle<FixedDoubleArray> CopyFixedDoubleArray(
|
|
|
|
Handle<FixedDoubleArray> array);
|
|
|
|
|
2012-01-16 12:38:59 +00:00
|
|
|
// Numbers (e.g. literals) are pretenured by the parser.
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<Object> NewNumber(double value,
|
|
|
|
PretenureFlag pretenure = NOT_TENURED);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-11-21 10:18:47 +00:00
|
|
|
Handle<Object> NewNumberFromInt(int32_t value,
|
|
|
|
PretenureFlag pretenure = NOT_TENURED);
|
|
|
|
Handle<Object> NewNumberFromUint(uint32_t value,
|
|
|
|
PretenureFlag pretenure = NOT_TENURED);
|
2013-05-14 15:03:27 +00:00
|
|
|
inline Handle<Object> NewNumberFromSize(size_t value,
|
|
|
|
PretenureFlag pretenure = NOT_TENURED);
|
2013-05-08 15:02:08 +00:00
|
|
|
Handle<HeapNumber> NewHeapNumber(double value,
|
|
|
|
PretenureFlag pretenure = NOT_TENURED);
|
|
|
|
|
2013-05-14 15:03:27 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// These objects are used by the api to create env-independent data
|
|
|
|
// structures in the heap.
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<JSObject> NewNeanderObject();
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<JSObject> NewArgumentsObject(Handle<Object> callee, int length);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// JS objects are pretenured when allocated by the bootstrapper and
|
|
|
|
// runtime.
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<JSObject> NewJSObject(Handle<JSFunction> constructor,
|
|
|
|
PretenureFlag pretenure = NOT_TENURED);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-07-01 11:44:37 +00:00
|
|
|
// Global objects are pretenured.
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<GlobalObject> NewGlobalObject(Handle<JSFunction> constructor);
|
2009-06-30 10:05:36 +00:00
|
|
|
|
2008-09-25 07:46:07 +00:00
|
|
|
// JS objects are pretenured when allocated by the bootstrapper and
|
|
|
|
// runtime.
|
2013-02-26 10:46:00 +00:00
|
|
|
Handle<JSObject> NewJSObjectFromMap(Handle<Map> map,
|
2013-08-07 11:24:14 +00:00
|
|
|
PretenureFlag pretenure = NOT_TENURED,
|
|
|
|
bool allocate_properties = true);
|
|
|
|
|
|
|
|
Handle<JSObject> NewJSObjectFromMapForDeoptimizer(
|
|
|
|
Handle<Map> map, PretenureFlag pretenure = NOT_TENURED);
|
2008-09-25 07:46:07 +00:00
|
|
|
|
2012-04-16 14:43:27 +00:00
|
|
|
// JS modules are pretenured.
|
2012-07-09 08:59:03 +00:00
|
|
|
Handle<JSModule> NewJSModule(Handle<Context> context,
|
|
|
|
Handle<ScopeInfo> scope_info);
|
2012-04-16 14:43:27 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// JS arrays are pretenured when allocated by the parser.
|
2012-05-23 14:24:29 +00:00
|
|
|
Handle<JSArray> NewJSArray(
|
|
|
|
int capacity,
|
|
|
|
ElementsKind elements_kind = TERMINAL_FAST_ELEMENTS_KIND,
|
|
|
|
PretenureFlag pretenure = NOT_TENURED);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<JSArray> NewJSArrayWithElements(
|
2011-12-09 08:50:19 +00:00
|
|
|
Handle<FixedArrayBase> elements,
|
2012-05-23 14:24:29 +00:00
|
|
|
ElementsKind elements_kind = TERMINAL_FAST_ELEMENTS_KIND,
|
2008-07-03 15:10:15 +00:00
|
|
|
PretenureFlag pretenure = NOT_TENURED);
|
|
|
|
|
2011-12-09 08:50:19 +00:00
|
|
|
void SetElementsCapacityAndLength(Handle<JSArray> array,
|
|
|
|
int capacity,
|
|
|
|
int length);
|
2011-09-22 11:30:04 +00:00
|
|
|
|
2011-12-09 08:50:19 +00:00
|
|
|
void SetContent(Handle<JSArray> array, Handle<FixedArrayBase> elements);
|
|
|
|
|
2013-04-25 12:02:23 +00:00
|
|
|
Handle<JSArrayBuffer> NewJSArrayBuffer();
|
|
|
|
|
2013-04-29 11:09:03 +00:00
|
|
|
Handle<JSTypedArray> NewJSTypedArray(ExternalArrayType type);
|
|
|
|
|
2013-06-21 13:02:38 +00:00
|
|
|
Handle<JSDataView> NewJSDataView();
|
|
|
|
|
2011-05-13 10:58:25 +00:00
|
|
|
Handle<JSProxy> NewJSProxy(Handle<Object> handler, Handle<Object> prototype);
|
|
|
|
|
2011-09-13 11:42:57 +00:00
|
|
|
// Change the type of the argument into a JS object/function and reinitialize.
|
|
|
|
void BecomeJSObject(Handle<JSReceiver> object);
|
|
|
|
void BecomeJSFunction(Handle<JSReceiver> object);
|
2011-07-18 13:04:52 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<JSFunction> NewFunction(Handle<String> name,
|
|
|
|
Handle<Object> prototype);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<JSFunction> NewFunctionWithoutPrototype(
|
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
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<JSFunction> NewFunction(Handle<Object> super, bool is_global);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<JSFunction> BaseNewFunctionFromSharedFunctionInfo(
|
2010-03-23 06:04:44 +00:00
|
|
|
Handle<SharedFunctionInfo> function_info,
|
|
|
|
Handle<Map> function_map,
|
|
|
|
PretenureFlag pretenure);
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<JSFunction> NewFunctionFromSharedFunctionInfo(
|
2010-03-23 06:04:44 +00:00
|
|
|
Handle<SharedFunctionInfo> function_info,
|
2009-12-16 15:43:20 +00:00
|
|
|
Handle<Context> context,
|
|
|
|
PretenureFlag pretenure = TENURED);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-11-03 10:36:55 +00:00
|
|
|
Handle<ScopeInfo> NewScopeInfo(int length);
|
2011-08-11 16:29:28 +00:00
|
|
|
|
2012-11-13 12:27:03 +00:00
|
|
|
Handle<JSObject> NewExternal(void* value);
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<Code> NewCode(const CodeDesc& desc,
|
|
|
|
Code::Flags flags,
|
|
|
|
Handle<Object> self_reference,
|
2013-04-18 09:50:46 +00:00
|
|
|
bool immovable = false,
|
|
|
|
bool crankshafted = false);
|
2008-11-25 11:07:48 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<Code> CopyCode(Handle<Code> code);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<Code> CopyCode(Handle<Code> code, Vector<byte> reloc_info);
|
2010-03-15 21:06:51 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<Object> ToObject(Handle<Object> object);
|
|
|
|
Handle<Object> ToObject(Handle<Object> object,
|
2012-08-17 09:03:08 +00:00
|
|
|
Handle<Context> native_context);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Interface for creating error objects.
|
|
|
|
|
2013-06-06 13:28:22 +00:00
|
|
|
Handle<Object> NewError(const char* maker, const char* message,
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<JSArray> args);
|
2013-06-06 13:28:22 +00:00
|
|
|
Handle<String> EmergencyNewError(const char* message, Handle<JSArray> args);
|
|
|
|
Handle<Object> NewError(const char* maker, const char* message,
|
2011-03-18 20:35:07 +00:00
|
|
|
Vector< Handle<Object> > args);
|
2013-06-06 13:28:22 +00:00
|
|
|
Handle<Object> NewError(const char* message,
|
2011-03-18 20:35:07 +00:00
|
|
|
Vector< Handle<Object> > args);
|
|
|
|
Handle<Object> NewError(Handle<String> message);
|
|
|
|
Handle<Object> NewError(const char* constructor,
|
|
|
|
Handle<String> message);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2013-06-06 13:28:22 +00:00
|
|
|
Handle<Object> NewTypeError(const char* message,
|
2011-03-18 20:35:07 +00:00
|
|
|
Vector< Handle<Object> > args);
|
|
|
|
Handle<Object> NewTypeError(Handle<String> message);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2013-06-06 13:28:22 +00:00
|
|
|
Handle<Object> NewRangeError(const char* message,
|
2011-03-18 20:35:07 +00:00
|
|
|
Vector< Handle<Object> > args);
|
|
|
|
Handle<Object> NewRangeError(Handle<String> message);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2013-06-06 13:28:22 +00:00
|
|
|
Handle<Object> NewSyntaxError(const char* message, Handle<JSArray> args);
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<Object> NewSyntaxError(Handle<String> message);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2013-06-06 13:28:22 +00:00
|
|
|
Handle<Object> NewReferenceError(const char* message,
|
2011-03-18 20:35:07 +00:00
|
|
|
Vector< Handle<Object> > args);
|
|
|
|
Handle<Object> NewReferenceError(Handle<String> message);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2013-06-06 13:28:22 +00:00
|
|
|
Handle<Object> NewEvalError(const char* message,
|
2011-03-18 20:35:07 +00:00
|
|
|
Vector< Handle<Object> > args);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<JSFunction> NewFunction(Handle<String> name,
|
|
|
|
InstanceType type,
|
|
|
|
int instance_size,
|
|
|
|
Handle<Code> code,
|
|
|
|
bool force_initial_map);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<JSFunction> NewFunction(Handle<Map> function_map,
|
2008-07-03 15:10:15 +00:00
|
|
|
Handle<SharedFunctionInfo> shared, Handle<Object> prototype);
|
|
|
|
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<JSFunction> NewFunctionWithPrototype(Handle<String> name,
|
|
|
|
InstanceType type,
|
|
|
|
int instance_size,
|
|
|
|
Handle<JSObject> prototype,
|
|
|
|
Handle<Code> code,
|
|
|
|
bool force_initial_map);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<JSFunction> NewFunctionWithoutPrototype(Handle<String> name,
|
|
|
|
Handle<Code> code);
|
2010-04-28 12:05:40 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<String> NumberToString(Handle<Object> number);
|
2011-09-22 10:45:37 +00:00
|
|
|
Handle<String> Uint32ToString(uint32_t value);
|
2009-10-02 13:43:16 +00:00
|
|
|
|
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
|
|
|
enum ApiInstanceType {
|
|
|
|
JavaScriptObject,
|
|
|
|
InnerGlobalObject,
|
|
|
|
OuterGlobalObject
|
|
|
|
};
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<JSFunction> 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> data,
|
|
|
|
ApiInstanceType type = JavaScriptObject);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<JSFunction> InstallMembers(Handle<JSFunction> function);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Installs interceptors on the instance. 'desc' is a function template,
|
|
|
|
// and instance is an object instance created by the function of this
|
2009-01-15 19:08:34 +00:00
|
|
|
// function template.
|
2011-03-18 20:35:07 +00:00
|
|
|
void ConfigureInstance(Handle<FunctionTemplateInfo> desc,
|
|
|
|
Handle<JSObject> instance,
|
|
|
|
bool* pending_exception);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-07-08 19:12:58 +00:00
|
|
|
#define ROOT_ACCESSOR(type, name, camel_name) \
|
2011-03-18 20:35:07 +00:00
|
|
|
inline Handle<type> name() { \
|
2010-08-11 10:52:34 +00:00
|
|
|
return Handle<type>(BitCast<type**>( \
|
2011-03-18 20:35:07 +00:00
|
|
|
&isolate()->heap()->roots_[Heap::k##camel_name##RootIndex])); \
|
2009-07-08 19:12:58 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
ROOT_LIST(ROOT_ACCESSOR)
|
2013-09-20 09:27:40 +00:00
|
|
|
#undef ROOT_ACCESSOR
|
|
|
|
|
|
|
|
#define STRUCT_MAP_ACCESSOR(NAME, Name, name) \
|
|
|
|
inline Handle<Map> name##_map() { \
|
|
|
|
return Handle<Map>(BitCast<Map**>( \
|
|
|
|
&isolate()->heap()->roots_[Heap::k##Name##MapRootIndex])); \
|
|
|
|
}
|
|
|
|
STRUCT_LIST(STRUCT_MAP_ACCESSOR)
|
|
|
|
#undef STRUCT_MAP_ACCESSOR
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2013-02-28 17:03:34 +00:00
|
|
|
#define STRING_ACCESSOR(name, str) \
|
2011-03-18 20:35:07 +00:00
|
|
|
inline Handle<String> name() { \
|
2010-08-11 10:52:34 +00:00
|
|
|
return Handle<String>(BitCast<String**>( \
|
2011-03-18 20:35:07 +00:00
|
|
|
&isolate()->heap()->roots_[Heap::k##name##RootIndex])); \
|
2009-07-08 19:12:58 +00:00
|
|
|
}
|
2013-02-28 17:03:34 +00:00
|
|
|
INTERNALIZED_STRING_LIST(STRING_ACCESSOR)
|
|
|
|
#undef STRING_ACCESSOR
|
2009-03-19 19:29:23 +00:00
|
|
|
|
2013-02-28 17:03:34 +00:00
|
|
|
Handle<String> hidden_string() {
|
|
|
|
return Handle<String>(&isolate()->heap()->hidden_string_);
|
2009-03-19 18:50:00 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<SharedFunctionInfo> 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);
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<SharedFunctionInfo> NewSharedFunctionInfo(Handle<String> name);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<JSMessageObject> NewJSMessageObject(
|
2011-02-02 13:31:52 +00:00
|
|
|
Handle<String> type,
|
|
|
|
Handle<JSArray> arguments,
|
|
|
|
int start_position,
|
|
|
|
int end_position,
|
|
|
|
Handle<Object> script,
|
|
|
|
Handle<Object> stack_trace,
|
|
|
|
Handle<Object> stack_frames);
|
|
|
|
|
2012-01-16 09:44:35 +00:00
|
|
|
Handle<SeededNumberDictionary> DictionaryAtNumberPut(
|
|
|
|
Handle<SeededNumberDictionary>,
|
|
|
|
uint32_t key,
|
|
|
|
Handle<Object> value);
|
|
|
|
|
|
|
|
Handle<UnseededNumberDictionary> DictionaryAtNumberPut(
|
|
|
|
Handle<UnseededNumberDictionary>,
|
2009-07-02 06:50:43 +00:00
|
|
|
uint32_t key,
|
|
|
|
Handle<Object> value);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-04-20 16:36:13 +00:00
|
|
|
#ifdef ENABLE_DEBUGGER_SUPPORT
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<DebugInfo> NewDebugInfo(Handle<SharedFunctionInfo> shared);
|
2009-04-20 16:36:13 +00:00
|
|
|
#endif
|
2008-09-25 07:46:07 +00:00
|
|
|
|
2012-08-17 09:03:08 +00:00
|
|
|
// Return a map using the map cache in the native context.
|
2008-09-25 07:46:07 +00:00
|
|
|
// The key the an ordered set of property names.
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<Map> ObjectLiteralMapFromCache(Handle<Context> context,
|
|
|
|
Handle<FixedArray> keys);
|
2008-09-25 07:46:07 +00:00
|
|
|
|
2008-10-24 08:40:02 +00:00
|
|
|
// Creates a new FixedArray that holds the data associated with the
|
2009-03-11 14:00:55 +00:00
|
|
|
// atom regexp and stores it in the regexp.
|
2011-03-18 20:35:07 +00:00
|
|
|
void SetRegExpAtomData(Handle<JSRegExp> regexp,
|
|
|
|
JSRegExp::Type type,
|
|
|
|
Handle<String> source,
|
|
|
|
JSRegExp::Flags flags,
|
|
|
|
Handle<Object> match_pattern);
|
2009-03-11 14:00:55 +00:00
|
|
|
|
|
|
|
// Creates a new FixedArray that holds the data associated with the
|
|
|
|
// irregexp regexp and stores it in the regexp.
|
2011-03-18 20:35:07 +00:00
|
|
|
void SetRegExpIrregexpData(Handle<JSRegExp> regexp,
|
|
|
|
JSRegExp::Type type,
|
|
|
|
Handle<String> source,
|
|
|
|
JSRegExp::Flags flags,
|
|
|
|
int capture_count);
|
2008-10-24 08:40:02 +00:00
|
|
|
|
2011-09-23 08:00:06 +00:00
|
|
|
// Returns the value for a known global constant (a property of the global
|
|
|
|
// object which is neither configurable nor writable) like 'undefined'.
|
|
|
|
// Returns a null handle when the given name is unknown.
|
|
|
|
Handle<Object> GlobalConstantFor(Handle<String> name);
|
|
|
|
|
2011-10-10 09:21:48 +00:00
|
|
|
// Converts the given boolean condition to JavaScript boolean value.
|
|
|
|
Handle<Object> ToBoolean(bool value);
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
private:
|
2011-03-18 20:35:07 +00:00
|
|
|
Isolate* isolate() { return reinterpret_cast<Isolate*>(this); }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<JSFunction> NewFunctionHelper(Handle<String> name,
|
|
|
|
Handle<Object> prototype);
|
|
|
|
|
|
|
|
Handle<JSFunction> 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
|
|
|
|
2008-09-25 07:46:07 +00:00
|
|
|
// Create a new map cache.
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<MapCache> NewMapCache(int at_least_space_for);
|
2008-09-25 07:46:07 +00:00
|
|
|
|
2012-08-17 09:03:08 +00:00
|
|
|
// Update the map cache in the native context with (keys, map)
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<MapCache> AddToMapCache(Handle<Context> context,
|
|
|
|
Handle<FixedArray> keys,
|
|
|
|
Handle<Map> map);
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-05-14 15:03:27 +00:00
|
|
|
Handle<Object> Factory::NewNumberFromSize(size_t value,
|
|
|
|
PretenureFlag pretenure) {
|
|
|
|
if (Smi::IsValid(static_cast<intptr_t>(value))) {
|
|
|
|
return Handle<Object>(Smi::FromIntptr(static_cast<intptr_t>(value)),
|
|
|
|
isolate());
|
|
|
|
} else {
|
|
|
|
return NewNumber(static_cast<double>(value), pretenure);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-05 09:36:11 +00:00
|
|
|
// Used to "safely" transition from pointer-based runtime code to Handle-based
|
|
|
|
// runtime code. When a GC happens during the called Handle-based code, a
|
|
|
|
// failure object is returned to the pointer-based code to cause it abort and
|
|
|
|
// re-trigger a gc of it's own. Since this double-gc will cause the Handle-based
|
|
|
|
// code to be called twice, it must be idempotent.
|
|
|
|
class IdempotentPointerToHandleCodeTrampoline {
|
|
|
|
public:
|
|
|
|
explicit IdempotentPointerToHandleCodeTrampoline(Isolate* isolate)
|
|
|
|
: isolate_(isolate) {}
|
|
|
|
|
|
|
|
template<typename R>
|
|
|
|
MUST_USE_RESULT MaybeObject* Call(R (*function)()) {
|
|
|
|
int collections = isolate_->heap()->gc_count();
|
|
|
|
(*function)();
|
|
|
|
return (collections == isolate_->heap()->gc_count())
|
|
|
|
? isolate_->heap()->true_value()
|
|
|
|
: reinterpret_cast<MaybeObject*>(Failure::RetryAfterGC());
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename R>
|
|
|
|
MUST_USE_RESULT MaybeObject* CallWithReturnValue(R (*function)()) {
|
|
|
|
int collections = isolate_->heap()->gc_count();
|
|
|
|
Object* result = (*function)();
|
|
|
|
return (collections == isolate_->heap()->gc_count())
|
|
|
|
? result
|
|
|
|
: reinterpret_cast<MaybeObject*>(Failure::RetryAfterGC());
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename R, typename P1>
|
|
|
|
MUST_USE_RESULT MaybeObject* Call(R (*function)(P1), P1 p1) {
|
|
|
|
int collections = isolate_->heap()->gc_count();
|
|
|
|
(*function)(p1);
|
|
|
|
return (collections == isolate_->heap()->gc_count())
|
|
|
|
? isolate_->heap()->true_value()
|
|
|
|
: reinterpret_cast<MaybeObject*>(Failure::RetryAfterGC());
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename R, typename P1>
|
|
|
|
MUST_USE_RESULT MaybeObject* CallWithReturnValue(
|
|
|
|
R (*function)(P1),
|
|
|
|
P1 p1) {
|
|
|
|
int collections = isolate_->heap()->gc_count();
|
|
|
|
Object* result = (*function)(p1);
|
|
|
|
return (collections == isolate_->heap()->gc_count())
|
|
|
|
? result
|
|
|
|
: reinterpret_cast<MaybeObject*>(Failure::RetryAfterGC());
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename R, typename P1, typename P2>
|
|
|
|
MUST_USE_RESULT MaybeObject* Call(
|
|
|
|
R (*function)(P1, P2),
|
|
|
|
P1 p1,
|
|
|
|
P2 p2) {
|
|
|
|
int collections = isolate_->heap()->gc_count();
|
|
|
|
(*function)(p1, p2);
|
|
|
|
return (collections == isolate_->heap()->gc_count())
|
|
|
|
? isolate_->heap()->true_value()
|
|
|
|
: reinterpret_cast<MaybeObject*>(Failure::RetryAfterGC());
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename R, typename P1, typename P2>
|
|
|
|
MUST_USE_RESULT MaybeObject* CallWithReturnValue(
|
|
|
|
R (*function)(P1, P2),
|
|
|
|
P1 p1,
|
|
|
|
P2 p2) {
|
|
|
|
int collections = isolate_->heap()->gc_count();
|
|
|
|
Object* result = (*function)(p1, p2);
|
|
|
|
return (collections == isolate_->heap()->gc_count())
|
|
|
|
? result
|
|
|
|
: reinterpret_cast<MaybeObject*>(Failure::RetryAfterGC());
|
|
|
|
}
|
|
|
|
|
2013-09-10 14:33:06 +00:00
|
|
|
template<typename R, typename P1, typename P2, typename P3, typename P4,
|
|
|
|
typename P5, typename P6, typename P7>
|
|
|
|
MUST_USE_RESULT MaybeObject* CallWithReturnValue(
|
|
|
|
R (*function)(P1, P2, P3, P4, P5, P6, P7),
|
|
|
|
P1 p1,
|
|
|
|
P2 p2,
|
|
|
|
P3 p3,
|
|
|
|
P4 p4,
|
|
|
|
P5 p5,
|
|
|
|
P6 p6,
|
|
|
|
P7 p7) {
|
|
|
|
int collections = isolate_->heap()->gc_count();
|
|
|
|
Handle<Object> result = (*function)(p1, p2, p3, p4, p5, p6, p7);
|
|
|
|
return (collections == isolate_->heap()->gc_count())
|
|
|
|
? *result
|
|
|
|
: reinterpret_cast<MaybeObject*>(Failure::RetryAfterGC());
|
|
|
|
}
|
|
|
|
|
2013-07-05 09:36:11 +00:00
|
|
|
private:
|
|
|
|
Isolate* isolate_;
|
|
|
|
};
|
|
|
|
|
2013-05-14 15:03:27 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
} } // namespace v8::internal
|
|
|
|
|
|
|
|
#endif // V8_FACTORY_H_
|