Commit ba6e17c4 authored by yangguo@chromium.org's avatar yangguo@chromium.org

Split off remaining runtime functions in runtime.cc.

R=bmeurer@chromium.org

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

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@24533 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 39600838
......@@ -825,19 +825,23 @@ source_set("v8_base") {
"src/rewriter.h",
"src/runtime-profiler.cc",
"src/runtime-profiler.h",
"src/runtime/runtime-api.cc",
"src/runtime/runtime-array.cc",
"src/runtime/runtime-classes.cc",
"src/runtime/runtime-collections.cc",
"src/runtime/runtime-compiler.cc",
"src/runtime/runtime-i18n.cc",
"src/runtime/runtime-date.cc",
"src/runtime/runtime-debug.cc",
"src/runtime/runtime-function.cc",
"src/runtime/runtime-generator.cc",
"src/runtime/runtime-i18n.cc",
"src/runtime/runtime-internal.cc",
"src/runtime/runtime-json.cc",
"src/runtime/runtime-literals.cc",
"src/runtime/runtime-liveedit.cc",
"src/runtime/runtime-maths.cc",
"src/runtime/runtime-numbers.cc",
"src/runtime/runtime-object.cc",
"src/runtime/runtime-observe.cc",
"src/runtime/runtime-proxy.cc",
"src/runtime/runtime-regexp.cc",
......
......@@ -254,7 +254,7 @@ macro OVERRIDE_SUBJECT(override) = ((override)[(override).length - 1]);
macro OVERRIDE_CAPTURE(override, index) = ((override)[(index)]);
# PropertyDescriptor return value indices - must match
# PropertyDescriptorIndices in runtime.cc.
# PropertyDescriptorIndices in runtime-object.cc.
const IS_ACCESSOR_INDEX = 0;
const VALUE_INDEX = 1;
const GETTER_INDEX = 2;
......
// Copyright 2014 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/v8.h"
#include "src/arguments.h"
#include "src/bootstrapper.h"
#include "src/runtime/runtime.h"
#include "src/runtime/runtime-utils.h"
namespace v8 {
namespace internal {
RUNTIME_FUNCTION(Runtime_CreateApiFunction) {
HandleScope scope(isolate);
DCHECK(args.length() == 2);
CONVERT_ARG_HANDLE_CHECKED(FunctionTemplateInfo, data, 0);
CONVERT_ARG_HANDLE_CHECKED(Object, prototype, 1);
return *isolate->factory()->CreateApiFunction(data, prototype);
}
RUNTIME_FUNCTION(Runtime_IsTemplate) {
SealHandleScope shs(isolate);
DCHECK(args.length() == 1);
CONVERT_ARG_HANDLE_CHECKED(Object, arg, 0);
bool result = arg->IsObjectTemplateInfo() || arg->IsFunctionTemplateInfo();
return isolate->heap()->ToBoolean(result);
}
RUNTIME_FUNCTION(Runtime_GetTemplateField) {
SealHandleScope shs(isolate);
DCHECK(args.length() == 2);
CONVERT_ARG_CHECKED(HeapObject, templ, 0);
CONVERT_SMI_ARG_CHECKED(index, 1);
int offset = index * kPointerSize + HeapObject::kHeaderSize;
InstanceType type = templ->map()->instance_type();
RUNTIME_ASSERT(type == FUNCTION_TEMPLATE_INFO_TYPE ||
type == OBJECT_TEMPLATE_INFO_TYPE);
RUNTIME_ASSERT(offset > 0);
if (type == FUNCTION_TEMPLATE_INFO_TYPE) {
RUNTIME_ASSERT(offset < FunctionTemplateInfo::kSize);
} else {
RUNTIME_ASSERT(offset < ObjectTemplateInfo::kSize);
}
return *HeapObject::RawField(templ, offset);
}
// Transform getter or setter into something DefineAccessor can handle.
static Handle<Object> InstantiateAccessorComponent(Isolate* isolate,
Handle<Object> component) {
if (component->IsUndefined()) return isolate->factory()->undefined_value();
Handle<FunctionTemplateInfo> info =
Handle<FunctionTemplateInfo>::cast(component);
return Utils::OpenHandle(*Utils::ToLocal(info)->GetFunction());
}
RUNTIME_FUNCTION(Runtime_DefineApiAccessorProperty) {
HandleScope scope(isolate);
DCHECK(args.length() == 5);
CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0);
CONVERT_ARG_HANDLE_CHECKED(Name, name, 1);
CONVERT_ARG_HANDLE_CHECKED(Object, getter, 2);
CONVERT_ARG_HANDLE_CHECKED(Object, setter, 3);
CONVERT_SMI_ARG_CHECKED(attribute, 4);
RUNTIME_ASSERT(getter->IsUndefined() || getter->IsFunctionTemplateInfo());
RUNTIME_ASSERT(setter->IsUndefined() || setter->IsFunctionTemplateInfo());
RUNTIME_ASSERT(PropertyDetails::AttributesField::is_valid(
static_cast<PropertyAttributes>(attribute)));
RETURN_FAILURE_ON_EXCEPTION(
isolate, JSObject::DefineAccessor(
object, name, InstantiateAccessorComponent(isolate, getter),
InstantiateAccessorComponent(isolate, setter),
static_cast<PropertyAttributes>(attribute)));
return isolate->heap()->undefined_value();
}
RUNTIME_FUNCTION(Runtime_AddPropertyForTemplate) {
HandleScope scope(isolate);
RUNTIME_ASSERT(args.length() == 4);
CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0);
CONVERT_ARG_HANDLE_CHECKED(Object, key, 1);
CONVERT_ARG_HANDLE_CHECKED(Object, value, 2);
CONVERT_SMI_ARG_CHECKED(unchecked_attributes, 3);
RUNTIME_ASSERT(
(unchecked_attributes & ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) == 0);
// Compute attributes.
PropertyAttributes attributes =
static_cast<PropertyAttributes>(unchecked_attributes);
#ifdef DEBUG
bool duplicate;
if (key->IsName()) {
LookupIterator it(object, Handle<Name>::cast(key),
LookupIterator::OWN_SKIP_INTERCEPTOR);
Maybe<PropertyAttributes> maybe = JSReceiver::GetPropertyAttributes(&it);
DCHECK(maybe.has_value);
duplicate = it.IsFound();
} else {
uint32_t index = 0;
RUNTIME_ASSERT(key->ToArrayIndex(&index));
Maybe<bool> maybe = JSReceiver::HasOwnElement(object, index);
if (!maybe.has_value) return isolate->heap()->exception();
duplicate = maybe.value;
}
if (duplicate) {
Handle<Object> args[1] = {key};
THROW_NEW_ERROR_RETURN_FAILURE(
isolate,
NewTypeError("duplicate_template_property", HandleVector(args, 1)));
}
#endif
Handle<Object> result;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
isolate, result,
Runtime::DefineObjectProperty(object, key, value, attributes));
return *result;
}
}
} // namespace v8::internal
This diff is collapsed.
......@@ -2732,5 +2732,11 @@ RUNTIME_FUNCTION(RuntimeReference_DebugIsActive) {
SealHandleScope shs(isolate);
return Smi::FromInt(isolate->debug()->is_active());
}
RUNTIME_FUNCTION(RuntimeReference_DebugBreakInOptimizedCode) {
UNIMPLEMENTED();
return NULL;
}
}
} // namespace v8::internal
// Copyright 2014 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/v8.h"
#include "src/arguments.h"
#include "src/bootstrapper.h"
#include "src/debug.h"
#include "src/runtime/runtime.h"
#include "src/runtime/runtime-utils.h"
namespace v8 {
namespace internal {
RUNTIME_FUNCTION(Runtime_CheckIsBootstrapping) {
SealHandleScope shs(isolate);
DCHECK(args.length() == 0);
RUNTIME_ASSERT(isolate->bootstrapper()->IsActive());
return isolate->heap()->undefined_value();
}
RUNTIME_FUNCTION(Runtime_Throw) {
HandleScope scope(isolate);
DCHECK(args.length() == 1);
return isolate->Throw(args[0]);
}
RUNTIME_FUNCTION(Runtime_ReThrow) {
HandleScope scope(isolate);
DCHECK(args.length() == 1);
return isolate->ReThrow(args[0]);
}
RUNTIME_FUNCTION(Runtime_PromoteScheduledException) {
SealHandleScope shs(isolate);
DCHECK(args.length() == 0);
return isolate->PromoteScheduledException();
}
RUNTIME_FUNCTION(Runtime_ThrowReferenceError) {
HandleScope scope(isolate);
DCHECK(args.length() == 1);
CONVERT_ARG_HANDLE_CHECKED(Object, name, 0);
THROW_NEW_ERROR_RETURN_FAILURE(
isolate, NewReferenceError("not_defined", HandleVector(&name, 1)));
}
RUNTIME_FUNCTION(Runtime_PromiseRejectEvent) {
DCHECK(args.length() == 3);
HandleScope scope(isolate);
CONVERT_ARG_HANDLE_CHECKED(JSObject, promise, 0);
CONVERT_ARG_HANDLE_CHECKED(Object, value, 1);
CONVERT_BOOLEAN_ARG_CHECKED(debug_event, 2);
if (debug_event) isolate->debug()->OnPromiseReject(promise, value);
Handle<Symbol> key = isolate->factory()->promise_has_handler_symbol();
// Do not report if we actually have a handler.
if (JSObject::GetDataProperty(promise, key)->IsUndefined()) {
isolate->ReportPromiseReject(promise, value,
v8::kPromiseRejectWithNoHandler);
}
return isolate->heap()->undefined_value();
}
RUNTIME_FUNCTION(Runtime_PromiseRevokeReject) {
DCHECK(args.length() == 1);
HandleScope scope(isolate);
CONVERT_ARG_HANDLE_CHECKED(JSObject, promise, 0);
Handle<Symbol> key = isolate->factory()->promise_has_handler_symbol();
// At this point, no revocation has been issued before
RUNTIME_ASSERT(JSObject::GetDataProperty(promise, key)->IsUndefined());
isolate->ReportPromiseReject(promise, Handle<Object>(),
v8::kPromiseHandlerAddedAfterReject);
return isolate->heap()->undefined_value();
}
RUNTIME_FUNCTION(Runtime_PromiseHasHandlerSymbol) {
DCHECK(args.length() == 0);
return isolate->heap()->promise_has_handler_symbol();
}
RUNTIME_FUNCTION(Runtime_StackGuard) {
SealHandleScope shs(isolate);
DCHECK(args.length() == 0);
// First check if this is a real stack overflow.
StackLimitCheck check(isolate);
if (check.JsHasOverflowed()) {
return isolate->StackOverflow();
}
return isolate->stack_guard()->HandleInterrupts();
}
RUNTIME_FUNCTION(Runtime_Interrupt) {
SealHandleScope shs(isolate);
DCHECK(args.length() == 0);
return isolate->stack_guard()->HandleInterrupts();
}
RUNTIME_FUNCTION(Runtime_AllocateInNewSpace) {
HandleScope scope(isolate);
DCHECK(args.length() == 1);
CONVERT_SMI_ARG_CHECKED(size, 0);
RUNTIME_ASSERT(IsAligned(size, kPointerSize));
RUNTIME_ASSERT(size > 0);
RUNTIME_ASSERT(size <= Page::kMaxRegularHeapObjectSize);
return *isolate->factory()->NewFillerObject(size, false, NEW_SPACE);
}
RUNTIME_FUNCTION(Runtime_AllocateInTargetSpace) {
HandleScope scope(isolate);
DCHECK(args.length() == 2);
CONVERT_SMI_ARG_CHECKED(size, 0);
CONVERT_SMI_ARG_CHECKED(flags, 1);
RUNTIME_ASSERT(IsAligned(size, kPointerSize));
RUNTIME_ASSERT(size > 0);
RUNTIME_ASSERT(size <= Page::kMaxRegularHeapObjectSize);
bool double_align = AllocateDoubleAlignFlag::decode(flags);
AllocationSpace space = AllocateTargetSpace::decode(flags);
return *isolate->factory()->NewFillerObject(size, double_align, space);
}
// Collect the raw data for a stack trace. Returns an array of 4
// element segments each containing a receiver, function, code and
// native code offset.
RUNTIME_FUNCTION(Runtime_CollectStackTrace) {
HandleScope scope(isolate);
DCHECK(args.length() == 2);
CONVERT_ARG_HANDLE_CHECKED(JSObject, error_object, 0);
CONVERT_ARG_HANDLE_CHECKED(Object, caller, 1);
if (!isolate->bootstrapper()->IsActive()) {
// Optionally capture a more detailed stack trace for the message.
isolate->CaptureAndSetDetailedStackTrace(error_object);
// Capture a simple stack trace for the stack property.
isolate->CaptureAndSetSimpleStackTrace(error_object, caller);
}
return isolate->heap()->undefined_value();
}
RUNTIME_FUNCTION(Runtime_GetFromCache) {
SealHandleScope shs(isolate);
// This is only called from codegen, so checks might be more lax.
CONVERT_ARG_CHECKED(JSFunctionResultCache, cache, 0);
CONVERT_ARG_CHECKED(Object, key, 1);
{
DisallowHeapAllocation no_alloc;
int finger_index = cache->finger_index();
Object* o = cache->get(finger_index);
if (o == key) {
// The fastest case: hit the same place again.
return cache->get(finger_index + 1);
}
for (int i = finger_index - 2; i >= JSFunctionResultCache::kEntriesIndex;
i -= 2) {
o = cache->get(i);
if (o == key) {
cache->set_finger_index(i);
return cache->get(i + 1);
}
}
int size = cache->size();
DCHECK(size <= cache->length());
for (int i = size - 2; i > finger_index; i -= 2) {
o = cache->get(i);
if (o == key) {
cache->set_finger_index(i);
return cache->get(i + 1);
}
}
}
// There is no value in the cache. Invoke the function and cache result.
HandleScope scope(isolate);
Handle<JSFunctionResultCache> cache_handle(cache);
Handle<Object> key_handle(key, isolate);
Handle<Object> value;
{
Handle<JSFunction> factory(JSFunction::cast(
cache_handle->get(JSFunctionResultCache::kFactoryIndex)));
// TODO(antonm): consider passing a receiver when constructing a cache.
Handle<JSObject> receiver(isolate->global_proxy());
// This handle is nor shared, nor used later, so it's safe.
Handle<Object> argv[] = {key_handle};
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
isolate, value,
Execution::Call(isolate, factory, receiver, arraysize(argv), argv));
}
#ifdef VERIFY_HEAP
if (FLAG_verify_heap) {
cache_handle->JSFunctionResultCacheVerify();
}
#endif
// Function invocation may have cleared the cache. Reread all the data.
int finger_index = cache_handle->finger_index();
int size = cache_handle->size();
// If we have spare room, put new data into it, otherwise evict post finger
// entry which is likely to be the least recently used.
int index = -1;
if (size < cache_handle->length()) {
cache_handle->set_size(size + JSFunctionResultCache::kEntrySize);
index = size;
} else {
index = finger_index + JSFunctionResultCache::kEntrySize;
if (index == cache_handle->length()) {
index = JSFunctionResultCache::kEntriesIndex;
}
}
DCHECK(index % 2 == 0);
DCHECK(index >= JSFunctionResultCache::kEntriesIndex);
DCHECK(index < cache_handle->length());
cache_handle->set(index, *key_handle);
cache_handle->set(index + 1, *value);
cache_handle->set_finger_index(index);
#ifdef VERIFY_HEAP
if (FLAG_verify_heap) {
cache_handle->JSFunctionResultCacheVerify();
}
#endif
return *value;
}
RUNTIME_FUNCTION(Runtime_MessageGetStartPosition) {
SealHandleScope shs(isolate);
DCHECK(args.length() == 1);
CONVERT_ARG_CHECKED(JSMessageObject, message, 0);
return Smi::FromInt(message->start_position());
}
RUNTIME_FUNCTION(Runtime_MessageGetScript) {
SealHandleScope shs(isolate);
DCHECK(args.length() == 1);
CONVERT_ARG_CHECKED(JSMessageObject, message, 0);
return message->script();
}
RUNTIME_FUNCTION(Runtime_IS_VAR) {
UNREACHABLE(); // implemented as macro in the parser
return NULL;
}
RUNTIME_FUNCTION(RuntimeReference_GetFromCache) {
HandleScope scope(isolate);
DCHECK(args.length() == 2);
CONVERT_SMI_ARG_CHECKED(id, 0);
args[0] = isolate->native_context()->jsfunction_result_caches()->get(id);
return __RT_impl_Runtime_GetFromCache(args, isolate);
}
}
} // namespace v8::internal
......@@ -5,6 +5,7 @@
#include "src/v8.h"
#include "src/arguments.h"
#include "src/bootstrapper.h"
#include "src/codegen.h"
#include "src/misc-intrinsics.h"
#include "src/runtime/runtime.h"
......@@ -557,6 +558,21 @@ RUNTIME_FUNCTION(Runtime_SmiLexicographicCompare) {
}
RUNTIME_FUNCTION(Runtime_GetRootNaN) {
SealHandleScope shs(isolate);
DCHECK(args.length() == 0);
RUNTIME_ASSERT(isolate->bootstrapper()->IsActive());
return isolate->heap()->nan_value();
}
RUNTIME_FUNCTION(Runtime_MaxSmi) {
SealHandleScope shs(isolate);
DCHECK(args.length() == 0);
return Smi::FromInt(Smi::kMaxValue);
}
RUNTIME_FUNCTION(RuntimeReference_NumberToString) {
SealHandleScope shs(isolate);
return __RT_impl_Runtime_NumberToStringRT(args, isolate);
......
This diff is collapsed.
......@@ -1256,5 +1256,11 @@ RUNTIME_FUNCTION(RuntimeReference_StringAdd) {
SealHandleScope shs(isolate);
return __RT_impl_Runtime_StringAdd(args, isolate);
}
RUNTIME_FUNCTION(RuntimeReference_IsStringWrapperSafeForDefaultValueOf) {
UNIMPLEMENTED();
return NULL;
}
}
} // namespace v8::internal
This diff is collapsed.
......@@ -736,6 +736,8 @@
'../../src/rewriter.h',
'../../src/runtime-profiler.cc',
'../../src/runtime-profiler.h',
'../../src/runtime/runtime-api.cc',
'../../src/runtime/runtime-array.cc',
'../../src/runtime/runtime-classes.cc',
'../../src/runtime/runtime-collections.cc',
'../../src/runtime/runtime-compiler.cc',
......@@ -744,11 +746,13 @@
'../../src/runtime/runtime-function.cc',
'../../src/runtime/runtime-generator.cc',
'../../src/runtime/runtime-i18n.cc',
'../../src/runtime/runtime-internal.cc',
'../../src/runtime/runtime-json.cc',
'../../src/runtime/runtime-literals.cc',
'../../src/runtime/runtime-liveedit.cc',
'../../src/runtime/runtime-maths.cc',
'../../src/runtime/runtime-numbers.cc',
'../../src/runtime/runtime-object.cc',
'../../src/runtime/runtime-observe.cc',
'../../src/runtime/runtime-proxy.cc',
'../../src/runtime/runtime-regexp.cc',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment