| 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 1168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1179 obj->set_length(length); | 1179 obj->set_length(length); |
| 1180 obj->set_undetectable(false); | 1180 obj->set_undetectable(false); |
| 1181 obj->set_needs_access_check(false); | 1181 obj->set_needs_access_check(false); |
| 1182 obj->set_accept_any_receiver(true); | 1182 obj->set_accept_any_receiver(true); |
| 1183 if (!signature.IsEmpty()) | 1183 if (!signature.IsEmpty()) |
| 1184 obj->set_signature(*Utils::OpenHandle(*signature)); | 1184 obj->set_signature(*Utils::OpenHandle(*signature)); |
| 1185 return Utils::ToLocal(obj); | 1185 return Utils::ToLocal(obj); |
| 1186 } | 1186 } |
| 1187 | 1187 |
| 1188 | 1188 |
| 1189 Local<FunctionTemplate> FunctionTemplate::New(Isolate* isolate, | 1189 Local<FunctionTemplate> FunctionTemplate::New( |
| 1190 FunctionCallback callback, | 1190 Isolate* isolate, FunctionCallback callback, v8::Local<Value> data, |
| 1191 v8::Local<Value> data, | 1191 v8::Local<Signature> signature, int length, ConstructorBehavior behavior) { |
| 1192 v8::Local<Signature> signature, | |
| 1193 int length) { | |
| 1194 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 1192 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 1195 // Changes to the environment cannot be captured in the snapshot. Expect no | 1193 // Changes to the environment cannot be captured in the snapshot. Expect no |
| 1196 // function templates when the isolate is created for serialization. | 1194 // function templates when the isolate is created for serialization. |
| 1197 LOG_API(i_isolate, FunctionTemplate, New); | 1195 LOG_API(i_isolate, FunctionTemplate, New); |
| 1198 ENTER_V8(i_isolate); | 1196 ENTER_V8(i_isolate); |
| 1199 return FunctionTemplateNew(i_isolate, callback, nullptr, data, signature, | 1197 auto templ = FunctionTemplateNew(i_isolate, callback, nullptr, data, |
| 1200 length, false); | 1198 signature, length, false); |
| 1199 if (behavior == ConstructorBehavior::kThrow) templ->RemovePrototype(); |
| 1200 return templ; |
| 1201 } | 1201 } |
| 1202 | 1202 |
| 1203 Local<FunctionTemplate> FunctionTemplate::FromSnapshot(Isolate* isolate, | 1203 Local<FunctionTemplate> FunctionTemplate::FromSnapshot(Isolate* isolate, |
| 1204 size_t index) { | 1204 size_t index) { |
| 1205 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 1205 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 1206 i::FixedArray* templates = i_isolate->heap()->serialized_templates(); | 1206 i::FixedArray* templates = i_isolate->heap()->serialized_templates(); |
| 1207 int int_index = static_cast<int>(index); | 1207 int int_index = static_cast<int>(index); |
| 1208 if (int_index < templates->length()) { | 1208 if (int_index < templates->length()) { |
| 1209 i::Object* info = i_isolate->heap()->serialized_templates()->get(int_index); | 1209 i::Object* info = i_isolate->heap()->serialized_templates()->get(int_index); |
| 1210 if (info->IsFunctionTemplateInfo()) { | 1210 if (info->IsFunctionTemplateInfo()) { |
| (...skipping 3269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4480 } | 4480 } |
| 4481 | 4481 |
| 4482 | 4482 |
| 4483 Local<v8::Value> Object::CallAsConstructor(int argc, | 4483 Local<v8::Value> Object::CallAsConstructor(int argc, |
| 4484 v8::Local<v8::Value> argv[]) { | 4484 v8::Local<v8::Value> argv[]) { |
| 4485 auto context = ContextFromHeapObject(Utils::OpenHandle(this)); | 4485 auto context = ContextFromHeapObject(Utils::OpenHandle(this)); |
| 4486 Local<Value>* argv_cast = reinterpret_cast<Local<Value>*>(argv); | 4486 Local<Value>* argv_cast = reinterpret_cast<Local<Value>*>(argv); |
| 4487 RETURN_TO_LOCAL_UNCHECKED(CallAsConstructor(context, argc, argv_cast), Value); | 4487 RETURN_TO_LOCAL_UNCHECKED(CallAsConstructor(context, argc, argv_cast), Value); |
| 4488 } | 4488 } |
| 4489 | 4489 |
| 4490 | |
| 4491 MaybeLocal<Function> Function::New(Local<Context> context, | 4490 MaybeLocal<Function> Function::New(Local<Context> context, |
| 4492 FunctionCallback callback, Local<Value> data, | 4491 FunctionCallback callback, Local<Value> data, |
| 4493 int length) { | 4492 int length, ConstructorBehavior behavior) { |
| 4494 i::Isolate* isolate = Utils::OpenHandle(*context)->GetIsolate(); | 4493 i::Isolate* isolate = Utils::OpenHandle(*context)->GetIsolate(); |
| 4495 LOG_API(isolate, Function, New); | 4494 LOG_API(isolate, Function, New); |
| 4496 ENTER_V8(isolate); | 4495 ENTER_V8(isolate); |
| 4497 return FunctionTemplateNew(isolate, callback, nullptr, data, | 4496 auto templ = FunctionTemplateNew(isolate, callback, nullptr, data, |
| 4498 Local<Signature>(), length, true) | 4497 Local<Signature>(), length, true); |
| 4499 ->GetFunction(context); | 4498 if (behavior == ConstructorBehavior::kThrow) templ->RemovePrototype(); |
| 4499 return templ->GetFunction(context); |
| 4500 } | 4500 } |
| 4501 | 4501 |
| 4502 | 4502 |
| 4503 Local<Function> Function::New(Isolate* v8_isolate, FunctionCallback callback, | 4503 Local<Function> Function::New(Isolate* v8_isolate, FunctionCallback callback, |
| 4504 Local<Value> data, int length) { | 4504 Local<Value> data, int length) { |
| 4505 return Function::New(v8_isolate->GetCurrentContext(), callback, data, length) | 4505 return Function::New(v8_isolate->GetCurrentContext(), callback, data, length, |
| 4506 ConstructorBehavior::kAllow) |
| 4506 .FromMaybe(Local<Function>()); | 4507 .FromMaybe(Local<Function>()); |
| 4507 } | 4508 } |
| 4508 | 4509 |
| 4509 | 4510 |
| 4510 Local<v8::Object> Function::NewInstance() const { | 4511 Local<v8::Object> Function::NewInstance() const { |
| 4511 return NewInstance(Isolate::GetCurrent()->GetCurrentContext(), 0, NULL) | 4512 return NewInstance(Isolate::GetCurrent()->GetCurrentContext(), 0, NULL) |
| 4512 .FromMaybe(Local<Object>()); | 4513 .FromMaybe(Local<Object>()); |
| 4513 } | 4514 } |
| 4514 | 4515 |
| 4515 | 4516 |
| (...skipping 4383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8899 Address callback_address = | 8900 Address callback_address = |
| 8900 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 8901 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
| 8901 VMState<EXTERNAL> state(isolate); | 8902 VMState<EXTERNAL> state(isolate); |
| 8902 ExternalCallbackScope call_scope(isolate, callback_address); | 8903 ExternalCallbackScope call_scope(isolate, callback_address); |
| 8903 callback(info); | 8904 callback(info); |
| 8904 } | 8905 } |
| 8905 | 8906 |
| 8906 | 8907 |
| 8907 } // namespace internal | 8908 } // namespace internal |
| 8908 } // namespace v8 | 8909 } // namespace v8 |
| OLD | NEW |