OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "factory.h" | 5 #include "factory.h" |
6 | 6 |
7 #include "isolate-inl.h" | 7 #include "isolate-inl.h" |
8 | 8 |
9 namespace v8 { | 9 namespace v8 { |
10 namespace internal { | 10 namespace internal { |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 DescriptorArray::Allocate( | 149 DescriptorArray::Allocate( |
150 isolate(), number_of_descriptors, slack), | 150 isolate(), number_of_descriptors, slack), |
151 DescriptorArray); | 151 DescriptorArray); |
152 } | 152 } |
153 | 153 |
154 | 154 |
155 Handle<DeoptimizationInputData> Factory::NewDeoptimizationInputData( | 155 Handle<DeoptimizationInputData> Factory::NewDeoptimizationInputData( |
156 int deopt_entry_count, | 156 int deopt_entry_count, |
157 PretenureFlag pretenure) { | 157 PretenureFlag pretenure) { |
158 ASSERT(deopt_entry_count > 0); | 158 ASSERT(deopt_entry_count > 0); |
159 CALL_HEAP_FUNCTION(isolate(), | 159 int len = DeoptimizationInputData::LengthFor(deopt_entry_count); |
160 DeoptimizationInputData::Allocate(isolate(), | 160 return Handle<DeoptimizationInputData>::cast(NewFixedArray(len, pretenure)); |
161 deopt_entry_count, | |
162 pretenure), | |
163 DeoptimizationInputData); | |
164 } | 161 } |
165 | 162 |
166 | 163 |
167 Handle<DeoptimizationOutputData> Factory::NewDeoptimizationOutputData( | 164 Handle<DeoptimizationOutputData> Factory::NewDeoptimizationOutputData( |
168 int deopt_entry_count, | 165 int deopt_entry_count, |
169 PretenureFlag pretenure) { | 166 PretenureFlag pretenure) { |
170 ASSERT(deopt_entry_count > 0); | 167 ASSERT(deopt_entry_count > 0); |
171 CALL_HEAP_FUNCTION(isolate(), | 168 int len = DeoptimizationOutputData::LengthOfFixedArray(deopt_entry_count); |
172 DeoptimizationOutputData::Allocate(isolate(), | 169 return Handle<DeoptimizationOutputData>::cast(NewFixedArray(len, pretenure)); |
173 deopt_entry_count, | |
174 pretenure), | |
175 DeoptimizationOutputData); | |
176 } | 170 } |
177 | 171 |
178 | 172 |
179 Handle<AccessorPair> Factory::NewAccessorPair() { | 173 Handle<AccessorPair> Factory::NewAccessorPair() { |
180 Handle<AccessorPair> accessors = | 174 Handle<AccessorPair> accessors = |
181 Handle<AccessorPair>::cast(NewStruct(ACCESSOR_PAIR_TYPE)); | 175 Handle<AccessorPair>::cast(NewStruct(ACCESSOR_PAIR_TYPE)); |
182 accessors->set_getter(*the_hole_value(), SKIP_WRITE_BARRIER); | 176 accessors->set_getter(*the_hole_value(), SKIP_WRITE_BARRIER); |
183 accessors->set_setter(*the_hole_value(), SKIP_WRITE_BARRIER); | 177 accessors->set_setter(*the_hole_value(), SKIP_WRITE_BARRIER); |
184 accessors->set_access_flags(Smi::FromInt(0), SKIP_WRITE_BARRIER); | 178 accessors->set_access_flags(Smi::FromInt(0), SKIP_WRITE_BARRIER); |
185 return accessors; | 179 return accessors; |
(...skipping 789 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
975 | 969 |
976 Handle<HeapNumber> Factory::NewHeapNumber(double value, | 970 Handle<HeapNumber> Factory::NewHeapNumber(double value, |
977 PretenureFlag pretenure) { | 971 PretenureFlag pretenure) { |
978 CALL_HEAP_FUNCTION( | 972 CALL_HEAP_FUNCTION( |
979 isolate(), | 973 isolate(), |
980 isolate()->heap()->AllocateHeapNumber(value, pretenure), HeapNumber); | 974 isolate()->heap()->AllocateHeapNumber(value, pretenure), HeapNumber); |
981 } | 975 } |
982 | 976 |
983 | 977 |
984 Handle<JSObject> Factory::NewNeanderObject() { | 978 Handle<JSObject> Factory::NewNeanderObject() { |
985 CALL_HEAP_FUNCTION( | 979 return NewJSObjectFromMap(neander_map()); |
986 isolate(), | |
987 isolate()->heap()->AllocateJSObjectFromMap( | |
988 isolate()->heap()->neander_map()), | |
989 JSObject); | |
990 } | 980 } |
991 | 981 |
992 | 982 |
993 Handle<Object> Factory::NewTypeError(const char* message, | 983 Handle<Object> Factory::NewTypeError(const char* message, |
994 Vector< Handle<Object> > args) { | 984 Vector< Handle<Object> > args) { |
995 return NewError("MakeTypeError", message, args); | 985 return NewError("MakeTypeError", message, args); |
996 } | 986 } |
997 | 987 |
998 | 988 |
999 Handle<Object> Factory::NewTypeError(Handle<String> message) { | 989 Handle<Object> Factory::NewTypeError(Handle<String> message) { |
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1442 mode)); | 1432 mode)); |
1443 } | 1433 } |
1444 | 1434 |
1445 | 1435 |
1446 Handle<JSGeneratorObject> Factory::NewJSGeneratorObject( | 1436 Handle<JSGeneratorObject> Factory::NewJSGeneratorObject( |
1447 Handle<JSFunction> function) { | 1437 Handle<JSFunction> function) { |
1448 ASSERT(function->shared()->is_generator()); | 1438 ASSERT(function->shared()->is_generator()); |
1449 JSFunction::EnsureHasInitialMap(function); | 1439 JSFunction::EnsureHasInitialMap(function); |
1450 Handle<Map> map(function->initial_map()); | 1440 Handle<Map> map(function->initial_map()); |
1451 ASSERT(map->instance_type() == JS_GENERATOR_OBJECT_TYPE); | 1441 ASSERT(map->instance_type() == JS_GENERATOR_OBJECT_TYPE); |
1452 CALL_HEAP_FUNCTION( | 1442 return Handle<JSGeneratorObject>::cast(NewJSObjectFromMap(map)); |
1453 isolate(), | |
1454 isolate()->heap()->AllocateJSObjectFromMap(*map), | |
1455 JSGeneratorObject); | |
1456 } | 1443 } |
1457 | 1444 |
1458 | 1445 |
1459 Handle<JSArrayBuffer> Factory::NewJSArrayBuffer() { | 1446 Handle<JSArrayBuffer> Factory::NewJSArrayBuffer() { |
1460 Handle<JSFunction> array_buffer_fun( | 1447 Handle<JSFunction> array_buffer_fun( |
1461 isolate()->context()->native_context()->array_buffer_fun()); | 1448 isolate()->context()->native_context()->array_buffer_fun()); |
1462 CALL_HEAP_FUNCTION( | 1449 return Handle<JSArrayBuffer>::cast(NewJSObject(array_buffer_fun)); |
1463 isolate(), | |
1464 isolate()->heap()->AllocateJSObject(*array_buffer_fun), | |
1465 JSArrayBuffer); | |
1466 } | 1450 } |
1467 | 1451 |
1468 | 1452 |
1469 Handle<JSDataView> Factory::NewJSDataView() { | 1453 Handle<JSDataView> Factory::NewJSDataView() { |
1470 Handle<JSFunction> data_view_fun( | 1454 Handle<JSFunction> data_view_fun( |
1471 isolate()->context()->native_context()->data_view_fun()); | 1455 isolate()->context()->native_context()->data_view_fun()); |
1472 CALL_HEAP_FUNCTION( | 1456 return Handle<JSDataView>::cast(NewJSObject(data_view_fun)); |
1473 isolate(), | |
1474 isolate()->heap()->AllocateJSObject(*data_view_fun), | |
1475 JSDataView); | |
1476 } | 1457 } |
1477 | 1458 |
1478 | 1459 |
1479 static JSFunction* GetTypedArrayFun(ExternalArrayType type, | 1460 static JSFunction* GetTypedArrayFun(ExternalArrayType type, |
1480 Isolate* isolate) { | 1461 Isolate* isolate) { |
1481 Context* native_context = isolate->context()->native_context(); | 1462 Context* native_context = isolate->context()->native_context(); |
1482 switch (type) { | 1463 switch (type) { |
1483 #define TYPED_ARRAY_FUN(Type, type, TYPE, ctype, size) \ | 1464 #define TYPED_ARRAY_FUN(Type, type, TYPE, ctype, size) \ |
1484 case kExternal##Type##Array: \ | 1465 case kExternal##Type##Array: \ |
1485 return native_context->type##_array_fun(); | 1466 return native_context->type##_array_fun(); |
1486 | 1467 |
1487 TYPED_ARRAYS(TYPED_ARRAY_FUN) | 1468 TYPED_ARRAYS(TYPED_ARRAY_FUN) |
1488 #undef TYPED_ARRAY_FUN | 1469 #undef TYPED_ARRAY_FUN |
1489 | 1470 |
1490 default: | 1471 default: |
1491 UNREACHABLE(); | 1472 UNREACHABLE(); |
1492 return NULL; | 1473 return NULL; |
1493 } | 1474 } |
1494 } | 1475 } |
1495 | 1476 |
1496 | 1477 |
1497 Handle<JSTypedArray> Factory::NewJSTypedArray(ExternalArrayType type) { | 1478 Handle<JSTypedArray> Factory::NewJSTypedArray(ExternalArrayType type) { |
1498 Handle<JSFunction> typed_array_fun_handle(GetTypedArrayFun(type, isolate())); | 1479 Handle<JSFunction> typed_array_fun_handle(GetTypedArrayFun(type, isolate())); |
1499 | 1480 return Handle<JSTypedArray>::cast(NewJSObject(typed_array_fun_handle)); |
1500 CALL_HEAP_FUNCTION( | |
1501 isolate(), | |
1502 isolate()->heap()->AllocateJSObject(*typed_array_fun_handle), | |
1503 JSTypedArray); | |
1504 } | 1481 } |
1505 | 1482 |
1506 | 1483 |
1507 Handle<JSProxy> Factory::NewJSProxy(Handle<Object> handler, | 1484 Handle<JSProxy> Factory::NewJSProxy(Handle<Object> handler, |
1508 Handle<Object> prototype) { | 1485 Handle<Object> prototype) { |
1509 CALL_HEAP_FUNCTION( | 1486 CALL_HEAP_FUNCTION( |
1510 isolate(), | 1487 isolate(), |
1511 isolate()->heap()->AllocateJSProxy(*handler, *prototype), | 1488 isolate()->heap()->AllocateJSProxy(*handler, *prototype), |
1512 JSProxy); | 1489 JSProxy); |
1513 } | 1490 } |
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1979 if (name->Equals(h->infinity_string())) return infinity_value(); | 1956 if (name->Equals(h->infinity_string())) return infinity_value(); |
1980 return Handle<Object>::null(); | 1957 return Handle<Object>::null(); |
1981 } | 1958 } |
1982 | 1959 |
1983 | 1960 |
1984 Handle<Object> Factory::ToBoolean(bool value) { | 1961 Handle<Object> Factory::ToBoolean(bool value) { |
1985 return value ? true_value() : false_value(); | 1962 return value ? true_value() : false_value(); |
1986 } | 1963 } |
1987 | 1964 |
1988 } } // namespace v8::internal | 1965 } } // namespace v8::internal |
OLD | NEW |