2014-03-31 12:01:02 +00:00
|
|
|
// Copyright 2014 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
#ifndef V8_FACTORY_H_
|
|
|
|
#define V8_FACTORY_H_
|
|
|
|
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/isolate.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
|
|
|
|
|
|
|
// Interface for handle based allocation.
|
|
|
|
|
2014-03-31 12:01:02 +00:00
|
|
|
class Factory V8_FINAL {
|
2008-07-03 15:10:15 +00:00
|
|
|
public:
|
2014-04-16 14:15:32 +00:00
|
|
|
Handle<Oddball> NewOddball(Handle<Map> map,
|
|
|
|
const char* to_string,
|
|
|
|
Handle<Object> to_number,
|
|
|
|
byte kind);
|
|
|
|
|
2014-03-20 13:01:08 +00:00
|
|
|
// Allocates a fixed array initialized with undefined values.
|
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
|
|
|
|
2014-03-20 13:01:08 +00:00
|
|
|
// Allocates an uninitialized fixed array. It must be filled by the caller.
|
|
|
|
Handle<FixedArray> NewUninitializedFixedArray(int size);
|
|
|
|
|
2011-06-09 10:03:35 +00:00
|
|
|
// Allocate a new uninitialized fixed double array.
|
2014-04-24 05:29:00 +00:00
|
|
|
// 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(
|
2011-06-09 10:03:35 +00:00
|
|
|
int size,
|
|
|
|
PretenureFlag pretenure = NOT_TENURED);
|
|
|
|
|
2014-04-14 16:05:19 +00:00
|
|
|
// Allocate a new fixed double array with hole values.
|
2014-04-24 05:29:00 +00:00
|
|
|
Handle<FixedArrayBase> NewFixedDoubleArrayWithHoles(
|
2014-04-14 16:05:19 +00:00
|
|
|
int size,
|
|
|
|
PretenureFlag pretenure = NOT_TENURED);
|
|
|
|
|
2013-10-14 13:35:06 +00:00
|
|
|
Handle<ConstantPoolArray> NewConstantPoolArray(
|
|
|
|
int number_of_int64_entries,
|
2014-03-10 19:05:43 +00:00
|
|
|
int number_of_code_ptr_entries,
|
|
|
|
int number_of_heap_ptr_entries,
|
2013-10-14 13:35:06 +00:00
|
|
|
int number_of_int32_entries);
|
|
|
|
|
2014-04-04 20:41:57 +00:00
|
|
|
Handle<OrderedHashSet> NewOrderedHashSet();
|
|
|
|
Handle<OrderedHashMap> NewOrderedHashMap();
|
|
|
|
|
2014-04-07 12:43:35 +00:00
|
|
|
// Create a new boxed value.
|
|
|
|
Handle<Box> NewBox(Handle<Object> value);
|
|
|
|
|
2014-04-07 10:12:54 +00:00
|
|
|
// Create a pre-tenured empty AccessorPair.
|
2012-01-10 16:11:33 +00:00
|
|
|
Handle<AccessorPair> NewAccessorPair();
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2014-04-07 10:12:54 +00:00
|
|
|
// Create an empty TypeFeedbackInfo.
|
2012-02-20 12:57:23 +00:00
|
|
|
Handle<TypeFeedbackInfo> NewTypeFeedbackInfo();
|
|
|
|
|
2014-04-23 15:43:39 +00:00
|
|
|
// Finds the internalized copy for string in the string table.
|
|
|
|
// If not found, a new string is added to the table and returned.
|
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);
|
2014-01-29 14:31:34 +00:00
|
|
|
Handle<String> InternalizeOneByteString(
|
|
|
|
Handle<SeqOneByteString>, 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
|
|
|
|
2014-01-17 10:27:57 +00:00
|
|
|
template<class StringTableKey>
|
|
|
|
Handle<String> InternalizeStringWithKey(StringTableKey* key);
|
|
|
|
|
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.
|
2014-04-17 13:27:02 +00:00
|
|
|
MUST_USE_RESULT MaybeHandle<String> NewStringFromOneByte(
|
2013-01-09 10:30:54 +00:00
|
|
|
Vector<const uint8_t> str,
|
2008-07-03 15:10:15 +00:00
|
|
|
PretenureFlag pretenure = NOT_TENURED);
|
2014-04-17 13:27:02 +00:00
|
|
|
|
|
|
|
template<size_t N>
|
|
|
|
inline Handle<String> NewStringFromStaticAscii(
|
|
|
|
const char (&str)[N],
|
|
|
|
PretenureFlag pretenure = NOT_TENURED) {
|
|
|
|
ASSERT(N == StrLength(str) + 1);
|
|
|
|
return NewStringFromOneByte(
|
|
|
|
STATIC_ASCII_VECTOR(str), pretenure).ToHandleChecked();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Handle<String> NewStringFromAsciiChecked(
|
|
|
|
const char* str,
|
|
|
|
PretenureFlag pretenure = NOT_TENURED) {
|
|
|
|
return NewStringFromOneByte(
|
|
|
|
OneByteVector(str), pretenure).ToHandleChecked();
|
|
|
|
}
|
|
|
|
|
2013-01-09 10:30:54 +00:00
|
|
|
// TODO(dcarney): remove this function.
|
2014-04-17 13:27:02 +00:00
|
|
|
MUST_USE_RESULT inline MaybeHandle<String> NewStringFromAscii(
|
2013-01-09 10:30:54 +00:00
|
|
|
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.
|
2014-04-17 13:27:02 +00:00
|
|
|
MUST_USE_RESULT MaybeHandle<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
|
|
|
|
2014-04-17 13:27:02 +00:00
|
|
|
MUST_USE_RESULT MaybeHandle<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
|
|
|
|
2014-04-25 13:59:33 +00:00
|
|
|
// 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> NewTwoByteInternalizedString(
|
|
|
|
Vector<const uc16> str,
|
|
|
|
uint32_t hash_field);
|
|
|
|
|
|
|
|
MUST_USE_RESULT Handle<String> NewInternalizedStringImpl(
|
2014-04-25 16:02:50 +00:00
|
|
|
Handle<String> string, int chars, uint32_t hash_field);
|
2014-04-25 13:59:33 +00:00
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
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.
|
2014-04-04 12:06:11 +00:00
|
|
|
MUST_USE_RESULT MaybeHandle<SeqOneByteString> NewRawOneByteString(
|
2010-07-05 12:49:00 +00:00
|
|
|
int length,
|
|
|
|
PretenureFlag pretenure = NOT_TENURED);
|
2014-04-04 12:06:11 +00:00
|
|
|
MUST_USE_RESULT MaybeHandle<SeqTwoByteString> NewRawTwoByteString(
|
2008-07-03 15:10:15 +00:00
|
|
|
int length,
|
|
|
|
PretenureFlag pretenure = NOT_TENURED);
|
|
|
|
|
2014-04-23 15:43:39 +00:00
|
|
|
// Creates a single character string where the character has given code.
|
|
|
|
// A cache is used for ASCII codes.
|
|
|
|
Handle<String> LookupSingleCharacterStringFromCode(uint32_t code);
|
2014-04-08 06:45:53 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// Create a new cons string object which consists of a pair of strings.
|
2014-04-03 12:30:37 +00:00
|
|
|
MUST_USE_RESULT MaybeHandle<String> NewConsString(Handle<String> left,
|
|
|
|
Handle<String> right);
|
2013-12-23 12:37:56 +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);
|
|
|
|
|
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);
|
|
|
|
|
2013-12-23 12:37:56 +00:00
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
|
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,
|
2014-04-16 13:35:36 +00:00
|
|
|
// because we cannot change the underlying buffer. Note that these strings
|
|
|
|
// are backed by a string resource that resides outside the V8 heap.
|
2014-04-04 12:06:11 +00:00
|
|
|
MUST_USE_RESULT MaybeHandle<String> NewExternalStringFromAscii(
|
2011-09-21 13:28:09 +00:00
|
|
|
const ExternalAsciiString::Resource* resource);
|
2014-04-04 12:06:11 +00:00
|
|
|
MUST_USE_RESULT MaybeHandle<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();
|
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> NewPrivateSymbol();
|
2013-03-01 10:34:31 +00:00
|
|
|
|
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,
|
2014-04-09 08:51:46 +00:00
|
|
|
Handle<JSReceiver> 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
|
|
|
|
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
|
|
|
|
2014-04-16 12:10:56 +00:00
|
|
|
Handle<CodeCache> NewCodeCache();
|
|
|
|
|
2013-11-14 17:30:48 +00:00
|
|
|
Handle<AliasedArgumentsEntry> NewAliasedArgumentsEntry(
|
|
|
|
int aliased_context_slot);
|
|
|
|
|
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);
|
2014-01-16 17:08:45 +00:00
|
|
|
|
|
|
|
Handle<FixedTypedArrayBase> NewFixedTypedArray(
|
|
|
|
int length,
|
|
|
|
ExternalArrayType array_type,
|
|
|
|
PretenureFlag pretenure = NOT_TENURED);
|
2009-10-20 15:26:17 +00:00
|
|
|
|
2013-06-12 15:03:44 +00:00
|
|
|
Handle<Cell> NewCell(Handle<Object> value);
|
|
|
|
|
2013-10-21 13:55:24 +00:00
|
|
|
Handle<PropertyCell> NewPropertyCellWithHole();
|
|
|
|
|
2013-06-14 16:06:12 +00:00
|
|
|
Handle<PropertyCell> NewPropertyCell(Handle<Object> value);
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2014-04-16 12:54:29 +00:00
|
|
|
// Allocate a tenured AllocationSite. It's payload is null.
|
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
|
|
|
|
2014-04-17 13:15:22 +00:00
|
|
|
Handle<HeapObject> NewFillerObject(int size,
|
|
|
|
bool double_align,
|
|
|
|
AllocationSpace space);
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<JSObject> NewFunctionPrototype(Handle<JSFunction> function);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2014-04-29 07:02:11 +00:00
|
|
|
Handle<JSObject> CopyJSObject(Handle<JSObject> object);
|
|
|
|
|
|
|
|
Handle<JSObject> CopyJSObjectWithAllocationSite(Handle<JSObject> object,
|
|
|
|
Handle<AllocationSite> site);
|
|
|
|
|
2014-04-28 15:33:16 +00:00
|
|
|
Handle<FixedArray> CopyFixedArrayWithMap(Handle<FixedArray> array,
|
|
|
|
Handle<Map> map);
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<FixedArray> CopyFixedArray(Handle<FixedArray> array);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2014-03-17 13:42:37 +00:00
|
|
|
// This method expects a COW array in new space, and creates a copy
|
|
|
|
// of it in old space.
|
|
|
|
Handle<FixedArray> CopyAndTenureFixedCOWArray(Handle<FixedArray> array);
|
|
|
|
|
2011-10-19 11:36:55 +00:00
|
|
|
Handle<FixedDoubleArray> CopyFixedDoubleArray(
|
|
|
|
Handle<FixedDoubleArray> array);
|
|
|
|
|
2013-10-14 13:35:06 +00:00
|
|
|
Handle<ConstantPoolArray> CopyConstantPoolArray(
|
|
|
|
Handle<ConstantPoolArray> array);
|
|
|
|
|
2012-01-16 12:38:59 +00:00
|
|
|
// Numbers (e.g. literals) are pretenured by the parser.
|
2014-04-16 14:04:54 +00:00
|
|
|
// The return value may be a smi or a heap number.
|
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);
|
2014-03-31 12:01:02 +00:00
|
|
|
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);
|
|
|
|
}
|
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.
|
2014-04-29 08:25:24 +00:00
|
|
|
inline Handle<JSObject> NewNeanderObject() {
|
|
|
|
return NewJSObjectFromMap(neander_map());
|
|
|
|
}
|
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);
|
2014-03-19 13:39:09 +00:00
|
|
|
// JSObject that should have a memento pointing to the allocation site.
|
|
|
|
Handle<JSObject> NewJSObjectWithMemento(Handle<JSFunction> constructor,
|
|
|
|
Handle<AllocationSite> site);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2013-10-21 13:55:24 +00:00
|
|
|
// Global objects are pretenured and initialized based on a constructor.
|
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.
|
2014-03-17 15:01:45 +00:00
|
|
|
Handle<JSObject> NewJSObjectFromMap(
|
|
|
|
Handle<Map> map,
|
|
|
|
PretenureFlag pretenure = NOT_TENURED,
|
|
|
|
bool allocate_properties = true,
|
|
|
|
Handle<AllocationSite> allocation_site = Handle<AllocationSite>::null());
|
2013-08-07 11:24:14 +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.
|
2014-04-07 10:00:14 +00:00
|
|
|
|
2014-04-07 12:43:35 +00:00
|
|
|
// Create a JSArray with no elements.
|
2014-04-07 10:00:14 +00:00
|
|
|
Handle<JSArray> NewJSArray(
|
|
|
|
ElementsKind elements_kind,
|
|
|
|
PretenureFlag pretenure = NOT_TENURED);
|
|
|
|
|
2014-04-07 12:43:35 +00:00
|
|
|
// Create a JSArray with a specified length and elements initialized
|
|
|
|
// according to the specified mode.
|
2014-03-21 11:22:16 +00:00
|
|
|
Handle<JSArray> NewJSArray(
|
|
|
|
ElementsKind elements_kind,
|
|
|
|
int length,
|
|
|
|
int capacity,
|
2014-03-27 16:41:09 +00:00
|
|
|
ArrayStorageAllocationMode mode = INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE,
|
2014-03-21 11:22:16 +00:00
|
|
|
PretenureFlag pretenure = NOT_TENURED);
|
|
|
|
|
2012-05-23 14:24:29 +00:00
|
|
|
Handle<JSArray> NewJSArray(
|
|
|
|
int capacity,
|
|
|
|
ElementsKind elements_kind = TERMINAL_FAST_ELEMENTS_KIND,
|
2014-03-21 11:22:16 +00:00
|
|
|
PretenureFlag pretenure = NOT_TENURED) {
|
2014-04-03 09:12:59 +00:00
|
|
|
if (capacity != 0) {
|
|
|
|
elements_kind = GetHoleyElementsKind(elements_kind);
|
|
|
|
}
|
2014-03-27 16:41:09 +00:00
|
|
|
return NewJSArray(elements_kind, 0, capacity,
|
|
|
|
INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE, pretenure);
|
2014-03-21 11:22:16 +00:00
|
|
|
}
|
|
|
|
|
2014-04-07 12:43:35 +00:00
|
|
|
// Create a JSArray with the given elements.
|
2014-03-21 11:22:16 +00:00
|
|
|
Handle<JSArray> NewJSArrayWithElements(
|
|
|
|
Handle<FixedArrayBase> elements,
|
|
|
|
ElementsKind elements_kind,
|
|
|
|
int length,
|
2012-05-23 14:24:29 +00:00
|
|
|
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,
|
2014-03-21 11:22:16 +00:00
|
|
|
PretenureFlag pretenure = NOT_TENURED) {
|
|
|
|
return NewJSArrayWithElements(
|
|
|
|
elements, elements_kind, elements->length(), pretenure);
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2014-03-17 15:01:45 +00:00
|
|
|
void NewJSArrayStorage(
|
|
|
|
Handle<JSArray> array,
|
|
|
|
int length,
|
|
|
|
int capacity,
|
|
|
|
ArrayStorageAllocationMode mode = DONT_INITIALIZE_ARRAY_ELEMENTS);
|
|
|
|
|
2013-11-05 12:11:27 +00:00
|
|
|
Handle<JSGeneratorObject> NewJSGeneratorObject(Handle<JSFunction> function);
|
|
|
|
|
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();
|
|
|
|
|
2014-04-16 13:35:36 +00:00
|
|
|
// Allocates a Harmony proxy.
|
2011-05-13 10:58:25 +00:00
|
|
|
Handle<JSProxy> NewJSProxy(Handle<Object> handler, Handle<Object> prototype);
|
|
|
|
|
2014-04-16 13:35:36 +00:00
|
|
|
// Allocates a Harmony function proxy.
|
2014-04-15 10:59:38 +00:00
|
|
|
Handle<JSProxy> NewJSFunctionProxy(Handle<Object> handler,
|
|
|
|
Handle<Object> call_trap,
|
|
|
|
Handle<Object> construct_trap,
|
|
|
|
Handle<Object> prototype);
|
|
|
|
|
2014-04-15 11:51:34 +00:00
|
|
|
// Reinitialize a JSReceiver 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 ReinitializeJSReceiver(
|
|
|
|
Handle<JSReceiver> object, InstanceType type, int size);
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
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,
|
2014-05-09 17:39:54 +00:00
|
|
|
Handle<Code> code,
|
2014-05-09 17:59:15 +00:00
|
|
|
Handle<Object> prototype,
|
|
|
|
bool read_only_prototype = false);
|
2014-05-09 16:39:33 +00:00
|
|
|
Handle<JSFunction> NewFunction(Handle<String> name);
|
2014-05-09 17:39:54 +00:00
|
|
|
Handle<JSFunction> NewFunctionWithoutPrototype(Handle<String> name,
|
|
|
|
Handle<Code> code);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
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
|
|
|
|
2014-05-09 17:39:54 +00:00
|
|
|
Handle<JSFunction> NewFunction(Handle<String> name,
|
|
|
|
Handle<Code> code,
|
|
|
|
Handle<Object> prototype,
|
2014-04-29 17:48:07 +00:00
|
|
|
InstanceType type,
|
2014-05-09 17:59:15 +00:00
|
|
|
int instance_size,
|
|
|
|
bool read_only_prototype = false);
|
2014-04-15 11:51:34 +00:00
|
|
|
Handle<JSFunction> NewFunction(Handle<String> name,
|
2014-05-09 17:39:54 +00:00
|
|
|
Handle<Code> code,
|
2014-04-15 11:51:34 +00:00
|
|
|
InstanceType type,
|
2014-05-09 17:39:54 +00:00
|
|
|
int instance_size);
|
2014-04-15 11:51:34 +00:00
|
|
|
|
2014-04-07 10:12:54 +00:00
|
|
|
// Create a serialized scope info.
|
2011-11-03 10:36:55 +00:00
|
|
|
Handle<ScopeInfo> NewScopeInfo(int length);
|
2011-08-11 16:29:28 +00:00
|
|
|
|
2014-04-07 10:12:54 +00:00
|
|
|
// Create an External object for V8's external API.
|
2012-11-13 12:27:03 +00:00
|
|
|
Handle<JSObject> NewExternal(void* value);
|
|
|
|
|
2014-04-16 11:38:56 +00:00
|
|
|
// 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.
|
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,
|
2013-10-23 13:48:04 +00:00
|
|
|
bool crankshafted = false,
|
2014-05-12 13:47:01 +00:00
|
|
|
int prologue_offset = Code::kPrologueOffsetNotSet,
|
|
|
|
bool is_debug = 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
|
|
|
|
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
|
|
|
|
2014-04-03 12:30:37 +00:00
|
|
|
Handle<Object> NewInvalidStringLengthError() {
|
|
|
|
return NewRangeError("invalid_string_length",
|
|
|
|
HandleVector<Object>(NULL, 0));
|
|
|
|
}
|
|
|
|
|
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);
|
2014-03-17 10:21:01 +00:00
|
|
|
Handle<Object> NewReferenceError(const char* message, Handle<JSArray> args);
|
2011-03-18 20:35:07 +00:00
|
|
|
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
|
|
|
|
2014-04-17 17:45:32 +00:00
|
|
|
Handle<JSObject> NewIteratorResultObject(Handle<Object> value, bool done);
|
|
|
|
|
2014-04-15 11:16:02 +00:00
|
|
|
Handle<String> NumberToString(Handle<Object> number,
|
|
|
|
bool check_number_string_cache = true);
|
2014-04-16 14:04:54 +00:00
|
|
|
|
|
|
|
Handle<String> Uint32ToString(uint32_t value) {
|
|
|
|
return NumberToString(NewNumberFromUint(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,
|
2014-04-29 17:48:07 +00:00
|
|
|
Handle<Object> prototype,
|
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
|
|
|
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.
|
2014-04-11 10:41:09 +00:00
|
|
|
MUST_USE_RESULT MaybeHandle<FunctionTemplateInfo> ConfigureInstance(
|
|
|
|
Handle<FunctionTemplateInfo> desc, Handle<JSObject> instance);
|
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
|
|
|
|
2014-04-23 15:43:39 +00:00
|
|
|
inline void set_string_table(Handle<StringTable> table) {
|
|
|
|
isolate()->heap()->set_string_table(*table);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2014-04-16 13:35:36 +00:00
|
|
|
// Allocates a new SharedFunctionInfo object.
|
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,
|
2014-04-30 10:51:01 +00:00
|
|
|
Handle<ScopeInfo> scope_info,
|
|
|
|
Handle<FixedArray> feedback_vector);
|
2014-05-09 17:39:54 +00:00
|
|
|
Handle<SharedFunctionInfo> NewSharedFunctionInfo(Handle<String> name,
|
|
|
|
MaybeHandle<Code> code);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2014-04-30 14:33:35 +00:00
|
|
|
// Allocate a new type feedback vector
|
|
|
|
Handle<FixedArray> NewTypeFeedbackVector(int slot_count);
|
|
|
|
|
2014-04-16 13:35:36 +00:00
|
|
|
// Allocates a new JSMessageObject object.
|
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_frames);
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<DebugInfo> NewDebugInfo(Handle<SharedFunctionInfo> shared);
|
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
|
|
|
|
2014-04-15 11:51:34 +00:00
|
|
|
// 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);
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
Handle<T> New(Handle<Map> map,
|
|
|
|
AllocationSpace space,
|
|
|
|
Handle<AllocationSite> allocation_site);
|
|
|
|
|
2014-04-29 13:58:55 +00:00
|
|
|
// Creates a code object that is not yet fully initialized yet.
|
|
|
|
inline Handle<Code> NewCodeRaw(int object_size, bool immovable);
|
|
|
|
|
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);
|
2014-04-16 14:04:54 +00:00
|
|
|
|
|
|
|
// 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);
|
2014-05-09 17:39:54 +00:00
|
|
|
|
|
|
|
// 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);
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} } // namespace v8::internal
|
|
|
|
|
|
|
|
#endif // V8_FACTORY_H_
|