OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 strong_nodes_.erase(strong_nodes_.begin() + offset); | 411 strong_nodes_.erase(strong_nodes_.begin() + offset); |
412 } | 412 } |
413 | 413 |
414 void AddWeak() { | 414 void AddWeak() { |
415 v8::Isolate* isolate = reinterpret_cast<v8::Isolate*>(isolate_); | 415 v8::Isolate* isolate = reinterpret_cast<v8::Isolate*>(isolate_); |
416 v8::HandleScope scope(isolate); | 416 v8::HandleScope scope(isolate); |
417 v8::Local<v8::Object> object = v8::Object::New(); | 417 v8::Local<v8::Object> object = v8::Object::New(); |
418 int32_t offset = ++weak_offset_; | 418 int32_t offset = ++weak_offset_; |
419 object->Set(7, v8::Integer::New(offset, isolate)); | 419 object->Set(7, v8::Integer::New(offset, isolate)); |
420 v8::Persistent<v8::Object> persistent(isolate, object); | 420 v8::Persistent<v8::Object> persistent(isolate, object); |
421 persistent.MakeWeak(isolate, this, WeakCallback); | 421 persistent.MakeWeak(this, WeakCallback); |
422 persistent.MarkIndependent(); | 422 persistent.MarkIndependent(); |
423 Object** location = v8::Utils::OpenPersistent(persistent).location(); | 423 Object** location = v8::Utils::OpenPersistent(persistent).location(); |
424 bool inserted = | 424 bool inserted = |
425 weak_nodes_.insert(std::make_pair(offset, location)).second; | 425 weak_nodes_.insert(std::make_pair(offset, location)).second; |
426 CHECK(inserted); | 426 CHECK(inserted); |
427 } | 427 } |
428 | 428 |
429 static void WeakCallback(v8::Isolate* isolate, | 429 static void WeakCallback(v8::Isolate* isolate, |
430 v8::Persistent<v8::Object>* persistent, | 430 v8::Persistent<v8::Object>* persistent, |
431 RandomMutationData* data) { | 431 RandomMutationData* data) { |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 v8::Utils::ToLocal(eternals->Get(indices[i])); | 497 v8::Utils::ToLocal(eternals->Get(indices[i])); |
498 v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(local); | 498 v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(local); |
499 v8::Handle<v8::Value> value = object->Get(i); | 499 v8::Handle<v8::Value> value = object->Get(i); |
500 CHECK(value->IsInt32()); | 500 CHECK(value->IsInt32()); |
501 CHECK_EQ(i, value->Int32Value()); | 501 CHECK_EQ(i, value->Int32Value()); |
502 } | 502 } |
503 | 503 |
504 CHECK_EQ(kArrayLength, eternals->NumberOfHandles()); | 504 CHECK_EQ(kArrayLength, eternals->NumberOfHandles()); |
505 } | 505 } |
506 | 506 |
OLD | NEW |