Reland "Move functions from handles.cc to where they belong."

R=jarin@chromium.org

Review URL: https://codereview.chromium.org/239113009

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20807 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
yangguo@chromium.org 2014-04-16 13:28:11 +00:00
parent 10bbd65525
commit 7af5597287
25 changed files with 704 additions and 720 deletions

View File

@ -524,7 +524,7 @@ MaybeObject* Accessors::ScriptGetLineEnds(Isolate* isolate,
JSValue* wrapper = JSValue::cast(object);
HandleScope scope(isolate);
Handle<Script> script(Script::cast(wrapper->value()), isolate);
InitScriptLineEnds(script);
Script::InitLineEnds(script);
ASSERT(script->line_ends()->IsFixedArray());
Handle<FixedArray> line_ends(FixedArray::cast(script->line_ends()));
// We do not want anyone to modify this array from JS.
@ -578,7 +578,7 @@ MaybeObject* Accessors::ScriptGetEvalFromScript(Isolate* isolate,
if (eval_from_shared->script()->IsScript()) {
Handle<Script> eval_from_script(Script::cast(eval_from_shared->script()));
return *GetScriptWrapper(eval_from_script);
return *Script::GetWrapper(eval_from_script);
}
}
return isolate->heap()->undefined_value();

View File

@ -349,8 +349,8 @@ AllocationTracker::UnresolvedLocation::~UnresolvedLocation() {
void AllocationTracker::UnresolvedLocation::Resolve() {
if (script_.is_null()) return;
HandleScope scope(script_->GetIsolate());
info_->line = GetScriptLineNumber(script_, start_position_);
info_->column = GetScriptColumnNumber(script_, start_position_);
info_->line = Script::GetLineNumber(script_, start_position_);
info_->column = Script::GetColumnNumber(script_, start_position_);
}

View File

@ -1615,7 +1615,7 @@ int UnboundScript::GetLineNumber(int code_pos) {
LOG_API(isolate, "UnboundScript::GetLineNumber");
if (obj->IsScript()) {
i::Handle<i::Script> script(i::Script::cast(*obj));
return i::GetScriptLineNumber(script, code_pos);
return i::Script::GetLineNumber(script, code_pos);
} else {
return -1;
}
@ -1983,11 +1983,9 @@ MUST_USE_RESULT static i::MaybeHandle<i::Object> CallV8HeapFunction(
int argc,
i::Handle<i::Object> argv[]) {
i::Isolate* isolate = i::Isolate::Current();
i::Handle<i::String> fmt_str =
isolate->factory()->InternalizeUtf8String(name);
i::Handle<i::Object> object_fun =
i::Object::GetProperty(
isolate->js_builtins_object(), fmt_str).ToHandleChecked();
isolate, isolate->js_builtins_object(), name).ToHandleChecked();
i::Handle<i::JSFunction> fun = i::Handle<i::JSFunction>::cast(object_fun);
return i::Execution::Call(isolate, fun, recv, argc, argv);
}
@ -2156,7 +2154,8 @@ int StackFrame::GetLineNumber() const {
ENTER_V8(isolate);
i::HandleScope scope(isolate);
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
i::Handle<i::Object> line = GetProperty(self, "lineNumber").ToHandleChecked();
i::Handle<i::Object> line = i::Object::GetProperty(
isolate, self, "lineNumber").ToHandleChecked();
if (!line->IsSmi()) {
return Message::kNoLineNumberInfo;
}
@ -2169,7 +2168,8 @@ int StackFrame::GetColumn() const {
ENTER_V8(isolate);
i::HandleScope scope(isolate);
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
i::Handle<i::Object> column = GetProperty(self, "column").ToHandleChecked();
i::Handle<i::Object> column = i::Object::GetProperty(
isolate, self, "column").ToHandleChecked();
if (!column->IsSmi()) {
return Message::kNoColumnInfo;
}
@ -2182,8 +2182,8 @@ int StackFrame::GetScriptId() const {
ENTER_V8(isolate);
i::HandleScope scope(isolate);
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
i::Handle<i::Object> scriptId =
GetProperty(self, "scriptId").ToHandleChecked();
i::Handle<i::Object> scriptId = i::Object::GetProperty(
isolate, self, "scriptId").ToHandleChecked();
if (!scriptId->IsSmi()) {
return Message::kNoScriptIdInfo;
}
@ -2196,7 +2196,8 @@ Local<String> StackFrame::GetScriptName() const {
ENTER_V8(isolate);
EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate));
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
i::Handle<i::Object> name = GetProperty(self, "scriptName").ToHandleChecked();
i::Handle<i::Object> name = i::Object::GetProperty(
isolate, self, "scriptName").ToHandleChecked();
if (!name->IsString()) {
return Local<String>();
}
@ -2209,8 +2210,8 @@ Local<String> StackFrame::GetScriptNameOrSourceURL() const {
ENTER_V8(isolate);
EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate));
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
i::Handle<i::Object> name =
GetProperty(self, "scriptNameOrSourceURL").ToHandleChecked();
i::Handle<i::Object> name = i::Object::GetProperty(
isolate, self, "scriptNameOrSourceURL").ToHandleChecked();
if (!name->IsString()) {
return Local<String>();
}
@ -2223,8 +2224,8 @@ Local<String> StackFrame::GetFunctionName() const {
ENTER_V8(isolate);
EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate));
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
i::Handle<i::Object> name =
GetProperty(self, "functionName").ToHandleChecked();
i::Handle<i::Object> name = i::Object::GetProperty(
isolate, self, "functionName").ToHandleChecked();
if (!name->IsString()) {
return Local<String>();
}
@ -2237,7 +2238,8 @@ bool StackFrame::IsEval() const {
ENTER_V8(isolate);
i::HandleScope scope(isolate);
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
i::Handle<i::Object> is_eval = GetProperty(self, "isEval").ToHandleChecked();
i::Handle<i::Object> is_eval = i::Object::GetProperty(
isolate, self, "isEval").ToHandleChecked();
return is_eval->IsTrue();
}
@ -2247,8 +2249,8 @@ bool StackFrame::IsConstructor() const {
ENTER_V8(isolate);
i::HandleScope scope(isolate);
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
i::Handle<i::Object> is_constructor =
GetProperty(self, "isConstructor").ToHandleChecked();
i::Handle<i::Object> is_constructor = i::Object::GetProperty(
isolate, self, "isConstructor").ToHandleChecked();
return is_constructor->IsTrue();
}
@ -2430,23 +2432,16 @@ bool Value::IsNumberObject() const {
}
static i::Object* LookupBuiltin(i::Isolate* isolate,
const char* builtin_name) {
i::Handle<i::String> string =
isolate->factory()->InternalizeUtf8String(builtin_name);
return *i::Object::GetProperty(
isolate->js_builtins_object(), string).ToHandleChecked();
}
static bool CheckConstructor(i::Isolate* isolate,
i::Handle<i::JSObject> obj,
const char* class_name) {
i::Object* constr = obj->map()->constructor();
i::Handle<i::Object> constr(obj->map()->constructor(), isolate);
if (!constr->IsJSFunction()) return false;
i::JSFunction* func = i::JSFunction::cast(constr);
return func->shared()->native() &&
constr == LookupBuiltin(isolate, class_name);
i::Handle<i::JSFunction> func = i::Handle<i::JSFunction>::cast(constr);
return func->shared()->native() && constr.is_identical_to(
i::Object::GetProperty(isolate,
isolate->js_builtins_object(),
class_name).ToHandleChecked());
}
@ -3209,8 +3204,8 @@ Local<Array> v8::Object::GetPropertyNames() {
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
EXCEPTION_PREAMBLE(isolate);
i::Handle<i::FixedArray> value;
has_pending_exception =
!i::GetKeysInFixedArrayFor(self, i::INCLUDE_PROTOS).ToHandle(&value);
has_pending_exception = !i::JSReceiver::GetKeys(
self, i::JSReceiver::INCLUDE_PROTOS).ToHandle(&value);
EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::Array>());
// Because we use caching to speed up enumeration it is important
// to never change the result of the basic enumeration function so
@ -3231,8 +3226,8 @@ Local<Array> v8::Object::GetOwnPropertyNames() {
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
EXCEPTION_PREAMBLE(isolate);
i::Handle<i::FixedArray> value;
has_pending_exception =
!i::GetKeysInFixedArrayFor(self, i::LOCAL_ONLY).ToHandle(&value);
has_pending_exception = !i::JSReceiver::GetKeys(
self, i::JSReceiver::LOCAL_ONLY).ToHandle(&value);
EXCEPTION_BAILOUT_CHECK(isolate, Local<v8::Array>());
// Because we use caching to speed up enumeration it is important
// to never change the result of the basic enumeration function so
@ -4043,7 +4038,7 @@ ScriptOrigin Function::GetScriptOrigin() const {
i::Handle<i::JSFunction> func = Utils::OpenHandle(this);
if (func->shared()->script()->IsScript()) {
i::Handle<i::Script> script(i::Script::cast(func->shared()->script()));
i::Handle<i::Object> scriptName = GetScriptNameOrSourceURL(script);
i::Handle<i::Object> scriptName = i::Script::GetNameOrSourceURL(script);
v8::Isolate* isolate = reinterpret_cast<v8::Isolate*>(func->GetIsolate());
v8::ScriptOrigin origin(
Utils::ToLocal(scriptName),
@ -4062,7 +4057,7 @@ int Function::GetScriptLineNumber() const {
i::Handle<i::JSFunction> func = Utils::OpenHandle(this);
if (func->shared()->script()->IsScript()) {
i::Handle<i::Script> script(i::Script::cast(func->shared()->script()));
return i::GetScriptLineNumber(script, func->shared()->start_position());
return i::Script::GetLineNumber(script, func->shared()->start_position());
}
return kLineOffsetNotFound;
}
@ -4072,7 +4067,7 @@ int Function::GetScriptColumnNumber() const {
i::Handle<i::JSFunction> func = Utils::OpenHandle(this);
if (func->shared()->script()->IsScript()) {
i::Handle<i::Script> script(i::Script::cast(func->shared()->script()));
return i::GetScriptColumnNumber(script, func->shared()->start_position());
return i::Script::GetColumnNumber(script, func->shared()->start_position());
}
return kLineOffsetNotFound;
}

View File

@ -2021,10 +2021,9 @@ static Handle<JSObject> ResolveBuiltinIdHolder(
static void InstallBuiltinFunctionId(Handle<JSObject> holder,
const char* function_name,
BuiltinFunctionId id) {
Factory* factory = holder->GetIsolate()->factory();
Handle<String> name = factory->InternalizeUtf8String(function_name);
Isolate* isolate = holder->GetIsolate();
Handle<Object> function_object =
Object::GetProperty(holder, name).ToHandleChecked();
Object::GetProperty(isolate, holder, function_name).ToHandleChecked();
Handle<JSFunction> function = Handle<JSFunction>::cast(function_object);
function->shared()->set_function_data(Smi::FromInt(id));
}
@ -2131,7 +2130,8 @@ bool Genesis::InstallSpecialObjects(Handle<Context> native_context) {
false);
}
Handle<Object> Error = GetProperty(global, "Error").ToHandleChecked();
Handle<Object> Error = Object::GetProperty(
isolate, global, "Error").ToHandleChecked();
if (Error->IsJSObject()) {
Handle<String> name = factory->InternalizeOneByteString(
STATIC_ASCII_VECTOR("stackTraceLimit"));
@ -2312,10 +2312,8 @@ bool Genesis::InstallJSBuiltins(Handle<JSBuiltinsObject> builtins) {
HandleScope scope(isolate());
for (int i = 0; i < Builtins::NumberOfJavaScriptBuiltins(); i++) {
Builtins::JavaScript id = static_cast<Builtins::JavaScript>(i);
Handle<String> name =
factory()->InternalizeUtf8String(Builtins::GetName(id));
Handle<Object> function_object =
Object::GetProperty(builtins, name).ToHandleChecked();
Handle<Object> function_object = Object::GetProperty(
isolate(), builtins, Builtins::GetName(id)).ToHandleChecked();
Handle<JSFunction> function = Handle<JSFunction>::cast(function_object);
builtins->set_javascript_builtin(id, *function);
if (!Compiler::EnsureCompiled(function, CLEAR_EXCEPTION)) {

View File

@ -372,9 +372,10 @@ MUST_USE_RESULT static MaybeObject* CallJsBuiltin(
BuiltinArguments<NO_EXTRA_ARGUMENTS> args) {
HandleScope handleScope(isolate);
Handle<Object> js_builtin =
GetProperty(Handle<JSObject>(isolate->native_context()->builtins()),
name).ToHandleChecked();
Handle<Object> js_builtin = Object::GetProperty(
isolate,
handle(isolate->native_context()->builtins(), isolate),
name).ToHandleChecked();
Handle<JSFunction> function = Handle<JSFunction>::cast(js_builtin);
int argc = args.length() - 1;
ScopedVector<Handle<Object> > argv(argc);

View File

@ -1257,12 +1257,13 @@ void Compiler::RecordFunctionCompilation(Logger::LogEventsAndTags tag,
info->isolate()->cpu_profiler()->is_profiling()) {
Handle<Script> script = info->script();
Handle<Code> code = info->code();
if (code.is_identical_to(info->isolate()->builtins()->CompileUnoptimized()))
if (code.is_identical_to(
info->isolate()->builtins()->CompileUnoptimized())) {
return;
int line_num = GetScriptLineNumber(script, shared->start_position()) + 1;
}
int line_num = Script::GetLineNumber(script, shared->start_position()) + 1;
int column_num =
GetScriptColumnNumber(script, shared->start_position()) + 1;
USE(line_num);
Script::GetColumnNumber(script, shared->start_position()) + 1;
String* script_name = script->name()->IsString()
? String::cast(script->name())
: info->isolate()->heap()->empty_string();

View File

@ -2643,7 +2643,7 @@ MaybeHandle<Object> Debugger::MakeCompileEvent(Handle<Script> script,
Handle<Object> exec_state;
if (!MakeExecutionState().ToHandle(&exec_state)) return MaybeHandle<Object>();
// Create the compile event object.
Handle<Object> script_wrapper = GetScriptWrapper(script);
Handle<Object> script_wrapper = Script::GetWrapper(script);
Handle<Object> argv[] = { exec_state,
script_wrapper,
isolate_->factory()->ToBoolean(before) };
@ -2787,7 +2787,7 @@ void Debugger::OnAfterCompile(Handle<Script> script,
// Wrap the script object in a proper JS object before passing it
// to JavaScript.
Handle<JSValue> wrapper = GetScriptWrapper(script);
Handle<Object> wrapper = Script::GetWrapper(script);
// Call UpdateScriptBreakPoints expect no exceptions.
Handle<Object> argv[] = { wrapper };
@ -3525,8 +3525,8 @@ v8::Handle<v8::String> MessageImpl::GetJSON() const {
if (IsEvent()) {
// Call toJSONProtocol on the debug event object.
Handle<Object> fun =
GetProperty(event_data_, "toJSONProtocol").ToHandleChecked();
Handle<Object> fun = Object::GetProperty(
isolate, event_data_, "toJSONProtocol").ToHandleChecked();
if (!fun->IsJSFunction()) {
return v8::Handle<v8::String>();
}

View File

@ -806,7 +806,6 @@ void JavaScriptFrame::PrintTop(Isolate* isolate,
bool print_args,
bool print_line_number) {
// constructor calls
HandleScope scope(isolate);
DisallowHeapAllocation no_allocation;
JavaScriptFrameIterator it(isolate);
while (!it.done()) {
@ -827,8 +826,8 @@ void JavaScriptFrame::PrintTop(Isolate* isolate,
int source_pos = code->SourcePosition(pc);
Object* maybe_script = shared->script();
if (maybe_script->IsScript()) {
Handle<Script> script(Script::cast(maybe_script));
int line = GetScriptLineNumberSafe(script, source_pos) + 1;
Script* script = Script::cast(maybe_script);
int line = script->GetLineNumber(source_pos) + 1;
Object* script_name_raw = script->name();
if (script_name_raw->IsString()) {
String* script_name = String::cast(script->name());
@ -1171,7 +1170,7 @@ void StackFrame::PrintIndex(StringStream* accumulator,
void JavaScriptFrame::Print(StringStream* accumulator,
PrintMode mode,
int index) const {
HandleScope scope(isolate());
DisallowHeapAllocation no_gc;
Object* receiver = this->receiver();
JSFunction* function = this->function();
@ -1185,13 +1184,11 @@ void JavaScriptFrame::Print(StringStream* accumulator,
// doesn't contain scope info, scope_info will return 0 for the number of
// parameters, stack local variables, context local variables, stack slots,
// or context slots.
Handle<ScopeInfo> scope_info(ScopeInfo::Empty(isolate()));
Handle<SharedFunctionInfo> shared(function->shared());
scope_info = Handle<ScopeInfo>(shared->scope_info());
SharedFunctionInfo* shared = function->shared();
ScopeInfo* scope_info = shared->scope_info();
Object* script_obj = shared->script();
if (script_obj->IsScript()) {
Handle<Script> script(Script::cast(script_obj));
Script* script = Script::cast(script_obj);
accumulator->Add(" [");
accumulator->PrintName(script->name());
@ -1199,11 +1196,11 @@ void JavaScriptFrame::Print(StringStream* accumulator,
if (code != NULL && code->kind() == Code::FUNCTION &&
pc >= code->instruction_start() && pc < code->instruction_end()) {
int source_pos = code->SourcePosition(pc);
int line = GetScriptLineNumberSafe(script, source_pos) + 1;
int line = script->GetLineNumber(source_pos) + 1;
accumulator->Add(":%d", line);
} else {
int function_start_pos = shared->start_position();
int line = GetScriptLineNumberSafe(script, function_start_pos) + 1;
int line = script->GetLineNumber(function_start_pos) + 1;
accumulator->Add(":~%d", line);
}

View File

@ -1002,7 +1002,7 @@ class CodeDescription BASE_EMBEDDED {
}
int GetScriptLineNumber(int pos) {
return GetScriptLineNumberSafe(script_, pos) + 1;
return script_->GetLineNumber(pos) + 1;
}
@ -2003,8 +2003,7 @@ void GDBJITInterface::AddCode(Handle<Name> name,
CompilationInfo* info) {
if (!FLAG_gdbjit) return;
// Force initialization of line_ends array.
GetScriptLineNumber(script, 0);
Script::InitLineEnds(script);
if (!name.is_null() && name->IsString()) {
SmartArrayPointer<char> name_cstring =

View File

@ -27,19 +27,7 @@
#include "v8.h"
#include "accessors.h"
#include "api.h"
#include "arguments.h"
#include "bootstrapper.h"
#include "compiler.h"
#include "debug.h"
#include "execution.h"
#include "global-handles.h"
#include "natives.h"
#include "runtime.h"
#include "string-search.h"
#include "stub-cache.h"
#include "vm-state-inl.h"
#include "handles.h"
namespace v8 {
namespace internal {
@ -124,522 +112,6 @@ Address HandleScope::current_limit_address(Isolate* isolate) {
}
MaybeHandle<Object> GetProperty(Handle<JSReceiver> obj,
const char* name) {
Isolate* isolate = obj->GetIsolate();
Handle<String> str = isolate->factory()->InternalizeUtf8String(name);
ASSERT(!str.is_null());
return Object::GetPropertyOrElement(obj, str);
}
// Wrappers for scripts are kept alive and cached in weak global
// handles referred from foreign objects held by the scripts as long as
// 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.
static void ClearWrapperCache(
const v8::WeakCallbackData<v8::Value, void>& data) {
Object** location = reinterpret_cast<Object**>(data.GetParameter());
JSValue* wrapper = JSValue::cast(*location);
Foreign* foreign = Script::cast(wrapper->value())->wrapper();
ASSERT_EQ(foreign->foreign_address(), reinterpret_cast<Address>(location));
foreign->set_foreign_address(0);
GlobalHandles::Destroy(location);
Isolate* isolate = reinterpret_cast<Isolate*>(data.GetIsolate());
isolate->counters()->script_wrappers()->Decrement();
}
Handle<JSValue> GetScriptWrapper(Handle<Script> script) {
if (script->wrapper()->foreign_address() != NULL) {
// Return a handle for the existing script wrapper from the cache.
return Handle<JSValue>(
*reinterpret_cast<JSValue**>(script->wrapper()->foreign_address()));
}
Isolate* isolate = script->GetIsolate();
// Construct a new script wrapper.
isolate->counters()->script_wrappers()->Increment();
Handle<JSFunction> constructor = isolate->script_function();
Handle<JSValue> result =
Handle<JSValue>::cast(isolate->factory()->NewJSObject(constructor));
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.
Handle<Object> handle = isolate->global_handles()->Create(*result);
GlobalHandles::MakeWeak(handle.location(),
reinterpret_cast<void*>(handle.location()),
&ClearWrapperCache);
script->wrapper()->set_foreign_address(
reinterpret_cast<Address>(handle.location()));
return result;
}
// Init line_ends array with code positions of line ends inside script
// source.
void InitScriptLineEnds(Handle<Script> script) {
if (!script->line_ends()->IsUndefined()) return;
Isolate* isolate = script->GetIsolate();
if (!script->source()->IsString()) {
ASSERT(script->source()->IsUndefined());
Handle<FixedArray> empty = isolate->factory()->NewFixedArray(0);
script->set_line_ends(*empty);
ASSERT(script->line_ends()->IsFixedArray());
return;
}
Handle<String> src(String::cast(script->source()), isolate);
Handle<FixedArray> array = CalculateLineEnds(src, true);
if (*array != isolate->heap()->empty_fixed_array()) {
array->set_map(isolate->heap()->fixed_cow_array_map());
}
script->set_line_ends(*array);
ASSERT(script->line_ends()->IsFixedArray());
}
template <typename SourceChar>
static void CalculateLineEnds(Isolate* isolate,
List<int>* line_ends,
Vector<const SourceChar> src,
bool with_last_line) {
const int src_len = src.length();
StringSearch<uint8_t, SourceChar> search(isolate, STATIC_ASCII_VECTOR("\n"));
// Find and record line ends.
int position = 0;
while (position != -1 && position < src_len) {
position = search.Search(src, position);
if (position != -1) {
line_ends->Add(position);
position++;
} else if (with_last_line) {
// Even if the last line misses a line end, it is counted.
line_ends->Add(src_len);
return;
}
}
}
Handle<FixedArray> CalculateLineEnds(Handle<String> src,
bool with_last_line) {
src = String::Flatten(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);
Isolate* isolate = src->GetIsolate();
{
DisallowHeapAllocation no_allocation; // ensure vectors stay valid.
// Dispatch on type of strings.
String::FlatContent content = src->GetFlatContent();
ASSERT(content.IsFlat());
if (content.IsAscii()) {
CalculateLineEnds(isolate,
&line_ends,
content.ToOneByteVector(),
with_last_line);
} else {
CalculateLineEnds(isolate,
&line_ends,
content.ToUC16Vector(),
with_last_line);
}
}
int line_count = line_ends.length();
Handle<FixedArray> array = isolate->factory()->NewFixedArray(line_count);
for (int i = 0; i < line_count; i++) {
array->set(i, Smi::FromInt(line_ends[i]));
}
return array;
}
// Convert code position into line number.
int GetScriptLineNumber(Handle<Script> script, int code_pos) {
InitScriptLineEnds(script);
DisallowHeapAllocation no_allocation;
FixedArray* line_ends_array = FixedArray::cast(script->line_ends());
const int line_ends_len = line_ends_array->length();
if (!line_ends_len) return -1;
if ((Smi::cast(line_ends_array->get(0)))->value() >= code_pos) {
return script->line_offset()->value();
}
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;
}
}
return right + script->line_offset()->value();
}
// 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;
DisallowHeapAllocation 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);
}
int GetScriptLineNumberSafe(Handle<Script> script, int code_pos) {
DisallowHeapAllocation 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;
}
// Compute the property keys from the interceptor.
// TODO(rossberg): support symbols in API, and filter here if needed.
v8::Handle<v8::Array> GetKeysForNamedInterceptor(Handle<JSReceiver> receiver,
Handle<JSObject> object) {
Isolate* isolate = receiver->GetIsolate();
Handle<InterceptorInfo> interceptor(object->GetNamedInterceptor());
PropertyCallbackArguments
args(isolate, interceptor->data(), *receiver, *object);
v8::Handle<v8::Array> result;
if (!interceptor->enumerator()->IsUndefined()) {
v8::NamedPropertyEnumeratorCallback enum_fun =
v8::ToCData<v8::NamedPropertyEnumeratorCallback>(
interceptor->enumerator());
LOG(isolate, ApiObjectAccess("interceptor-named-enum", *object));
result = args.Call(enum_fun);
}
#if ENABLE_EXTRA_CHECKS
CHECK(result.IsEmpty() || v8::Utils::OpenHandle(*result)->IsJSObject());
#endif
return v8::Local<v8::Array>::New(reinterpret_cast<v8::Isolate*>(isolate),
result);
}
// Compute the element keys from the interceptor.
v8::Handle<v8::Array> GetKeysForIndexedInterceptor(Handle<JSReceiver> receiver,
Handle<JSObject> object) {
Isolate* isolate = receiver->GetIsolate();
Handle<InterceptorInfo> interceptor(object->GetIndexedInterceptor());
PropertyCallbackArguments
args(isolate, interceptor->data(), *receiver, *object);
v8::Handle<v8::Array> result;
if (!interceptor->enumerator()->IsUndefined()) {
v8::IndexedPropertyEnumeratorCallback enum_fun =
v8::ToCData<v8::IndexedPropertyEnumeratorCallback>(
interceptor->enumerator());
LOG(isolate, ApiObjectAccess("interceptor-indexed-enum", *object));
result = args.Call(enum_fun);
#if ENABLE_EXTRA_CHECKS
CHECK(result.IsEmpty() || v8::Utils::OpenHandle(*result)->IsJSObject());
#endif
}
return v8::Local<v8::Array>::New(reinterpret_cast<v8::Isolate*>(isolate),
result);
}
Handle<Object> GetScriptNameOrSourceURL(Handle<Script> script) {
Isolate* isolate = script->GetIsolate();
Handle<String> name_or_source_url_key =
isolate->factory()->InternalizeOneByteString(
STATIC_ASCII_VECTOR("nameOrSourceURL"));
Handle<JSValue> script_wrapper = GetScriptWrapper(script);
Handle<Object> property = Object::GetProperty(
script_wrapper, name_or_source_url_key).ToHandleChecked();
ASSERT(property->IsJSFunction());
Handle<JSFunction> method = Handle<JSFunction>::cast(property);
Handle<Object> result;
// Do not check against pending exception, since this function may be called
// when an exception has already been pending.
if (!Execution::TryCall(method, script_wrapper, 0, NULL).ToHandle(&result)) {
return isolate->factory()->undefined_value();
}
return result;
}
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;
}
MaybeHandle<FixedArray> GetKeysInFixedArrayFor(Handle<JSReceiver> object,
KeyCollectionType type) {
USE(ContainsOnlyValidKeys);
Isolate* isolate = object->GetIsolate();
Handle<FixedArray> content = isolate->factory()->empty_fixed_array();
Handle<JSObject> arguments_boilerplate = Handle<JSObject>(
isolate->context()->native_context()->sloppy_arguments_boilerplate(),
isolate);
Handle<JSFunction> arguments_function = Handle<JSFunction>(
JSFunction::cast(arguments_boilerplate->map()->constructor()),
isolate);
// Only collect keys if access is permitted.
for (Handle<Object> p = object;
*p != isolate->heap()->null_value();
p = Handle<Object>(p->GetPrototype(isolate), isolate)) {
if (p->IsJSProxy()) {
Handle<JSProxy> proxy(JSProxy::cast(*p), isolate);
Handle<Object> args[] = { proxy };
Handle<Object> names;
ASSIGN_RETURN_ON_EXCEPTION(
isolate, names,
Execution::Call(isolate,
isolate->proxy_enumerate(),
object,
ARRAY_SIZE(args),
args),
FixedArray);
ASSIGN_RETURN_ON_EXCEPTION(
isolate, content,
FixedArray::AddKeysFromJSArray(
content, Handle<JSArray>::cast(names)),
FixedArray);
break;
}
Handle<JSObject> current(JSObject::cast(*p), isolate);
// Check access rights if required.
if (current->IsAccessCheckNeeded() &&
!isolate->MayNamedAccess(
current, isolate->factory()->undefined_value(), v8::ACCESS_KEYS)) {
isolate->ReportFailedAccessCheck(current, v8::ACCESS_KEYS);
RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, FixedArray);
break;
}
// Compute the element keys.
Handle<FixedArray> element_keys =
isolate->factory()->NewFixedArray(current->NumberOfEnumElements());
current->GetEnumElementKeys(*element_keys);
ASSIGN_RETURN_ON_EXCEPTION(
isolate, content,
FixedArray::UnionOfKeys(content, element_keys),
FixedArray);
ASSERT(ContainsOnlyValidKeys(content));
// Add the element keys from the interceptor.
if (current->HasIndexedInterceptor()) {
v8::Handle<v8::Array> result =
GetKeysForIndexedInterceptor(object, current);
if (!result.IsEmpty()) {
ASSIGN_RETURN_ON_EXCEPTION(
isolate, content,
FixedArray::AddKeysFromJSArray(
content, v8::Utils::OpenHandle(*result)),
FixedArray);
}
ASSERT(ContainsOnlyValidKeys(content));
}
// 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.
// 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.
bool cache_enum_keys =
((current->map()->constructor() != *arguments_function) &&
!current->IsJSValue() &&
!current->IsAccessCheckNeeded() &&
!current->HasNamedInterceptor() &&
!current->HasIndexedInterceptor());
// Compute the property keys and cache them if possible.
ASSIGN_RETURN_ON_EXCEPTION(
isolate, content,
FixedArray::UnionOfKeys(
content, GetEnumPropertyKeys(current, cache_enum_keys)),
FixedArray);
ASSERT(ContainsOnlyValidKeys(content));
// Add the property keys from the interceptor.
if (current->HasNamedInterceptor()) {
v8::Handle<v8::Array> result =
GetKeysForNamedInterceptor(object, current);
if (!result.IsEmpty()) {
ASSIGN_RETURN_ON_EXCEPTION(
isolate, content,
FixedArray::AddKeysFromJSArray(
content, v8::Utils::OpenHandle(*result)),
FixedArray);
}
ASSERT(ContainsOnlyValidKeys(content));
}
// If we only want local properties we bail out after the first
// iteration.
if (type == LOCAL_ONLY) break;
}
return content;
}
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;
}
Handle<FixedArray> GetEnumPropertyKeys(Handle<JSObject> object,
bool cache_result) {
Isolate* isolate = object->GetIsolate();
if (object->HasFastProperties()) {
int own_property_count = object->map()->EnumLength();
// If 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 or
// SYMBOLIC.
if (own_property_count == kInvalidEnumCacheSentinel) {
own_property_count = object->map()->NumberOfDescribedProperties(
OWN_DESCRIPTORS, DONT_SHOW);
} else {
ASSERT(own_property_count == object->map()->NumberOfDescribedProperties(
OWN_DESCRIPTORS, DONT_SHOW));
}
if (object->map()->instance_descriptors()->HasEnumCache()) {
DescriptorArray* desc = object->map()->instance_descriptors();
Handle<FixedArray> keys(desc->GetEnumCache(), isolate);
// 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()) {
if (cache_result) object->map()->SetEnumLength(own_property_count);
isolate->counters()->enum_cache_hits()->Increment();
return ReduceFixedArrayTo(keys, own_property_count);
}
}
Handle<Map> map(object->map());
if (map->instance_descriptors()->IsEmpty()) {
isolate->counters()->enum_cache_hits()->Increment();
if (cache_result) map->SetEnumLength(0);
return isolate->factory()->empty_fixed_array();
}
isolate->counters()->enum_cache_misses()->Increment();
Handle<FixedArray> storage = isolate->factory()->NewFixedArray(
own_property_count);
Handle<FixedArray> indices = isolate->factory()->NewFixedArray(
own_property_count);
Handle<DescriptorArray> descs =
Handle<DescriptorArray>(object->map()->instance_descriptors(), isolate);
int size = map->NumberOfOwnDescriptors();
int index = 0;
for (int i = 0; i < size; i++) {
PropertyDetails details = descs->GetDetails(i);
Object* key = descs->GetKey(i);
if (!(details.IsDontEnum() || key->IsSymbol())) {
storage->set(index, key);
if (!indices.is_null()) {
if (details.type() != FIELD) {
indices = Handle<FixedArray>();
} else {
int field_index = descs->GetFieldIndex(i);
if (field_index >= map->inobject_properties()) {
field_index = -(field_index - map->inobject_properties() + 1);
}
field_index = field_index << 1;
if (details.representation().IsDouble()) {
field_index |= 1;
}
indices->set(index, Smi::FromInt(field_index));
}
}
index++;
}
}
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));
if (cache_result) {
object->map()->SetEnumLength(own_property_count);
}
return storage;
} else {
Handle<NameDictionary> dictionary(object->property_dictionary());
int length = dictionary->NumberOfEnumElements();
if (length == 0) {
return Handle<FixedArray>(isolate->heap()->empty_fixed_array());
}
Handle<FixedArray> storage = isolate->factory()->NewFixedArray(length);
dictionary->CopyEnumKeysTo(*storage);
return storage;
}
}
DeferredHandleScope::DeferredHandleScope(Isolate* isolate)
: impl_(isolate->handle_scope_implementer()) {
impl_->BeginDeferredScope();
@ -678,16 +150,4 @@ DeferredHandles* DeferredHandleScope::Detach() {
return deferred;
}
void AddWeakObjectToCodeDependency(Heap* heap,
Handle<Object> object,
Handle<Code> code) {
heap->EnsureWeakObjectToCodeTable();
Handle<DependentCode> dep(heap->LookupWeakObjectToCodeDependency(*object));
dep = DependentCode::Insert(dep, DependentCode::kWeakCodeGroup, code);
CALL_HEAP_FUNCTION_VOID(heap->isolate(),
heap->AddWeakObjectToCodeDependency(*object, *dep));
}
} } // namespace v8::internal

View File

@ -28,7 +28,6 @@
#ifndef V8_HANDLES_H_
#define V8_HANDLES_H_
#include "allocation.h"
#include "objects.h"
namespace v8 {
@ -281,53 +280,6 @@ class DeferredHandleScope {
};
// ----------------------------------------------------------------------------
// Handle operations.
// They might invoke garbage collection. The result is an handle to
// an object of expected type, or the handle is an error if running out
// of space or encountering an internal error.
MUST_USE_RESULT MaybeHandle<Object> GetProperty(Handle<JSReceiver> obj,
const char* name);
// Get the JS object corresponding to the given script; create it
// if none exists.
Handle<JSValue> GetScriptWrapper(Handle<Script> script);
// Script line number computations. Note that the line number is zero-based.
void InitScriptLineEnds(Handle<Script> script);
// For string calculates an array of line end positions. If the string
// does not end with a new line character, this character may optionally be
// imagined.
Handle<FixedArray> CalculateLineEnds(Handle<String> string,
bool with_imaginary_last_new_line);
int GetScriptLineNumber(Handle<Script> script, int code_position);
// The safe version does not make heap allocations but may work much slower.
int GetScriptLineNumberSafe(Handle<Script> script, int code_position);
int GetScriptColumnNumber(Handle<Script> script, int code_position);
Handle<Object> GetScriptNameOrSourceURL(Handle<Script> script);
// Computes the enumerable keys from interceptors. Used for debug mirrors and
// by GetKeysInFixedArrayFor below.
v8::Handle<v8::Array> GetKeysForNamedInterceptor(Handle<JSReceiver> receiver,
Handle<JSObject> object);
v8::Handle<v8::Array> GetKeysForIndexedInterceptor(Handle<JSReceiver> receiver,
Handle<JSObject> object);
enum KeyCollectionType { LOCAL_ONLY, INCLUDE_PROTOS };
// Computes the enumerable keys for a JSObject. Used for implementing
// "for (n in object) { }".
MUST_USE_RESULT MaybeHandle<FixedArray> GetKeysInFixedArrayFor(
Handle<JSReceiver> object, KeyCollectionType type);
Handle<FixedArray> ReduceFixedArrayTo(Handle<FixedArray> array, int length);
Handle<FixedArray> GetEnumPropertyKeys(Handle<JSObject> object,
bool cache_result);
void AddWeakObjectToCodeDependency(Heap* heap,
Handle<Object> object,
Handle<Code> code);
// Seal off the current HandleScope so that new handles can only be created
// if a new HandleScope is entered.
class SealHandleScope BASE_EMBEDDED {

View File

@ -519,7 +519,7 @@ Handle<JSArray> Isolate::CaptureCurrentStackTrace(
if (options & StackTrace::kLineNumber) {
int script_line_offset = script->line_offset()->value();
int position = frames[i].code()->SourcePosition(frames[i].pc());
int line_number = GetScriptLineNumber(script, position);
int line_number = Script::GetLineNumber(script, position);
// line_number is already shifted by the script_line_offset.
int relative_line_number = line_number - script_line_offset;
if (options & StackTrace::kColumnOffset && relative_line_number >= 0) {
@ -554,7 +554,7 @@ Handle<JSArray> Isolate::CaptureCurrentStackTrace(
}
if (options & StackTrace::kScriptNameOrSourceURL) {
Handle<Object> result = GetScriptNameOrSourceURL(script);
Handle<Object> result = Script::GetNameOrSourceURL(script);
JSObject::SetLocalPropertyIgnoreAttributes(
stack_frame, script_name_or_source_url_key, result, NONE).Check();
}
@ -819,8 +819,8 @@ Failure* Isolate::StackOverflow() {
DoThrow(*exception, NULL);
// Get stack trace limit.
Handle<Object> error =
GetProperty(js_builtins_object(), "$Error").ToHandleChecked();
Handle<Object> error = Object::GetProperty(
this, js_builtins_object(), "$Error").ToHandleChecked();
if (!error->IsJSObject()) return Failure::Exception();
Handle<String> stackTraceLimit =
@ -1137,19 +1137,19 @@ void Isolate::DoThrow(Object* exception, MessageLocation* location) {
// In this case we could have an extension (or an internal error
// somewhere) and we print out the line number at which the error occured
// to the console for easier debugging.
int line_number = GetScriptLineNumberSafe(location->script(),
location->start_pos());
int line_number =
location->script()->GetLineNumber(location->start_pos()) + 1;
if (exception->IsString() && location->script()->name()->IsString()) {
OS::PrintError(
"Extension or internal compilation error: %s in %s at line %d.\n",
String::cast(exception)->ToCString().get(),
String::cast(location->script()->name())->ToCString().get(),
line_number + 1);
line_number);
} else if (location->script()->name()->IsString()) {
OS::PrintError(
"Extension or internal compilation error in %s at line %d.\n",
String::cast(location->script()->name())->ToCString().get(),
line_number + 1);
line_number);
} else {
OS::PrintError("Extension or internal compilation error.\n");
}

View File

@ -484,9 +484,9 @@ BasicJsonStringifier::Result BasicJsonStringifier::SerializeGeneric(
Handle<Object> key,
bool deferred_comma,
bool deferred_key) {
Handle<JSObject> builtins(isolate_->native_context()->builtins());
Handle<JSFunction> builtin = Handle<JSFunction>::cast(
GetProperty(builtins, "JSONSerializeAdapter").ToHandleChecked());
Handle<JSObject> builtins(isolate_->native_context()->builtins(), isolate_);
Handle<JSFunction> builtin = Handle<JSFunction>::cast(Object::GetProperty(
isolate_, builtins, "JSONSerializeAdapter").ToHandleChecked());
Handle<Object> argv[] = { key, object };
Handle<Object> result;
@ -695,7 +695,7 @@ BasicJsonStringifier::Result BasicJsonStringifier::SerializeJSObject(
Handle<FixedArray> contents;
ASSIGN_RETURN_ON_EXCEPTION_VALUE(
isolate_, contents,
GetKeysInFixedArrayFor(object, LOCAL_ONLY),
JSReceiver::GetKeys(object, JSReceiver::LOCAL_ONLY),
EXCEPTION);
for (int i = 0; i < contents->length(); i++) {

View File

@ -173,6 +173,18 @@ int LCodeGenBase::GetNextEmittedBlock() const {
}
static void AddWeakObjectToCodeDependency(Isolate* isolate,
Handle<Object> object,
Handle<Code> code) {
Heap* heap = isolate->heap();
heap->EnsureWeakObjectToCodeTable();
Handle<DependentCode> dep(heap->LookupWeakObjectToCodeDependency(*object));
dep = DependentCode::Insert(dep, DependentCode::kWeakCodeGroup, code);
CALL_HEAP_FUNCTION_VOID(isolate,
heap->AddWeakObjectToCodeDependency(*object, *dep));
}
void LCodeGenBase::RegisterWeakObjectsInOptimizedCode(Handle<Code> code) {
ASSERT(code->is_optimized_code());
ZoneList<Handle<Map> > maps(1, zone());
@ -214,10 +226,10 @@ void LCodeGenBase::RegisterWeakObjectsInOptimizedCode(Handle<Code> code) {
Map::AddDependentCode(maps.at(i), DependentCode::kWeakCodeGroup, code);
}
for (int i = 0; i < objects.length(); i++) {
AddWeakObjectToCodeDependency(isolate()->heap(), objects.at(i), code);
AddWeakObjectToCodeDependency(isolate(), objects.at(i), code);
}
for (int i = 0; i < cells.length(); i++) {
AddWeakObjectToCodeDependency(isolate()->heap(), cells.at(i), code);
AddWeakObjectToCodeDependency(isolate(), cells.at(i), code);
}
}

View File

@ -431,7 +431,7 @@ class TokensCompareOutput : public Comparator::Output {
class LineEndsWrapper {
public:
explicit LineEndsWrapper(Handle<String> string)
: ends_array_(CalculateLineEnds(string, false)),
: ends_array_(String::CalculateLineEnds(string, false)),
string_len_(string->length()) {
}
int length() {
@ -852,7 +852,8 @@ MaybeHandle<JSArray> LiveEdit::GatherCompileInfo(Handle<Script> script,
Handle<Smi> start_pos(
Smi::FromInt(message_location.start_pos()), isolate);
Handle<Smi> end_pos(Smi::FromInt(message_location.end_pos()), isolate);
Handle<JSValue> script_obj = GetScriptWrapper(message_location.script());
Handle<JSObject> script_obj =
Script::GetWrapper(message_location.script());
JSReceiver::SetProperty(
rethrow_exception, start_pos_key, start_pos, NONE, SLOPPY).Assert();
JSReceiver::SetProperty(

View File

@ -1150,7 +1150,8 @@ void Logger::LogRegExpSource(Handle<JSRegExp> regexp) {
// (re.global?"g":"") + (re.ignorecase?"i":"") + (re.multiline?"m":"")
Log::MessageBuilder msg(log_);
Handle<Object> source = GetProperty(regexp, "source").ToHandleChecked();
Handle<Object> source = Object::GetProperty(
isolate_, regexp, "source").ToHandleChecked();
if (!source->IsString()) {
msg.Append("no source");
return;
@ -1168,18 +1169,20 @@ void Logger::LogRegExpSource(Handle<JSRegExp> regexp) {
msg.Append('/');
// global flag
Handle<Object> global = GetProperty(regexp, "global").ToHandleChecked();
Handle<Object> global = Object::GetProperty(
isolate_, regexp, "global").ToHandleChecked();
if (global->IsTrue()) {
msg.Append('g');
}
// ignorecase flag
Handle<Object> ignorecase =
GetProperty(regexp, "ignoreCase").ToHandleChecked();
Handle<Object> ignorecase = Object::GetProperty(
isolate_, regexp, "ignoreCase").ToHandleChecked();
if (ignorecase->IsTrue()) {
msg.Append('i');
}
// multiline flag
Handle<Object> multiline = GetProperty(regexp, "multiline").ToHandleChecked();
Handle<Object> multiline = Object::GetProperty(
isolate_, regexp, "multiline").ToHandleChecked();
if (multiline->IsTrue()) {
msg.Append('m');
}
@ -1905,9 +1908,9 @@ void Logger::LogExistingFunction(Handle<SharedFunctionInfo> shared,
Handle<String> func_name(shared->DebugName());
if (shared->script()->IsScript()) {
Handle<Script> script(Script::cast(shared->script()));
int line_num = GetScriptLineNumber(script, shared->start_position()) + 1;
int line_num = Script::GetLineNumber(script, shared->start_position()) + 1;
int column_num =
GetScriptColumnNumber(script, shared->start_position()) + 1;
Script::GetColumnNumber(script, shared->start_position()) + 1;
if (script->name()->IsString()) {
Handle<String> script_name(String::cast(script->name()));
if (line_num > 0) {

View File

@ -78,7 +78,7 @@ Handle<JSMessageObject> MessageHandler::MakeMessageObject(
if (loc) {
start = loc->start_pos();
end = loc->end_pos();
script_handle = GetScriptWrapper(loc->script());
script_handle = Script::GetWrapper(loc->script());
}
Handle<Object> stack_frames_handle = stack_frames.is_null()

View File

@ -1106,6 +1106,19 @@ MaybeHandle<Object> Object::GetPropertyOrElement(Handle<Object> object,
}
MaybeHandle<Object> Object::GetProperty(Isolate* isolate,
Handle<Object> object,
const char* name) {
Handle<String> str = isolate->factory()->InternalizeUtf8String(name);
ASSERT(!str.is_null());
#ifdef DEBUG
uint32_t index; // Assert that the name is not an array index.
ASSERT(!str->AsArrayIndex(&index));
#endif // DEBUG
return GetProperty(object, str);
}
MaybeHandle<Object> JSProxy::GetElementWithHandler(Handle<JSProxy> proxy,
Handle<Object> receiver,
uint32_t index) {

View File

@ -49,6 +49,7 @@
#include "macro-assembler.h"
#include "mark-compact.h"
#include "safepoint-table.h"
#include "string-search.h"
#include "string-stream.h"
#include "utils.h"
@ -6239,6 +6240,247 @@ void JSObject::LookupCallbackProperty(Name* name, LookupResult* result) {
}
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;
}
static 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;
}
static Handle<FixedArray> GetEnumPropertyKeys(Handle<JSObject> object,
bool cache_result) {
Isolate* isolate = object->GetIsolate();
if (object->HasFastProperties()) {
int own_property_count = object->map()->EnumLength();
// If 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 or
// SYMBOLIC.
if (own_property_count == kInvalidEnumCacheSentinel) {
own_property_count = object->map()->NumberOfDescribedProperties(
OWN_DESCRIPTORS, DONT_SHOW);
} else {
ASSERT(own_property_count == object->map()->NumberOfDescribedProperties(
OWN_DESCRIPTORS, DONT_SHOW));
}
if (object->map()->instance_descriptors()->HasEnumCache()) {
DescriptorArray* desc = object->map()->instance_descriptors();
Handle<FixedArray> keys(desc->GetEnumCache(), isolate);
// 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()) {
if (cache_result) object->map()->SetEnumLength(own_property_count);
isolate->counters()->enum_cache_hits()->Increment();
return ReduceFixedArrayTo(keys, own_property_count);
}
}
Handle<Map> map(object->map());
if (map->instance_descriptors()->IsEmpty()) {
isolate->counters()->enum_cache_hits()->Increment();
if (cache_result) map->SetEnumLength(0);
return isolate->factory()->empty_fixed_array();
}
isolate->counters()->enum_cache_misses()->Increment();
Handle<FixedArray> storage = isolate->factory()->NewFixedArray(
own_property_count);
Handle<FixedArray> indices = isolate->factory()->NewFixedArray(
own_property_count);
Handle<DescriptorArray> descs =
Handle<DescriptorArray>(object->map()->instance_descriptors(), isolate);
int size = map->NumberOfOwnDescriptors();
int index = 0;
for (int i = 0; i < size; i++) {
PropertyDetails details = descs->GetDetails(i);
Object* key = descs->GetKey(i);
if (!(details.IsDontEnum() || key->IsSymbol())) {
storage->set(index, key);
if (!indices.is_null()) {
if (details.type() != FIELD) {
indices = Handle<FixedArray>();
} else {
int field_index = descs->GetFieldIndex(i);
if (field_index >= map->inobject_properties()) {
field_index = -(field_index - map->inobject_properties() + 1);
}
field_index = field_index << 1;
if (details.representation().IsDouble()) {
field_index |= 1;
}
indices->set(index, Smi::FromInt(field_index));
}
}
index++;
}
}
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));
if (cache_result) {
object->map()->SetEnumLength(own_property_count);
}
return storage;
} else {
Handle<NameDictionary> dictionary(object->property_dictionary());
int length = dictionary->NumberOfEnumElements();
if (length == 0) {
return Handle<FixedArray>(isolate->heap()->empty_fixed_array());
}
Handle<FixedArray> storage = isolate->factory()->NewFixedArray(length);
dictionary->CopyEnumKeysTo(*storage);
return storage;
}
}
MaybeHandle<FixedArray> JSReceiver::GetKeys(Handle<JSReceiver> object,
KeyCollectionType type) {
USE(ContainsOnlyValidKeys);
Isolate* isolate = object->GetIsolate();
Handle<FixedArray> content = isolate->factory()->empty_fixed_array();
Handle<JSObject> arguments_boilerplate = Handle<JSObject>(
isolate->context()->native_context()->sloppy_arguments_boilerplate(),
isolate);
Handle<JSFunction> arguments_function = Handle<JSFunction>(
JSFunction::cast(arguments_boilerplate->map()->constructor()),
isolate);
// Only collect keys if access is permitted.
for (Handle<Object> p = object;
*p != isolate->heap()->null_value();
p = Handle<Object>(p->GetPrototype(isolate), isolate)) {
if (p->IsJSProxy()) {
Handle<JSProxy> proxy(JSProxy::cast(*p), isolate);
Handle<Object> args[] = { proxy };
Handle<Object> names;
ASSIGN_RETURN_ON_EXCEPTION(
isolate, names,
Execution::Call(isolate,
isolate->proxy_enumerate(),
object,
ARRAY_SIZE(args),
args),
FixedArray);
ASSIGN_RETURN_ON_EXCEPTION(
isolate, content,
FixedArray::AddKeysFromJSArray(
content, Handle<JSArray>::cast(names)),
FixedArray);
break;
}
Handle<JSObject> current(JSObject::cast(*p), isolate);
// Check access rights if required.
if (current->IsAccessCheckNeeded() &&
!isolate->MayNamedAccess(
current, isolate->factory()->undefined_value(), v8::ACCESS_KEYS)) {
isolate->ReportFailedAccessCheck(current, v8::ACCESS_KEYS);
RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, FixedArray);
break;
}
// Compute the element keys.
Handle<FixedArray> element_keys =
isolate->factory()->NewFixedArray(current->NumberOfEnumElements());
current->GetEnumElementKeys(*element_keys);
ASSIGN_RETURN_ON_EXCEPTION(
isolate, content,
FixedArray::UnionOfKeys(content, element_keys),
FixedArray);
ASSERT(ContainsOnlyValidKeys(content));
// Add the element keys from the interceptor.
if (current->HasIndexedInterceptor()) {
Handle<JSArray> result;
if (JSObject::GetKeysForIndexedInterceptor(
current, object).ToHandle(&result)) {
ASSIGN_RETURN_ON_EXCEPTION(
isolate, content,
FixedArray::AddKeysFromJSArray(content, result),
FixedArray);
}
ASSERT(ContainsOnlyValidKeys(content));
}
// 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.
// 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.
bool cache_enum_keys =
((current->map()->constructor() != *arguments_function) &&
!current->IsJSValue() &&
!current->IsAccessCheckNeeded() &&
!current->HasNamedInterceptor() &&
!current->HasIndexedInterceptor());
// Compute the property keys and cache them if possible.
ASSIGN_RETURN_ON_EXCEPTION(
isolate, content,
FixedArray::UnionOfKeys(
content, GetEnumPropertyKeys(current, cache_enum_keys)),
FixedArray);
ASSERT(ContainsOnlyValidKeys(content));
// Add the property keys from the interceptor.
if (current->HasNamedInterceptor()) {
Handle<JSArray> result;
if (JSObject::GetKeysForNamedInterceptor(
current, object).ToHandle(&result)) {
ASSIGN_RETURN_ON_EXCEPTION(
isolate, content,
FixedArray::AddKeysFromJSArray(content, result),
FixedArray);
}
ASSERT(ContainsOnlyValidKeys(content));
}
// If we only want local properties we bail out after the first
// iteration.
if (type == LOCAL_ONLY) break;
}
return content;
}
// Try to update an accessor in an elements dictionary. Return true if the
// update succeeded, and false otherwise.
static bool UpdateGetterSetterInDictionary(
@ -8901,6 +9143,64 @@ void String::WriteToFlat(String* src,
}
template <typename SourceChar>
static void CalculateLineEndsImpl(Isolate* isolate,
List<int>* line_ends,
Vector<const SourceChar> src,
bool include_ending_line) {
const int src_len = src.length();
StringSearch<uint8_t, SourceChar> search(isolate, STATIC_ASCII_VECTOR("\n"));
// Find and record line ends.
int position = 0;
while (position != -1 && position < src_len) {
position = search.Search(src, position);
if (position != -1) {
line_ends->Add(position);
position++;
} else if (include_ending_line) {
// Even if the last line misses a line end, it is counted.
line_ends->Add(src_len);
return;
}
}
}
Handle<FixedArray> String::CalculateLineEnds(Handle<String> src,
bool include_ending_line) {
src = Flatten(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);
Isolate* isolate = src->GetIsolate();
{ DisallowHeapAllocation no_allocation; // ensure vectors stay valid.
// Dispatch on type of strings.
String::FlatContent content = src->GetFlatContent();
ASSERT(content.IsFlat());
if (content.IsAscii()) {
CalculateLineEndsImpl(isolate,
&line_ends,
content.ToOneByteVector(),
include_ending_line);
} else {
CalculateLineEndsImpl(isolate,
&line_ends,
content.ToUC16Vector(),
include_ending_line);
}
}
int line_count = line_ends.length();
Handle<FixedArray> array = isolate->factory()->NewFixedArray(line_count);
for (int i = 0; i < line_count; i++) {
array->set(i, Smi::FromInt(line_ends[i]));
}
return array;
}
// Compares the contents of two strings by reading and comparing
// int-sized blocks of characters.
template <typename Char>
@ -10110,6 +10410,161 @@ MaybeObject* Oddball::Initialize(Heap* heap,
}
void Script::InitLineEnds(Handle<Script> script) {
if (!script->line_ends()->IsUndefined()) return;
Isolate* isolate = script->GetIsolate();
if (!script->source()->IsString()) {
ASSERT(script->source()->IsUndefined());
Handle<FixedArray> empty = isolate->factory()->NewFixedArray(0);
script->set_line_ends(*empty);
ASSERT(script->line_ends()->IsFixedArray());
return;
}
Handle<String> src(String::cast(script->source()), isolate);
Handle<FixedArray> array = String::CalculateLineEnds(src, true);
if (*array != isolate->heap()->empty_fixed_array()) {
array->set_map(isolate->heap()->fixed_cow_array_map());
}
script->set_line_ends(*array);
ASSERT(script->line_ends()->IsFixedArray());
}
int Script::GetColumnNumber(Handle<Script> script, int code_pos) {
int line_number = GetLineNumber(script, code_pos);
if (line_number == -1) return -1;
DisallowHeapAllocation 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);
}
int Script::GetLineNumberWithArray(int code_pos) {
DisallowHeapAllocation no_allocation;
ASSERT(line_ends()->IsFixedArray());
FixedArray* line_ends_array = FixedArray::cast(line_ends());
int line_ends_len = line_ends_array->length();
if (line_ends_len == 0) return -1;
if ((Smi::cast(line_ends_array->get(0)))->value() >= code_pos) {
return line_offset()->value();
}
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;
}
}
return right + line_offset()->value();
}
int Script::GetLineNumber(Handle<Script> script, int code_pos) {
InitLineEnds(script);
return script->GetLineNumberWithArray(code_pos);
}
int Script::GetLineNumber(int code_pos) {
DisallowHeapAllocation no_allocation;
if (!line_ends()->IsUndefined()) return GetLineNumberWithArray(code_pos);
// Slow mode: we do not have line_ends. We have to iterate through source.
if (!source()->IsString()) return -1;
String* source_string = String::cast(source());
int line = 0;
int len = source_string->length();
for (int pos = 0; pos < len; pos++) {
if (pos == code_pos) break;
if (source_string->Get(pos) == '\n') line++;
}
return line;
}
Handle<Object> Script::GetNameOrSourceURL(Handle<Script> script) {
Isolate* isolate = script->GetIsolate();
Handle<String> name_or_source_url_key =
isolate->factory()->InternalizeOneByteString(
STATIC_ASCII_VECTOR("nameOrSourceURL"));
Handle<JSObject> script_wrapper = Script::GetWrapper(script);
Handle<Object> property = Object::GetProperty(
script_wrapper, name_or_source_url_key).ToHandleChecked();
ASSERT(property->IsJSFunction());
Handle<JSFunction> method = Handle<JSFunction>::cast(property);
Handle<Object> result;
// Do not check against pending exception, since this function may be called
// when an exception has already been pending.
if (!Execution::TryCall(method, script_wrapper, 0, NULL).ToHandle(&result)) {
return isolate->factory()->undefined_value();
}
return result;
}
// Wrappers for scripts are kept alive and cached in weak global
// handles referred from foreign objects held by the scripts as long as
// 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.
static void ClearWrapperCache(
const v8::WeakCallbackData<v8::Value, void>& data) {
Object** location = reinterpret_cast<Object**>(data.GetParameter());
JSValue* wrapper = JSValue::cast(*location);
Foreign* foreign = Script::cast(wrapper->value())->wrapper();
ASSERT_EQ(foreign->foreign_address(), reinterpret_cast<Address>(location));
foreign->set_foreign_address(0);
GlobalHandles::Destroy(location);
Isolate* isolate = reinterpret_cast<Isolate*>(data.GetIsolate());
isolate->counters()->script_wrappers()->Decrement();
}
Handle<JSObject> Script::GetWrapper(Handle<Script> script) {
if (script->wrapper()->foreign_address() != NULL) {
// Return a handle for the existing script wrapper from the cache.
return Handle<JSValue>(
*reinterpret_cast<JSValue**>(script->wrapper()->foreign_address()));
}
Isolate* isolate = script->GetIsolate();
// Construct a new script wrapper.
isolate->counters()->script_wrappers()->Increment();
Handle<JSFunction> constructor = isolate->script_function();
Handle<JSValue> result =
Handle<JSValue>::cast(isolate->factory()->NewJSObject(constructor));
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.
Handle<Object> handle = isolate->global_handles()->Create(*result);
GlobalHandles::MakeWeak(handle.location(),
reinterpret_cast<void*>(handle.location()),
&ClearWrapperCache);
script->wrapper()->set_foreign_address(
reinterpret_cast<Address>(handle.location()));
return result;
}
String* SharedFunctionInfo::DebugName() {
Object* n = name();
if (!n->IsString() || String::cast(n)->length() == 0) return inferred_name();
@ -13437,6 +13892,55 @@ MaybeHandle<Object> JSObject::GetPropertyWithInterceptor(
}
// Compute the property keys from the interceptor.
// TODO(rossberg): support symbols in API, and filter here if needed.
MaybeHandle<JSArray> JSObject::GetKeysForNamedInterceptor(
Handle<JSObject> object, Handle<JSReceiver> receiver) {
Isolate* isolate = receiver->GetIsolate();
Handle<InterceptorInfo> interceptor(object->GetNamedInterceptor());
PropertyCallbackArguments
args(isolate, interceptor->data(), *receiver, *object);
v8::Handle<v8::Array> result;
if (!interceptor->enumerator()->IsUndefined()) {
v8::NamedPropertyEnumeratorCallback enum_fun =
v8::ToCData<v8::NamedPropertyEnumeratorCallback>(
interceptor->enumerator());
LOG(isolate, ApiObjectAccess("interceptor-named-enum", *object));
result = args.Call(enum_fun);
}
if (result.IsEmpty()) return MaybeHandle<JSArray>();
#if ENABLE_EXTRA_CHECKS
CHECK(v8::Utils::OpenHandle(*result)->IsJSObject());
#endif
// Rebox before returning.
return handle(*v8::Utils::OpenHandle(*result), isolate);
}
// Compute the element keys from the interceptor.
MaybeHandle<JSArray> JSObject::GetKeysForIndexedInterceptor(
Handle<JSObject> object, Handle<JSReceiver> receiver) {
Isolate* isolate = receiver->GetIsolate();
Handle<InterceptorInfo> interceptor(object->GetIndexedInterceptor());
PropertyCallbackArguments
args(isolate, interceptor->data(), *receiver, *object);
v8::Handle<v8::Array> result;
if (!interceptor->enumerator()->IsUndefined()) {
v8::IndexedPropertyEnumeratorCallback enum_fun =
v8::ToCData<v8::IndexedPropertyEnumeratorCallback>(
interceptor->enumerator());
LOG(isolate, ApiObjectAccess("interceptor-indexed-enum", *object));
result = args.Call(enum_fun);
}
if (result.IsEmpty()) return MaybeHandle<JSArray>();
#if ENABLE_EXTRA_CHECKS
CHECK(v8::Utils::OpenHandle(*result)->IsJSObject());
#endif
// Rebox before returning.
return handle(*v8::Utils::OpenHandle(*result), isolate);
}
bool JSObject::HasRealNamedProperty(Handle<JSObject> object,
Handle<Name> key) {
Isolate* isolate = object->GetIsolate();

View File

@ -1535,7 +1535,10 @@ class Object : public MaybeObject {
MUST_USE_RESULT static inline MaybeHandle<Object> GetPropertyOrElement(
Handle<Object> object,
Handle<Name> key);
MUST_USE_RESULT static inline MaybeHandle<Object> GetProperty(
Isolate* isolate,
Handle<Object> object,
const char* key);
MUST_USE_RESULT static inline MaybeHandle<Object> GetProperty(
Handle<Object> object,
Handle<Name> key);
@ -2108,6 +2111,14 @@ class JSReceiver: public HeapObject {
bool search_hidden_prototypes = false);
void Lookup(Name* name, LookupResult* result);
enum KeyCollectionType { LOCAL_ONLY, INCLUDE_PROTOS };
// Computes the enumerable keys for a JSObject. Used for implementing
// "for (n in object) { }".
MUST_USE_RESULT static MaybeHandle<FixedArray> GetKeys(
Handle<JSReceiver> object,
KeyCollectionType type);
protected:
Smi* GenerateIdentityHash();
@ -2523,6 +2534,15 @@ class JSObject: public JSReceiver {
inline bool HasNamedInterceptor();
inline bool HasIndexedInterceptor();
// Computes the enumerable keys from interceptors. Used for debug mirrors and
// by JSReceiver::GetKeys.
MUST_USE_RESULT static MaybeHandle<JSArray> GetKeysForNamedInterceptor(
Handle<JSObject> object,
Handle<JSReceiver> receiver);
MUST_USE_RESULT static MaybeHandle<JSArray> GetKeysForIndexedInterceptor(
Handle<JSObject> object,
Handle<JSReceiver> receiver);
// Support functions for v8 api (needed for correct interceptor behavior).
static bool HasRealNamedProperty(Handle<JSObject> object,
Handle<Name> key);
@ -6841,6 +6861,22 @@ class Script: public Struct {
// resource is accessible. Otherwise, always return true.
inline bool HasValidSource();
// Convert code position into column number.
static int GetColumnNumber(Handle<Script> script, int code_pos);
// Convert code position into (zero-based) line number.
// The non-handlified version does not allocate, but may be much slower.
static int GetLineNumber(Handle<Script> script, int code_pos);
int GetLineNumber(int code_pos);
static Handle<Object> GetNameOrSourceURL(Handle<Script> script);
// Init line_ends array with code positions of line ends inside script source.
static void InitLineEnds(Handle<Script> script);
// Get the JS object wrapping the given script; create it if none exists.
static Handle<JSObject> GetWrapper(Handle<Script> script);
// Dispatched behavior.
DECLARE_PRINTER(Script)
DECLARE_VERIFIER(Script)
@ -6862,6 +6898,8 @@ class Script: public Struct {
static const int kSize = kFlagsOffset + kPointerSize;
private:
int GetLineNumberWithArray(int code_pos);
// Bit positions in the flags field.
static const int kCompilationTypeBit = 0;
static const int kCompilationStateBit = 1;
@ -9239,6 +9277,9 @@ class String: public Name {
return VisitFlat(visitor, string, offset, string->length(), type);
}
static Handle<FixedArray> CalculateLineEnds(Handle<String> string,
bool include_ending_line);
private:
friend class Name;

View File

@ -2870,7 +2870,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_FunctionGetScript) {
Handle<Object> script = Handle<Object>(fun->shared()->script(), isolate);
if (!script->IsScript()) return isolate->heap()->undefined_value();
return *GetScriptWrapper(Handle<Script>::cast(script));
return *Script::GetWrapper(Handle<Script>::cast(script));
}
@ -5727,7 +5727,8 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_GetPropertyNames) {
isolate->counters()->for_in()->Increment();
Handle<FixedArray> elements;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
isolate, elements, GetKeysInFixedArrayFor(object, INCLUDE_PROTOS));
isolate, elements,
JSReceiver::GetKeys(object, JSReceiver::INCLUDE_PROTOS));
return *isolate->factory()->NewJSArrayWithElements(elements);
}
@ -5749,7 +5750,8 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_GetPropertyNamesFast) {
Handle<JSReceiver> object(raw_object);
Handle<FixedArray> content;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
isolate, content, GetKeysInFixedArrayFor(object, INCLUDE_PROTOS));
isolate, content,
JSReceiver::GetKeys(object, JSReceiver::INCLUDE_PROTOS));
// Test again, since cache may have been built by preceding call.
if (object->IsSimpleEnum()) return object->map();
@ -5931,8 +5933,10 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_GetNamedInterceptorPropertyNames) {
CONVERT_ARG_HANDLE_CHECKED(JSObject, obj, 0);
if (obj->HasNamedInterceptor()) {
v8::Handle<v8::Array> result = GetKeysForNamedInterceptor(obj, obj);
if (!result.IsEmpty()) return *v8::Utils::OpenHandle(*result);
Handle<JSArray> result;
if (JSObject::GetKeysForNamedInterceptor(obj, obj).ToHandle(&result)) {
return *result;
}
}
return isolate->heap()->undefined_value();
}
@ -5946,8 +5950,10 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_GetIndexedInterceptorElementNames) {
CONVERT_ARG_HANDLE_CHECKED(JSObject, obj, 0);
if (obj->HasIndexedInterceptor()) {
v8::Handle<v8::Array> result = GetKeysForIndexedInterceptor(obj, obj);
if (!result.IsEmpty()) return *v8::Utils::OpenHandle(*result);
Handle<JSArray> result;
if (JSObject::GetKeysForIndexedInterceptor(obj, obj).ToHandle(&result)) {
return *result;
}
}
return isolate->heap()->undefined_value();
}
@ -5977,7 +5983,8 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_LocalKeys) {
Handle<FixedArray> contents;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
isolate, contents, GetKeysInFixedArrayFor(object, LOCAL_ONLY));
isolate, contents,
JSReceiver::GetKeys(object, JSReceiver::LOCAL_ONLY));
// Some fast paths through GetKeysInFixedArrayFor reuse a cached
// property array and since the result is mutable we have to create
@ -11448,7 +11455,9 @@ MUST_USE_RESULT static MaybeHandle<JSObject> MaterializeLocalContext(
Handle<JSObject> ext(JSObject::cast(function_context->extension()));
Handle<FixedArray> keys;
ASSIGN_RETURN_ON_EXCEPTION(
isolate, keys, GetKeysInFixedArrayFor(ext, INCLUDE_PROTOS), JSObject);
isolate, keys,
JSReceiver::GetKeys(ext, JSReceiver::INCLUDE_PROTOS),
JSObject);
for (int i = 0; i < keys->length(); i++) {
// Names of variables introduced by eval are strings.
@ -11603,7 +11612,8 @@ MUST_USE_RESULT static MaybeHandle<JSObject> MaterializeClosure(
Handle<JSObject> ext(JSObject::cast(context->extension()));
Handle<FixedArray> keys;
ASSIGN_RETURN_ON_EXCEPTION(
isolate, keys, GetKeysInFixedArrayFor(ext, INCLUDE_PROTOS), JSObject);
isolate, keys,
JSReceiver::GetKeys(ext, JSReceiver::INCLUDE_PROTOS), JSObject);
for (int i = 0; i < keys->length(); i++) {
HandleScope scope(isolate);
@ -12937,7 +12947,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_DebugGetLoadedScripts) {
// instances->set(i, *GetScriptWrapper(script))
// is unsafe as GetScriptWrapper might call GC and the C++ compiler might
// already have dereferenced the instances handle.
Handle<JSValue> wrapper = GetScriptWrapper(script);
Handle<JSObject> wrapper = Script::GetWrapper(script);
instances->set(i, *wrapper);
}
@ -13348,7 +13358,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditReplaceScript) {
if (old_script->IsScript()) {
Handle<Script> script_handle = Handle<Script>::cast(old_script);
return *(GetScriptWrapper(script_handle));
return *Script::GetWrapper(script_handle);
} else {
return isolate->heap()->null_value();
}
@ -14364,7 +14374,7 @@ static Handle<Object> Runtime_GetScriptFromScriptName(
if (script.is_null()) return factory->undefined_value();
// Return the script found.
return GetScriptWrapper(script);
return Script::GetWrapper(script);
}

View File

@ -38,10 +38,8 @@ using namespace v8::internal;
static Handle<Object> GetGlobalProperty(const char* name) {
Isolate* isolate = CcTest::i_isolate();
Handle<String> internalized_name =
isolate->factory()->InternalizeUtf8String(name);
return Object::GetProperty(
isolate->global_object(), internalized_name).ToHandleChecked();
isolate, isolate->global_object(), name).ToHandleChecked();
}
@ -259,9 +257,9 @@ TEST(Regression236) {
Handle<Script> script = factory->NewScript(factory->empty_string());
script->set_source(CcTest::heap()->undefined_value());
CHECK_EQ(-1, GetScriptLineNumber(script, 0));
CHECK_EQ(-1, GetScriptLineNumber(script, 100));
CHECK_EQ(-1, GetScriptLineNumber(script, -1));
CHECK_EQ(-1, Script::GetLineNumber(script, 0));
CHECK_EQ(-1, Script::GetLineNumber(script, 100));
CHECK_EQ(-1, Script::GetLineNumber(script, -1));
}

View File

@ -7510,7 +7510,7 @@ static void DebugBreakInlineListener(
OS::SNPrintF(script_vector, "%%GetFrameDetails(%d, %d)[5]", break_id, i);
v8::Local<v8::Value> result = CompileRun(script);
CHECK_EQ(expected_line_number[i],
i::GetScriptLineNumber(source_script, result->Int32Value()));
i::Script::GetLineNumber(source_script, result->Int32Value()));
}
v8::Debug::SetDebugEventListener2(NULL);
v8::V8::TerminateExecution(CcTest::isolate());

View File

@ -407,20 +407,19 @@ TEST(ObservationWeakMap) {
"Object.observe(obj, function(){});"
"Object.getNotifier(obj);"
"obj = null;");
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(CcTest::isolate());
i::Isolate* i_isolate = CcTest::i_isolate();
i::Handle<i::JSObject> observation_state =
i_isolate->factory()->observation_state();
i::Handle<i::JSWeakMap> callbackInfoMap =
i::Handle<i::JSWeakMap>::cast(
i::GetProperty(
observation_state, "callbackInfoMap").ToHandleChecked());
i::Handle<i::JSWeakMap>::cast(i::Object::GetProperty(
i_isolate, observation_state, "callbackInfoMap").ToHandleChecked());
i::Handle<i::JSWeakMap> objectInfoMap =
i::Handle<i::JSWeakMap>::cast(
i::GetProperty(observation_state, "objectInfoMap").ToHandleChecked());
i::Handle<i::JSWeakMap>::cast(i::Object::GetProperty(
i_isolate, observation_state, "objectInfoMap").ToHandleChecked());
i::Handle<i::JSWeakMap> notifierObjectInfoMap =
i::Handle<i::JSWeakMap>::cast(
i::GetProperty(
observation_state, "notifierObjectInfoMap").ToHandleChecked());
i::Handle<i::JSWeakMap>::cast(i::Object::GetProperty(
i_isolate, observation_state, "notifierObjectInfoMap")
.ToHandleChecked());
CHECK_EQ(1, NumberOfElements(callbackInfoMap));
CHECK_EQ(1, NumberOfElements(objectInfoMap));
CHECK_EQ(1, NumberOfElements(notifierObjectInfoMap));

View File

@ -1254,8 +1254,8 @@ i::Handle<i::String> FormatMessage(i::ScriptData* data) {
NONE, i::SLOPPY).Check();
}
i::Handle<i::JSObject> builtins(isolate->js_builtins_object());
i::Handle<i::Object> format_fun =
i::GetProperty(builtins, "FormatMessage").ToHandleChecked();
i::Handle<i::Object> format_fun = i::Object::GetProperty(
isolate, builtins, "FormatMessage").ToHandleChecked();
i::Handle<i::Object> arg_handles[] = { format, args_array };
i::Handle<i::Object> result = i::Execution::Call(
isolate, format_fun, builtins, 2, arg_handles).ToHandleChecked();
@ -1340,8 +1340,8 @@ void TestParserSyncWithFlags(i::Handle<i::String> source,
i::Handle<i::JSObject> exception_handle(
i::JSObject::cast(isolate->pending_exception()));
i::Handle<i::String> message_string =
i::Handle<i::String>::cast(
i::GetProperty(exception_handle, "message").ToHandleChecked());
i::Handle<i::String>::cast(i::Object::GetProperty(
isolate, exception_handle, "message").ToHandleChecked());
if (result == kSuccess) {
i::OS::Print(