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 1034 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1045 | 1045 |
1046 | 1046 |
1047 void FunctionTemplate::Inherit(v8::Handle<FunctionTemplate> value) { | 1047 void FunctionTemplate::Inherit(v8::Handle<FunctionTemplate> value) { |
1048 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 1048 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
1049 if (IsDeadCheck(isolate, "v8::FunctionTemplate::Inherit()")) return; | 1049 if (IsDeadCheck(isolate, "v8::FunctionTemplate::Inherit()")) return; |
1050 ENTER_V8(isolate); | 1050 ENTER_V8(isolate); |
1051 Utils::OpenHandle(this)->set_parent_template(*Utils::OpenHandle(*value)); | 1051 Utils::OpenHandle(this)->set_parent_template(*Utils::OpenHandle(*value)); |
1052 } | 1052 } |
1053 | 1053 |
1054 | 1054 |
1055 static Local<FunctionTemplate> FunctionTemplateNew( | 1055 Local<FunctionTemplate> FunctionTemplate::New( |
1056 i::Isolate* isolate, | |
1057 FunctionCallback callback, | 1056 FunctionCallback callback, |
1058 v8::Handle<Value> data, | 1057 v8::Handle<Value> data, |
1059 v8::Handle<Signature> signature, | 1058 v8::Handle<Signature> signature, |
1060 int length, | 1059 int length) { |
1061 bool do_not_cache) { | 1060 i::Isolate* isolate = i::Isolate::Current(); |
| 1061 EnsureInitializedForIsolate(isolate, "v8::FunctionTemplate::New()"); |
| 1062 LOG_API(isolate, "FunctionTemplate::New"); |
| 1063 ENTER_V8(isolate); |
1062 i::Handle<i::Struct> struct_obj = | 1064 i::Handle<i::Struct> struct_obj = |
1063 isolate->factory()->NewStruct(i::FUNCTION_TEMPLATE_INFO_TYPE); | 1065 isolate->factory()->NewStruct(i::FUNCTION_TEMPLATE_INFO_TYPE); |
1064 i::Handle<i::FunctionTemplateInfo> obj = | 1066 i::Handle<i::FunctionTemplateInfo> obj = |
1065 i::Handle<i::FunctionTemplateInfo>::cast(struct_obj); | 1067 i::Handle<i::FunctionTemplateInfo>::cast(struct_obj); |
1066 InitializeFunctionTemplate(obj); | 1068 InitializeFunctionTemplate(obj); |
1067 obj->set_do_not_cache(do_not_cache); | 1069 int next_serial_number = isolate->next_serial_number(); |
1068 int next_serial_number = 0; | 1070 isolate->set_next_serial_number(next_serial_number + 1); |
1069 if (!do_not_cache) { | |
1070 next_serial_number = isolate->next_serial_number() + 1; | |
1071 isolate->set_next_serial_number(next_serial_number); | |
1072 } | |
1073 obj->set_serial_number(i::Smi::FromInt(next_serial_number)); | 1071 obj->set_serial_number(i::Smi::FromInt(next_serial_number)); |
1074 if (callback != 0) { | 1072 if (callback != 0) { |
1075 if (data.IsEmpty()) data = v8::Undefined(); | 1073 if (data.IsEmpty()) data = v8::Undefined(); |
1076 Utils::ToLocal(obj)->SetCallHandler(callback, data); | 1074 Utils::ToLocal(obj)->SetCallHandler(callback, data); |
1077 } | 1075 } |
1078 obj->set_length(length); | 1076 obj->set_length(length); |
1079 obj->set_undetectable(false); | 1077 obj->set_undetectable(false); |
1080 obj->set_needs_access_check(false); | 1078 obj->set_needs_access_check(false); |
| 1079 |
1081 if (!signature.IsEmpty()) | 1080 if (!signature.IsEmpty()) |
1082 obj->set_signature(*Utils::OpenHandle(*signature)); | 1081 obj->set_signature(*Utils::OpenHandle(*signature)); |
1083 return Utils::ToLocal(obj); | 1082 return Utils::ToLocal(obj); |
1084 } | 1083 } |
1085 | 1084 |
1086 Local<FunctionTemplate> FunctionTemplate::New( | |
1087 FunctionCallback callback, | |
1088 v8::Handle<Value> data, | |
1089 v8::Handle<Signature> signature, | |
1090 int length) { | |
1091 i::Isolate* isolate = i::Isolate::Current(); | |
1092 EnsureInitializedForIsolate(isolate, "v8::FunctionTemplate::New()"); | |
1093 LOG_API(isolate, "FunctionTemplate::New"); | |
1094 ENTER_V8(isolate); | |
1095 return FunctionTemplateNew( | |
1096 isolate, callback, data, signature, length, false); | |
1097 } | |
1098 | |
1099 | 1085 |
1100 Local<Signature> Signature::New(Handle<FunctionTemplate> receiver, | 1086 Local<Signature> Signature::New(Handle<FunctionTemplate> receiver, |
1101 int argc, Handle<FunctionTemplate> argv[]) { | 1087 int argc, Handle<FunctionTemplate> argv[]) { |
1102 i::Isolate* isolate = i::Isolate::Current(); | 1088 i::Isolate* isolate = i::Isolate::Current(); |
1103 EnsureInitializedForIsolate(isolate, "v8::Signature::New()"); | 1089 EnsureInitializedForIsolate(isolate, "v8::Signature::New()"); |
1104 LOG_API(isolate, "Signature::New"); | 1090 LOG_API(isolate, "Signature::New"); |
1105 ENTER_V8(isolate); | 1091 ENTER_V8(isolate); |
1106 i::Handle<i::Struct> struct_obj = | 1092 i::Handle<i::Struct> struct_obj = |
1107 isolate->factory()->NewStruct(i::SIGNATURE_INFO_TYPE); | 1093 isolate->factory()->NewStruct(i::SIGNATURE_INFO_TYPE); |
1108 i::Handle<i::SignatureInfo> obj = | 1094 i::Handle<i::SignatureInfo> obj = |
(...skipping 3087 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4196 i::Handle<i::Object> returned = i::Execution::Call( | 4182 i::Handle<i::Object> returned = i::Execution::Call( |
4197 isolate, fun, obj, argc, args, &has_pending_exception); | 4183 isolate, fun, obj, argc, args, &has_pending_exception); |
4198 EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, Local<v8::Object>()); | 4184 EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, Local<v8::Object>()); |
4199 ASSERT(!delegate->IsUndefined()); | 4185 ASSERT(!delegate->IsUndefined()); |
4200 return Utils::ToLocal(scope.CloseAndEscape(returned)); | 4186 return Utils::ToLocal(scope.CloseAndEscape(returned)); |
4201 } | 4187 } |
4202 return Local<v8::Object>(); | 4188 return Local<v8::Object>(); |
4203 } | 4189 } |
4204 | 4190 |
4205 | 4191 |
4206 Local<Function> Function::New(Isolate* v8_isolate, | |
4207 FunctionCallback callback, | |
4208 Local<Value> data, | |
4209 int length) { | |
4210 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); | |
4211 LOG_API(isolate, "Function::New"); | |
4212 ENTER_V8(isolate); | |
4213 return FunctionTemplateNew( | |
4214 isolate, callback, data, Local<Signature>(), length, true)-> | |
4215 GetFunction(); | |
4216 } | |
4217 | |
4218 | |
4219 Local<v8::Object> Function::NewInstance() const { | 4192 Local<v8::Object> Function::NewInstance() const { |
4220 return NewInstance(0, NULL); | 4193 return NewInstance(0, NULL); |
4221 } | 4194 } |
4222 | 4195 |
4223 | 4196 |
4224 Local<v8::Object> Function::NewInstance(int argc, | 4197 Local<v8::Object> Function::NewInstance(int argc, |
4225 v8::Handle<v8::Value> argv[]) const { | 4198 v8::Handle<v8::Value> argv[]) const { |
4226 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 4199 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
4227 ON_BAILOUT(isolate, "v8::Function::NewInstance()", | 4200 ON_BAILOUT(isolate, "v8::Function::NewInstance()", |
4228 return Local<v8::Object>()); | 4201 return Local<v8::Object>()); |
(...skipping 3672 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7901 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); | 7874 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); |
7902 Address callback_address = | 7875 Address callback_address = |
7903 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 7876 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
7904 VMState<EXTERNAL> state(isolate); | 7877 VMState<EXTERNAL> state(isolate); |
7905 ExternalCallbackScope call_scope(isolate, callback_address); | 7878 ExternalCallbackScope call_scope(isolate, callback_address); |
7906 return callback(info); | 7879 return callback(info); |
7907 } | 7880 } |
7908 | 7881 |
7909 | 7882 |
7910 } } // namespace v8::internal | 7883 } } // namespace v8::internal |
OLD | NEW |