2012-01-24 08:43:12 +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"
|
2012-01-25 00:16:07 +00:00
|
|
|
|
2013-12-23 14:30:35 +00:00
|
|
|
#include "compiler.h"
|
2012-01-25 00:16:07 +00:00
|
|
|
#include "contexts.h"
|
2010-12-07 11:31:57 +00:00
|
|
|
#include "deoptimizer.h"
|
2008-07-03 15:10:15 +00:00
|
|
|
#include "execution.h"
|
|
|
|
#include "factory.h"
|
2012-01-25 00:16:07 +00:00
|
|
|
#include "frames-inl.h"
|
|
|
|
#include "isolate.h"
|
2011-05-03 08:23:58 +00:00
|
|
|
#include "list-inl.h"
|
2012-01-25 00:16:07 +00:00
|
|
|
#include "property-details.h"
|
2014-04-15 13:25:17 +00:00
|
|
|
#include "api.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
|
|
|
|
|
|
|
|
2014-04-15 13:25:17 +00:00
|
|
|
static Handle<AccessorInfo> MakeAccessor(Isolate* isolate,
|
|
|
|
Handle<String> name,
|
|
|
|
AccessorGetterCallback getter,
|
|
|
|
AccessorSetterCallback setter,
|
|
|
|
PropertyAttributes attributes) {
|
|
|
|
Factory* factory = isolate->factory();
|
|
|
|
Handle<ExecutableAccessorInfo> info = factory->NewExecutableAccessorInfo();
|
|
|
|
info->set_property_attributes(attributes);
|
|
|
|
info->set_all_can_read(true);
|
|
|
|
info->set_all_can_write(true);
|
|
|
|
info->set_prohibits_overwriting(false);
|
2014-04-16 11:57:23 +00:00
|
|
|
info->set_name(*name);
|
2014-04-15 13:25:17 +00:00
|
|
|
Handle<Object> get = v8::FromCData(isolate, getter);
|
|
|
|
Handle<Object> set = v8::FromCData(isolate, setter);
|
|
|
|
info->set_getter(*get);
|
|
|
|
info->set_setter(*set);
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
template <class C>
|
2013-02-27 13:22:29 +00:00
|
|
|
static C* FindInstanceOf(Isolate* isolate, Object* obj) {
|
|
|
|
for (Object* cur = obj; !cur->IsNull(); cur = cur->GetPrototype(isolate)) {
|
2012-10-08 12:58:46 +00:00
|
|
|
if (Is<C>(cur)) return C::cast(cur);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2012-10-08 12:58:46 +00:00
|
|
|
return NULL;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Entry point that never should be called.
|
2013-09-02 09:25:20 +00:00
|
|
|
MaybeObject* Accessors::IllegalSetter(Isolate* isolate,
|
|
|
|
JSObject*,
|
|
|
|
Object*,
|
|
|
|
void*) {
|
2008-07-03 15:10:15 +00:00
|
|
|
UNREACHABLE();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-02 09:25:20 +00:00
|
|
|
Object* Accessors::IllegalGetAccessor(Isolate* isolate,
|
|
|
|
Object* object,
|
|
|
|
void*) {
|
2008-07-03 15:10:15 +00:00
|
|
|
UNREACHABLE();
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-02 09:25:20 +00:00
|
|
|
MaybeObject* Accessors::ReadOnlySetAccessor(Isolate* isolate,
|
|
|
|
JSObject*,
|
|
|
|
Object* value,
|
|
|
|
void*) {
|
2008-07-03 15:10:15 +00:00
|
|
|
// According to ECMA-262, section 8.6.2.2, page 28, setting
|
|
|
|
// read-only properties must be silently ignored.
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-25 08:19:35 +00:00
|
|
|
static V8_INLINE bool CheckForName(Handle<String> name,
|
2014-04-11 07:27:25 +00:00
|
|
|
Handle<String> property_name,
|
2013-09-25 08:19:35 +00:00
|
|
|
int offset,
|
|
|
|
int* object_offset) {
|
2014-04-11 07:27:25 +00:00
|
|
|
if (String::Equals(name, property_name)) {
|
2013-09-25 08:19:35 +00:00
|
|
|
*object_offset = offset;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-04 12:44:15 +00:00
|
|
|
// Returns true for properties that are accessors to object fields.
|
|
|
|
// If true, *object_offset contains offset of object field.
|
|
|
|
template <class T>
|
|
|
|
bool Accessors::IsJSObjectFieldAccessor(typename T::TypeHandle type,
|
2014-01-30 11:30:38 +00:00
|
|
|
Handle<String> name,
|
|
|
|
int* object_offset) {
|
|
|
|
Isolate* isolate = name->GetIsolate();
|
|
|
|
|
2014-02-04 12:44:15 +00:00
|
|
|
if (type->Is(T::String())) {
|
2014-04-11 07:27:25 +00:00
|
|
|
return CheckForName(name, isolate->factory()->length_string(),
|
2014-01-30 11:30:38 +00:00
|
|
|
String::kLengthOffset, object_offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!type->IsClass()) return false;
|
|
|
|
Handle<Map> map = type->AsClass();
|
|
|
|
|
2013-09-25 08:19:35 +00:00
|
|
|
switch (map->instance_type()) {
|
|
|
|
case JS_ARRAY_TYPE:
|
|
|
|
return
|
2014-04-11 07:27:25 +00:00
|
|
|
CheckForName(name, isolate->factory()->length_string(),
|
2013-09-25 08:19:35 +00:00
|
|
|
JSArray::kLengthOffset, object_offset);
|
|
|
|
case JS_TYPED_ARRAY_TYPE:
|
|
|
|
return
|
2014-04-11 07:27:25 +00:00
|
|
|
CheckForName(name, isolate->factory()->length_string(),
|
2013-09-25 08:19:35 +00:00
|
|
|
JSTypedArray::kLengthOffset, object_offset) ||
|
2014-04-11 07:27:25 +00:00
|
|
|
CheckForName(name, isolate->factory()->byte_length_string(),
|
2013-09-25 08:19:35 +00:00
|
|
|
JSTypedArray::kByteLengthOffset, object_offset) ||
|
2014-04-11 07:27:25 +00:00
|
|
|
CheckForName(name, isolate->factory()->byte_offset_string(),
|
2014-03-26 12:50:13 +00:00
|
|
|
JSTypedArray::kByteOffsetOffset, object_offset);
|
2013-09-25 08:19:35 +00:00
|
|
|
case JS_ARRAY_BUFFER_TYPE:
|
|
|
|
return
|
2014-04-11 07:27:25 +00:00
|
|
|
CheckForName(name, isolate->factory()->byte_length_string(),
|
2013-09-25 08:19:35 +00:00
|
|
|
JSArrayBuffer::kByteLengthOffset, object_offset);
|
|
|
|
case JS_DATA_VIEW_TYPE:
|
|
|
|
return
|
2014-04-11 07:27:25 +00:00
|
|
|
CheckForName(name, isolate->factory()->byte_length_string(),
|
2013-09-25 08:19:35 +00:00
|
|
|
JSDataView::kByteLengthOffset, object_offset) ||
|
2014-04-11 07:27:25 +00:00
|
|
|
CheckForName(name, isolate->factory()->byte_offset_string(),
|
2014-03-26 12:50:13 +00:00
|
|
|
JSDataView::kByteOffsetOffset, object_offset);
|
2014-01-30 11:30:38 +00:00
|
|
|
default:
|
2013-09-25 08:19:35 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-04 12:44:15 +00:00
|
|
|
template
|
|
|
|
bool Accessors::IsJSObjectFieldAccessor<Type>(Type* type,
|
|
|
|
Handle<String> name,
|
|
|
|
int* object_offset);
|
|
|
|
|
|
|
|
|
|
|
|
template
|
|
|
|
bool Accessors::IsJSObjectFieldAccessor<HeapType>(Handle<HeapType> type,
|
|
|
|
Handle<String> name,
|
|
|
|
int* object_offset);
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
//
|
|
|
|
// Accessors::ArrayLength
|
|
|
|
//
|
|
|
|
|
|
|
|
|
2013-09-02 09:25:20 +00:00
|
|
|
MaybeObject* Accessors::ArrayGetLength(Isolate* isolate,
|
|
|
|
Object* object,
|
|
|
|
void*) {
|
2008-07-03 15:10:15 +00:00
|
|
|
// Traverse the prototype chain until we reach an array.
|
2013-09-02 09:25:20 +00:00
|
|
|
JSArray* holder = FindInstanceOf<JSArray>(isolate, object);
|
2012-10-08 12:58:46 +00:00
|
|
|
return holder == NULL ? Smi::FromInt(0) : holder->length();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// The helper function will 'flatten' Number objects.
|
2013-11-05 13:47:51 +00:00
|
|
|
Handle<Object> Accessors::FlattenNumber(Isolate* isolate,
|
|
|
|
Handle<Object> value) {
|
2008-07-03 15:10:15 +00:00
|
|
|
if (value->IsNumber() || !value->IsJSValue()) return value;
|
2013-11-05 13:47:51 +00:00
|
|
|
Handle<JSValue> wrapper = Handle<JSValue>::cast(value);
|
2013-09-02 09:25:20 +00:00
|
|
|
ASSERT(wrapper->GetIsolate()->context()->native_context()->number_function()->
|
2011-03-18 20:35:07 +00:00
|
|
|
has_initial_map());
|
2013-11-05 13:47:51 +00:00
|
|
|
if (wrapper->map() ==
|
|
|
|
isolate->context()->native_context()->number_function()->initial_map()) {
|
|
|
|
return handle(wrapper->value(), isolate);
|
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-02 09:25:20 +00:00
|
|
|
MaybeObject* Accessors::ArraySetLength(Isolate* isolate,
|
2013-11-05 13:47:51 +00:00
|
|
|
JSObject* object_raw,
|
|
|
|
Object* value_raw,
|
2013-09-02 09:25:20 +00:00
|
|
|
void*) {
|
2013-11-05 13:47:51 +00:00
|
|
|
HandleScope scope(isolate);
|
|
|
|
Handle<JSObject> object(object_raw, isolate);
|
|
|
|
Handle<Object> value(value_raw, isolate);
|
|
|
|
|
2011-06-21 08:07:45 +00:00
|
|
|
// This means one of the object's prototypes is a JSArray and the
|
|
|
|
// object does not have a 'length' property. Calling SetProperty
|
|
|
|
// causes an infinite loop.
|
|
|
|
if (!object->IsJSArray()) {
|
2014-04-04 12:06:11 +00:00
|
|
|
Handle<Object> result;
|
|
|
|
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
|
|
|
|
isolate, result,
|
|
|
|
JSObject::SetLocalPropertyIgnoreAttributes(
|
|
|
|
object, isolate->factory()->length_string(), value, NONE));
|
2013-11-05 13:47:51 +00:00
|
|
|
return *result;
|
2011-06-21 08:07:45 +00:00
|
|
|
}
|
|
|
|
|
2013-09-02 09:25:20 +00:00
|
|
|
value = FlattenNumber(isolate, value);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2013-11-05 13:47:51 +00:00
|
|
|
Handle<JSArray> array_handle = Handle<JSArray>::cast(object);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2014-04-11 10:41:09 +00:00
|
|
|
Handle<Object> uint32_v;
|
|
|
|
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
|
|
|
|
isolate, uint32_v, Execution::ToUint32(isolate, value));
|
|
|
|
Handle<Object> number_v;
|
|
|
|
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
|
|
|
|
isolate, number_v, Execution::ToNumber(isolate, value));
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
if (uint32_v->Number() == number_v->Number()) {
|
2014-04-09 13:16:19 +00:00
|
|
|
Handle<Object> result;
|
|
|
|
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
|
|
|
|
isolate, result,
|
|
|
|
JSArray::SetElementsLength(array_handle, uint32_v));
|
2014-03-19 14:09:50 +00:00
|
|
|
return *result;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2011-03-29 07:34:23 +00:00
|
|
|
return isolate->Throw(
|
|
|
|
*isolate->factory()->NewRangeError("invalid_array_length",
|
|
|
|
HandleVector<Object>(NULL, 0)));
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const AccessorDescriptor Accessors::ArrayLength = {
|
|
|
|
ArrayGetLength,
|
|
|
|
ArraySetLength,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// Accessors::StringLength
|
|
|
|
//
|
|
|
|
|
2014-04-15 13:25:17 +00:00
|
|
|
void Accessors::StringLengthGetter(
|
|
|
|
v8::Local<v8::String> name,
|
|
|
|
const v8::PropertyCallbackInfo<v8::Value>& info) {
|
|
|
|
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate());
|
|
|
|
DisallowHeapAllocation no_allocation;
|
|
|
|
HandleScope scope(isolate);
|
|
|
|
Object* value = *Utils::OpenHandle(*info.This());
|
|
|
|
Object* result;
|
|
|
|
if (value->IsJSValue()) value = JSValue::cast(value)->value();
|
|
|
|
if (value->IsString()) {
|
|
|
|
result = Smi::FromInt(String::cast(value)->length());
|
|
|
|
} else {
|
|
|
|
// If object is not a string we return 0 to be compatible with WebKit.
|
|
|
|
// Note: Firefox returns the length of ToString(object).
|
|
|
|
result = Smi::FromInt(0);
|
|
|
|
}
|
|
|
|
info.GetReturnValue().Set(Utils::ToLocal(Handle<Object>(result, isolate)));
|
|
|
|
}
|
2014-04-10 12:00:36 +00:00
|
|
|
|
2014-04-15 13:25:17 +00:00
|
|
|
|
|
|
|
void Accessors::StringLengthSetter(
|
|
|
|
v8::Local<v8::String> name,
|
|
|
|
v8::Local<v8::Value> value,
|
|
|
|
const v8::PropertyCallbackInfo<void>& info) {
|
|
|
|
UNREACHABLE();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-15 13:25:17 +00:00
|
|
|
Handle<AccessorInfo> Accessors::StringLengthInfo(
|
|
|
|
Isolate* isolate, PropertyAttributes attributes) {
|
|
|
|
return MakeAccessor(isolate,
|
|
|
|
isolate->factory()->length_string(),
|
|
|
|
&StringLengthGetter,
|
|
|
|
&StringLengthSetter,
|
|
|
|
attributes);
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
//
|
2014-04-16 11:57:23 +00:00
|
|
|
// Accessors::ScriptColumnOffset
|
2008-07-03 15:10:15 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
|
2014-04-16 11:57:23 +00:00
|
|
|
void Accessors::ScriptColumnOffsetGetter(
|
|
|
|
v8::Local<v8::String> name,
|
|
|
|
const v8::PropertyCallbackInfo<v8::Value>& info) {
|
|
|
|
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate());
|
|
|
|
DisallowHeapAllocation no_allocation;
|
|
|
|
HandleScope scope(isolate);
|
|
|
|
Object* object = *Utils::OpenHandle(*info.This());
|
|
|
|
Object* res = Script::cast(JSValue::cast(object)->value())->column_offset();
|
|
|
|
info.GetReturnValue().Set(Utils::ToLocal(Handle<Object>(res, isolate)));
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-16 11:57:23 +00:00
|
|
|
void Accessors::ScriptColumnOffsetSetter(
|
|
|
|
v8::Local<v8::String> name,
|
|
|
|
v8::Local<v8::Value> value,
|
|
|
|
const v8::PropertyCallbackInfo<void>& info) {
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<AccessorInfo> Accessors::ScriptColumnOffsetInfo(
|
|
|
|
Isolate* isolate, PropertyAttributes attributes) {
|
|
|
|
Handle<String> name(isolate->factory()->InternalizeOneByteString(
|
|
|
|
STATIC_ASCII_VECTOR("column_offset")));
|
|
|
|
return MakeAccessor(isolate,
|
|
|
|
name,
|
|
|
|
&ScriptColumnOffsetGetter,
|
|
|
|
&ScriptColumnOffsetSetter,
|
|
|
|
attributes);
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
//
|
2014-04-16 11:57:23 +00:00
|
|
|
// Accessors::ScriptId
|
2008-07-03 15:10:15 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
|
2014-04-16 11:57:23 +00:00
|
|
|
void Accessors::ScriptIdGetter(
|
|
|
|
v8::Local<v8::String> name,
|
|
|
|
const v8::PropertyCallbackInfo<v8::Value>& info) {
|
|
|
|
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate());
|
|
|
|
DisallowHeapAllocation no_allocation;
|
|
|
|
HandleScope scope(isolate);
|
|
|
|
Object* object = *Utils::OpenHandle(*info.This());
|
|
|
|
Object* id = Script::cast(JSValue::cast(object)->value())->id();
|
|
|
|
info.GetReturnValue().Set(Utils::ToLocal(Handle<Object>(id, isolate)));
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-16 11:57:23 +00:00
|
|
|
void Accessors::ScriptIdSetter(
|
|
|
|
v8::Local<v8::String> name,
|
|
|
|
v8::Local<v8::Value> value,
|
|
|
|
const v8::PropertyCallbackInfo<void>& info) {
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<AccessorInfo> Accessors::ScriptIdInfo(
|
|
|
|
Isolate* isolate, PropertyAttributes attributes) {
|
|
|
|
Handle<String> name(isolate->factory()->InternalizeOneByteString(
|
|
|
|
STATIC_ASCII_VECTOR("id")));
|
|
|
|
return MakeAccessor(isolate,
|
|
|
|
name,
|
|
|
|
&ScriptIdGetter,
|
|
|
|
&ScriptIdSetter,
|
|
|
|
attributes);
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2009-03-10 08:10:50 +00:00
|
|
|
//
|
2014-04-16 11:57:23 +00:00
|
|
|
// Accessors::ScriptName
|
2009-03-10 08:10:50 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
|
2014-04-16 11:57:23 +00:00
|
|
|
void Accessors::ScriptNameGetter(
|
|
|
|
v8::Local<v8::String> name,
|
|
|
|
const v8::PropertyCallbackInfo<v8::Value>& info) {
|
|
|
|
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate());
|
|
|
|
DisallowHeapAllocation no_allocation;
|
|
|
|
HandleScope scope(isolate);
|
|
|
|
Object* object = *Utils::OpenHandle(*info.This());
|
|
|
|
Object* source = Script::cast(JSValue::cast(object)->value())->name();
|
|
|
|
info.GetReturnValue().Set(Utils::ToLocal(Handle<Object>(source, isolate)));
|
2009-03-10 08:10:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-16 11:57:23 +00:00
|
|
|
void Accessors::ScriptNameSetter(
|
|
|
|
v8::Local<v8::String> name,
|
|
|
|
v8::Local<v8::Value> value,
|
|
|
|
const v8::PropertyCallbackInfo<void>& info) {
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<AccessorInfo> Accessors::ScriptNameInfo(
|
|
|
|
Isolate* isolate, PropertyAttributes attributes) {
|
|
|
|
return MakeAccessor(isolate,
|
|
|
|
isolate->factory()->name_string(),
|
|
|
|
&ScriptNameGetter,
|
|
|
|
&ScriptNameSetter,
|
|
|
|
attributes);
|
|
|
|
}
|
2009-03-10 08:10:50 +00:00
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
//
|
2014-04-16 11:57:23 +00:00
|
|
|
// Accessors::ScriptSource
|
2008-07-03 15:10:15 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
|
2014-04-16 11:57:23 +00:00
|
|
|
void Accessors::ScriptSourceGetter(
|
|
|
|
v8::Local<v8::String> name,
|
|
|
|
const v8::PropertyCallbackInfo<v8::Value>& info) {
|
|
|
|
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate());
|
|
|
|
DisallowHeapAllocation no_allocation;
|
|
|
|
HandleScope scope(isolate);
|
|
|
|
Object* object = *Utils::OpenHandle(*info.This());
|
|
|
|
Object* source = Script::cast(JSValue::cast(object)->value())->source();
|
|
|
|
info.GetReturnValue().Set(Utils::ToLocal(Handle<Object>(source, isolate)));
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-16 11:57:23 +00:00
|
|
|
void Accessors::ScriptSourceSetter(
|
|
|
|
v8::Local<v8::String> name,
|
|
|
|
v8::Local<v8::Value> value,
|
|
|
|
const v8::PropertyCallbackInfo<void>& info) {
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<AccessorInfo> Accessors::ScriptSourceInfo(
|
|
|
|
Isolate* isolate, PropertyAttributes attributes) {
|
|
|
|
return MakeAccessor(isolate,
|
|
|
|
isolate->factory()->source_string(),
|
|
|
|
&ScriptSourceGetter,
|
|
|
|
&ScriptSourceSetter,
|
|
|
|
attributes);
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
//
|
2014-04-16 11:57:23 +00:00
|
|
|
// Accessors::ScriptLineOffset
|
2008-07-03 15:10:15 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
|
2014-04-16 11:57:23 +00:00
|
|
|
void Accessors::ScriptLineOffsetGetter(
|
|
|
|
v8::Local<v8::String> name,
|
|
|
|
const v8::PropertyCallbackInfo<v8::Value>& info) {
|
|
|
|
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate());
|
|
|
|
DisallowHeapAllocation no_allocation;
|
|
|
|
HandleScope scope(isolate);
|
|
|
|
Object* object = *Utils::OpenHandle(*info.This());
|
|
|
|
Object* res = Script::cast(JSValue::cast(object)->value())->line_offset();
|
|
|
|
info.GetReturnValue().Set(Utils::ToLocal(Handle<Object>(res, isolate)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Accessors::ScriptLineOffsetSetter(
|
|
|
|
v8::Local<v8::String> name,
|
|
|
|
v8::Local<v8::Value> value,
|
|
|
|
const v8::PropertyCallbackInfo<void>& info) {
|
|
|
|
UNREACHABLE();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-16 11:57:23 +00:00
|
|
|
Handle<AccessorInfo> Accessors::ScriptLineOffsetInfo(
|
|
|
|
Isolate* isolate, PropertyAttributes attributes) {
|
|
|
|
Handle<String> name(isolate->factory()->InternalizeOneByteString(
|
|
|
|
STATIC_ASCII_VECTOR("line_offset")));
|
|
|
|
return MakeAccessor(isolate,
|
|
|
|
name,
|
|
|
|
&ScriptLineOffsetGetter,
|
|
|
|
&ScriptLineOffsetSetter,
|
|
|
|
attributes);
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// Accessors::ScriptType
|
|
|
|
//
|
|
|
|
|
|
|
|
|
2013-09-02 09:25:20 +00:00
|
|
|
MaybeObject* Accessors::ScriptGetType(Isolate* isolate,
|
|
|
|
Object* object,
|
|
|
|
void*) {
|
2008-07-03 15:10:15 +00:00
|
|
|
Object* script = JSValue::cast(object)->value();
|
|
|
|
return Script::cast(script)->type();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const AccessorDescriptor Accessors::ScriptType = {
|
|
|
|
ScriptGetType,
|
|
|
|
IllegalSetter,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-06-08 10:47:49 +00:00
|
|
|
//
|
|
|
|
// Accessors::ScriptCompilationType
|
|
|
|
//
|
|
|
|
|
|
|
|
|
2013-09-02 09:25:20 +00:00
|
|
|
MaybeObject* Accessors::ScriptGetCompilationType(Isolate* isolate,
|
|
|
|
Object* object,
|
|
|
|
void*) {
|
2009-06-08 10:47:49 +00:00
|
|
|
Object* script = JSValue::cast(object)->value();
|
2013-07-30 17:00:05 +00:00
|
|
|
return Smi::FromInt(Script::cast(script)->compilation_type());
|
2009-06-08 10:47:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const AccessorDescriptor Accessors::ScriptCompilationType = {
|
|
|
|
ScriptGetCompilationType,
|
|
|
|
IllegalSetter,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-02-04 12:07:45 +00:00
|
|
|
//
|
|
|
|
// Accessors::ScriptGetLineEnds
|
|
|
|
//
|
|
|
|
|
|
|
|
|
2013-09-02 09:25:20 +00:00
|
|
|
MaybeObject* Accessors::ScriptGetLineEnds(Isolate* isolate,
|
|
|
|
Object* object,
|
|
|
|
void*) {
|
2011-03-29 07:34:23 +00:00
|
|
|
JSValue* wrapper = JSValue::cast(object);
|
|
|
|
HandleScope scope(isolate);
|
|
|
|
Handle<Script> script(Script::cast(wrapper->value()), isolate);
|
2014-04-16 12:35:50 +00:00
|
|
|
InitScriptLineEnds(script);
|
2009-11-27 14:10:48 +00:00
|
|
|
ASSERT(script->line_ends()->IsFixedArray());
|
|
|
|
Handle<FixedArray> line_ends(FixedArray::cast(script->line_ends()));
|
2010-11-17 12:49:27 +00:00
|
|
|
// We do not want anyone to modify this array from JS.
|
2011-03-29 07:34:23 +00:00
|
|
|
ASSERT(*line_ends == isolate->heap()->empty_fixed_array() ||
|
|
|
|
line_ends->map() == isolate->heap()->fixed_cow_array_map());
|
|
|
|
Handle<JSArray> js_array =
|
|
|
|
isolate->factory()->NewJSArrayWithElements(line_ends);
|
2009-11-27 14:10:48 +00:00
|
|
|
return *js_array;
|
2009-02-04 12:07:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const AccessorDescriptor Accessors::ScriptLineEnds = {
|
|
|
|
ScriptGetLineEnds,
|
|
|
|
IllegalSetter,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-05-06 08:52:48 +00:00
|
|
|
//
|
|
|
|
// Accessors::ScriptGetContextData
|
|
|
|
//
|
|
|
|
|
|
|
|
|
2013-09-02 09:25:20 +00:00
|
|
|
MaybeObject* Accessors::ScriptGetContextData(Isolate* isolate,
|
|
|
|
Object* object,
|
|
|
|
void*) {
|
2009-06-08 10:47:49 +00:00
|
|
|
Object* script = JSValue::cast(object)->value();
|
|
|
|
return Script::cast(script)->context_data();
|
2009-05-06 08:52:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const AccessorDescriptor Accessors::ScriptContextData = {
|
|
|
|
ScriptGetContextData,
|
|
|
|
IllegalSetter,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-06-08 10:47:49 +00:00
|
|
|
//
|
2009-12-01 14:36:45 +00:00
|
|
|
// Accessors::ScriptGetEvalFromScript
|
2009-06-08 10:47:49 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
|
2013-09-02 09:25:20 +00:00
|
|
|
MaybeObject* Accessors::ScriptGetEvalFromScript(Isolate* isolate,
|
|
|
|
Object* object,
|
|
|
|
void*) {
|
2009-06-08 10:47:49 +00:00
|
|
|
Object* script = JSValue::cast(object)->value();
|
2009-12-01 14:36:45 +00:00
|
|
|
if (!Script::cast(script)->eval_from_shared()->IsUndefined()) {
|
|
|
|
Handle<SharedFunctionInfo> eval_from_shared(
|
|
|
|
SharedFunctionInfo::cast(Script::cast(script)->eval_from_shared()));
|
|
|
|
|
|
|
|
if (eval_from_shared->script()->IsScript()) {
|
|
|
|
Handle<Script> eval_from_script(Script::cast(eval_from_shared->script()));
|
2014-04-16 12:35:50 +00:00
|
|
|
return *GetScriptWrapper(eval_from_script);
|
2009-12-01 14:36:45 +00:00
|
|
|
}
|
|
|
|
}
|
2013-09-10 14:30:36 +00:00
|
|
|
return isolate->heap()->undefined_value();
|
2009-06-08 10:47:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-01 14:36:45 +00:00
|
|
|
const AccessorDescriptor Accessors::ScriptEvalFromScript = {
|
|
|
|
ScriptGetEvalFromScript,
|
2009-06-08 10:47:49 +00:00
|
|
|
IllegalSetter,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//
|
2009-12-01 14:36:45 +00:00
|
|
|
// Accessors::ScriptGetEvalFromScriptPosition
|
2009-06-08 10:47:49 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
|
2013-09-02 09:25:20 +00:00
|
|
|
MaybeObject* Accessors::ScriptGetEvalFromScriptPosition(Isolate* isolate,
|
|
|
|
Object* object,
|
|
|
|
void*) {
|
2013-02-15 09:27:10 +00:00
|
|
|
Script* raw_script = Script::cast(JSValue::cast(object)->value());
|
2013-09-02 09:25:20 +00:00
|
|
|
HandleScope scope(isolate);
|
2013-02-15 09:27:10 +00:00
|
|
|
Handle<Script> script(raw_script);
|
2009-06-08 10:47:49 +00:00
|
|
|
|
|
|
|
// If this is not a script compiled through eval there is no eval position.
|
2013-07-30 17:00:05 +00:00
|
|
|
if (script->compilation_type() != Script::COMPILATION_TYPE_EVAL) {
|
2013-02-15 09:27:10 +00:00
|
|
|
return script->GetHeap()->undefined_value();
|
2009-06-08 10:47:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get the function from where eval was called and find the source position
|
|
|
|
// from the instruction offset.
|
2009-12-01 14:36:45 +00:00
|
|
|
Handle<Code> code(SharedFunctionInfo::cast(
|
|
|
|
script->eval_from_shared())->code());
|
2009-06-08 10:47:49 +00:00
|
|
|
return Smi::FromInt(code->SourcePosition(code->instruction_start() +
|
|
|
|
script->eval_from_instructions_offset()->value()));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-01 14:36:45 +00:00
|
|
|
const AccessorDescriptor Accessors::ScriptEvalFromScriptPosition = {
|
|
|
|
ScriptGetEvalFromScriptPosition,
|
|
|
|
IllegalSetter,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// Accessors::ScriptGetEvalFromFunctionName
|
|
|
|
//
|
|
|
|
|
|
|
|
|
2013-09-02 09:25:20 +00:00
|
|
|
MaybeObject* Accessors::ScriptGetEvalFromFunctionName(Isolate* isolate,
|
|
|
|
Object* object,
|
|
|
|
void*) {
|
2009-12-01 14:36:45 +00:00
|
|
|
Object* script = JSValue::cast(object)->value();
|
|
|
|
Handle<SharedFunctionInfo> shared(SharedFunctionInfo::cast(
|
|
|
|
Script::cast(script)->eval_from_shared()));
|
|
|
|
|
|
|
|
|
|
|
|
// Find the name of the function calling eval.
|
|
|
|
if (!shared->name()->IsUndefined()) {
|
|
|
|
return shared->name();
|
|
|
|
} else {
|
|
|
|
return shared->inferred_name();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const AccessorDescriptor Accessors::ScriptEvalFromFunctionName = {
|
|
|
|
ScriptGetEvalFromFunctionName,
|
2009-06-08 10:47:49 +00:00
|
|
|
IllegalSetter,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
//
|
|
|
|
// Accessors::FunctionPrototype
|
|
|
|
//
|
|
|
|
|
|
|
|
|
2013-08-16 21:27:11 +00:00
|
|
|
Handle<Object> Accessors::FunctionGetPrototype(Handle<JSFunction> function) {
|
|
|
|
CALL_HEAP_FUNCTION(function->GetIsolate(),
|
2013-09-02 09:25:20 +00:00
|
|
|
Accessors::FunctionGetPrototype(function->GetIsolate(),
|
|
|
|
*function,
|
|
|
|
NULL),
|
2013-08-16 21:27:11 +00:00
|
|
|
Object);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Object> Accessors::FunctionSetPrototype(Handle<JSFunction> function,
|
|
|
|
Handle<Object> prototype) {
|
|
|
|
ASSERT(function->should_have_prototype());
|
|
|
|
CALL_HEAP_FUNCTION(function->GetIsolate(),
|
2013-09-02 09:25:20 +00:00
|
|
|
Accessors::FunctionSetPrototype(function->GetIsolate(),
|
|
|
|
*function,
|
2013-08-16 21:27:11 +00:00
|
|
|
*prototype,
|
|
|
|
NULL),
|
|
|
|
Object);
|
2013-04-19 08:30:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-02 09:25:20 +00:00
|
|
|
MaybeObject* Accessors::FunctionGetPrototype(Isolate* isolate,
|
|
|
|
Object* object,
|
|
|
|
void*) {
|
2013-07-18 07:59:48 +00:00
|
|
|
JSFunction* function_raw = FindInstanceOf<JSFunction>(isolate, object);
|
|
|
|
if (function_raw == NULL) return isolate->heap()->undefined_value();
|
|
|
|
while (!function_raw->should_have_prototype()) {
|
|
|
|
function_raw = FindInstanceOf<JSFunction>(isolate,
|
|
|
|
function_raw->GetPrototype());
|
2011-02-22 12:27:36 +00:00
|
|
|
// There has to be one because we hit the getter.
|
2013-07-18 07:59:48 +00:00
|
|
|
ASSERT(function_raw != NULL);
|
2011-02-22 12:27:36 +00:00
|
|
|
}
|
|
|
|
|
2013-07-18 07:59:48 +00:00
|
|
|
if (!function_raw->has_prototype()) {
|
|
|
|
HandleScope scope(isolate);
|
|
|
|
Handle<JSFunction> function(function_raw);
|
|
|
|
Handle<Object> proto = isolate->factory()->NewFunctionPrototype(function);
|
|
|
|
JSFunction::SetPrototype(function, proto);
|
|
|
|
function_raw = *function;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2013-07-18 07:59:48 +00:00
|
|
|
return function_raw->prototype();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-02 09:25:20 +00:00
|
|
|
MaybeObject* Accessors::FunctionSetPrototype(Isolate* isolate,
|
2013-11-05 13:47:51 +00:00
|
|
|
JSObject* object_raw,
|
2012-12-10 10:53:57 +00:00
|
|
|
Object* value_raw,
|
2010-10-25 15:22:03 +00:00
|
|
|
void*) {
|
2013-11-05 13:47:51 +00:00
|
|
|
JSFunction* function_raw = FindInstanceOf<JSFunction>(isolate, object_raw);
|
|
|
|
if (function_raw == NULL) return isolate->heap()->undefined_value();
|
2011-02-22 12:27:36 +00:00
|
|
|
|
2012-12-10 10:53:57 +00:00
|
|
|
HandleScope scope(isolate);
|
|
|
|
Handle<JSFunction> function(function_raw, isolate);
|
2013-11-05 13:47:51 +00:00
|
|
|
Handle<JSObject> object(object_raw, isolate);
|
2012-12-10 10:53:57 +00:00
|
|
|
Handle<Object> value(value_raw, isolate);
|
2013-11-05 13:47:51 +00:00
|
|
|
if (!function->should_have_prototype()) {
|
|
|
|
// Since we hit this accessor, object will have no prototype property.
|
2014-04-04 12:06:11 +00:00
|
|
|
Handle<Object> result;
|
|
|
|
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
|
|
|
|
isolate, result,
|
|
|
|
JSObject::SetLocalPropertyIgnoreAttributes(
|
|
|
|
object, isolate->factory()->prototype_string(), value, NONE));
|
2013-11-05 13:47:51 +00:00
|
|
|
return *result;
|
|
|
|
}
|
2012-12-10 10:53:57 +00:00
|
|
|
|
|
|
|
Handle<Object> old_value;
|
2014-03-13 00:20:06 +00:00
|
|
|
bool is_observed = *function == *object && function->map()->is_observed();
|
2012-12-10 10:53:57 +00:00
|
|
|
if (is_observed) {
|
|
|
|
if (function->has_prototype())
|
|
|
|
old_value = handle(function->prototype(), isolate);
|
|
|
|
else
|
|
|
|
old_value = isolate->factory()->NewFunctionPrototype(function);
|
|
|
|
}
|
|
|
|
|
2013-07-18 07:59:48 +00:00
|
|
|
JSFunction::SetPrototype(function, value);
|
2012-12-10 10:53:57 +00:00
|
|
|
ASSERT(function->prototype() == *value);
|
|
|
|
|
|
|
|
if (is_observed && !old_value->SameValue(*value)) {
|
|
|
|
JSObject::EnqueueChangeRecord(
|
2013-11-06 12:14:24 +00:00
|
|
|
function, "update", isolate->factory()->prototype_string(), old_value);
|
2010-10-25 15:22:03 +00:00
|
|
|
}
|
2012-12-10 10:53:57 +00:00
|
|
|
|
|
|
|
return *function;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const AccessorDescriptor Accessors::FunctionPrototype = {
|
|
|
|
FunctionGetPrototype,
|
|
|
|
FunctionSetPrototype,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// Accessors::FunctionLength
|
|
|
|
//
|
|
|
|
|
|
|
|
|
2013-09-02 09:25:20 +00:00
|
|
|
MaybeObject* Accessors::FunctionGetLength(Isolate* isolate,
|
|
|
|
Object* object,
|
|
|
|
void*) {
|
2013-02-27 13:22:29 +00:00
|
|
|
JSFunction* function = FindInstanceOf<JSFunction>(isolate, object);
|
2012-10-08 12:58:46 +00:00
|
|
|
if (function == NULL) return Smi::FromInt(0);
|
2008-07-03 15:10:15 +00:00
|
|
|
// Check if already compiled.
|
2012-10-08 12:58:46 +00:00
|
|
|
if (function->shared()->is_compiled()) {
|
2008-07-03 15:10:15 +00:00
|
|
|
return Smi::FromInt(function->shared()->length());
|
|
|
|
}
|
2012-10-08 12:58:46 +00:00
|
|
|
// If the function isn't compiled yet, the length is not computed correctly
|
|
|
|
// yet. Compile it now and return the right length.
|
2013-02-27 13:22:29 +00:00
|
|
|
HandleScope scope(isolate);
|
2013-12-23 14:30:35 +00:00
|
|
|
Handle<JSFunction> function_handle(function);
|
|
|
|
if (Compiler::EnsureCompiled(function_handle, KEEP_EXCEPTION)) {
|
|
|
|
return Smi::FromInt(function_handle->shared()->length());
|
2012-10-08 12:58:46 +00:00
|
|
|
}
|
|
|
|
return Failure::Exception();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const AccessorDescriptor Accessors::FunctionLength = {
|
|
|
|
FunctionGetLength,
|
|
|
|
ReadOnlySetAccessor,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// Accessors::FunctionName
|
|
|
|
//
|
|
|
|
|
|
|
|
|
2013-09-02 09:25:20 +00:00
|
|
|
MaybeObject* Accessors::FunctionGetName(Isolate* isolate,
|
|
|
|
Object* object,
|
|
|
|
void*) {
|
2013-02-27 13:22:29 +00:00
|
|
|
JSFunction* holder = FindInstanceOf<JSFunction>(isolate, object);
|
|
|
|
return holder == NULL
|
|
|
|
? isolate->heap()->undefined_value()
|
|
|
|
: holder->shared()->name();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const AccessorDescriptor Accessors::FunctionName = {
|
|
|
|
FunctionGetName,
|
|
|
|
ReadOnlySetAccessor,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// Accessors::FunctionArguments
|
|
|
|
//
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2013-08-16 21:27:11 +00:00
|
|
|
Handle<Object> Accessors::FunctionGetArguments(Handle<JSFunction> function) {
|
|
|
|
CALL_HEAP_FUNCTION(function->GetIsolate(),
|
2013-09-02 09:25:20 +00:00
|
|
|
Accessors::FunctionGetArguments(function->GetIsolate(),
|
|
|
|
*function,
|
|
|
|
NULL),
|
2013-08-16 21:27:11 +00:00
|
|
|
Object);
|
2013-07-18 14:00:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
static MaybeObject* ConstructArgumentsObjectForInlinedFunction(
|
|
|
|
JavaScriptFrame* frame,
|
|
|
|
Handle<JSFunction> inlined_function,
|
|
|
|
int inlined_frame_index) {
|
2013-02-25 14:46:09 +00:00
|
|
|
Isolate* isolate = inlined_function->GetIsolate();
|
|
|
|
Factory* factory = isolate->factory();
|
The current
version is passing all the existing test + a bunch of new tests
(packaged in the change list, too).
The patch extends the SlotRef object to describe captured and duplicated
objects. Since the SlotRefs are not independent of each other anymore,
there is a new SlotRefValueBuilder class that stores the SlotRefs and
later materializes the objects from the SlotRefs.
Note that unlike the previous implementation of SlotRefs, we now build
the SlotRef entries for the entire frame, not just the particular
function. This is because duplicate objects might refer to previous
captured objects (that might live inside other inlined function's part
of the frame).
We also need to store the materialized objects between other potential
invocations of the same arguments object so that we materialize each
captured object at most once. The materialized objects of frames live
in the new MaterielizedObjectStore object (contained in Isolate),
indexed by the frame's FP address. Each argument materialization (and
deoptimization) tries to lookup its captured objects in the store before
building new ones. Deoptimization also removes the materialized objects
from the store. We also schedule a lazy deopt to be sure that we always
get rid of the materialized objects and that the optmized function
adopts the materialized objects (instead of happily computing with its
captured representations).
Concerns:
- Is the FP address the right key for a frame? (Note that deoptimizer's
representation of frame is different from the argument object
materializer's one - it is not easy to find common ground.)
- Performance is suboptimal in several places, but a quick local run of
benchmarks does not seem to show a perf hit. Examples of possible
improvements: smarter generation of SlotRefs (build other functions'
SlotRefs only for captured objects and only if necessary), smarter
lookup of stored materialized objects.
- Ideally, we would like to share the code for argument materialization
with deoptimizer's materializer. However, the supporting data structures
(mainly the frame descriptor) are quite different in each case, so it
looks more like a separate project.
Thanks for any feedback.
R=danno@chromium.org, mstarzinger@chromium.org
LOG=N
BUG=
Committed: https://code.google.com/p/v8/source/detail?r=18918
Review URL: https://codereview.chromium.org/103243005
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@18936 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-01-30 10:33:53 +00:00
|
|
|
SlotRefValueBuilder slot_refs(
|
|
|
|
frame,
|
|
|
|
inlined_frame_index,
|
|
|
|
inlined_function->shared()->formal_parameter_count());
|
|
|
|
|
|
|
|
int args_count = slot_refs.args_length();
|
2010-12-07 11:31:57 +00:00
|
|
|
Handle<JSObject> arguments =
|
2011-03-18 20:35:07 +00:00
|
|
|
factory->NewArgumentsObject(inlined_function, args_count);
|
|
|
|
Handle<FixedArray> array = factory->NewFixedArray(args_count);
|
The current
version is passing all the existing test + a bunch of new tests
(packaged in the change list, too).
The patch extends the SlotRef object to describe captured and duplicated
objects. Since the SlotRefs are not independent of each other anymore,
there is a new SlotRefValueBuilder class that stores the SlotRefs and
later materializes the objects from the SlotRefs.
Note that unlike the previous implementation of SlotRefs, we now build
the SlotRef entries for the entire frame, not just the particular
function. This is because duplicate objects might refer to previous
captured objects (that might live inside other inlined function's part
of the frame).
We also need to store the materialized objects between other potential
invocations of the same arguments object so that we materialize each
captured object at most once. The materialized objects of frames live
in the new MaterielizedObjectStore object (contained in Isolate),
indexed by the frame's FP address. Each argument materialization (and
deoptimization) tries to lookup its captured objects in the store before
building new ones. Deoptimization also removes the materialized objects
from the store. We also schedule a lazy deopt to be sure that we always
get rid of the materialized objects and that the optmized function
adopts the materialized objects (instead of happily computing with its
captured representations).
Concerns:
- Is the FP address the right key for a frame? (Note that deoptimizer's
representation of frame is different from the argument object
materializer's one - it is not easy to find common ground.)
- Performance is suboptimal in several places, but a quick local run of
benchmarks does not seem to show a perf hit. Examples of possible
improvements: smarter generation of SlotRefs (build other functions'
SlotRefs only for captured objects and only if necessary), smarter
lookup of stored materialized objects.
- Ideally, we would like to share the code for argument materialization
with deoptimizer's materializer. However, the supporting data structures
(mainly the frame descriptor) are quite different in each case, so it
looks more like a separate project.
Thanks for any feedback.
R=danno@chromium.org, mstarzinger@chromium.org
LOG=N
BUG=
Committed: https://code.google.com/p/v8/source/detail?r=18918
Review URL: https://codereview.chromium.org/103243005
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@18936 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-01-30 10:33:53 +00:00
|
|
|
slot_refs.Prepare(isolate);
|
2010-12-07 11:31:57 +00:00
|
|
|
for (int i = 0; i < args_count; ++i) {
|
The current
version is passing all the existing test + a bunch of new tests
(packaged in the change list, too).
The patch extends the SlotRef object to describe captured and duplicated
objects. Since the SlotRefs are not independent of each other anymore,
there is a new SlotRefValueBuilder class that stores the SlotRefs and
later materializes the objects from the SlotRefs.
Note that unlike the previous implementation of SlotRefs, we now build
the SlotRef entries for the entire frame, not just the particular
function. This is because duplicate objects might refer to previous
captured objects (that might live inside other inlined function's part
of the frame).
We also need to store the materialized objects between other potential
invocations of the same arguments object so that we materialize each
captured object at most once. The materialized objects of frames live
in the new MaterielizedObjectStore object (contained in Isolate),
indexed by the frame's FP address. Each argument materialization (and
deoptimization) tries to lookup its captured objects in the store before
building new ones. Deoptimization also removes the materialized objects
from the store. We also schedule a lazy deopt to be sure that we always
get rid of the materialized objects and that the optmized function
adopts the materialized objects (instead of happily computing with its
captured representations).
Concerns:
- Is the FP address the right key for a frame? (Note that deoptimizer's
representation of frame is different from the argument object
materializer's one - it is not easy to find common ground.)
- Performance is suboptimal in several places, but a quick local run of
benchmarks does not seem to show a perf hit. Examples of possible
improvements: smarter generation of SlotRefs (build other functions'
SlotRefs only for captured objects and only if necessary), smarter
lookup of stored materialized objects.
- Ideally, we would like to share the code for argument materialization
with deoptimizer's materializer. However, the supporting data structures
(mainly the frame descriptor) are quite different in each case, so it
looks more like a separate project.
Thanks for any feedback.
R=danno@chromium.org, mstarzinger@chromium.org
LOG=N
BUG=
Committed: https://code.google.com/p/v8/source/detail?r=18918
Review URL: https://codereview.chromium.org/103243005
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@18936 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-01-30 10:33:53 +00:00
|
|
|
Handle<Object> value = slot_refs.GetNext(isolate, 0);
|
2010-12-07 11:31:57 +00:00
|
|
|
array->set(i, *value);
|
|
|
|
}
|
The current
version is passing all the existing test + a bunch of new tests
(packaged in the change list, too).
The patch extends the SlotRef object to describe captured and duplicated
objects. Since the SlotRefs are not independent of each other anymore,
there is a new SlotRefValueBuilder class that stores the SlotRefs and
later materializes the objects from the SlotRefs.
Note that unlike the previous implementation of SlotRefs, we now build
the SlotRef entries for the entire frame, not just the particular
function. This is because duplicate objects might refer to previous
captured objects (that might live inside other inlined function's part
of the frame).
We also need to store the materialized objects between other potential
invocations of the same arguments object so that we materialize each
captured object at most once. The materialized objects of frames live
in the new MaterielizedObjectStore object (contained in Isolate),
indexed by the frame's FP address. Each argument materialization (and
deoptimization) tries to lookup its captured objects in the store before
building new ones. Deoptimization also removes the materialized objects
from the store. We also schedule a lazy deopt to be sure that we always
get rid of the materialized objects and that the optmized function
adopts the materialized objects (instead of happily computing with its
captured representations).
Concerns:
- Is the FP address the right key for a frame? (Note that deoptimizer's
representation of frame is different from the argument object
materializer's one - it is not easy to find common ground.)
- Performance is suboptimal in several places, but a quick local run of
benchmarks does not seem to show a perf hit. Examples of possible
improvements: smarter generation of SlotRefs (build other functions'
SlotRefs only for captured objects and only if necessary), smarter
lookup of stored materialized objects.
- Ideally, we would like to share the code for argument materialization
with deoptimizer's materializer. However, the supporting data structures
(mainly the frame descriptor) are quite different in each case, so it
looks more like a separate project.
Thanks for any feedback.
R=danno@chromium.org, mstarzinger@chromium.org
LOG=N
BUG=
Committed: https://code.google.com/p/v8/source/detail?r=18918
Review URL: https://codereview.chromium.org/103243005
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@18936 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-01-30 10:33:53 +00:00
|
|
|
slot_refs.Finish(isolate);
|
2010-12-07 11:31:57 +00:00
|
|
|
arguments->set_elements(*array);
|
|
|
|
|
|
|
|
// Return the freshly allocated arguments object.
|
|
|
|
return *arguments;
|
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2013-09-02 09:25:20 +00:00
|
|
|
MaybeObject* Accessors::FunctionGetArguments(Isolate* isolate,
|
|
|
|
Object* object,
|
|
|
|
void*) {
|
2011-03-18 20:35:07 +00:00
|
|
|
HandleScope scope(isolate);
|
2013-02-27 13:22:29 +00:00
|
|
|
JSFunction* holder = FindInstanceOf<JSFunction>(isolate, object);
|
2012-10-08 12:58:46 +00:00
|
|
|
if (holder == NULL) return isolate->heap()->undefined_value();
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<JSFunction> function(holder, isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-09-06 14:03:32 +00:00
|
|
|
if (function->shared()->native()) return isolate->heap()->null_value();
|
2008-07-03 15:10:15 +00:00
|
|
|
// Find the top invocation of the function by traversing frames.
|
2010-12-07 11:31:57 +00:00
|
|
|
List<JSFunction*> functions(2);
|
Simplify isolates access during stack iteration (WAS: Move SafeStackFrameIterator::active_count_...)
While trying to fix Mac and Windows versions for this change:
http://codereview.chromium.org/6771047/, I figured out, that we
already store an isolate in StackFrameIterator, so we can use it in
frame objects, instead of requiring it from caller.
I've changed iterators usage to the following scheme: whenever a
caller maintains an isolate pointer, it just passes it to stack
iterator, and no more worries about passing it to frame content
accessors. If a caller uses current isolate, it can omit passing it
to iterator, in this case, an iterator will use the current isolate,
too.
There was a special case with LiveEdit, which creates
detached copies of frame objects.
R=vitalyr@chromium.org
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/6794019
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@7499 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2011-04-05 09:01:47 +00:00
|
|
|
for (JavaScriptFrameIterator it(isolate); !it.done(); it.Advance()) {
|
2008-07-03 15:10:15 +00:00
|
|
|
JavaScriptFrame* frame = it.frame();
|
2010-12-07 11:31:57 +00:00
|
|
|
frame->GetFunctions(&functions);
|
|
|
|
for (int i = functions.length() - 1; i >= 0; i--) {
|
|
|
|
// Skip all frames that aren't invocations of the given function.
|
|
|
|
if (functions[i] != *function) continue;
|
|
|
|
|
|
|
|
if (i > 0) {
|
2011-02-02 15:08:29 +00:00
|
|
|
// The function in question was inlined. Inlined functions have the
|
|
|
|
// correct number of arguments and no allocated arguments object, so
|
|
|
|
// we can construct a fresh one by interpreting the function's
|
|
|
|
// deoptimization input data.
|
2010-12-07 11:31:57 +00:00
|
|
|
return ConstructArgumentsObjectForInlinedFunction(frame, function, i);
|
2011-02-02 15:08:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!frame->is_optimized()) {
|
2010-12-07 11:31:57 +00:00
|
|
|
// If there is an arguments variable in the stack, we return that.
|
2011-11-03 10:36:55 +00:00
|
|
|
Handle<ScopeInfo> scope_info(function->shared()->scope_info());
|
|
|
|
int index = scope_info->StackSlotIndex(
|
2013-02-28 17:03:34 +00:00
|
|
|
isolate->heap()->arguments_string());
|
2010-12-07 11:31:57 +00:00
|
|
|
if (index >= 0) {
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<Object> arguments(frame->GetExpression(index), isolate);
|
2011-01-06 15:53:56 +00:00
|
|
|
if (!arguments->IsArgumentsMarker()) return *arguments;
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
}
|
2011-02-02 15:08:29 +00:00
|
|
|
|
|
|
|
// If there is no arguments variable in the stack or we have an
|
|
|
|
// optimized frame, we find the frame that holds the actual arguments
|
|
|
|
// passed to the function.
|
|
|
|
it.AdvanceToArgumentsFrame();
|
|
|
|
frame = it.frame();
|
|
|
|
|
|
|
|
// Get the number of arguments and construct an arguments object
|
|
|
|
// mirror for the right frame.
|
2011-03-08 14:18:28 +00:00
|
|
|
const int length = frame->ComputeParametersCount();
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<JSObject> arguments = isolate->factory()->NewArgumentsObject(
|
|
|
|
function, length);
|
|
|
|
Handle<FixedArray> array = isolate->factory()->NewFixedArray(length);
|
2011-02-02 15:08:29 +00:00
|
|
|
|
|
|
|
// Copy the parameters to the arguments object.
|
|
|
|
ASSERT(array->length() == length);
|
|
|
|
for (int i = 0; i < length; i++) array->set(i, frame->GetParameter(i));
|
|
|
|
arguments->set_elements(*array);
|
|
|
|
|
|
|
|
// Return the freshly allocated arguments object.
|
|
|
|
return *arguments;
|
2009-06-24 08:01:38 +00:00
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
functions.Rewind(0);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// No frame corresponding to the given function found. Return null.
|
2011-03-18 20:35:07 +00:00
|
|
|
return isolate->heap()->null_value();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const AccessorDescriptor Accessors::FunctionArguments = {
|
|
|
|
FunctionGetArguments,
|
|
|
|
ReadOnlySetAccessor,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// Accessors::FunctionCaller
|
|
|
|
//
|
|
|
|
|
|
|
|
|
2011-08-25 13:38:58 +00:00
|
|
|
class FrameFunctionIterator {
|
|
|
|
public:
|
2013-06-03 15:32:22 +00:00
|
|
|
FrameFunctionIterator(Isolate* isolate, const DisallowHeapAllocation& promise)
|
2011-08-25 13:38:58 +00:00
|
|
|
: frame_iterator_(isolate),
|
|
|
|
functions_(2),
|
|
|
|
index_(0) {
|
|
|
|
GetFunctions();
|
|
|
|
}
|
|
|
|
JSFunction* next() {
|
|
|
|
if (functions_.length() == 0) return NULL;
|
|
|
|
JSFunction* next_function = functions_[index_];
|
|
|
|
index_--;
|
|
|
|
if (index_ < 0) {
|
|
|
|
GetFunctions();
|
|
|
|
}
|
|
|
|
return next_function;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Iterate through functions until the first occurence of 'function'.
|
|
|
|
// Returns true if 'function' is found, and false if the iterator ends
|
|
|
|
// without finding it.
|
|
|
|
bool Find(JSFunction* function) {
|
|
|
|
JSFunction* next_function;
|
|
|
|
do {
|
|
|
|
next_function = next();
|
|
|
|
if (next_function == function) return true;
|
|
|
|
} while (next_function != NULL);
|
|
|
|
return false;
|
|
|
|
}
|
2011-09-08 19:57:14 +00:00
|
|
|
|
2011-08-25 13:38:58 +00:00
|
|
|
private:
|
|
|
|
void GetFunctions() {
|
|
|
|
functions_.Rewind(0);
|
|
|
|
if (frame_iterator_.done()) return;
|
|
|
|
JavaScriptFrame* frame = frame_iterator_.frame();
|
|
|
|
frame->GetFunctions(&functions_);
|
|
|
|
ASSERT(functions_.length() > 0);
|
|
|
|
frame_iterator_.Advance();
|
|
|
|
index_ = functions_.length() - 1;
|
|
|
|
}
|
|
|
|
JavaScriptFrameIterator frame_iterator_;
|
|
|
|
List<JSFunction*> functions_;
|
|
|
|
int index_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-09-02 09:25:20 +00:00
|
|
|
MaybeObject* Accessors::FunctionGetCaller(Isolate* isolate,
|
|
|
|
Object* object,
|
|
|
|
void*) {
|
2011-03-18 20:35:07 +00:00
|
|
|
HandleScope scope(isolate);
|
2013-06-03 15:32:22 +00:00
|
|
|
DisallowHeapAllocation no_allocation;
|
2013-02-27 13:22:29 +00:00
|
|
|
JSFunction* holder = FindInstanceOf<JSFunction>(isolate, object);
|
2012-10-08 12:58:46 +00:00
|
|
|
if (holder == NULL) return isolate->heap()->undefined_value();
|
2011-09-06 14:03:32 +00:00
|
|
|
if (holder->shared()->native()) return isolate->heap()->null_value();
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<JSFunction> function(holder, isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2013-06-03 15:32:22 +00:00
|
|
|
FrameFunctionIterator it(isolate, no_allocation);
|
2011-08-25 13:38:58 +00:00
|
|
|
|
|
|
|
// Find the function from the frames.
|
|
|
|
if (!it.Find(*function)) {
|
|
|
|
// No frame corresponding to the given function found. Return null.
|
|
|
|
return isolate->heap()->null_value();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2011-08-25 13:38:58 +00:00
|
|
|
// Find previously called non-toplevel function.
|
|
|
|
JSFunction* caller;
|
|
|
|
do {
|
|
|
|
caller = it.next();
|
|
|
|
if (caller == NULL) return isolate->heap()->null_value();
|
|
|
|
} while (caller->shared()->is_toplevel());
|
|
|
|
|
|
|
|
// If caller is a built-in function and caller's caller is also built-in,
|
|
|
|
// use that instead.
|
|
|
|
JSFunction* potential_caller = caller;
|
|
|
|
while (potential_caller != NULL && potential_caller->IsBuiltin()) {
|
|
|
|
caller = potential_caller;
|
|
|
|
potential_caller = it.next();
|
|
|
|
}
|
2012-09-05 08:19:49 +00:00
|
|
|
if (!caller->shared()->native() && potential_caller != NULL) {
|
|
|
|
caller = potential_caller;
|
|
|
|
}
|
2011-10-18 12:26:53 +00:00
|
|
|
// If caller is bound, return null. This is compatible with JSC, and
|
|
|
|
// allows us to make bound functions use the strict function map
|
|
|
|
// and its associated throwing caller and arguments.
|
|
|
|
if (caller->shared()->bound()) {
|
|
|
|
return isolate->heap()->null_value();
|
|
|
|
}
|
2014-03-11 14:39:08 +00:00
|
|
|
// Censor if the caller is not a sloppy mode function.
|
2012-11-23 15:47:58 +00:00
|
|
|
// Change from ES5, which used to throw, see:
|
|
|
|
// https://bugs.ecmascript.org/show_bug.cgi?id=310
|
2014-03-11 14:41:22 +00:00
|
|
|
if (caller->shared()->strict_mode() == STRICT) {
|
2012-11-23 15:47:58 +00:00
|
|
|
return isolate->heap()->null_value();
|
|
|
|
}
|
|
|
|
|
|
|
|
return caller;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const AccessorDescriptor Accessors::FunctionCaller = {
|
|
|
|
FunctionGetCaller,
|
|
|
|
ReadOnlySetAccessor,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-07-09 08:59:03 +00:00
|
|
|
//
|
|
|
|
// Accessors::MakeModuleExport
|
|
|
|
//
|
|
|
|
|
2013-06-05 12:36:33 +00:00
|
|
|
static void ModuleGetExport(
|
2012-07-09 08:59:03 +00:00
|
|
|
v8::Local<v8::String> property,
|
2013-06-05 12:36:33 +00:00
|
|
|
const v8::PropertyCallbackInfo<v8::Value>& info) {
|
2012-07-09 08:59:03 +00:00
|
|
|
JSModule* instance = JSModule::cast(*v8::Utils::OpenHandle(*info.Holder()));
|
|
|
|
Context* context = Context::cast(instance->context());
|
|
|
|
ASSERT(context->IsModuleContext());
|
|
|
|
int slot = info.Data()->Int32Value();
|
|
|
|
Object* value = context->get(slot);
|
2013-02-25 14:46:09 +00:00
|
|
|
Isolate* isolate = instance->GetIsolate();
|
2012-07-09 08:59:03 +00:00
|
|
|
if (value->IsTheHole()) {
|
|
|
|
Handle<String> name = v8::Utils::OpenHandle(*property);
|
|
|
|
isolate->ScheduleThrow(
|
|
|
|
*isolate->factory()->NewReferenceError("not_defined",
|
|
|
|
HandleVector(&name, 1)));
|
2013-06-05 12:36:33 +00:00
|
|
|
return;
|
2012-07-09 08:59:03 +00:00
|
|
|
}
|
2013-06-05 12:36:33 +00:00
|
|
|
info.GetReturnValue().Set(v8::Utils::ToLocal(Handle<Object>(value, isolate)));
|
2012-07-09 08:59:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void ModuleSetExport(
|
|
|
|
v8::Local<v8::String> property,
|
|
|
|
v8::Local<v8::Value> value,
|
2013-06-05 12:36:33 +00:00
|
|
|
const v8::PropertyCallbackInfo<v8::Value>& info) {
|
2012-07-09 08:59:03 +00:00
|
|
|
JSModule* instance = JSModule::cast(*v8::Utils::OpenHandle(*info.Holder()));
|
|
|
|
Context* context = Context::cast(instance->context());
|
|
|
|
ASSERT(context->IsModuleContext());
|
|
|
|
int slot = info.Data()->Int32Value();
|
|
|
|
Object* old_value = context->get(slot);
|
|
|
|
if (old_value->IsTheHole()) {
|
|
|
|
Handle<String> name = v8::Utils::OpenHandle(*property);
|
|
|
|
Isolate* isolate = instance->GetIsolate();
|
|
|
|
isolate->ScheduleThrow(
|
|
|
|
*isolate->factory()->NewReferenceError("not_defined",
|
|
|
|
HandleVector(&name, 1)));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
context->set(slot, *v8::Utils::OpenHandle(*value));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<AccessorInfo> Accessors::MakeModuleExport(
|
|
|
|
Handle<String> name,
|
|
|
|
int index,
|
|
|
|
PropertyAttributes attributes) {
|
2013-09-02 09:27:27 +00:00
|
|
|
Isolate* isolate = name->GetIsolate();
|
|
|
|
Factory* factory = isolate->factory();
|
2013-02-12 14:33:08 +00:00
|
|
|
Handle<ExecutableAccessorInfo> info = factory->NewExecutableAccessorInfo();
|
2012-07-09 08:59:03 +00:00
|
|
|
info->set_property_attributes(attributes);
|
|
|
|
info->set_all_can_read(true);
|
|
|
|
info->set_all_can_write(true);
|
|
|
|
info->set_name(*name);
|
|
|
|
info->set_data(Smi::FromInt(index));
|
2013-09-02 09:27:27 +00:00
|
|
|
Handle<Object> getter = v8::FromCData(isolate, &ModuleGetExport);
|
|
|
|
Handle<Object> setter = v8::FromCData(isolate, &ModuleSetExport);
|
2012-07-09 16:22:53 +00:00
|
|
|
info->set_getter(*getter);
|
|
|
|
if (!(attributes & ReadOnly)) info->set_setter(*setter);
|
2012-07-09 08:59:03 +00:00
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
} } // namespace v8::internal
|