2012-04-17 07:16:19 +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.
|
|
|
|
|
|
|
|
#include "v8.h"
|
|
|
|
|
|
|
|
#include "accessors.h"
|
|
|
|
#include "api.h"
|
2009-09-30 12:25:46 +00:00
|
|
|
#include "arguments.h"
|
2008-07-03 15:10:15 +00:00
|
|
|
#include "bootstrapper.h"
|
|
|
|
#include "compiler.h"
|
|
|
|
#include "debug.h"
|
|
|
|
#include "execution.h"
|
|
|
|
#include "global-handles.h"
|
|
|
|
#include "natives.h"
|
|
|
|
#include "runtime.h"
|
2010-11-18 10:42:22 +00:00
|
|
|
#include "string-search.h"
|
2009-11-04 17:59:24 +00:00
|
|
|
#include "stub-cache.h"
|
2010-12-07 11:31:57 +00:00
|
|
|
#include "vm-state-inl.h"
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-05-25 10:05:56 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2013-02-25 14:46:09 +00:00
|
|
|
int HandleScope::NumberOfHandles(Isolate* isolate) {
|
2011-03-18 20:35:07 +00:00
|
|
|
HandleScopeImplementer* impl = isolate->handle_scope_implementer();
|
|
|
|
int n = impl->blocks()->length();
|
2009-01-23 17:22:23 +00:00
|
|
|
if (n == 0) return 0;
|
2009-11-11 09:50:06 +00:00
|
|
|
return ((n - 1) * kHandleBlockSize) + static_cast<int>(
|
2011-03-18 20:35:07 +00:00
|
|
|
(isolate->handle_scope_data()->next - impl->blocks()->last()));
|
2009-01-23 17:22:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-25 14:46:09 +00:00
|
|
|
Object** HandleScope::Extend(Isolate* isolate) {
|
2011-03-18 20:35:07 +00:00
|
|
|
v8::ImplementationUtilities::HandleScopeData* current =
|
|
|
|
isolate->handle_scope_data();
|
2009-01-23 17:22:23 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
Object** result = current->next;
|
|
|
|
|
|
|
|
ASSERT(result == current->limit);
|
2009-03-18 18:50:35 +00:00
|
|
|
// Make sure there's at least one scope on the stack and that the
|
|
|
|
// top of the scope stack isn't a barrier.
|
2011-03-18 20:35:07 +00:00
|
|
|
if (current->level == 0) {
|
2009-03-18 18:50:35 +00:00
|
|
|
Utils::ReportApiFailure("v8::HandleScope::CreateHandle()",
|
|
|
|
"Cannot create a handle without a HandleScope");
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-03-18 20:35:07 +00:00
|
|
|
HandleScopeImplementer* impl = isolate->handle_scope_implementer();
|
2009-03-18 18:50:35 +00:00
|
|
|
// If there's more room in the last block, we use that. This is used
|
|
|
|
// for fast creation of scopes after scope barriers.
|
2009-09-28 12:25:21 +00:00
|
|
|
if (!impl->blocks()->is_empty()) {
|
|
|
|
Object** limit = &impl->blocks()->last()[kHandleBlockSize];
|
2011-03-18 20:35:07 +00:00
|
|
|
if (current->limit != limit) {
|
|
|
|
current->limit = limit;
|
|
|
|
ASSERT(limit - current->next < kHandleBlockSize);
|
2009-01-23 17:22:23 +00:00
|
|
|
}
|
|
|
|
}
|
2009-03-18 21:14:46 +00:00
|
|
|
|
2009-03-18 18:50:35 +00:00
|
|
|
// If we still haven't found a slot for the handle, we extend the
|
|
|
|
// current handle scope by allocating a new handle block.
|
2011-03-18 20:35:07 +00:00
|
|
|
if (result == current->limit) {
|
2009-03-18 18:50:35 +00:00
|
|
|
// If there's a spare block, use it for growing the current scope.
|
|
|
|
result = impl->GetSpareOrNewBlock();
|
|
|
|
// Add the extension to the global list of blocks, but count the
|
|
|
|
// extension as part of the current scope.
|
2009-09-28 12:25:21 +00:00
|
|
|
impl->blocks()->Add(result);
|
2011-03-18 20:35:07 +00:00
|
|
|
current->limit = &result[kHandleBlockSize];
|
2009-03-18 18:50:35 +00:00
|
|
|
}
|
2009-01-23 17:22:23 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
void HandleScope::DeleteExtensions(Isolate* isolate) {
|
|
|
|
v8::ImplementationUtilities::HandleScopeData* current =
|
|
|
|
isolate->handle_scope_data();
|
|
|
|
isolate->handle_scope_implementer()->DeleteExtensions(current->limit);
|
2009-01-23 17:22:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-26 10:33:11 +00:00
|
|
|
void HandleScope::ZapRange(Object** start, Object** end) {
|
2010-10-21 14:21:00 +00:00
|
|
|
ASSERT(end - start <= kHandleBlockSize);
|
|
|
|
for (Object** p = start; p != end; p++) {
|
2009-08-26 10:33:11 +00:00
|
|
|
*reinterpret_cast<Address*>(p) = v8::internal::kHandleZapValue;
|
2009-01-23 17:22:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-25 14:46:09 +00:00
|
|
|
Address HandleScope::current_level_address(Isolate* isolate) {
|
|
|
|
return reinterpret_cast<Address>(&isolate->handle_scope_data()->level);
|
2009-11-04 08:51:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-25 14:46:09 +00:00
|
|
|
Address HandleScope::current_next_address(Isolate* isolate) {
|
|
|
|
return reinterpret_cast<Address>(&isolate->handle_scope_data()->next);
|
2009-11-04 08:51:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-25 14:46:09 +00:00
|
|
|
Address HandleScope::current_limit_address(Isolate* isolate) {
|
|
|
|
return reinterpret_cast<Address>(&isolate->handle_scope_data()->limit);
|
2009-11-04 08:51:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
Handle<FixedArray> AddKeysFromJSArray(Handle<FixedArray> content,
|
|
|
|
Handle<JSArray> array) {
|
2011-03-21 16:00:52 +00:00
|
|
|
CALL_HEAP_FUNCTION(content->GetIsolate(),
|
2011-03-18 20:35:07 +00:00
|
|
|
content->AddKeysFromJSArray(*array), FixedArray);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<FixedArray> UnionOfKeys(Handle<FixedArray> first,
|
|
|
|
Handle<FixedArray> second) {
|
2011-03-21 16:00:52 +00:00
|
|
|
CALL_HEAP_FUNCTION(first->GetIsolate(),
|
2011-03-18 20:35:07 +00:00
|
|
|
first->UnionOfKeys(*second), FixedArray);
|
2008-07-03 15:10:15 +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
|
|
|
Handle<JSGlobalProxy> ReinitializeJSGlobalProxy(
|
2008-07-03 15:10:15 +00:00
|
|
|
Handle<JSFunction> constructor,
|
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<JSGlobalProxy> global) {
|
2011-03-18 20:35:07 +00:00
|
|
|
CALL_HEAP_FUNCTION(
|
2011-03-21 16:00:52 +00:00
|
|
|
constructor->GetIsolate(),
|
2011-03-18 20:35:07 +00:00
|
|
|
constructor->GetHeap()->ReinitializeJSGlobalProxy(*constructor, *global),
|
|
|
|
JSGlobalProxy);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SetExpectedNofProperties(Handle<JSFunction> func, int nof) {
|
2010-09-23 09:15:26 +00:00
|
|
|
// If objects constructed from this function exist then changing
|
2010-11-24 06:26:36 +00:00
|
|
|
// 'estimated_nof_properties' is dangerous since the previous value might
|
2010-09-23 09:15:26 +00:00
|
|
|
// have been compiled into the fast construct stub. More over, the inobject
|
|
|
|
// slack tracking logic might have adjusted the previous value, so even
|
|
|
|
// passing the same value is risky.
|
|
|
|
if (func->shared()->live_objects_may_exist()) return;
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
func->shared()->set_expected_nof_properties(nof);
|
|
|
|
if (func->has_initial_map()) {
|
|
|
|
Handle<Map> new_initial_map =
|
2012-07-17 13:50:19 +00:00
|
|
|
func->GetIsolate()->factory()->CopyMap(
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<Map>(func->initial_map()));
|
2008-07-03 15:10:15 +00:00
|
|
|
new_initial_map->set_unused_property_fields(nof);
|
|
|
|
func->set_initial_map(*new_initial_map);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SetPrototypeProperty(Handle<JSFunction> func, Handle<JSObject> value) {
|
2011-03-21 16:00:52 +00:00
|
|
|
CALL_HEAP_FUNCTION_VOID(func->GetIsolate(),
|
2011-03-18 20:35:07 +00:00
|
|
|
func->SetPrototype(*value));
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-03 09:16:12 +00:00
|
|
|
static int ExpectedNofPropertiesFromEstimate(int estimate) {
|
2010-09-23 09:15:26 +00:00
|
|
|
// If no properties are added in the constructor, they are more likely
|
|
|
|
// to be added later.
|
|
|
|
if (estimate == 0) estimate = 2;
|
|
|
|
|
|
|
|
// We do not shrink objects that go into a snapshot (yet), so we adjust
|
|
|
|
// the estimate conservatively.
|
|
|
|
if (Serializer::enabled()) return estimate + 2;
|
|
|
|
|
|
|
|
// Inobject slack tracking will reclaim redundant inobject space later,
|
|
|
|
// so we can afford to adjust the estimate generously.
|
2011-10-11 11:35:04 +00:00
|
|
|
if (FLAG_clever_optimizations) {
|
|
|
|
return estimate + 8;
|
|
|
|
} else {
|
|
|
|
return estimate + 3;
|
|
|
|
}
|
2008-10-03 09:16:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SetExpectedNofPropertiesFromEstimate(Handle<SharedFunctionInfo> shared,
|
|
|
|
int estimate) {
|
2010-09-23 09:15:26 +00:00
|
|
|
// See the comment in SetExpectedNofProperties.
|
|
|
|
if (shared->live_objects_may_exist()) return;
|
|
|
|
|
2008-10-03 09:16:12 +00:00
|
|
|
shared->set_expected_nof_properties(
|
|
|
|
ExpectedNofPropertiesFromEstimate(estimate));
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FlattenString(Handle<String> string) {
|
2011-03-18 20:35:07 +00:00
|
|
|
CALL_HEAP_FUNCTION_VOID(string->GetIsolate(), string->TryFlatten());
|
2010-06-30 07:40:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<String> FlattenGetString(Handle<String> string) {
|
2011-03-18 20:35:07 +00:00
|
|
|
CALL_HEAP_FUNCTION(string->GetIsolate(), string->TryFlatten(), String);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Object> SetPrototype(Handle<JSFunction> function,
|
|
|
|
Handle<Object> prototype) {
|
2010-04-28 12:05:40 +00:00
|
|
|
ASSERT(function->should_have_prototype());
|
2011-03-21 16:00:52 +00:00
|
|
|
CALL_HEAP_FUNCTION(function->GetIsolate(),
|
2011-03-18 20:35:07 +00:00
|
|
|
Accessors::FunctionSetPrototype(*function,
|
2008-07-03 15:10:15 +00:00
|
|
|
*prototype,
|
|
|
|
NULL),
|
|
|
|
Object);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-22 07:58:59 +00:00
|
|
|
Handle<Object> SetProperty(Isolate* isolate,
|
|
|
|
Handle<Object> object,
|
2008-07-03 15:10:15 +00:00
|
|
|
Handle<Object> key,
|
|
|
|
Handle<Object> value,
|
2011-03-02 04:53:43 +00:00
|
|
|
PropertyAttributes attributes,
|
2011-03-03 16:17:28 +00:00
|
|
|
StrictModeFlag strict_mode) {
|
2008-10-02 13:45:21 +00:00
|
|
|
CALL_HEAP_FUNCTION(
|
2011-03-18 20:35:07 +00:00
|
|
|
isolate,
|
|
|
|
Runtime::SetObjectProperty(
|
|
|
|
isolate, object, key, value, attributes, strict_mode),
|
2011-03-02 04:53:43 +00:00
|
|
|
Object);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-21 13:28:11 +00:00
|
|
|
Handle<Object> ForceSetProperty(Handle<JSObject> object,
|
|
|
|
Handle<Object> key,
|
|
|
|
Handle<Object> value,
|
|
|
|
PropertyAttributes attributes) {
|
2011-03-18 20:35:07 +00:00
|
|
|
Isolate* isolate = object->GetIsolate();
|
2009-04-21 13:28:11 +00:00
|
|
|
CALL_HEAP_FUNCTION(
|
2011-03-18 20:35:07 +00:00
|
|
|
isolate,
|
2011-03-04 00:21:52 +00:00
|
|
|
Runtime::ForceSetObjectProperty(
|
2011-03-18 20:35:07 +00:00
|
|
|
isolate, object, key, value, attributes),
|
2011-03-04 00:21:52 +00:00
|
|
|
Object);
|
2009-04-21 13:28:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-08 09:46:09 +00:00
|
|
|
Handle<Object> ForceDeleteProperty(Handle<JSObject> object,
|
|
|
|
Handle<Object> key) {
|
2011-03-18 20:35:07 +00:00
|
|
|
Isolate* isolate = object->GetIsolate();
|
|
|
|
CALL_HEAP_FUNCTION(isolate,
|
|
|
|
Runtime::ForceDeleteObjectProperty(isolate, object, key),
|
|
|
|
Object);
|
2009-06-08 09:46:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
Handle<Object> SetPropertyWithInterceptor(Handle<JSObject> object,
|
|
|
|
Handle<String> key,
|
|
|
|
Handle<Object> value,
|
2011-03-02 04:53:43 +00:00
|
|
|
PropertyAttributes attributes,
|
2011-03-03 16:17:28 +00:00
|
|
|
StrictModeFlag strict_mode) {
|
2011-03-18 20:35:07 +00:00
|
|
|
CALL_HEAP_FUNCTION(object->GetIsolate(),
|
|
|
|
object->SetPropertyWithInterceptor(*key,
|
2008-07-03 15:10:15 +00:00
|
|
|
*value,
|
2011-03-02 04:53:43 +00:00
|
|
|
attributes,
|
2011-03-03 16:17:28 +00:00
|
|
|
strict_mode),
|
2008-07-03 15:10:15 +00:00
|
|
|
Object);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Implement set trap for proxies, and revamp class hierarchy in preparation:
- Introduce a class JSReceiver, that is a common superclass of JSObject and
JSProxy. Use JSReceiver where appropriate (probably lots of places that we
still have to migrate, but we will find those later with proxy test suite).
- Move appropriate methods to JSReceiver class (SetProperty,
GetPropertyAttribute, Get/SetPrototype, Lookup, and so on).
- Introduce new JSFunctionProxy subclass of JSProxy. Currently only a stub.
- Overhaul enum InstanceType:
* Introduce FIRST/LAST_SPEC_OBJECT_TYPE that ranges over all types that
represent JS objects, and use that consistently to check language types.
* Rename FIRST/LAST_JS_OBJECT_TYPE and FIRST/LAST_FUNCTION_CLASS_TYPE
to FIRST/LAST_[NON]CALLABLE_SPEC_OBJECT_TYPE for clarity.
* Eliminate the overlap over JS_REGEXP_TYPE.
* Also replace FIRST_JS_OBJECT with FIRST_JS_RECEIVER, but only use it where
we exclusively talk about the internal representation type.
* Insert JS_PROXY and JS_FUNCTION_PROXY in the appropriate places.
- Fix all checks concerning classification, especially for functions, to
use the CALLABLE_SPEC_OBJECT range (that includes funciton proxies).
- Handle proxies in SetProperty (that was the easiest part :) ).
- A few simple test cases.
R=kmillikin@chromium.org
Review URL: http://codereview.chromium.org/6992072
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@8126 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2011-05-31 16:38:40 +00:00
|
|
|
Handle<Object> GetProperty(Handle<JSReceiver> obj,
|
2008-07-03 15:10:15 +00:00
|
|
|
const char* name) {
|
2011-03-18 20:35:07 +00:00
|
|
|
Isolate* isolate = obj->GetIsolate();
|
2012-12-17 15:56:16 +00:00
|
|
|
Handle<String> str = isolate->factory()->LookupUtf8Symbol(name);
|
2011-03-18 20:35:07 +00:00
|
|
|
CALL_HEAP_FUNCTION(isolate, obj->GetProperty(*str), Object);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-25 14:46:09 +00:00
|
|
|
Handle<Object> GetProperty(Isolate* isolate,
|
|
|
|
Handle<Object> obj,
|
2008-07-03 15:10:15 +00:00
|
|
|
Handle<Object> key) {
|
2011-03-18 20:35:07 +00:00
|
|
|
CALL_HEAP_FUNCTION(isolate,
|
|
|
|
Runtime::GetObjectProperty(isolate, obj, key), Object);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Object> GetPropertyWithInterceptor(Handle<JSObject> receiver,
|
|
|
|
Handle<JSObject> holder,
|
|
|
|
Handle<String> name,
|
|
|
|
PropertyAttributes* attributes) {
|
2011-03-18 20:35:07 +00:00
|
|
|
Isolate* isolate = receiver->GetIsolate();
|
|
|
|
CALL_HEAP_FUNCTION(isolate,
|
|
|
|
holder->GetPropertyWithInterceptor(*receiver,
|
2008-07-03 15:10:15 +00:00
|
|
|
*name,
|
|
|
|
attributes),
|
|
|
|
Object);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-10 14:44:15 +00:00
|
|
|
Handle<Object> SetPrototype(Handle<JSObject> obj, Handle<Object> value) {
|
|
|
|
const bool skip_hidden_prototypes = false;
|
2011-03-18 20:35:07 +00:00
|
|
|
CALL_HEAP_FUNCTION(obj->GetIsolate(),
|
|
|
|
obj->SetPrototype(*value, skip_hidden_prototypes), Object);
|
2010-02-10 14:44:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-25 14:46:09 +00:00
|
|
|
Handle<Object> LookupSingleCharacterStringFromCode(Isolate* isolate,
|
|
|
|
uint32_t index) {
|
2011-03-18 20:35:07 +00:00
|
|
|
CALL_HEAP_FUNCTION(
|
|
|
|
isolate,
|
|
|
|
isolate->heap()->LookupSingleCharacterStringFromCode(index), Object);
|
2008-08-29 08:48:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-26 14:37:33 +00:00
|
|
|
Handle<String> SubString(Handle<String> str,
|
|
|
|
int start,
|
|
|
|
int end,
|
|
|
|
PretenureFlag pretenure) {
|
2011-03-18 20:35:07 +00:00
|
|
|
CALL_HEAP_FUNCTION(str->GetIsolate(),
|
|
|
|
str->SubString(start, end, pretenure), String);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-22 08:21:18 +00:00
|
|
|
Handle<JSObject> Copy(Handle<JSObject> obj) {
|
2011-03-18 20:35:07 +00:00
|
|
|
Isolate* isolate = obj->GetIsolate();
|
|
|
|
CALL_HEAP_FUNCTION(isolate,
|
|
|
|
isolate->heap()->CopyJSObject(*obj), JSObject);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-25 12:14:49 +00:00
|
|
|
Handle<Object> SetAccessor(Handle<JSObject> obj, Handle<AccessorInfo> info) {
|
2011-03-18 20:35:07 +00:00
|
|
|
CALL_HEAP_FUNCTION(obj->GetIsolate(), obj->DefineAccessor(*info), Object);
|
2010-05-25 12:14:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// Wrappers for scripts are kept alive and cached in weak global
|
2011-05-19 11:47:34 +00:00
|
|
|
// handles referred from foreign objects held by the scripts as long as
|
2008-07-03 15:10:15 +00:00
|
|
|
// they are used. When they are not used anymore, the garbage
|
|
|
|
// collector will call the weak callback on the global handle
|
|
|
|
// associated with the wrapper and get rid of both the wrapper and the
|
|
|
|
// handle.
|
2013-01-25 08:31:46 +00:00
|
|
|
static void ClearWrapperCache(v8::Isolate* v8_isolate,
|
|
|
|
Persistent<v8::Value> handle,
|
|
|
|
void*) {
|
2008-07-03 15:10:15 +00:00
|
|
|
Handle<Object> cache = Utils::OpenHandle(*handle);
|
|
|
|
JSValue* wrapper = JSValue::cast(*cache);
|
2011-05-19 11:47:34 +00:00
|
|
|
Foreign* foreign = Script::cast(wrapper->value())->wrapper();
|
2011-10-28 12:37:29 +00:00
|
|
|
ASSERT(foreign->foreign_address() ==
|
|
|
|
reinterpret_cast<Address>(cache.location()));
|
|
|
|
foreign->set_foreign_address(0);
|
2013-01-25 08:31:46 +00:00
|
|
|
Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate);
|
2011-03-21 16:00:52 +00:00
|
|
|
isolate->global_handles()->Destroy(cache.location());
|
|
|
|
isolate->counters()->script_wrappers()->Decrement();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<JSValue> GetScriptWrapper(Handle<Script> script) {
|
2011-10-28 12:37:29 +00:00
|
|
|
if (script->wrapper()->foreign_address() != NULL) {
|
2008-07-03 15:10:15 +00:00
|
|
|
// Return the script wrapper directly from the cache.
|
2009-07-07 11:41:21 +00:00
|
|
|
return Handle<JSValue>(
|
2011-10-28 12:37:29 +00:00
|
|
|
reinterpret_cast<JSValue**>(script->wrapper()->foreign_address()));
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2013-02-25 14:46:09 +00:00
|
|
|
Isolate* isolate = script->GetIsolate();
|
2008-07-03 15:10:15 +00:00
|
|
|
// Construct a new script wrapper.
|
2011-03-18 20:35:07 +00:00
|
|
|
isolate->counters()->script_wrappers()->Increment();
|
|
|
|
Handle<JSFunction> constructor = isolate->script_function();
|
2008-07-03 15:10:15 +00:00
|
|
|
Handle<JSValue> result =
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<JSValue>::cast(isolate->factory()->NewJSObject(constructor));
|
2013-01-14 13:19:27 +00:00
|
|
|
|
|
|
|
// The allocation might have triggered a GC, which could have called this
|
|
|
|
// function recursively, and a wrapper has already been created and cached.
|
|
|
|
// In that case, simply return the cached wrapper.
|
|
|
|
if (script->wrapper()->foreign_address() != NULL) {
|
|
|
|
return Handle<JSValue>(
|
|
|
|
reinterpret_cast<JSValue**>(script->wrapper()->foreign_address()));
|
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
result->set_value(*script);
|
|
|
|
|
|
|
|
// Create a new weak global handle and use it to cache the wrapper
|
|
|
|
// for future use. The cache will automatically be cleared by the
|
|
|
|
// garbage collector when it is not used anymore.
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<Object> handle = isolate->global_handles()->Create(*result);
|
2013-01-25 08:31:46 +00:00
|
|
|
isolate->global_handles()->MakeWeak(handle.location(),
|
|
|
|
NULL,
|
|
|
|
NULL,
|
2011-03-18 20:35:07 +00:00
|
|
|
&ClearWrapperCache);
|
2011-10-28 12:37:29 +00:00
|
|
|
script->wrapper()->set_foreign_address(
|
|
|
|
reinterpret_cast<Address>(handle.location()));
|
2008-07-03 15:10:15 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-03-10 15:08:45 +00:00
|
|
|
// Init line_ends array with code positions of line ends inside script
|
|
|
|
// source.
|
|
|
|
void InitScriptLineEnds(Handle<Script> script) {
|
2009-11-27 14:10:48 +00:00
|
|
|
if (!script->line_ends()->IsUndefined()) return;
|
2009-03-10 15:08:45 +00:00
|
|
|
|
2011-03-21 16:00:52 +00:00
|
|
|
Isolate* isolate = script->GetIsolate();
|
|
|
|
|
2009-03-10 15:08:45 +00:00
|
|
|
if (!script->source()->IsString()) {
|
|
|
|
ASSERT(script->source()->IsUndefined());
|
2011-03-21 16:00:52 +00:00
|
|
|
Handle<FixedArray> empty = isolate->factory()->NewFixedArray(0);
|
2010-09-23 08:27:51 +00:00
|
|
|
script->set_line_ends(*empty);
|
2009-11-27 14:10:48 +00:00
|
|
|
ASSERT(script->line_ends()->IsFixedArray());
|
2009-03-10 15:08:45 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-03-21 16:00:52 +00:00
|
|
|
Handle<String> src(String::cast(script->source()), isolate);
|
2010-04-19 16:08:26 +00:00
|
|
|
|
|
|
|
Handle<FixedArray> array = CalculateLineEnds(src, true);
|
|
|
|
|
2011-03-21 16:00:52 +00:00
|
|
|
if (*array != isolate->heap()->empty_fixed_array()) {
|
|
|
|
array->set_map(isolate->heap()->fixed_cow_array_map());
|
2010-11-17 12:49:27 +00:00
|
|
|
}
|
|
|
|
|
2010-04-19 16:08:26 +00:00
|
|
|
script->set_line_ends(*array);
|
|
|
|
ASSERT(script->line_ends()->IsFixedArray());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-18 10:42:22 +00:00
|
|
|
template <typename SourceChar>
|
2011-03-18 20:35:07 +00:00
|
|
|
static void CalculateLineEnds(Isolate* isolate,
|
|
|
|
List<int>* line_ends,
|
2010-11-18 10:42:22 +00:00
|
|
|
Vector<const SourceChar> src,
|
|
|
|
bool with_last_line) {
|
|
|
|
const int src_len = src.length();
|
2013-01-09 15:47:53 +00:00
|
|
|
StringSearch<uint8_t, SourceChar> search(isolate, STATIC_ASCII_VECTOR("\n"));
|
2009-03-10 15:08:45 +00:00
|
|
|
|
2010-11-18 10:42:22 +00:00
|
|
|
// Find and record line ends.
|
2009-03-10 15:08:45 +00:00
|
|
|
int position = 0;
|
|
|
|
while (position != -1 && position < src_len) {
|
2010-11-18 10:42:22 +00:00
|
|
|
position = search.Search(src, position);
|
2009-03-10 15:08:45 +00:00
|
|
|
if (position != -1) {
|
2010-11-18 10:42:22 +00:00
|
|
|
line_ends->Add(position);
|
2009-03-10 15:08:45 +00:00
|
|
|
position++;
|
2010-11-18 10:42:22 +00:00
|
|
|
} else if (with_last_line) {
|
2010-04-19 16:08:26 +00:00
|
|
|
// Even if the last line misses a line end, it is counted.
|
2010-11-18 10:42:22 +00:00
|
|
|
line_ends->Add(src_len);
|
|
|
|
return;
|
2010-04-19 16:08:26 +00:00
|
|
|
}
|
2009-03-10 15:08:45 +00:00
|
|
|
}
|
2010-11-18 10:42:22 +00:00
|
|
|
}
|
2009-03-10 15:08:45 +00:00
|
|
|
|
2010-11-18 10:42:22 +00:00
|
|
|
|
|
|
|
Handle<FixedArray> CalculateLineEnds(Handle<String> src,
|
|
|
|
bool with_last_line) {
|
|
|
|
src = FlattenGetString(src);
|
|
|
|
// Rough estimate of line count based on a roughly estimated average
|
|
|
|
// length of (unpacked) code.
|
|
|
|
int line_count_estimate = src->length() >> 4;
|
|
|
|
List<int> line_ends(line_count_estimate);
|
2011-03-21 16:00:52 +00:00
|
|
|
Isolate* isolate = src->GetIsolate();
|
2010-11-18 10:42:22 +00:00
|
|
|
{
|
|
|
|
AssertNoAllocation no_heap_allocation; // ensure vectors stay valid.
|
|
|
|
// Dispatch on type of strings.
|
2011-08-23 13:23:30 +00:00
|
|
|
String::FlatContent content = src->GetFlatContent();
|
2011-08-23 12:22:12 +00:00
|
|
|
ASSERT(content.IsFlat());
|
|
|
|
if (content.IsAscii()) {
|
2011-03-18 20:35:07 +00:00
|
|
|
CalculateLineEnds(isolate,
|
|
|
|
&line_ends,
|
2013-01-09 15:47:53 +00:00
|
|
|
content.ToOneByteVector(),
|
2011-03-18 20:35:07 +00:00
|
|
|
with_last_line);
|
2010-11-18 10:42:22 +00:00
|
|
|
} else {
|
2011-03-18 20:35:07 +00:00
|
|
|
CalculateLineEnds(isolate,
|
|
|
|
&line_ends,
|
2011-08-23 12:22:12 +00:00
|
|
|
content.ToUC16Vector(),
|
2011-03-18 20:35:07 +00:00
|
|
|
with_last_line);
|
2010-04-19 16:08:26 +00:00
|
|
|
}
|
2009-03-10 15:08:45 +00:00
|
|
|
}
|
2010-11-18 10:42:22 +00:00
|
|
|
int line_count = line_ends.length();
|
2011-03-21 16:00:52 +00:00
|
|
|
Handle<FixedArray> array = isolate->factory()->NewFixedArray(line_count);
|
2010-11-18 10:42:22 +00:00
|
|
|
for (int i = 0; i < line_count; i++) {
|
|
|
|
array->set(i, Smi::FromInt(line_ends[i]));
|
|
|
|
}
|
2010-04-19 16:08:26 +00:00
|
|
|
return array;
|
2009-03-10 15:08:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Convert code position into line number.
|
|
|
|
int GetScriptLineNumber(Handle<Script> script, int code_pos) {
|
|
|
|
InitScriptLineEnds(script);
|
|
|
|
AssertNoAllocation no_allocation;
|
2010-02-16 12:08:10 +00:00
|
|
|
FixedArray* line_ends_array = FixedArray::cast(script->line_ends());
|
2009-11-11 09:19:39 +00:00
|
|
|
const int line_ends_len = line_ends_array->length();
|
2009-03-10 15:08:45 +00:00
|
|
|
|
2010-11-18 10:42:22 +00:00
|
|
|
if (!line_ends_len) return -1;
|
2010-02-16 12:08:10 +00:00
|
|
|
|
2010-11-18 10:42:22 +00:00
|
|
|
if ((Smi::cast(line_ends_array->get(0)))->value() >= code_pos) {
|
2010-02-16 12:08:10 +00:00
|
|
|
return script->line_offset()->value();
|
2010-11-18 10:42:22 +00:00
|
|
|
}
|
2010-02-16 12:08:10 +00:00
|
|
|
|
|
|
|
int left = 0;
|
|
|
|
int right = line_ends_len;
|
|
|
|
while (int half = (right - left) / 2) {
|
|
|
|
if ((Smi::cast(line_ends_array->get(left + half)))->value() > code_pos) {
|
|
|
|
right -= half;
|
|
|
|
} else {
|
|
|
|
left += half;
|
2009-03-10 15:08:45 +00:00
|
|
|
}
|
|
|
|
}
|
2010-02-16 12:08:10 +00:00
|
|
|
return right + script->line_offset()->value();
|
2009-03-10 15:08:45 +00:00
|
|
|
}
|
|
|
|
|
2011-11-09 14:18:30 +00:00
|
|
|
// Convert code position into column number.
|
|
|
|
int GetScriptColumnNumber(Handle<Script> script, int code_pos) {
|
|
|
|
int line_number = GetScriptLineNumber(script, code_pos);
|
|
|
|
if (line_number == -1) return -1;
|
|
|
|
|
|
|
|
AssertNoAllocation no_allocation;
|
|
|
|
FixedArray* line_ends_array = FixedArray::cast(script->line_ends());
|
|
|
|
line_number = line_number - script->line_offset()->value();
|
|
|
|
if (line_number == 0) return code_pos + script->column_offset()->value();
|
|
|
|
int prev_line_end_pos =
|
|
|
|
Smi::cast(line_ends_array->get(line_number - 1))->value();
|
|
|
|
return code_pos - (prev_line_end_pos + 1);
|
|
|
|
}
|
2009-03-10 15:08:45 +00:00
|
|
|
|
2010-03-18 22:15:54 +00:00
|
|
|
int GetScriptLineNumberSafe(Handle<Script> script, int code_pos) {
|
|
|
|
AssertNoAllocation no_allocation;
|
|
|
|
if (!script->line_ends()->IsUndefined()) {
|
|
|
|
return GetScriptLineNumber(script, code_pos);
|
|
|
|
}
|
|
|
|
// Slow mode: we do not have line_ends. We have to iterate through source.
|
|
|
|
if (!script->source()->IsString()) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
String* source = String::cast(script->source());
|
|
|
|
int line = 0;
|
|
|
|
int len = source->length();
|
|
|
|
for (int pos = 0; pos < len; pos++) {
|
|
|
|
if (pos == code_pos) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (source->Get(pos) == '\n') {
|
|
|
|
line++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return line;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-30 12:25:46 +00:00
|
|
|
void CustomArguments::IterateInstance(ObjectVisitor* v) {
|
2010-03-25 17:08:22 +00:00
|
|
|
v->VisitPointers(values_, values_ + ARRAY_SIZE(values_));
|
2009-09-30 12:25:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// Compute the property keys from the interceptor.
|
2011-10-24 15:56:18 +00:00
|
|
|
v8::Handle<v8::Array> GetKeysForNamedInterceptor(Handle<JSReceiver> receiver,
|
2008-07-03 15:10:15 +00:00
|
|
|
Handle<JSObject> object) {
|
2011-03-18 20:35:07 +00:00
|
|
|
Isolate* isolate = receiver->GetIsolate();
|
2008-07-03 15:10:15 +00:00
|
|
|
Handle<InterceptorInfo> interceptor(object->GetNamedInterceptor());
|
2011-03-18 20:35:07 +00:00
|
|
|
CustomArguments args(isolate, interceptor->data(), *receiver, *object);
|
2009-09-30 12:25:46 +00:00
|
|
|
v8::AccessorInfo info(args.end());
|
2008-07-03 15:10:15 +00:00
|
|
|
v8::Handle<v8::Array> result;
|
|
|
|
if (!interceptor->enumerator()->IsUndefined()) {
|
|
|
|
v8::NamedPropertyEnumerator enum_fun =
|
|
|
|
v8::ToCData<v8::NamedPropertyEnumerator>(interceptor->enumerator());
|
2011-03-18 20:35:07 +00:00
|
|
|
LOG(isolate, ApiObjectAccess("interceptor-named-enum", *object));
|
2008-07-03 15:10:15 +00:00
|
|
|
{
|
|
|
|
// Leaving JavaScript.
|
2011-03-18 20:35:07 +00:00
|
|
|
VMState state(isolate, EXTERNAL);
|
2008-07-03 15:10:15 +00:00
|
|
|
result = enum_fun(info);
|
|
|
|
}
|
|
|
|
}
|
2012-09-10 13:38:21 +00:00
|
|
|
#if ENABLE_EXTRA_CHECKS
|
|
|
|
CHECK(result.IsEmpty() || v8::Utils::OpenHandle(*result)->IsJSObject());
|
|
|
|
#endif
|
2008-07-03 15:10:15 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Compute the element keys from the interceptor.
|
2011-10-24 15:56:18 +00:00
|
|
|
v8::Handle<v8::Array> GetKeysForIndexedInterceptor(Handle<JSReceiver> receiver,
|
2008-07-03 15:10:15 +00:00
|
|
|
Handle<JSObject> object) {
|
2011-03-18 20:35:07 +00:00
|
|
|
Isolate* isolate = receiver->GetIsolate();
|
2008-07-03 15:10:15 +00:00
|
|
|
Handle<InterceptorInfo> interceptor(object->GetIndexedInterceptor());
|
2011-03-18 20:35:07 +00:00
|
|
|
CustomArguments args(isolate, interceptor->data(), *receiver, *object);
|
2009-09-30 12:25:46 +00:00
|
|
|
v8::AccessorInfo info(args.end());
|
2008-07-03 15:10:15 +00:00
|
|
|
v8::Handle<v8::Array> result;
|
|
|
|
if (!interceptor->enumerator()->IsUndefined()) {
|
|
|
|
v8::IndexedPropertyEnumerator enum_fun =
|
|
|
|
v8::ToCData<v8::IndexedPropertyEnumerator>(interceptor->enumerator());
|
2011-03-18 20:35:07 +00:00
|
|
|
LOG(isolate, ApiObjectAccess("interceptor-indexed-enum", *object));
|
2008-07-03 15:10:15 +00:00
|
|
|
{
|
|
|
|
// Leaving JavaScript.
|
2011-03-18 20:35:07 +00:00
|
|
|
VMState state(isolate, EXTERNAL);
|
2008-07-03 15:10:15 +00:00
|
|
|
result = enum_fun(info);
|
2012-09-10 13:38:21 +00:00
|
|
|
#if ENABLE_EXTRA_CHECKS
|
|
|
|
CHECK(result.IsEmpty() || v8::Utils::OpenHandle(*result)->IsJSObject());
|
|
|
|
#endif
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-12 12:34:18 +00:00
|
|
|
Handle<Object> GetScriptNameOrSourceURL(Handle<Script> script) {
|
|
|
|
Isolate* isolate = script->GetIsolate();
|
|
|
|
Handle<String> name_or_source_url_key =
|
2012-12-17 15:56:16 +00:00
|
|
|
isolate->factory()->LookupOneByteSymbol(
|
|
|
|
STATIC_ASCII_VECTOR("nameOrSourceURL"));
|
2012-11-12 12:34:18 +00:00
|
|
|
Handle<JSValue> script_wrapper = GetScriptWrapper(script);
|
2013-02-25 14:46:09 +00:00
|
|
|
Handle<Object> property = GetProperty(isolate,
|
|
|
|
script_wrapper,
|
2012-11-12 12:34:18 +00:00
|
|
|
name_or_source_url_key);
|
|
|
|
ASSERT(property->IsJSFunction());
|
|
|
|
Handle<JSFunction> method = Handle<JSFunction>::cast(property);
|
|
|
|
bool caught_exception;
|
|
|
|
Handle<Object> result = Execution::TryCall(method, script_wrapper, 0,
|
|
|
|
NULL, &caught_exception);
|
|
|
|
if (caught_exception) {
|
|
|
|
result = isolate->factory()->undefined_value();
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-05 13:10:43 +00:00
|
|
|
static bool ContainsOnlyValidKeys(Handle<FixedArray> array) {
|
|
|
|
int len = array->length();
|
|
|
|
for (int i = 0; i < len; i++) {
|
|
|
|
Object* e = array->get(i);
|
|
|
|
if (!(e->IsString() || e->IsNumber())) return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-24 15:56:18 +00:00
|
|
|
Handle<FixedArray> GetKeysInFixedArrayFor(Handle<JSReceiver> object,
|
|
|
|
KeyCollectionType type,
|
|
|
|
bool* threw) {
|
2010-10-05 13:10:43 +00:00
|
|
|
USE(ContainsOnlyValidKeys);
|
2011-03-18 20:35:07 +00:00
|
|
|
Isolate* isolate = object->GetIsolate();
|
|
|
|
Handle<FixedArray> content = isolate->factory()->empty_fixed_array();
|
2011-03-21 16:00:52 +00:00
|
|
|
Handle<JSObject> arguments_boilerplate = Handle<JSObject>(
|
2012-08-17 09:03:08 +00:00
|
|
|
isolate->context()->native_context()->arguments_boilerplate(),
|
2011-03-21 16:00:52 +00:00
|
|
|
isolate);
|
|
|
|
Handle<JSFunction> arguments_function = Handle<JSFunction>(
|
|
|
|
JSFunction::cast(arguments_boilerplate->map()->constructor()),
|
|
|
|
isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Only collect keys if access is permitted.
|
2009-09-16 08:25:54 +00:00
|
|
|
for (Handle<Object> p = object;
|
2011-03-18 20:35:07 +00:00
|
|
|
*p != isolate->heap()->null_value();
|
2013-02-27 13:22:29 +00:00
|
|
|
p = Handle<Object>(p->GetPrototype(isolate), isolate)) {
|
2011-10-24 15:56:18 +00:00
|
|
|
if (p->IsJSProxy()) {
|
|
|
|
Handle<JSProxy> proxy(JSProxy::cast(*p), isolate);
|
|
|
|
Handle<Object> args[] = { proxy };
|
|
|
|
Handle<Object> names = Execution::Call(
|
|
|
|
isolate->proxy_enumerate(), object, ARRAY_SIZE(args), args, threw);
|
|
|
|
if (*threw) return content;
|
|
|
|
content = AddKeysFromJSArray(content, Handle<JSArray>::cast(names));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-03-21 16:00:52 +00:00
|
|
|
Handle<JSObject> current(JSObject::cast(*p), isolate);
|
2009-09-16 08:25:54 +00:00
|
|
|
|
|
|
|
// Check access rights if required.
|
|
|
|
if (current->IsAccessCheckNeeded() &&
|
2011-03-18 20:35:07 +00:00
|
|
|
!isolate->MayNamedAccess(*current,
|
|
|
|
isolate->heap()->undefined_value(),
|
|
|
|
v8::ACCESS_KEYS)) {
|
|
|
|
isolate->ReportFailedAccessCheck(*current, v8::ACCESS_KEYS);
|
2009-09-16 08:25:54 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-04-16 11:30:55 +00:00
|
|
|
|
2009-09-16 08:25:54 +00:00
|
|
|
// Compute the element keys.
|
|
|
|
Handle<FixedArray> element_keys =
|
2011-03-18 20:35:07 +00:00
|
|
|
isolate->factory()->NewFixedArray(current->NumberOfEnumElements());
|
2009-09-16 08:25:54 +00:00
|
|
|
current->GetEnumElementKeys(*element_keys);
|
|
|
|
content = UnionOfKeys(content, element_keys);
|
2010-10-05 13:10:43 +00:00
|
|
|
ASSERT(ContainsOnlyValidKeys(content));
|
2009-09-16 08:25:54 +00:00
|
|
|
|
|
|
|
// Add the element keys from the interceptor.
|
|
|
|
if (current->HasIndexedInterceptor()) {
|
|
|
|
v8::Handle<v8::Array> result =
|
|
|
|
GetKeysForIndexedInterceptor(object, current);
|
|
|
|
if (!result.IsEmpty())
|
|
|
|
content = AddKeysFromJSArray(content, v8::Utils::OpenHandle(*result));
|
2010-10-05 13:10:43 +00:00
|
|
|
ASSERT(ContainsOnlyValidKeys(content));
|
2009-09-16 08:25:54 +00:00
|
|
|
}
|
2009-04-16 11:30:55 +00:00
|
|
|
|
2009-12-01 10:25:29 +00:00
|
|
|
// We can cache the computed property keys if access checks are
|
|
|
|
// not needed and no interceptors are involved.
|
|
|
|
//
|
|
|
|
// We do not use the cache if the object has elements and
|
|
|
|
// therefore it does not make sense to cache the property names
|
|
|
|
// for arguments objects. Arguments objects will always have
|
|
|
|
// elements.
|
2010-07-19 12:45:21 +00:00
|
|
|
// Wrapped strings have elements, but don't have an elements
|
|
|
|
// array or dictionary. So the fast inline test for whether to
|
|
|
|
// use the cache says yes, so we should not create a cache.
|
2009-12-01 10:25:29 +00:00
|
|
|
bool cache_enum_keys =
|
|
|
|
((current->map()->constructor() != *arguments_function) &&
|
2010-07-19 12:45:21 +00:00
|
|
|
!current->IsJSValue() &&
|
2009-12-01 10:25:29 +00:00
|
|
|
!current->IsAccessCheckNeeded() &&
|
|
|
|
!current->HasNamedInterceptor() &&
|
|
|
|
!current->HasIndexedInterceptor());
|
|
|
|
// Compute the property keys and cache them if possible.
|
|
|
|
content =
|
|
|
|
UnionOfKeys(content, GetEnumPropertyKeys(current, cache_enum_keys));
|
2010-10-05 13:10:43 +00:00
|
|
|
ASSERT(ContainsOnlyValidKeys(content));
|
2009-09-15 11:51:40 +00:00
|
|
|
|
2009-09-16 08:25:54 +00:00
|
|
|
// Add the property keys from the interceptor.
|
|
|
|
if (current->HasNamedInterceptor()) {
|
|
|
|
v8::Handle<v8::Array> result =
|
|
|
|
GetKeysForNamedInterceptor(object, current);
|
|
|
|
if (!result.IsEmpty())
|
|
|
|
content = AddKeysFromJSArray(content, v8::Utils::OpenHandle(*result));
|
2010-10-05 13:10:43 +00:00
|
|
|
ASSERT(ContainsOnlyValidKeys(content));
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2009-09-16 08:25:54 +00:00
|
|
|
|
|
|
|
// If we only want local properties we bail out after the first
|
|
|
|
// iteration.
|
|
|
|
if (type == LOCAL_ONLY)
|
|
|
|
break;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
return content;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-24 15:56:18 +00:00
|
|
|
Handle<JSArray> GetKeysFor(Handle<JSReceiver> object, bool* threw) {
|
2011-03-18 20:35:07 +00:00
|
|
|
Isolate* isolate = object->GetIsolate();
|
|
|
|
isolate->counters()->for_in()->Increment();
|
2011-10-24 15:56:18 +00:00
|
|
|
Handle<FixedArray> elements =
|
|
|
|
GetKeysInFixedArrayFor(object, INCLUDE_PROTOS, threw);
|
2011-03-18 20:35:07 +00:00
|
|
|
return isolate->factory()->NewJSArrayWithElements(elements);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
Sharing of descriptor arrays.
This CL adds multiple things:
Transition arrays do not directly point at their descriptor array anymore, but rather do so via an indirect pointer (a JSGlobalPropertyCell).
An ownership bit is added to maps indicating whether it owns its own descriptor array or not.
Maps owning a descriptor array can pass on ownership if a transition from that map is generated; but only if the descriptor array stays exactly the same; or if a descriptor is added.
Maps that don't have ownership get ownership back if their direct child to which ownership was passed is cleared in ClearNonLiveTransitions.
To detect which descriptors in an array are valid, each map knows its own NumberOfOwnDescriptors. Since the descriptors are sorted in order of addition, if we search and find a descriptor with index bigger than this number, it is not valid for the given map.
We currently still build up an enumeration cache (although this may disappear). The enumeration cache is always built for the entire descriptor array, even if not all descriptors are owned by the map. Once a descriptor array has an enumeration cache for a given map; this invariant will always be true, even if the descriptor array was extended. The extended array will inherit the enumeration cache from the smaller descriptor array. If a map with more descriptors needs an enumeration cache, it's EnumLength will still be set to invalid, so it will have to recompute the enumeration cache. This new cache will also be valid for smaller maps since they have their own enumlength; and use this to loop over the cache. If the EnumLength is still invalid, but there is already a cache present that is big enough; we just initialize the EnumLength field for the map.
When we apply ClearNonLiveTransitions and descriptor ownership is passed back to a parent map, the descriptor array is trimmed in-place and resorted. At the same time, the enumeration cache is trimmed in-place.
Only transition arrays contain descriptor arrays. If we transition to a map and pass ownership of the descriptor array along, the child map will not store the descriptor array it owns. Rather its parent will keep the pointer. So for every leaf-map, we find the descriptor array by following the back pointer, reading out the transition array, and fetching the descriptor array from the JSGlobalPropertyCell. If a map has a transition array, we fetch it from there. If a map has undefined as its back-pointer and has no transition array; it is considered to have an empty descriptor array.
When we modify properties, we cannot share the descriptor array. To accommodate this, the child map will get its own transition array; even if there are not necessarily any transitions leaving from the child map. This is necessary since it's the only way to store its own descriptor array.
Review URL: https://chromiumcodereview.appspot.com/10909007
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@12492 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2012-09-12 16:43:57 +00:00
|
|
|
Handle<FixedArray> ReduceFixedArrayTo(Handle<FixedArray> array, int length) {
|
|
|
|
ASSERT(array->length() >= length);
|
|
|
|
if (array->length() == length) return array;
|
|
|
|
|
|
|
|
Handle<FixedArray> new_array =
|
|
|
|
array->GetIsolate()->factory()->NewFixedArray(length);
|
|
|
|
for (int i = 0; i < length; ++i) new_array->set(i, array->get(i));
|
|
|
|
return new_array;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-01 10:25:29 +00:00
|
|
|
Handle<FixedArray> GetEnumPropertyKeys(Handle<JSObject> object,
|
|
|
|
bool cache_result) {
|
2011-03-18 20:35:07 +00:00
|
|
|
Isolate* isolate = object->GetIsolate();
|
2008-07-03 15:10:15 +00:00
|
|
|
if (object->HasFastProperties()) {
|
|
|
|
if (object->map()->instance_descriptors()->HasEnumCache()) {
|
2012-08-28 14:20:50 +00:00
|
|
|
int own_property_count = object->map()->EnumLength();
|
Sharing of descriptor arrays.
This CL adds multiple things:
Transition arrays do not directly point at their descriptor array anymore, but rather do so via an indirect pointer (a JSGlobalPropertyCell).
An ownership bit is added to maps indicating whether it owns its own descriptor array or not.
Maps owning a descriptor array can pass on ownership if a transition from that map is generated; but only if the descriptor array stays exactly the same; or if a descriptor is added.
Maps that don't have ownership get ownership back if their direct child to which ownership was passed is cleared in ClearNonLiveTransitions.
To detect which descriptors in an array are valid, each map knows its own NumberOfOwnDescriptors. Since the descriptors are sorted in order of addition, if we search and find a descriptor with index bigger than this number, it is not valid for the given map.
We currently still build up an enumeration cache (although this may disappear). The enumeration cache is always built for the entire descriptor array, even if not all descriptors are owned by the map. Once a descriptor array has an enumeration cache for a given map; this invariant will always be true, even if the descriptor array was extended. The extended array will inherit the enumeration cache from the smaller descriptor array. If a map with more descriptors needs an enumeration cache, it's EnumLength will still be set to invalid, so it will have to recompute the enumeration cache. This new cache will also be valid for smaller maps since they have their own enumlength; and use this to loop over the cache. If the EnumLength is still invalid, but there is already a cache present that is big enough; we just initialize the EnumLength field for the map.
When we apply ClearNonLiveTransitions and descriptor ownership is passed back to a parent map, the descriptor array is trimmed in-place and resorted. At the same time, the enumeration cache is trimmed in-place.
Only transition arrays contain descriptor arrays. If we transition to a map and pass ownership of the descriptor array along, the child map will not store the descriptor array it owns. Rather its parent will keep the pointer. So for every leaf-map, we find the descriptor array by following the back pointer, reading out the transition array, and fetching the descriptor array from the JSGlobalPropertyCell. If a map has a transition array, we fetch it from there. If a map has undefined as its back-pointer and has no transition array; it is considered to have an empty descriptor array.
When we modify properties, we cannot share the descriptor array. To accommodate this, the child map will get its own transition array; even if there are not necessarily any transitions leaving from the child map. This is necessary since it's the only way to store its own descriptor array.
Review URL: https://chromiumcodereview.appspot.com/10909007
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@12492 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2012-09-12 16:43:57 +00:00
|
|
|
// If we have an enum cache, but the enum length of the given map is set
|
|
|
|
// to kInvalidEnumCache, this means that the map itself has never used the
|
|
|
|
// present enum cache. The first step to using the cache is to set the
|
|
|
|
// enum length of the map by counting the number of own descriptors that
|
|
|
|
// are not DONT_ENUM.
|
|
|
|
if (own_property_count == Map::kInvalidEnumCache) {
|
|
|
|
own_property_count = object->map()->NumberOfDescribedProperties(
|
|
|
|
OWN_DESCRIPTORS, DONT_ENUM);
|
|
|
|
|
|
|
|
if (cache_result) object->map()->SetEnumLength(own_property_count);
|
2012-08-28 14:20:50 +00:00
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
DescriptorArray* desc = object->map()->instance_descriptors();
|
2012-09-19 08:08:02 +00:00
|
|
|
Handle<FixedArray> keys(desc->GetEnumCache(), isolate);
|
2012-08-28 14:20:50 +00:00
|
|
|
|
Sharing of descriptor arrays.
This CL adds multiple things:
Transition arrays do not directly point at their descriptor array anymore, but rather do so via an indirect pointer (a JSGlobalPropertyCell).
An ownership bit is added to maps indicating whether it owns its own descriptor array or not.
Maps owning a descriptor array can pass on ownership if a transition from that map is generated; but only if the descriptor array stays exactly the same; or if a descriptor is added.
Maps that don't have ownership get ownership back if their direct child to which ownership was passed is cleared in ClearNonLiveTransitions.
To detect which descriptors in an array are valid, each map knows its own NumberOfOwnDescriptors. Since the descriptors are sorted in order of addition, if we search and find a descriptor with index bigger than this number, it is not valid for the given map.
We currently still build up an enumeration cache (although this may disappear). The enumeration cache is always built for the entire descriptor array, even if not all descriptors are owned by the map. Once a descriptor array has an enumeration cache for a given map; this invariant will always be true, even if the descriptor array was extended. The extended array will inherit the enumeration cache from the smaller descriptor array. If a map with more descriptors needs an enumeration cache, it's EnumLength will still be set to invalid, so it will have to recompute the enumeration cache. This new cache will also be valid for smaller maps since they have their own enumlength; and use this to loop over the cache. If the EnumLength is still invalid, but there is already a cache present that is big enough; we just initialize the EnumLength field for the map.
When we apply ClearNonLiveTransitions and descriptor ownership is passed back to a parent map, the descriptor array is trimmed in-place and resorted. At the same time, the enumeration cache is trimmed in-place.
Only transition arrays contain descriptor arrays. If we transition to a map and pass ownership of the descriptor array along, the child map will not store the descriptor array it owns. Rather its parent will keep the pointer. So for every leaf-map, we find the descriptor array by following the back pointer, reading out the transition array, and fetching the descriptor array from the JSGlobalPropertyCell. If a map has a transition array, we fetch it from there. If a map has undefined as its back-pointer and has no transition array; it is considered to have an empty descriptor array.
When we modify properties, we cannot share the descriptor array. To accommodate this, the child map will get its own transition array; even if there are not necessarily any transitions leaving from the child map. This is necessary since it's the only way to store its own descriptor array.
Review URL: https://chromiumcodereview.appspot.com/10909007
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@12492 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2012-09-12 16:43:57 +00:00
|
|
|
// In case the number of properties required in the enum are actually
|
|
|
|
// present, we can reuse the enum cache. Otherwise, this means that the
|
|
|
|
// enum cache was generated for a previous (smaller) version of the
|
|
|
|
// Descriptor Array. In that case we regenerate the enum cache.
|
|
|
|
if (own_property_count <= keys->length()) {
|
|
|
|
isolate->counters()->enum_cache_hits()->Increment();
|
|
|
|
return ReduceFixedArrayTo(keys, own_property_count);
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2012-02-22 12:47:42 +00:00
|
|
|
|
2012-08-28 14:20:50 +00:00
|
|
|
Handle<Map> map(object->map());
|
2012-02-22 12:47:42 +00:00
|
|
|
|
2012-08-28 14:20:50 +00:00
|
|
|
if (map->instance_descriptors()->IsEmpty()) {
|
|
|
|
isolate->counters()->enum_cache_hits()->Increment();
|
|
|
|
if (cache_result) map->SetEnumLength(0);
|
|
|
|
return isolate->factory()->empty_fixed_array();
|
2012-02-22 12:47:42 +00:00
|
|
|
}
|
|
|
|
|
2012-08-28 14:20:50 +00:00
|
|
|
isolate->counters()->enum_cache_misses()->Increment();
|
Sharing of descriptor arrays.
This CL adds multiple things:
Transition arrays do not directly point at their descriptor array anymore, but rather do so via an indirect pointer (a JSGlobalPropertyCell).
An ownership bit is added to maps indicating whether it owns its own descriptor array or not.
Maps owning a descriptor array can pass on ownership if a transition from that map is generated; but only if the descriptor array stays exactly the same; or if a descriptor is added.
Maps that don't have ownership get ownership back if their direct child to which ownership was passed is cleared in ClearNonLiveTransitions.
To detect which descriptors in an array are valid, each map knows its own NumberOfOwnDescriptors. Since the descriptors are sorted in order of addition, if we search and find a descriptor with index bigger than this number, it is not valid for the given map.
We currently still build up an enumeration cache (although this may disappear). The enumeration cache is always built for the entire descriptor array, even if not all descriptors are owned by the map. Once a descriptor array has an enumeration cache for a given map; this invariant will always be true, even if the descriptor array was extended. The extended array will inherit the enumeration cache from the smaller descriptor array. If a map with more descriptors needs an enumeration cache, it's EnumLength will still be set to invalid, so it will have to recompute the enumeration cache. This new cache will also be valid for smaller maps since they have their own enumlength; and use this to loop over the cache. If the EnumLength is still invalid, but there is already a cache present that is big enough; we just initialize the EnumLength field for the map.
When we apply ClearNonLiveTransitions and descriptor ownership is passed back to a parent map, the descriptor array is trimmed in-place and resorted. At the same time, the enumeration cache is trimmed in-place.
Only transition arrays contain descriptor arrays. If we transition to a map and pass ownership of the descriptor array along, the child map will not store the descriptor array it owns. Rather its parent will keep the pointer. So for every leaf-map, we find the descriptor array by following the back pointer, reading out the transition array, and fetching the descriptor array from the JSGlobalPropertyCell. If a map has a transition array, we fetch it from there. If a map has undefined as its back-pointer and has no transition array; it is considered to have an empty descriptor array.
When we modify properties, we cannot share the descriptor array. To accommodate this, the child map will get its own transition array; even if there are not necessarily any transitions leaving from the child map. This is necessary since it's the only way to store its own descriptor array.
Review URL: https://chromiumcodereview.appspot.com/10909007
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@12492 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2012-09-12 16:43:57 +00:00
|
|
|
int num_enum = map->NumberOfDescribedProperties(ALL_DESCRIPTORS, DONT_ENUM);
|
2012-08-28 14:20:50 +00:00
|
|
|
|
|
|
|
Handle<FixedArray> storage = isolate->factory()->NewFixedArray(num_enum);
|
|
|
|
Handle<FixedArray> indices = isolate->factory()->NewFixedArray(num_enum);
|
|
|
|
|
2009-07-10 19:25:18 +00:00
|
|
|
Handle<DescriptorArray> descs =
|
2011-03-21 16:00:52 +00:00
|
|
|
Handle<DescriptorArray>(object->map()->instance_descriptors(), isolate);
|
2012-02-22 12:47:42 +00:00
|
|
|
|
Sharing of descriptor arrays.
This CL adds multiple things:
Transition arrays do not directly point at their descriptor array anymore, but rather do so via an indirect pointer (a JSGlobalPropertyCell).
An ownership bit is added to maps indicating whether it owns its own descriptor array or not.
Maps owning a descriptor array can pass on ownership if a transition from that map is generated; but only if the descriptor array stays exactly the same; or if a descriptor is added.
Maps that don't have ownership get ownership back if their direct child to which ownership was passed is cleared in ClearNonLiveTransitions.
To detect which descriptors in an array are valid, each map knows its own NumberOfOwnDescriptors. Since the descriptors are sorted in order of addition, if we search and find a descriptor with index bigger than this number, it is not valid for the given map.
We currently still build up an enumeration cache (although this may disappear). The enumeration cache is always built for the entire descriptor array, even if not all descriptors are owned by the map. Once a descriptor array has an enumeration cache for a given map; this invariant will always be true, even if the descriptor array was extended. The extended array will inherit the enumeration cache from the smaller descriptor array. If a map with more descriptors needs an enumeration cache, it's EnumLength will still be set to invalid, so it will have to recompute the enumeration cache. This new cache will also be valid for smaller maps since they have their own enumlength; and use this to loop over the cache. If the EnumLength is still invalid, but there is already a cache present that is big enough; we just initialize the EnumLength field for the map.
When we apply ClearNonLiveTransitions and descriptor ownership is passed back to a parent map, the descriptor array is trimmed in-place and resorted. At the same time, the enumeration cache is trimmed in-place.
Only transition arrays contain descriptor arrays. If we transition to a map and pass ownership of the descriptor array along, the child map will not store the descriptor array it owns. Rather its parent will keep the pointer. So for every leaf-map, we find the descriptor array by following the back pointer, reading out the transition array, and fetching the descriptor array from the JSGlobalPropertyCell. If a map has a transition array, we fetch it from there. If a map has undefined as its back-pointer and has no transition array; it is considered to have an empty descriptor array.
When we modify properties, we cannot share the descriptor array. To accommodate this, the child map will get its own transition array; even if there are not necessarily any transitions leaving from the child map. This is necessary since it's the only way to store its own descriptor array.
Review URL: https://chromiumcodereview.appspot.com/10909007
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@12492 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2012-09-12 16:43:57 +00:00
|
|
|
int real_size = map->NumberOfOwnDescriptors();
|
|
|
|
int enum_size = 0;
|
2012-08-27 13:47:34 +00:00
|
|
|
int index = 0;
|
Sharing of descriptor arrays.
This CL adds multiple things:
Transition arrays do not directly point at their descriptor array anymore, but rather do so via an indirect pointer (a JSGlobalPropertyCell).
An ownership bit is added to maps indicating whether it owns its own descriptor array or not.
Maps owning a descriptor array can pass on ownership if a transition from that map is generated; but only if the descriptor array stays exactly the same; or if a descriptor is added.
Maps that don't have ownership get ownership back if their direct child to which ownership was passed is cleared in ClearNonLiveTransitions.
To detect which descriptors in an array are valid, each map knows its own NumberOfOwnDescriptors. Since the descriptors are sorted in order of addition, if we search and find a descriptor with index bigger than this number, it is not valid for the given map.
We currently still build up an enumeration cache (although this may disappear). The enumeration cache is always built for the entire descriptor array, even if not all descriptors are owned by the map. Once a descriptor array has an enumeration cache for a given map; this invariant will always be true, even if the descriptor array was extended. The extended array will inherit the enumeration cache from the smaller descriptor array. If a map with more descriptors needs an enumeration cache, it's EnumLength will still be set to invalid, so it will have to recompute the enumeration cache. This new cache will also be valid for smaller maps since they have their own enumlength; and use this to loop over the cache. If the EnumLength is still invalid, but there is already a cache present that is big enough; we just initialize the EnumLength field for the map.
When we apply ClearNonLiveTransitions and descriptor ownership is passed back to a parent map, the descriptor array is trimmed in-place and resorted. At the same time, the enumeration cache is trimmed in-place.
Only transition arrays contain descriptor arrays. If we transition to a map and pass ownership of the descriptor array along, the child map will not store the descriptor array it owns. Rather its parent will keep the pointer. So for every leaf-map, we find the descriptor array by following the back pointer, reading out the transition array, and fetching the descriptor array from the JSGlobalPropertyCell. If a map has a transition array, we fetch it from there. If a map has undefined as its back-pointer and has no transition array; it is considered to have an empty descriptor array.
When we modify properties, we cannot share the descriptor array. To accommodate this, the child map will get its own transition array; even if there are not necessarily any transitions leaving from the child map. This is necessary since it's the only way to store its own descriptor array.
Review URL: https://chromiumcodereview.appspot.com/10909007
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@12492 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2012-09-12 16:43:57 +00:00
|
|
|
|
2009-07-10 19:25:18 +00:00
|
|
|
for (int i = 0; i < descs->number_of_descriptors(); i++) {
|
2012-08-28 14:20:50 +00:00
|
|
|
PropertyDetails details = descs->GetDetails(i);
|
|
|
|
if (!details.IsDontEnum()) {
|
Sharing of descriptor arrays.
This CL adds multiple things:
Transition arrays do not directly point at their descriptor array anymore, but rather do so via an indirect pointer (a JSGlobalPropertyCell).
An ownership bit is added to maps indicating whether it owns its own descriptor array or not.
Maps owning a descriptor array can pass on ownership if a transition from that map is generated; but only if the descriptor array stays exactly the same; or if a descriptor is added.
Maps that don't have ownership get ownership back if their direct child to which ownership was passed is cleared in ClearNonLiveTransitions.
To detect which descriptors in an array are valid, each map knows its own NumberOfOwnDescriptors. Since the descriptors are sorted in order of addition, if we search and find a descriptor with index bigger than this number, it is not valid for the given map.
We currently still build up an enumeration cache (although this may disappear). The enumeration cache is always built for the entire descriptor array, even if not all descriptors are owned by the map. Once a descriptor array has an enumeration cache for a given map; this invariant will always be true, even if the descriptor array was extended. The extended array will inherit the enumeration cache from the smaller descriptor array. If a map with more descriptors needs an enumeration cache, it's EnumLength will still be set to invalid, so it will have to recompute the enumeration cache. This new cache will also be valid for smaller maps since they have their own enumlength; and use this to loop over the cache. If the EnumLength is still invalid, but there is already a cache present that is big enough; we just initialize the EnumLength field for the map.
When we apply ClearNonLiveTransitions and descriptor ownership is passed back to a parent map, the descriptor array is trimmed in-place and resorted. At the same time, the enumeration cache is trimmed in-place.
Only transition arrays contain descriptor arrays. If we transition to a map and pass ownership of the descriptor array along, the child map will not store the descriptor array it owns. Rather its parent will keep the pointer. So for every leaf-map, we find the descriptor array by following the back pointer, reading out the transition array, and fetching the descriptor array from the JSGlobalPropertyCell. If a map has a transition array, we fetch it from there. If a map has undefined as its back-pointer and has no transition array; it is considered to have an empty descriptor array.
When we modify properties, we cannot share the descriptor array. To accommodate this, the child map will get its own transition array; even if there are not necessarily any transitions leaving from the child map. This is necessary since it's the only way to store its own descriptor array.
Review URL: https://chromiumcodereview.appspot.com/10909007
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@12492 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2012-09-12 16:43:57 +00:00
|
|
|
if (i < real_size) ++enum_size;
|
2012-02-22 12:47:42 +00:00
|
|
|
storage->set(index, descs->GetKey(i));
|
|
|
|
if (!indices.is_null()) {
|
|
|
|
if (details.type() != FIELD) {
|
|
|
|
indices = Handle<FixedArray>();
|
|
|
|
} else {
|
|
|
|
int field_index = Descriptor::IndexFromValue(descs->GetValue(i));
|
|
|
|
if (field_index >= map->inobject_properties()) {
|
|
|
|
field_index = -(field_index - map->inobject_properties() + 1);
|
|
|
|
}
|
|
|
|
indices->set(index, Smi::FromInt(field_index));
|
|
|
|
}
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
index++;
|
|
|
|
}
|
|
|
|
}
|
2012-08-28 14:20:50 +00:00
|
|
|
ASSERT(index == storage->length());
|
|
|
|
|
|
|
|
Handle<FixedArray> bridge_storage =
|
|
|
|
isolate->factory()->NewFixedArray(
|
|
|
|
DescriptorArray::kEnumCacheBridgeLength);
|
|
|
|
DescriptorArray* desc = object->map()->instance_descriptors();
|
|
|
|
desc->SetEnumCache(*bridge_storage,
|
|
|
|
*storage,
|
|
|
|
indices.is_null() ? Object::cast(Smi::FromInt(0))
|
|
|
|
: Object::cast(*indices));
|
2009-12-01 10:25:29 +00:00
|
|
|
if (cache_result) {
|
Sharing of descriptor arrays.
This CL adds multiple things:
Transition arrays do not directly point at their descriptor array anymore, but rather do so via an indirect pointer (a JSGlobalPropertyCell).
An ownership bit is added to maps indicating whether it owns its own descriptor array or not.
Maps owning a descriptor array can pass on ownership if a transition from that map is generated; but only if the descriptor array stays exactly the same; or if a descriptor is added.
Maps that don't have ownership get ownership back if their direct child to which ownership was passed is cleared in ClearNonLiveTransitions.
To detect which descriptors in an array are valid, each map knows its own NumberOfOwnDescriptors. Since the descriptors are sorted in order of addition, if we search and find a descriptor with index bigger than this number, it is not valid for the given map.
We currently still build up an enumeration cache (although this may disappear). The enumeration cache is always built for the entire descriptor array, even if not all descriptors are owned by the map. Once a descriptor array has an enumeration cache for a given map; this invariant will always be true, even if the descriptor array was extended. The extended array will inherit the enumeration cache from the smaller descriptor array. If a map with more descriptors needs an enumeration cache, it's EnumLength will still be set to invalid, so it will have to recompute the enumeration cache. This new cache will also be valid for smaller maps since they have their own enumlength; and use this to loop over the cache. If the EnumLength is still invalid, but there is already a cache present that is big enough; we just initialize the EnumLength field for the map.
When we apply ClearNonLiveTransitions and descriptor ownership is passed back to a parent map, the descriptor array is trimmed in-place and resorted. At the same time, the enumeration cache is trimmed in-place.
Only transition arrays contain descriptor arrays. If we transition to a map and pass ownership of the descriptor array along, the child map will not store the descriptor array it owns. Rather its parent will keep the pointer. So for every leaf-map, we find the descriptor array by following the back pointer, reading out the transition array, and fetching the descriptor array from the JSGlobalPropertyCell. If a map has a transition array, we fetch it from there. If a map has undefined as its back-pointer and has no transition array; it is considered to have an empty descriptor array.
When we modify properties, we cannot share the descriptor array. To accommodate this, the child map will get its own transition array; even if there are not necessarily any transitions leaving from the child map. This is necessary since it's the only way to store its own descriptor array.
Review URL: https://chromiumcodereview.appspot.com/10909007
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@12492 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2012-09-12 16:43:57 +00:00
|
|
|
object->map()->SetEnumLength(enum_size);
|
2009-12-01 10:25:29 +00:00
|
|
|
}
|
Sharing of descriptor arrays.
This CL adds multiple things:
Transition arrays do not directly point at their descriptor array anymore, but rather do so via an indirect pointer (a JSGlobalPropertyCell).
An ownership bit is added to maps indicating whether it owns its own descriptor array or not.
Maps owning a descriptor array can pass on ownership if a transition from that map is generated; but only if the descriptor array stays exactly the same; or if a descriptor is added.
Maps that don't have ownership get ownership back if their direct child to which ownership was passed is cleared in ClearNonLiveTransitions.
To detect which descriptors in an array are valid, each map knows its own NumberOfOwnDescriptors. Since the descriptors are sorted in order of addition, if we search and find a descriptor with index bigger than this number, it is not valid for the given map.
We currently still build up an enumeration cache (although this may disappear). The enumeration cache is always built for the entire descriptor array, even if not all descriptors are owned by the map. Once a descriptor array has an enumeration cache for a given map; this invariant will always be true, even if the descriptor array was extended. The extended array will inherit the enumeration cache from the smaller descriptor array. If a map with more descriptors needs an enumeration cache, it's EnumLength will still be set to invalid, so it will have to recompute the enumeration cache. This new cache will also be valid for smaller maps since they have their own enumlength; and use this to loop over the cache. If the EnumLength is still invalid, but there is already a cache present that is big enough; we just initialize the EnumLength field for the map.
When we apply ClearNonLiveTransitions and descriptor ownership is passed back to a parent map, the descriptor array is trimmed in-place and resorted. At the same time, the enumeration cache is trimmed in-place.
Only transition arrays contain descriptor arrays. If we transition to a map and pass ownership of the descriptor array along, the child map will not store the descriptor array it owns. Rather its parent will keep the pointer. So for every leaf-map, we find the descriptor array by following the back pointer, reading out the transition array, and fetching the descriptor array from the JSGlobalPropertyCell. If a map has a transition array, we fetch it from there. If a map has undefined as its back-pointer and has no transition array; it is considered to have an empty descriptor array.
When we modify properties, we cannot share the descriptor array. To accommodate this, the child map will get its own transition array; even if there are not necessarily any transitions leaving from the child map. This is necessary since it's the only way to store its own descriptor array.
Review URL: https://chromiumcodereview.appspot.com/10909007
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@12492 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2012-09-12 16:43:57 +00:00
|
|
|
|
|
|
|
return ReduceFixedArrayTo(storage, enum_size);
|
2008-07-03 15:10:15 +00:00
|
|
|
} else {
|
2012-09-03 12:31:24 +00:00
|
|
|
Handle<StringDictionary> dictionary(object->property_dictionary());
|
|
|
|
|
|
|
|
int length = dictionary->NumberOfElements();
|
|
|
|
if (length == 0) {
|
|
|
|
return Handle<FixedArray>(isolate->heap()->empty_fixed_array());
|
|
|
|
}
|
|
|
|
|
|
|
|
// The enumeration array is generated by allocating an array big enough to
|
|
|
|
// hold all properties that have been seen, whether they are are deleted or
|
|
|
|
// not. Subsequently all visible properties are added to the array. If some
|
|
|
|
// properties were not visible, the array is trimmed so it only contains
|
|
|
|
// visible properties. This improves over adding elements and sorting by
|
|
|
|
// index by having linear complexity rather than n*log(n).
|
|
|
|
|
|
|
|
// By comparing the monotonous NextEnumerationIndex to the NumberOfElements,
|
|
|
|
// we can predict the number of holes in the final array. If there will be
|
|
|
|
// more than 50% holes, regenerate the enumeration indices to reduce the
|
|
|
|
// number of holes to a minimum. This avoids allocating a large array if
|
|
|
|
// many properties were added but subsequently deleted.
|
|
|
|
int next_enumeration = dictionary->NextEnumerationIndex();
|
2012-09-03 15:15:32 +00:00
|
|
|
if (!object->IsGlobalObject() && next_enumeration > (length * 3) / 2) {
|
2012-09-03 12:31:24 +00:00
|
|
|
StringDictionary::DoGenerateNewEnumerationIndices(dictionary);
|
|
|
|
next_enumeration = dictionary->NextEnumerationIndex();
|
|
|
|
}
|
|
|
|
|
|
|
|
Handle<FixedArray> storage =
|
|
|
|
isolate->factory()->NewFixedArray(next_enumeration);
|
|
|
|
|
2012-09-03 13:27:17 +00:00
|
|
|
storage = Handle<FixedArray>(dictionary->CopyEnumKeysTo(*storage));
|
2012-09-03 12:31:24 +00:00
|
|
|
ASSERT(storage->length() == object->NumberOfLocalProperties(DONT_ENUM));
|
2008-07-03 15:10:15 +00:00
|
|
|
return storage;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-25 14:14:56 +00:00
|
|
|
Handle<ObjectHashSet> ObjectHashSetAdd(Handle<ObjectHashSet> table,
|
|
|
|
Handle<Object> key) {
|
|
|
|
CALL_HEAP_FUNCTION(table->GetIsolate(),
|
|
|
|
table->Add(*key),
|
|
|
|
ObjectHashSet);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<ObjectHashSet> ObjectHashSetRemove(Handle<ObjectHashSet> table,
|
|
|
|
Handle<Object> key) {
|
|
|
|
CALL_HEAP_FUNCTION(table->GetIsolate(),
|
|
|
|
table->Remove(*key),
|
|
|
|
ObjectHashSet);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-28 17:21:22 +00:00
|
|
|
Handle<ObjectHashTable> PutIntoObjectHashTable(Handle<ObjectHashTable> table,
|
2011-10-25 14:14:56 +00:00
|
|
|
Handle<Object> key,
|
2011-07-28 17:21:22 +00:00
|
|
|
Handle<Object> value) {
|
|
|
|
CALL_HEAP_FUNCTION(table->GetIsolate(),
|
|
|
|
table->Put(*key, *value),
|
|
|
|
ObjectHashTable);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-06 09:31:31 +00:00
|
|
|
DeferredHandleScope::DeferredHandleScope(Isolate* isolate)
|
|
|
|
: impl_(isolate->handle_scope_implementer()) {
|
|
|
|
impl_->BeginDeferredScope();
|
2012-07-06 14:09:11 +00:00
|
|
|
v8::ImplementationUtilities::HandleScopeData* data =
|
|
|
|
impl_->isolate()->handle_scope_data();
|
2012-07-06 09:31:31 +00:00
|
|
|
Object** new_next = impl_->GetSpareOrNewBlock();
|
|
|
|
Object** new_limit = &new_next[kHandleBlockSize];
|
2012-07-06 14:09:11 +00:00
|
|
|
ASSERT(data->limit == &impl_->blocks()->last()[kHandleBlockSize]);
|
2012-07-06 09:31:31 +00:00
|
|
|
impl_->blocks()->Add(new_next);
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
prev_level_ = data->level;
|
|
|
|
#endif
|
|
|
|
data->level++;
|
|
|
|
prev_limit_ = data->limit;
|
|
|
|
prev_next_ = data->next;
|
|
|
|
data->next = new_next;
|
|
|
|
data->limit = new_limit;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DeferredHandleScope::~DeferredHandleScope() {
|
|
|
|
impl_->isolate()->handle_scope_data()->level--;
|
|
|
|
ASSERT(handles_detached_);
|
|
|
|
ASSERT(impl_->isolate()->handle_scope_data()->level == prev_level_);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DeferredHandles* DeferredHandleScope::Detach() {
|
|
|
|
DeferredHandles* deferred = impl_->Detach(prev_limit_);
|
|
|
|
v8::ImplementationUtilities::HandleScopeData* data =
|
|
|
|
impl_->isolate()->handle_scope_data();
|
|
|
|
data->next = prev_next_;
|
|
|
|
data->limit = prev_limit_;
|
|
|
|
#ifdef DEBUG
|
|
|
|
handles_detached_ = true;
|
|
|
|
#endif
|
|
|
|
return deferred;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
} } // namespace v8::internal
|