OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 8246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8257 Execution::New(Handle<JSFunction>::cast(bound_function), | 8257 Execution::New(Handle<JSFunction>::cast(bound_function), |
8258 total_argc, param_data.get(), &exception); | 8258 total_argc, param_data.get(), &exception); |
8259 if (exception) { | 8259 if (exception) { |
8260 return Failure::Exception(); | 8260 return Failure::Exception(); |
8261 } | 8261 } |
8262 ASSERT(!result.is_null()); | 8262 ASSERT(!result.is_null()); |
8263 return *result; | 8263 return *result; |
8264 } | 8264 } |
8265 | 8265 |
8266 | 8266 |
8267 RUNTIME_FUNCTION(MaybeObject*, Runtime_NewObject) { | 8267 static MaybeObject* Runtime_NewObjectHelper(Isolate* isolate, |
8268 HandleScope scope(isolate); | 8268 Handle<Object> constructor, |
8269 ASSERT(args.length() == 1); | 8269 Handle<AllocationSite> site) { |
8270 | |
8271 Handle<Object> constructor = args.at<Object>(0); | |
8272 | |
8273 // If the constructor isn't a proper function we throw a type error. | 8270 // If the constructor isn't a proper function we throw a type error. |
8274 if (!constructor->IsJSFunction()) { | 8271 if (!constructor->IsJSFunction()) { |
8275 Vector< Handle<Object> > arguments = HandleVector(&constructor, 1); | 8272 Vector< Handle<Object> > arguments = HandleVector(&constructor, 1); |
8276 Handle<Object> type_error = | 8273 Handle<Object> type_error = |
8277 isolate->factory()->NewTypeError("not_constructor", arguments); | 8274 isolate->factory()->NewTypeError("not_constructor", arguments); |
8278 return isolate->Throw(*type_error); | 8275 return isolate->Throw(*type_error); |
8279 } | 8276 } |
8280 | 8277 |
8281 Handle<JSFunction> function = Handle<JSFunction>::cast(constructor); | 8278 Handle<JSFunction> function = Handle<JSFunction>::cast(constructor); |
8282 | 8279 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8320 | 8317 |
8321 Handle<SharedFunctionInfo> shared(function->shared(), isolate); | 8318 Handle<SharedFunctionInfo> shared(function->shared(), isolate); |
8322 if (!function->has_initial_map() && | 8319 if (!function->has_initial_map() && |
8323 shared->IsInobjectSlackTrackingInProgress()) { | 8320 shared->IsInobjectSlackTrackingInProgress()) { |
8324 // The tracking is already in progress for another function. We can only | 8321 // The tracking is already in progress for another function. We can only |
8325 // track one initial_map at a time, so we force the completion before the | 8322 // track one initial_map at a time, so we force the completion before the |
8326 // function is called as a constructor for the first time. | 8323 // function is called as a constructor for the first time. |
8327 shared->CompleteInobjectSlackTracking(); | 8324 shared->CompleteInobjectSlackTracking(); |
8328 } | 8325 } |
8329 | 8326 |
8330 Handle<JSObject> result = isolate->factory()->NewJSObject(function); | 8327 Handle<JSObject> result; |
| 8328 if (site.is_null()) { |
| 8329 result = isolate->factory()->NewJSObject(function); |
| 8330 } else { |
| 8331 result = isolate->factory()->NewJSObjectWithMemento(function, site); |
| 8332 } |
8331 RETURN_IF_EMPTY_HANDLE(isolate, result); | 8333 RETURN_IF_EMPTY_HANDLE(isolate, result); |
8332 | 8334 |
8333 isolate->counters()->constructed_objects()->Increment(); | 8335 isolate->counters()->constructed_objects()->Increment(); |
8334 isolate->counters()->constructed_objects_runtime()->Increment(); | 8336 isolate->counters()->constructed_objects_runtime()->Increment(); |
8335 | 8337 |
8336 return *result; | 8338 return *result; |
8337 } | 8339 } |
8338 | 8340 |
8339 | 8341 |
| 8342 RUNTIME_FUNCTION(MaybeObject*, Runtime_NewObject) { |
| 8343 HandleScope scope(isolate); |
| 8344 ASSERT(args.length() == 1); |
| 8345 |
| 8346 Handle<Object> constructor = args.at<Object>(0); |
| 8347 return Runtime_NewObjectHelper(isolate, |
| 8348 constructor, |
| 8349 Handle<AllocationSite>::null()); |
| 8350 } |
| 8351 |
| 8352 |
| 8353 RUNTIME_FUNCTION(MaybeObject*, Runtime_NewObjectWithAllocationSite) { |
| 8354 HandleScope scope(isolate); |
| 8355 ASSERT(args.length() == 2); |
| 8356 |
| 8357 Handle<Object> constructor = args.at<Object>(1); |
| 8358 Handle<Object> feedback = args.at<Object>(0); |
| 8359 Handle<AllocationSite> site; |
| 8360 if (feedback->IsAllocationSite()) { |
| 8361 // The feedback can be an AllocationSite or undefined. |
| 8362 site = Handle<AllocationSite>::cast(feedback); |
| 8363 } |
| 8364 return Runtime_NewObjectHelper(isolate, |
| 8365 constructor, |
| 8366 site); |
| 8367 } |
| 8368 |
| 8369 |
8340 RUNTIME_FUNCTION(MaybeObject*, Runtime_FinalizeInstanceSize) { | 8370 RUNTIME_FUNCTION(MaybeObject*, Runtime_FinalizeInstanceSize) { |
8341 HandleScope scope(isolate); | 8371 HandleScope scope(isolate); |
8342 ASSERT(args.length() == 1); | 8372 ASSERT(args.length() == 1); |
8343 | 8373 |
8344 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); | 8374 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); |
8345 function->shared()->CompleteInobjectSlackTracking(); | 8375 function->shared()->CompleteInobjectSlackTracking(); |
8346 | 8376 |
8347 return isolate->heap()->undefined_value(); | 8377 return isolate->heap()->undefined_value(); |
8348 } | 8378 } |
8349 | 8379 |
(...skipping 6666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15016 // Handle last resort GC and make sure to allow future allocations | 15046 // Handle last resort GC and make sure to allow future allocations |
15017 // to grow the heap without causing GCs (if possible). | 15047 // to grow the heap without causing GCs (if possible). |
15018 isolate->counters()->gc_last_resort_from_js()->Increment(); | 15048 isolate->counters()->gc_last_resort_from_js()->Increment(); |
15019 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, | 15049 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, |
15020 "Runtime::PerformGC"); | 15050 "Runtime::PerformGC"); |
15021 } | 15051 } |
15022 } | 15052 } |
15023 | 15053 |
15024 | 15054 |
15025 } } // namespace v8::internal | 15055 } } // namespace v8::internal |
OLD | NEW |