Commit 1a91d420 authored by yangguo@chromium.org's avatar yangguo@chromium.org

Remove some direct uses of heap allocators from runtime.cc

R=jarin@chromium.org

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20760 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 4d3bd166
...@@ -1554,6 +1554,18 @@ Handle<JSProxy> Factory::NewJSProxy(Handle<Object> handler, ...@@ -1554,6 +1554,18 @@ Handle<JSProxy> Factory::NewJSProxy(Handle<Object> handler,
} }
Handle<JSProxy> Factory::NewJSFunctionProxy(Handle<Object> handler,
Handle<Object> call_trap,
Handle<Object> construct_trap,
Handle<Object> prototype) {
CALL_HEAP_FUNCTION(
isolate(),
isolate()->heap()->AllocateJSFunctionProxy(
*handler, *call_trap, *construct_trap, *prototype),
JSProxy);
}
void Factory::BecomeJSObject(Handle<JSReceiver> object) { void Factory::BecomeJSObject(Handle<JSReceiver> object) {
CALL_HEAP_FUNCTION_VOID( CALL_HEAP_FUNCTION_VOID(
isolate(), isolate(),
......
...@@ -388,6 +388,11 @@ class Factory V8_FINAL { ...@@ -388,6 +388,11 @@ class Factory V8_FINAL {
Handle<JSProxy> NewJSProxy(Handle<Object> handler, Handle<Object> prototype); Handle<JSProxy> NewJSProxy(Handle<Object> handler, Handle<Object> prototype);
Handle<JSProxy> NewJSFunctionProxy(Handle<Object> handler,
Handle<Object> call_trap,
Handle<Object> construct_trap,
Handle<Object> prototype);
// Change the type of the argument into a JS object/function and reinitialize. // Change the type of the argument into a JS object/function and reinitialize.
void BecomeJSObject(Handle<JSReceiver> object); void BecomeJSObject(Handle<JSReceiver> object);
void BecomeJSFunction(Handle<JSReceiver> object); void BecomeJSFunction(Handle<JSReceiver> object);
......
...@@ -614,7 +614,7 @@ RUNTIME_FUNCTION(MaybeObject*, RuntimeHidden_CreateArrayLiteralStubBailout) { ...@@ -614,7 +614,7 @@ RUNTIME_FUNCTION(MaybeObject*, RuntimeHidden_CreateArrayLiteralStubBailout) {
RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateSymbol) { RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateSymbol) {
HandleScope scope(isolate); HandleScope scope(isolate);
ASSERT(args.length() == 1); ASSERT(args.length() == 1);
Handle<Object> name(args[0], isolate); Handle<Object> name = args.at<Object>(0);
RUNTIME_ASSERT(name->IsString() || name->IsUndefined()); RUNTIME_ASSERT(name->IsString() || name->IsUndefined());
Handle<Symbol> symbol = isolate->factory()->NewSymbol(); Handle<Symbol> symbol = isolate->factory()->NewSymbol();
if (name->IsString()) symbol->set_name(*name); if (name->IsString()) symbol->set_name(*name);
...@@ -625,7 +625,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateSymbol) { ...@@ -625,7 +625,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateSymbol) {
RUNTIME_FUNCTION(MaybeObject*, Runtime_CreatePrivateSymbol) { RUNTIME_FUNCTION(MaybeObject*, Runtime_CreatePrivateSymbol) {
HandleScope scope(isolate); HandleScope scope(isolate);
ASSERT(args.length() == 1); ASSERT(args.length() == 1);
Handle<Object> name(args[0], isolate); Handle<Object> name = args.at<Object>(0);
RUNTIME_ASSERT(name->IsString() || name->IsUndefined()); RUNTIME_ASSERT(name->IsString() || name->IsUndefined());
Handle<Symbol> symbol = isolate->factory()->NewPrivateSymbol(); Handle<Symbol> symbol = isolate->factory()->NewPrivateSymbol();
if (name->IsString()) symbol->set_name(*name); if (name->IsString()) symbol->set_name(*name);
...@@ -688,28 +688,26 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_SymbolIsPrivate) { ...@@ -688,28 +688,26 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_SymbolIsPrivate) {
RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateJSProxy) { RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateJSProxy) {
SealHandleScope shs(isolate); HandleScope scope(isolate);
ASSERT(args.length() == 2); ASSERT(args.length() == 2);
CONVERT_ARG_CHECKED(JSReceiver, handler, 0); CONVERT_ARG_HANDLE_CHECKED(JSReceiver, handler, 0);
Object* prototype = args[1]; Handle<Object> prototype = args.at<Object>(1);
Object* used_prototype = if (!prototype->IsJSReceiver()) prototype = isolate->factory()->null_value();
prototype->IsJSReceiver() ? prototype : isolate->heap()->null_value(); return *isolate->factory()->NewJSProxy(handler, prototype);
return isolate->heap()->AllocateJSProxy(handler, used_prototype);
} }
RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateJSFunctionProxy) { RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateJSFunctionProxy) {
SealHandleScope shs(isolate); HandleScope scope(isolate);
ASSERT(args.length() == 4); ASSERT(args.length() == 4);
CONVERT_ARG_CHECKED(JSReceiver, handler, 0); CONVERT_ARG_HANDLE_CHECKED(JSReceiver, handler, 0);
Object* call_trap = args[1]; Handle<Object> call_trap = args.at<Object>(1);
RUNTIME_ASSERT(call_trap->IsJSFunction() || call_trap->IsJSFunctionProxy()); RUNTIME_ASSERT(call_trap->IsJSFunction() || call_trap->IsJSFunctionProxy());
CONVERT_ARG_CHECKED(JSFunction, construct_trap, 2); CONVERT_ARG_HANDLE_CHECKED(JSFunction, construct_trap, 2);
Object* prototype = args[3]; Handle<Object> prototype = args.at<Object>(3);
Object* used_prototype = if (!prototype->IsJSReceiver()) prototype = isolate->factory()->null_value();
prototype->IsJSReceiver() ? prototype : isolate->heap()->null_value(); return *isolate->factory()->NewJSFunctionProxy(
return isolate->heap()->AllocateJSFunctionProxy( handler, call_trap, construct_trap, prototype);
handler, call_trap, construct_trap, used_prototype);
} }
...@@ -3121,9 +3119,9 @@ RUNTIME_FUNCTION(MaybeObject*, RuntimeHidden_CreateJSGeneratorObject) { ...@@ -3121,9 +3119,9 @@ RUNTIME_FUNCTION(MaybeObject*, RuntimeHidden_CreateJSGeneratorObject) {
RUNTIME_FUNCTION(MaybeObject*, RuntimeHidden_SuspendJSGeneratorObject) { RUNTIME_FUNCTION(MaybeObject*, RuntimeHidden_SuspendJSGeneratorObject) {
SealHandleScope shs(isolate); HandleScope handle_scope(isolate);
ASSERT(args.length() == 1); ASSERT(args.length() == 1);
CONVERT_ARG_CHECKED(JSGeneratorObject, generator_object, 0); CONVERT_ARG_HANDLE_CHECKED(JSGeneratorObject, generator_object, 0);
JavaScriptFrameIterator stack_iterator(isolate); JavaScriptFrameIterator stack_iterator(isolate);
JavaScriptFrame* frame = stack_iterator.frame(); JavaScriptFrame* frame = stack_iterator.frame();
...@@ -3152,11 +3150,10 @@ RUNTIME_FUNCTION(MaybeObject*, RuntimeHidden_SuspendJSGeneratorObject) { ...@@ -3152,11 +3150,10 @@ RUNTIME_FUNCTION(MaybeObject*, RuntimeHidden_SuspendJSGeneratorObject) {
ASSERT(!frame->HasHandler()); ASSERT(!frame->HasHandler());
} else { } else {
int stack_handler_index = -1; int stack_handler_index = -1;
MaybeObject* alloc = isolate->heap()->AllocateFixedArray(operands_count); Handle<FixedArray> operand_stack =
FixedArray* operand_stack; isolate->factory()->NewFixedArray(operands_count);
if (!alloc->To(&operand_stack)) return alloc; frame->SaveOperandStack(*operand_stack, &stack_handler_index);
frame->SaveOperandStack(operand_stack, &stack_handler_index); generator_object->set_operand_stack(*operand_stack);
generator_object->set_operand_stack(operand_stack);
generator_object->set_stack_handler_index(stack_handler_index); generator_object->set_stack_handler_index(stack_handler_index);
} }
...@@ -4772,7 +4769,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_RegExpExecMultiple) { ...@@ -4772,7 +4769,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_RegExpExecMultiple) {
RUNTIME_FUNCTION(MaybeObject*, Runtime_NumberToRadixString) { RUNTIME_FUNCTION(MaybeObject*, Runtime_NumberToRadixString) {
SealHandleScope shs(isolate); HandleScope scope(isolate);
ASSERT(args.length() == 2); ASSERT(args.length() == 2);
CONVERT_SMI_ARG_CHECKED(radix, 1); CONVERT_SMI_ARG_CHECKED(radix, 1);
RUNTIME_ASSERT(2 <= radix && radix <= 36); RUNTIME_ASSERT(2 <= radix && radix <= 36);
...@@ -4783,7 +4780,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_NumberToRadixString) { ...@@ -4783,7 +4780,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_NumberToRadixString) {
if (value >= 0 && value < radix) { if (value >= 0 && value < radix) {
// Character array used for conversion. // Character array used for conversion.
static const char kCharTable[] = "0123456789abcdefghijklmnopqrstuvwxyz"; static const char kCharTable[] = "0123456789abcdefghijklmnopqrstuvwxyz";
return isolate->heap()-> return *isolate->factory()->
LookupSingleCharacterStringFromCode(kCharTable[value]); LookupSingleCharacterStringFromCode(kCharTable[value]);
} }
} }
...@@ -4791,24 +4788,24 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_NumberToRadixString) { ...@@ -4791,24 +4788,24 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_NumberToRadixString) {
// Slow case. // Slow case.
CONVERT_DOUBLE_ARG_CHECKED(value, 0); CONVERT_DOUBLE_ARG_CHECKED(value, 0);
if (std::isnan(value)) { if (std::isnan(value)) {
return *isolate->factory()->nan_string(); return isolate->heap()->nan_string();
} }
if (std::isinf(value)) { if (std::isinf(value)) {
if (value < 0) { if (value < 0) {
return *isolate->factory()->minus_infinity_string(); return isolate->heap()->minus_infinity_string();
} }
return *isolate->factory()->infinity_string(); return isolate->heap()->infinity_string();
} }
char* str = DoubleToRadixCString(value, radix); char* str = DoubleToRadixCString(value, radix);
MaybeObject* result = Handle<String> result =
isolate->heap()->AllocateStringFromOneByte(CStrVector(str)); isolate->factory()->NewStringFromOneByte(OneByteVector(str));
DeleteArray(str); DeleteArray(str);
return result; return *result;
} }
RUNTIME_FUNCTION(MaybeObject*, Runtime_NumberToFixed) { RUNTIME_FUNCTION(MaybeObject*, Runtime_NumberToFixed) {
SealHandleScope shs(isolate); HandleScope scope(isolate);
ASSERT(args.length() == 2); ASSERT(args.length() == 2);
CONVERT_DOUBLE_ARG_CHECKED(value, 0); CONVERT_DOUBLE_ARG_CHECKED(value, 0);
...@@ -4816,15 +4813,15 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_NumberToFixed) { ...@@ -4816,15 +4813,15 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_NumberToFixed) {
int f = FastD2IChecked(f_number); int f = FastD2IChecked(f_number);
RUNTIME_ASSERT(f >= 0); RUNTIME_ASSERT(f >= 0);
char* str = DoubleToFixedCString(value, f); char* str = DoubleToFixedCString(value, f);
MaybeObject* res = Handle<String> result =
isolate->heap()->AllocateStringFromOneByte(CStrVector(str)); isolate->factory()->NewStringFromOneByte(OneByteVector(str));
DeleteArray(str); DeleteArray(str);
return res; return *result;
} }
RUNTIME_FUNCTION(MaybeObject*, Runtime_NumberToExponential) { RUNTIME_FUNCTION(MaybeObject*, Runtime_NumberToExponential) {
SealHandleScope shs(isolate); HandleScope scope(isolate);
ASSERT(args.length() == 2); ASSERT(args.length() == 2);
CONVERT_DOUBLE_ARG_CHECKED(value, 0); CONVERT_DOUBLE_ARG_CHECKED(value, 0);
...@@ -4832,15 +4829,15 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_NumberToExponential) { ...@@ -4832,15 +4829,15 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_NumberToExponential) {
int f = FastD2IChecked(f_number); int f = FastD2IChecked(f_number);
RUNTIME_ASSERT(f >= -1 && f <= 20); RUNTIME_ASSERT(f >= -1 && f <= 20);
char* str = DoubleToExponentialCString(value, f); char* str = DoubleToExponentialCString(value, f);
MaybeObject* res = Handle<String> result =
isolate->heap()->AllocateStringFromOneByte(CStrVector(str)); isolate->factory()->NewStringFromOneByte(OneByteVector(str));
DeleteArray(str); DeleteArray(str);
return res; return *result;
} }
RUNTIME_FUNCTION(MaybeObject*, Runtime_NumberToPrecision) { RUNTIME_FUNCTION(MaybeObject*, Runtime_NumberToPrecision) {
SealHandleScope shs(isolate); HandleScope scope(isolate);
ASSERT(args.length() == 2); ASSERT(args.length() == 2);
CONVERT_DOUBLE_ARG_CHECKED(value, 0); CONVERT_DOUBLE_ARG_CHECKED(value, 0);
...@@ -4848,15 +4845,15 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_NumberToPrecision) { ...@@ -4848,15 +4845,15 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_NumberToPrecision) {
int f = FastD2IChecked(f_number); int f = FastD2IChecked(f_number);
RUNTIME_ASSERT(f >= 1 && f <= 21); RUNTIME_ASSERT(f >= 1 && f <= 21);
char* str = DoubleToPrecisionCString(value, f); char* str = DoubleToPrecisionCString(value, f);
MaybeObject* res = Handle<String> result =
isolate->heap()->AllocateStringFromOneByte(CStrVector(str)); isolate->factory()->NewStringFromOneByte(OneByteVector(str));
DeleteArray(str); DeleteArray(str);
return res; return *result;
} }
RUNTIME_FUNCTION(MaybeObject*, Runtime_IsValidSmi) { RUNTIME_FUNCTION(MaybeObject*, Runtime_IsValidSmi) {
HandleScope shs(isolate); SealHandleScope shs(isolate);
ASSERT(args.length() == 1); ASSERT(args.length() == 1);
CONVERT_NUMBER_CHECKED(int32_t, number, Int32, args[0]); CONVERT_NUMBER_CHECKED(int32_t, number, Int32, args[0]);
......
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