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 5392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5403 Handle<JSArray> stack_trace_array = Handle<JSArray>::cast(stack_trace); | 5403 Handle<JSArray> stack_trace_array = Handle<JSArray>::cast(stack_trace); |
5404 int array_length = Smi::cast(stack_trace_array->length())->value(); | 5404 int array_length = Smi::cast(stack_trace_array->length())->value(); |
5405 for (int i = 0; i < array_length; i++) { | 5405 for (int i = 0; i < array_length; i++) { |
5406 Handle<Object> element = | 5406 Handle<Object> element = |
5407 Object::GetElement(isolate, stack_trace, i).ToHandleChecked(); | 5407 Object::GetElement(isolate, stack_trace, i).ToHandleChecked(); |
5408 CHECK(!element->IsCode()); | 5408 CHECK(!element->IsCode()); |
5409 } | 5409 } |
5410 } | 5410 } |
5411 | 5411 |
5412 | 5412 |
5413 static bool utils_has_been_collected = false; | 5413 static bool shared_has_been_collected = false; |
| 5414 static bool builtin_exports_has_been_collected = false; |
5414 | 5415 |
5415 static void UtilsHasBeenCollected( | 5416 static void SharedHasBeenCollected( |
5416 const v8::WeakCallbackInfo<v8::Persistent<v8::Object>>& data) { | 5417 const v8::WeakCallbackInfo<v8::Persistent<v8::Object>>& data) { |
5417 utils_has_been_collected = true; | 5418 shared_has_been_collected = true; |
5418 data.GetParameter()->Reset(); | 5419 data.GetParameter()->Reset(); |
5419 } | 5420 } |
5420 | 5421 |
| 5422 |
| 5423 static void BuiltinExportsHasBeenCollected( |
| 5424 const v8::WeakCallbackInfo<v8::Persistent<v8::Object>>& data) { |
| 5425 builtin_exports_has_been_collected = true; |
| 5426 data.GetParameter()->Reset(); |
| 5427 } |
| 5428 |
5421 | 5429 |
5422 TEST(BootstrappingExports) { | 5430 TEST(BootstrappingExports) { |
5423 FLAG_expose_natives_as = "natives"; | 5431 FLAG_expose_natives_as = "natives"; |
5424 CcTest::InitializeVM(); | 5432 CcTest::InitializeVM(); |
5425 v8::Isolate* isolate = CcTest::isolate(); | 5433 v8::Isolate* isolate = CcTest::isolate(); |
5426 | 5434 |
5427 if (Snapshot::HaveASnapshotToStartFrom(CcTest::i_isolate())) return; | 5435 if (Snapshot::HaveASnapshotToStartFrom(CcTest::i_isolate())) return; |
5428 | 5436 |
5429 utils_has_been_collected = false; | 5437 shared_has_been_collected = false; |
| 5438 builtin_exports_has_been_collected = false; |
5430 | 5439 |
5431 v8::Persistent<v8::Object> utils; | 5440 v8::Persistent<v8::Object> shared; |
| 5441 v8::Persistent<v8::Object> builtin_exports; |
5432 | 5442 |
5433 { | 5443 { |
5434 v8::HandleScope scope(isolate); | 5444 v8::HandleScope scope(isolate); |
5435 v8::Handle<v8::Object> natives = | 5445 v8::Handle<v8::Object> natives = |
5436 CcTest::global()->Get(v8_str("natives"))->ToObject(isolate); | 5446 CcTest::global()->Get(v8_str("natives"))->ToObject(isolate); |
5437 utils.Reset(isolate, natives->Get(v8_str("utils"))->ToObject(isolate)); | 5447 shared.Reset(isolate, natives->Get(v8_str("shared"))->ToObject(isolate)); |
5438 natives->Delete(v8_str("utils")); | 5448 natives->Delete(v8_str("shared")); |
| 5449 builtin_exports.Reset( |
| 5450 isolate, natives->Get(v8_str("builtin_exports"))->ToObject(isolate)); |
| 5451 natives->Delete(v8_str("builtin_exports")); |
5439 } | 5452 } |
5440 | 5453 |
5441 utils.SetWeak(&utils, UtilsHasBeenCollected, | 5454 shared.SetWeak(&shared, SharedHasBeenCollected, |
5442 v8::WeakCallbackType::kParameter); | 5455 v8::WeakCallbackType::kParameter); |
| 5456 builtin_exports.SetWeak(&builtin_exports, BuiltinExportsHasBeenCollected, |
| 5457 v8::WeakCallbackType::kParameter); |
5443 | 5458 |
5444 CcTest::heap()->CollectAllAvailableGarbage("fire weak callbacks"); | 5459 CcTest::heap()->CollectAllAvailableGarbage("fire weak callbacks"); |
5445 | 5460 |
5446 CHECK(utils_has_been_collected); | 5461 CHECK(shared_has_been_collected); |
| 5462 CHECK(builtin_exports_has_been_collected); |
5447 } | 5463 } |
5448 | |
5449 | |
5450 TEST(Regress1878) { | |
5451 FLAG_allow_natives_syntax = true; | |
5452 CcTest::InitializeVM(); | |
5453 v8::Isolate* isolate = CcTest::isolate(); | |
5454 v8::HandleScope scope(isolate); | |
5455 v8::Local<v8::Function> constructor = | |
5456 v8::Utils::ToLocal(CcTest::i_isolate()->internal_array_function()); | |
5457 CcTest::global()->Set(v8_str("InternalArray"), constructor); | |
5458 | |
5459 v8::TryCatch try_catch; | |
5460 | |
5461 CompileRun( | |
5462 "var a = Array();" | |
5463 "for (var i = 0; i < 1000; i++) {" | |
5464 " var ai = new InternalArray(10000);" | |
5465 " if (%HaveSameMap(ai, a)) throw Error();" | |
5466 " if (!%HasFastObjectElements(ai)) throw Error();" | |
5467 "}" | |
5468 "for (var i = 0; i < 1000; i++) {" | |
5469 " var ai = new InternalArray(10000);" | |
5470 " if (%HaveSameMap(ai, a)) throw Error();" | |
5471 " if (!%HasFastObjectElements(ai)) throw Error();" | |
5472 "}"); | |
5473 | |
5474 CHECK(!try_catch.HasCaught()); | |
5475 } | |
OLD | NEW |