| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 "src/api.h" | 5 #include "src/api.h" |
| 6 | 6 |
| 7 #include <string.h> // For memcpy, strlen. | 7 #include <string.h> // For memcpy, strlen. |
| 8 #ifdef V8_USE_ADDRESS_SANITIZER | 8 #ifdef V8_USE_ADDRESS_SANITIZER |
| 9 #include <sanitizer/asan_interface.h> | 9 #include <sanitizer/asan_interface.h> |
| 10 #endif // V8_USE_ADDRESS_SANITIZER | 10 #endif // V8_USE_ADDRESS_SANITIZER |
| (...skipping 757 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 768 Utils::ApiCheck(smi->IsSmi(), location, "Pointer is not aligned"); | 768 Utils::ApiCheck(smi->IsSmi(), location, "Pointer is not aligned"); |
| 769 return smi; | 769 return smi; |
| 770 } | 770 } |
| 771 | 771 |
| 772 | 772 |
| 773 static i::Handle<i::FixedArray> EmbedderDataFor(Context* context, | 773 static i::Handle<i::FixedArray> EmbedderDataFor(Context* context, |
| 774 int index, | 774 int index, |
| 775 bool can_grow, | 775 bool can_grow, |
| 776 const char* location) { | 776 const char* location) { |
| 777 i::Handle<i::Context> env = Utils::OpenHandle(context); | 777 i::Handle<i::Context> env = Utils::OpenHandle(context); |
| 778 i::Isolate* isolate = env->GetIsolate(); |
| 778 bool ok = | 779 bool ok = |
| 779 Utils::ApiCheck(env->IsNativeContext(), | 780 Utils::ApiCheck(env->IsNativeContext(), |
| 780 location, | 781 location, |
| 781 "Not a native context") && | 782 "Not a native context") && |
| 782 Utils::ApiCheck(index >= 0, location, "Negative index"); | 783 Utils::ApiCheck(index >= 0, location, "Negative index"); |
| 783 if (!ok) return i::Handle<i::FixedArray>(); | 784 if (!ok) return i::Handle<i::FixedArray>(); |
| 784 i::Handle<i::FixedArray> data(env->embedder_data()); | 785 i::Handle<i::FixedArray> data(env->embedder_data()); |
| 785 if (index < data->length()) return data; | 786 if (index < data->length()) return data; |
| 786 if (!Utils::ApiCheck(can_grow, location, "Index too large")) { | 787 if (!Utils::ApiCheck(can_grow, location, "Index too large")) { |
| 787 return i::Handle<i::FixedArray>(); | 788 return i::Handle<i::FixedArray>(); |
| 788 } | 789 } |
| 789 int new_size = i::Max(index, data->length() << 1) + 1; | 790 int new_size = i::Max(index, data->length() << 1) + 1; |
| 790 data = i::FixedArray::CopySize(data, new_size); | 791 int grow_by = new_size - data->length(); |
| 792 data = isolate->factory()->CopyFixedArrayAndGrow(data, grow_by); |
| 791 env->set_embedder_data(*data); | 793 env->set_embedder_data(*data); |
| 792 return data; | 794 return data; |
| 793 } | 795 } |
| 794 | 796 |
| 795 | 797 |
| 796 v8::Local<v8::Value> Context::SlowGetEmbedderData(int index) { | 798 v8::Local<v8::Value> Context::SlowGetEmbedderData(int index) { |
| 797 const char* location = "v8::Context::GetEmbedderData()"; | 799 const char* location = "v8::Context::GetEmbedderData()"; |
| 798 i::Handle<i::FixedArray> data = EmbedderDataFor(this, index, false, location); | 800 i::Handle<i::FixedArray> data = EmbedderDataFor(this, index, false, location); |
| 799 if (data.is_null()) return Local<Value>(); | 801 if (data.is_null()) return Local<Value>(); |
| 800 i::Handle<i::Object> result(data->get(index), data->GetIsolate()); | 802 i::Handle<i::Object> result(data->get(index), data->GetIsolate()); |
| (...skipping 7602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8403 Address callback_address = | 8405 Address callback_address = |
| 8404 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 8406 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
| 8405 VMState<EXTERNAL> state(isolate); | 8407 VMState<EXTERNAL> state(isolate); |
| 8406 ExternalCallbackScope call_scope(isolate, callback_address); | 8408 ExternalCallbackScope call_scope(isolate, callback_address); |
| 8407 callback(info); | 8409 callback(info); |
| 8408 } | 8410 } |
| 8409 | 8411 |
| 8410 | 8412 |
| 8411 } // namespace internal | 8413 } // namespace internal |
| 8412 } // namespace v8 | 8414 } // namespace v8 |
| OLD | NEW |