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 } | 1179 } |
1180 obj->set_length(length); | 1180 obj->set_length(length); |
1181 obj->set_undetectable(false); | 1181 obj->set_undetectable(false); |
1182 obj->set_needs_access_check(false); | 1182 obj->set_needs_access_check(false); |
1183 obj->set_accept_any_receiver(true); | 1183 obj->set_accept_any_receiver(true); |
1184 if (!signature.IsEmpty()) | 1184 if (!signature.IsEmpty()) |
1185 obj->set_signature(*Utils::OpenHandle(*signature)); | 1185 obj->set_signature(*Utils::OpenHandle(*signature)); |
1186 return Utils::ToLocal(obj); | 1186 return Utils::ToLocal(obj); |
1187 } | 1187 } |
1188 | 1188 |
1189 | 1189 Local<FunctionTemplate> FunctionTemplate::New( |
1190 Local<FunctionTemplate> FunctionTemplate::New(Isolate* isolate, | 1190 Isolate* isolate, FunctionCallback callback, v8::Local<Value> data, |
1191 FunctionCallback callback, | 1191 v8::Local<Signature> signature, int length, ConstructorBehavior behavior) { |
1192 v8::Local<Value> data, | |
1193 v8::Local<Signature> signature, | |
1194 int length) { | |
1195 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 1192 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
1196 // 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 |
1197 // function templates when the isolate is created for serialization. | 1194 // function templates when the isolate is created for serialization. |
1198 LOG_API(i_isolate, FunctionTemplate, New); | 1195 LOG_API(i_isolate, FunctionTemplate, New); |
1199 ENTER_V8(i_isolate); | 1196 ENTER_V8(i_isolate); |
1200 return FunctionTemplateNew(i_isolate, callback, nullptr, data, signature, | 1197 auto templ = FunctionTemplateNew(i_isolate, callback, nullptr, data, |
1201 length, false); | 1198 signature, length, false); |
| 1199 if (behavior == ConstructorBehavior::kThrow) templ->RemovePrototype(); |
| 1200 return templ; |
1202 } | 1201 } |
1203 | 1202 |
1204 MaybeLocal<FunctionTemplate> FunctionTemplate::FromSnapshot(Isolate* isolate, | 1203 MaybeLocal<FunctionTemplate> FunctionTemplate::FromSnapshot(Isolate* isolate, |
1205 size_t index) { | 1204 size_t index) { |
1206 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 1205 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
1207 i::FixedArray* templates = i_isolate->heap()->serialized_templates(); | 1206 i::FixedArray* templates = i_isolate->heap()->serialized_templates(); |
1208 int int_index = static_cast<int>(index); | 1207 int int_index = static_cast<int>(index); |
1209 if (int_index < templates->length()) { | 1208 if (int_index < templates->length()) { |
1210 i::Object* info = templates->get(int_index); | 1209 i::Object* info = templates->get(int_index); |
1211 if (info->IsFunctionTemplateInfo()) { | 1210 if (info->IsFunctionTemplateInfo()) { |
(...skipping 3278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4490 } | 4489 } |
4491 | 4490 |
4492 | 4491 |
4493 Local<v8::Value> Object::CallAsConstructor(int argc, | 4492 Local<v8::Value> Object::CallAsConstructor(int argc, |
4494 v8::Local<v8::Value> argv[]) { | 4493 v8::Local<v8::Value> argv[]) { |
4495 auto context = ContextFromHeapObject(Utils::OpenHandle(this)); | 4494 auto context = ContextFromHeapObject(Utils::OpenHandle(this)); |
4496 Local<Value>* argv_cast = reinterpret_cast<Local<Value>*>(argv); | 4495 Local<Value>* argv_cast = reinterpret_cast<Local<Value>*>(argv); |
4497 RETURN_TO_LOCAL_UNCHECKED(CallAsConstructor(context, argc, argv_cast), Value); | 4496 RETURN_TO_LOCAL_UNCHECKED(CallAsConstructor(context, argc, argv_cast), Value); |
4498 } | 4497 } |
4499 | 4498 |
4500 | |
4501 MaybeLocal<Function> Function::New(Local<Context> context, | 4499 MaybeLocal<Function> Function::New(Local<Context> context, |
4502 FunctionCallback callback, Local<Value> data, | 4500 FunctionCallback callback, Local<Value> data, |
4503 int length) { | 4501 int length, ConstructorBehavior behavior) { |
4504 i::Isolate* isolate = Utils::OpenHandle(*context)->GetIsolate(); | 4502 i::Isolate* isolate = Utils::OpenHandle(*context)->GetIsolate(); |
4505 LOG_API(isolate, Function, New); | 4503 LOG_API(isolate, Function, New); |
4506 ENTER_V8(isolate); | 4504 ENTER_V8(isolate); |
4507 return FunctionTemplateNew(isolate, callback, nullptr, data, | 4505 auto templ = FunctionTemplateNew(isolate, callback, nullptr, data, |
4508 Local<Signature>(), length, true) | 4506 Local<Signature>(), length, true); |
4509 ->GetFunction(context); | 4507 if (behavior == ConstructorBehavior::kThrow) templ->RemovePrototype(); |
| 4508 return templ->GetFunction(context); |
4510 } | 4509 } |
4511 | 4510 |
4512 | 4511 |
4513 Local<Function> Function::New(Isolate* v8_isolate, FunctionCallback callback, | 4512 Local<Function> Function::New(Isolate* v8_isolate, FunctionCallback callback, |
4514 Local<Value> data, int length) { | 4513 Local<Value> data, int length) { |
4515 return Function::New(v8_isolate->GetCurrentContext(), callback, data, length) | 4514 return Function::New(v8_isolate->GetCurrentContext(), callback, data, length, |
| 4515 ConstructorBehavior::kAllow) |
4516 .FromMaybe(Local<Function>()); | 4516 .FromMaybe(Local<Function>()); |
4517 } | 4517 } |
4518 | 4518 |
4519 | 4519 |
4520 Local<v8::Object> Function::NewInstance() const { | 4520 Local<v8::Object> Function::NewInstance() const { |
4521 return NewInstance(Isolate::GetCurrent()->GetCurrentContext(), 0, NULL) | 4521 return NewInstance(Isolate::GetCurrent()->GetCurrentContext(), 0, NULL) |
4522 .FromMaybe(Local<Object>()); | 4522 .FromMaybe(Local<Object>()); |
4523 } | 4523 } |
4524 | 4524 |
4525 | 4525 |
(...skipping 4413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8939 Address callback_address = | 8939 Address callback_address = |
8940 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 8940 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
8941 VMState<EXTERNAL> state(isolate); | 8941 VMState<EXTERNAL> state(isolate); |
8942 ExternalCallbackScope call_scope(isolate, callback_address); | 8942 ExternalCallbackScope call_scope(isolate, callback_address); |
8943 callback(info); | 8943 callback(info); |
8944 } | 8944 } |
8945 | 8945 |
8946 | 8946 |
8947 } // namespace internal | 8947 } // namespace internal |
8948 } // namespace v8 | 8948 } // namespace v8 |
OLD | NEW |