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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 UNREACHABLE(); \ | 65 UNREACHABLE(); \ |
66 } | 66 } |
67 | 67 |
68 | 68 |
69 #define EXCEPTION_PREAMBLE(isolate) \ | 69 #define EXCEPTION_PREAMBLE(isolate) \ |
70 (isolate)->handle_scope_implementer()->IncrementCallDepth(); \ | 70 (isolate)->handle_scope_implementer()->IncrementCallDepth(); \ |
71 DCHECK(!(isolate)->external_caught_exception()); \ | 71 DCHECK(!(isolate)->external_caught_exception()); \ |
72 bool has_pending_exception = false | 72 bool has_pending_exception = false |
73 | 73 |
74 | 74 |
75 #define EXCEPTION_BAILOUT_CHECK_GENERIC(isolate, value, do_callback) \ | 75 #define EXCEPTION_BAILOUT_CHECK(isolate, value) \ |
76 do { \ | 76 do { \ |
77 i::HandleScopeImplementer* handle_scope_implementer = \ | 77 i::HandleScopeImplementer* handle_scope_implementer = \ |
78 (isolate)->handle_scope_implementer(); \ | 78 (isolate)->handle_scope_implementer(); \ |
79 handle_scope_implementer->DecrementCallDepth(); \ | 79 handle_scope_implementer->DecrementCallDepth(); \ |
80 if (has_pending_exception) { \ | 80 if (has_pending_exception) { \ |
81 bool call_depth_is_zero = handle_scope_implementer->CallDepthIsZero(); \ | 81 bool call_depth_is_zero = handle_scope_implementer->CallDepthIsZero(); \ |
82 (isolate)->OptionalRescheduleException(call_depth_is_zero); \ | 82 (isolate)->OptionalRescheduleException(call_depth_is_zero); \ |
83 do_callback \ | 83 return value; \ |
84 return value; \ | 84 } \ |
85 } \ | |
86 do_callback \ | |
87 } while (false) | 85 } while (false) |
88 | 86 |
89 | 87 |
90 #define EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, value) \ | |
91 EXCEPTION_BAILOUT_CHECK_GENERIC( \ | |
92 isolate, value, isolate->FireCallCompletedCallback();) | |
93 | |
94 | |
95 #define EXCEPTION_BAILOUT_CHECK(isolate, value) \ | |
96 EXCEPTION_BAILOUT_CHECK_GENERIC(isolate, value, ;) | |
97 | |
98 | |
99 #define PREPARE_FOR_EXECUTION_GENERIC(isolate, context, function_name, \ | 88 #define PREPARE_FOR_EXECUTION_GENERIC(isolate, context, function_name, \ |
100 bailout_value, HandleScopeClass, \ | 89 bailout_value, HandleScopeClass, \ |
101 do_callback) \ | 90 do_callback) \ |
102 if (IsExecutionTerminatingCheck(isolate)) { \ | 91 if (IsExecutionTerminatingCheck(isolate)) { \ |
103 return bailout_value; \ | 92 return bailout_value; \ |
104 } \ | 93 } \ |
105 HandleScopeClass handle_scope(isolate); \ | 94 HandleScopeClass handle_scope(isolate); \ |
106 CallDepthScope call_depth_scope(isolate, context, do_callback); \ | 95 CallDepthScope call_depth_scope(isolate, context, do_callback); \ |
107 LOG_API(isolate, function_name); \ | 96 LOG_API(isolate, function_name); \ |
108 ENTER_V8(isolate); \ | 97 ENTER_V8(isolate); \ |
(...skipping 4273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4382 isolate, callback, data, Local<Signature>(), length, true)-> | 4371 isolate, callback, data, Local<Signature>(), length, true)-> |
4383 GetFunction(); | 4372 GetFunction(); |
4384 } | 4373 } |
4385 | 4374 |
4386 | 4375 |
4387 Local<v8::Object> Function::NewInstance() const { | 4376 Local<v8::Object> Function::NewInstance() const { |
4388 return NewInstance(0, NULL); | 4377 return NewInstance(0, NULL); |
4389 } | 4378 } |
4390 | 4379 |
4391 | 4380 |
| 4381 MaybeLocal<Object> Function::NewInstance(Local<Context> context, int argc, |
| 4382 v8::Handle<v8::Value> argv[]) const { |
| 4383 PREPARE_FOR_EXECUTION_WITH_CALLBACK(context, "v8::Function::NewInstance()", |
| 4384 Object); |
| 4385 i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate); |
| 4386 auto self = Utils::OpenHandle(this); |
| 4387 STATIC_ASSERT(sizeof(v8::Handle<v8::Value>) == sizeof(i::Object**)); |
| 4388 i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv); |
| 4389 Local<Object> result; |
| 4390 has_pending_exception = |
| 4391 !ToLocal<Object>(i::Execution::New(self, argc, args), &result); |
| 4392 RETURN_ON_FAILED_EXECUTION(Object); |
| 4393 RETURN_ESCAPED(result); |
| 4394 } |
| 4395 |
| 4396 |
4392 Local<v8::Object> Function::NewInstance(int argc, | 4397 Local<v8::Object> Function::NewInstance(int argc, |
4393 v8::Handle<v8::Value> argv[]) const { | 4398 v8::Handle<v8::Value> argv[]) const { |
4394 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 4399 auto context = ContextFromHeapObject(Utils::OpenHandle(this)); |
4395 ON_BAILOUT(isolate, "v8::Function::NewInstance()", | 4400 RETURN_TO_LOCAL_UNCHECKED(NewInstance(context, argc, argv), Object); |
4396 return Local<v8::Object>()); | 4401 } |
4397 LOG_API(isolate, "Function::NewInstance"); | 4402 |
4398 ENTER_V8(isolate); | 4403 |
| 4404 MaybeLocal<v8::Value> Function::Call(Local<Context> context, |
| 4405 v8::Handle<v8::Value> recv, int argc, |
| 4406 v8::Handle<v8::Value> argv[]) { |
| 4407 PREPARE_FOR_EXECUTION_WITH_CALLBACK(context, "v8::Function::Call()", Value); |
4399 i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate); | 4408 i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate); |
4400 EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate)); | 4409 auto self = Utils::OpenHandle(this); |
4401 i::Handle<i::JSFunction> function = Utils::OpenHandle(this); | 4410 i::Handle<i::Object> recv_obj = Utils::OpenHandle(*recv); |
4402 STATIC_ASSERT(sizeof(v8::Handle<v8::Value>) == sizeof(i::Object**)); | 4411 STATIC_ASSERT(sizeof(v8::Handle<v8::Value>) == sizeof(i::Object**)); |
4403 i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv); | 4412 i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv); |
4404 EXCEPTION_PREAMBLE(isolate); | 4413 Local<Value> result; |
4405 i::Handle<i::Object> returned; | 4414 has_pending_exception = |
4406 has_pending_exception = !i::Execution::New( | 4415 !ToLocal<Value>( |
4407 function, argc, args).ToHandle(&returned); | 4416 i::Execution::Call(isolate, self, recv_obj, argc, args, true), |
4408 EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, Local<v8::Object>()); | 4417 &result); |
4409 return scope.Escape(Utils::ToLocal(i::Handle<i::JSObject>::cast(returned))); | 4418 RETURN_ON_FAILED_EXECUTION(Value); |
| 4419 RETURN_ESCAPED(result); |
4410 } | 4420 } |
4411 | 4421 |
4412 | 4422 |
4413 Local<v8::Value> Function::Call(v8::Handle<v8::Value> recv, int argc, | 4423 Local<v8::Value> Function::Call(v8::Handle<v8::Value> recv, int argc, |
4414 v8::Handle<v8::Value> argv[]) { | 4424 v8::Handle<v8::Value> argv[]) { |
4415 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 4425 auto context = ContextFromHeapObject(Utils::OpenHandle(this)); |
4416 ON_BAILOUT(isolate, "v8::Function::Call()", return Local<v8::Value>()); | 4426 RETURN_TO_LOCAL_UNCHECKED(Call(context, recv, argc, argv), Value); |
4417 LOG_API(isolate, "Function::Call"); | |
4418 ENTER_V8(isolate); | |
4419 i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate); | |
4420 i::HandleScope scope(isolate); | |
4421 i::Handle<i::JSFunction> fun = Utils::OpenHandle(this); | |
4422 i::Handle<i::Object> recv_obj = Utils::OpenHandle(*recv); | |
4423 STATIC_ASSERT(sizeof(v8::Handle<v8::Value>) == sizeof(i::Object**)); | |
4424 i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv); | |
4425 EXCEPTION_PREAMBLE(isolate); | |
4426 i::Handle<i::Object> returned; | |
4427 has_pending_exception = !i::Execution::Call( | |
4428 isolate, fun, recv_obj, argc, args, true).ToHandle(&returned); | |
4429 EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, Local<Object>()); | |
4430 return Utils::ToLocal(scope.CloseAndEscape(returned)); | |
4431 } | 4427 } |
4432 | 4428 |
4433 | 4429 |
4434 void Function::SetName(v8::Handle<v8::String> name) { | 4430 void Function::SetName(v8::Handle<v8::String> name) { |
4435 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | |
4436 ENTER_V8(isolate); | |
4437 USE(isolate); | |
4438 i::Handle<i::JSFunction> func = Utils::OpenHandle(this); | 4431 i::Handle<i::JSFunction> func = Utils::OpenHandle(this); |
4439 func->shared()->set_name(*Utils::OpenHandle(*name)); | 4432 func->shared()->set_name(*Utils::OpenHandle(*name)); |
4440 } | 4433 } |
4441 | 4434 |
4442 | 4435 |
4443 Handle<Value> Function::GetName() const { | 4436 Handle<Value> Function::GetName() const { |
4444 i::Handle<i::JSFunction> func = Utils::OpenHandle(this); | 4437 i::Handle<i::JSFunction> func = Utils::OpenHandle(this); |
4445 return Utils::ToLocal(i::Handle<i::Object>(func->shared()->name(), | 4438 return Utils::ToLocal(i::Handle<i::Object>(func->shared()->name(), |
4446 func->GetIsolate())); | 4439 func->GetIsolate())); |
4447 } | 4440 } |
4448 | 4441 |
4449 | 4442 |
4450 Handle<Value> Function::GetInferredName() const { | 4443 Handle<Value> Function::GetInferredName() const { |
4451 i::Handle<i::JSFunction> func = Utils::OpenHandle(this); | 4444 i::Handle<i::JSFunction> func = Utils::OpenHandle(this); |
4452 return Utils::ToLocal(i::Handle<i::Object>(func->shared()->inferred_name(), | 4445 return Utils::ToLocal(i::Handle<i::Object>(func->shared()->inferred_name(), |
4453 func->GetIsolate())); | 4446 func->GetIsolate())); |
4454 } | 4447 } |
4455 | 4448 |
4456 | 4449 |
4457 Handle<Value> Function::GetDisplayName() const { | 4450 Handle<Value> Function::GetDisplayName() const { |
4458 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 4451 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
4459 ON_BAILOUT(isolate, "v8::Function::GetDisplayName()", | |
4460 return ToApiHandle<Primitive>( | |
4461 isolate->factory()->undefined_value())); | |
4462 ENTER_V8(isolate); | 4452 ENTER_V8(isolate); |
4463 i::Handle<i::JSFunction> func = Utils::OpenHandle(this); | 4453 i::Handle<i::JSFunction> func = Utils::OpenHandle(this); |
4464 i::Handle<i::String> property_name = | 4454 i::Handle<i::String> property_name = |
4465 isolate->factory()->InternalizeOneByteString( | 4455 isolate->factory()->NewStringFromStaticChars("displayName"); |
4466 STATIC_CHAR_VECTOR("displayName")); | |
4467 | |
4468 i::Handle<i::Object> value = | 4456 i::Handle<i::Object> value = |
4469 i::JSObject::GetDataProperty(func, property_name); | 4457 i::JSObject::GetDataProperty(func, property_name); |
4470 if (value->IsString()) { | 4458 if (value->IsString()) { |
4471 i::Handle<i::String> name = i::Handle<i::String>::cast(value); | 4459 i::Handle<i::String> name = i::Handle<i::String>::cast(value); |
4472 if (name->length() > 0) return Utils::ToLocal(name); | 4460 if (name->length() > 0) return Utils::ToLocal(name); |
4473 } | 4461 } |
4474 | |
4475 return ToApiHandle<Primitive>(isolate->factory()->undefined_value()); | 4462 return ToApiHandle<Primitive>(isolate->factory()->undefined_value()); |
4476 } | 4463 } |
4477 | 4464 |
4478 | 4465 |
4479 ScriptOrigin Function::GetScriptOrigin() const { | 4466 ScriptOrigin Function::GetScriptOrigin() const { |
4480 i::Handle<i::JSFunction> func = Utils::OpenHandle(this); | 4467 i::Handle<i::JSFunction> func = Utils::OpenHandle(this); |
4481 if (func->shared()->script()->IsScript()) { | 4468 if (func->shared()->script()->IsScript()) { |
4482 i::Handle<i::Script> script(i::Script::cast(func->shared()->script())); | 4469 i::Handle<i::Script> script(i::Script::cast(func->shared()->script())); |
4483 return GetScriptOriginForScript(func->GetIsolate(), script); | 4470 return GetScriptOriginForScript(func->GetIsolate(), script); |
4484 } | 4471 } |
(...skipping 1655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6140 isolate, | 6127 isolate, |
6141 isolate->is_promise(), | 6128 isolate->is_promise(), |
6142 isolate->factory()->undefined_value(), | 6129 isolate->factory()->undefined_value(), |
6143 arraysize(argv), argv, | 6130 arraysize(argv), argv, |
6144 false).ToHandle(&b); | 6131 false).ToHandle(&b); |
6145 EXCEPTION_BAILOUT_CHECK(isolate, false); | 6132 EXCEPTION_BAILOUT_CHECK(isolate, false); |
6146 return b->BooleanValue(); | 6133 return b->BooleanValue(); |
6147 } | 6134 } |
6148 | 6135 |
6149 | 6136 |
6150 Local<Promise::Resolver> Promise::Resolver::New(Isolate* v8_isolate) { | 6137 MaybeLocal<Promise::Resolver> Promise::Resolver::New(Local<Context> context) { |
6151 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); | 6138 PREPARE_FOR_EXECUTION(context, "Promise::Resolver::New", Resolver); |
6152 LOG_API(isolate, "Promise::Resolver::New"); | |
6153 ENTER_V8(isolate); | |
6154 EXCEPTION_PREAMBLE(isolate); | |
6155 i::Handle<i::Object> result; | 6139 i::Handle<i::Object> result; |
6156 has_pending_exception = !i::Execution::Call( | 6140 has_pending_exception = !i::Execution::Call( |
6157 isolate, | 6141 isolate, |
6158 isolate->promise_create(), | 6142 isolate->promise_create(), |
6159 isolate->factory()->undefined_value(), | 6143 isolate->factory()->undefined_value(), |
6160 0, NULL, | 6144 0, NULL, |
6161 false).ToHandle(&result); | 6145 false).ToHandle(&result); |
6162 EXCEPTION_BAILOUT_CHECK(isolate, Local<Promise::Resolver>()); | 6146 RETURN_ON_FAILED_EXECUTION(Promise::Resolver); |
6163 return Local<Promise::Resolver>::Cast(Utils::ToLocal(result)); | 6147 RETURN_ESCAPED(Local<Promise::Resolver>::Cast(Utils::ToLocal(result))); |
6164 } | 6148 } |
6165 | 6149 |
6166 | 6150 |
| 6151 Local<Promise::Resolver> Promise::Resolver::New(Isolate* isolate) { |
| 6152 RETURN_TO_LOCAL_UNCHECKED(New(isolate->GetCurrentContext()), |
| 6153 Promise::Resolver); |
| 6154 } |
| 6155 |
| 6156 |
6167 Local<Promise> Promise::Resolver::GetPromise() { | 6157 Local<Promise> Promise::Resolver::GetPromise() { |
6168 i::Handle<i::JSObject> promise = Utils::OpenHandle(this); | 6158 i::Handle<i::JSObject> promise = Utils::OpenHandle(this); |
6169 return Local<Promise>::Cast(Utils::ToLocal(promise)); | 6159 return Local<Promise>::Cast(Utils::ToLocal(promise)); |
6170 } | 6160 } |
6171 | 6161 |
6172 | 6162 |
6173 void Promise::Resolver::Resolve(Handle<Value> value) { | 6163 Maybe<bool> Promise::Resolver::Resolve(Local<Context> context, |
6174 i::Handle<i::JSObject> promise = Utils::OpenHandle(this); | 6164 Handle<Value> value) { |
6175 i::Isolate* isolate = promise->GetIsolate(); | 6165 PREPARE_FOR_EXECUTION_PRIMITIVE(context, "Promise::Resolver::Resolve", bool); |
6176 LOG_API(isolate, "Promise::Resolver::Resolve"); | 6166 auto self = Utils::OpenHandle(this); |
6177 ENTER_V8(isolate); | 6167 i::Handle<i::Object> argv[] = {self, Utils::OpenHandle(*value)}; |
6178 EXCEPTION_PREAMBLE(isolate); | |
6179 i::Handle<i::Object> argv[] = { promise, Utils::OpenHandle(*value) }; | |
6180 has_pending_exception = i::Execution::Call( | 6168 has_pending_exception = i::Execution::Call( |
6181 isolate, | 6169 isolate, |
6182 isolate->promise_resolve(), | 6170 isolate->promise_resolve(), |
6183 isolate->factory()->undefined_value(), | 6171 isolate->factory()->undefined_value(), |
6184 arraysize(argv), argv, | 6172 arraysize(argv), argv, |
6185 false).is_null(); | 6173 false).is_null(); |
6186 EXCEPTION_BAILOUT_CHECK(isolate, /* void */ ;); | 6174 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); |
| 6175 return Just(true); |
6187 } | 6176 } |
6188 | 6177 |
6189 | 6178 |
6190 void Promise::Resolver::Reject(Handle<Value> value) { | 6179 void Promise::Resolver::Resolve(Handle<Value> value) { |
6191 i::Handle<i::JSObject> promise = Utils::OpenHandle(this); | 6180 auto context = ContextFromHeapObject(Utils::OpenHandle(this)); |
6192 i::Isolate* isolate = promise->GetIsolate(); | 6181 Resolve(context, value); |
6193 LOG_API(isolate, "Promise::Resolver::Reject"); | 6182 } |
6194 ENTER_V8(isolate); | 6183 |
6195 EXCEPTION_PREAMBLE(isolate); | 6184 |
6196 i::Handle<i::Object> argv[] = { promise, Utils::OpenHandle(*value) }; | 6185 Maybe<bool> Promise::Resolver::Reject(Local<Context> context, |
| 6186 Handle<Value> value) { |
| 6187 PREPARE_FOR_EXECUTION_PRIMITIVE(context, "Promise::Resolver::Resolve", bool); |
| 6188 auto self = Utils::OpenHandle(this); |
| 6189 i::Handle<i::Object> argv[] = {self, Utils::OpenHandle(*value)}; |
6197 has_pending_exception = i::Execution::Call( | 6190 has_pending_exception = i::Execution::Call( |
6198 isolate, | 6191 isolate, |
6199 isolate->promise_reject(), | 6192 isolate->promise_reject(), |
6200 isolate->factory()->undefined_value(), | 6193 isolate->factory()->undefined_value(), |
6201 arraysize(argv), argv, | 6194 arraysize(argv), argv, |
6202 false).is_null(); | 6195 false).is_null(); |
6203 EXCEPTION_BAILOUT_CHECK(isolate, /* void */ ;); | 6196 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); |
| 6197 return Just(true); |
| 6198 } |
| 6199 |
| 6200 |
| 6201 void Promise::Resolver::Reject(Handle<Value> value) { |
| 6202 auto context = ContextFromHeapObject(Utils::OpenHandle(this)); |
| 6203 Reject(context, value); |
| 6204 } |
| 6205 |
| 6206 |
| 6207 MaybeLocal<Promise> Promise::Chain(Local<Context> context, |
| 6208 Handle<Function> handler) { |
| 6209 PREPARE_FOR_EXECUTION(context, "Promise::Chain", Promise); |
| 6210 auto self = Utils::OpenHandle(this); |
| 6211 i::Handle<i::Object> argv[] = {Utils::OpenHandle(*handler)}; |
| 6212 i::Handle<i::Object> result; |
| 6213 has_pending_exception = |
| 6214 !i::Execution::Call(isolate, isolate->promise_chain(), self, |
| 6215 arraysize(argv), argv, false).ToHandle(&result); |
| 6216 RETURN_ON_FAILED_EXECUTION(Promise); |
| 6217 RETURN_ESCAPED(Local<Promise>::Cast(Utils::ToLocal(result))); |
6204 } | 6218 } |
6205 | 6219 |
6206 | 6220 |
6207 Local<Promise> Promise::Chain(Handle<Function> handler) { | 6221 Local<Promise> Promise::Chain(Handle<Function> handler) { |
6208 i::Handle<i::JSObject> promise = Utils::OpenHandle(this); | 6222 auto context = ContextFromHeapObject(Utils::OpenHandle(this)); |
6209 i::Isolate* isolate = promise->GetIsolate(); | 6223 RETURN_TO_LOCAL_UNCHECKED(Chain(context, handler), Promise); |
6210 LOG_API(isolate, "Promise::Chain"); | 6224 } |
6211 ENTER_V8(isolate); | 6225 |
6212 EXCEPTION_PREAMBLE(isolate); | 6226 |
| 6227 MaybeLocal<Promise> Promise::Catch(Local<Context> context, |
| 6228 Handle<Function> handler) { |
| 6229 PREPARE_FOR_EXECUTION(context, "Promise::Catch", Promise); |
| 6230 auto self = Utils::OpenHandle(this); |
6213 i::Handle<i::Object> argv[] = { Utils::OpenHandle(*handler) }; | 6231 i::Handle<i::Object> argv[] = { Utils::OpenHandle(*handler) }; |
6214 i::Handle<i::Object> result; | 6232 i::Handle<i::Object> result; |
6215 has_pending_exception = !i::Execution::Call( | 6233 has_pending_exception = |
6216 isolate, | 6234 !i::Execution::Call(isolate, isolate->promise_catch(), self, |
6217 isolate->promise_chain(), | 6235 arraysize(argv), argv, false).ToHandle(&result); |
6218 promise, | 6236 RETURN_ON_FAILED_EXECUTION(Promise); |
6219 arraysize(argv), argv, | 6237 RETURN_ESCAPED(Local<Promise>::Cast(Utils::ToLocal(result))); |
6220 false).ToHandle(&result); | |
6221 EXCEPTION_BAILOUT_CHECK(isolate, Local<Promise>()); | |
6222 return Local<Promise>::Cast(Utils::ToLocal(result)); | |
6223 } | 6238 } |
6224 | 6239 |
6225 | 6240 |
6226 Local<Promise> Promise::Catch(Handle<Function> handler) { | 6241 Local<Promise> Promise::Catch(Handle<Function> handler) { |
6227 i::Handle<i::JSObject> promise = Utils::OpenHandle(this); | 6242 auto context = ContextFromHeapObject(Utils::OpenHandle(this)); |
6228 i::Isolate* isolate = promise->GetIsolate(); | 6243 RETURN_TO_LOCAL_UNCHECKED(Catch(context, handler), Promise); |
6229 LOG_API(isolate, "Promise::Catch"); | 6244 } |
6230 ENTER_V8(isolate); | 6245 |
6231 EXCEPTION_PREAMBLE(isolate); | 6246 |
| 6247 MaybeLocal<Promise> Promise::Then(Local<Context> context, |
| 6248 Handle<Function> handler) { |
| 6249 PREPARE_FOR_EXECUTION(context, "Promise::Then", Promise); |
| 6250 auto self = Utils::OpenHandle(this); |
6232 i::Handle<i::Object> argv[] = { Utils::OpenHandle(*handler) }; | 6251 i::Handle<i::Object> argv[] = { Utils::OpenHandle(*handler) }; |
6233 i::Handle<i::Object> result; | 6252 i::Handle<i::Object> result; |
6234 has_pending_exception = !i::Execution::Call( | 6253 has_pending_exception = |
6235 isolate, | 6254 !i::Execution::Call(isolate, isolate->promise_then(), self, |
6236 isolate->promise_catch(), | 6255 arraysize(argv), argv, false).ToHandle(&result); |
6237 promise, | 6256 RETURN_ON_FAILED_EXECUTION(Promise); |
6238 arraysize(argv), argv, | 6257 RETURN_ESCAPED(Local<Promise>::Cast(Utils::ToLocal(result))); |
6239 false).ToHandle(&result); | |
6240 EXCEPTION_BAILOUT_CHECK(isolate, Local<Promise>()); | |
6241 return Local<Promise>::Cast(Utils::ToLocal(result)); | |
6242 } | 6258 } |
6243 | 6259 |
6244 | 6260 |
6245 Local<Promise> Promise::Then(Handle<Function> handler) { | 6261 Local<Promise> Promise::Then(Handle<Function> handler) { |
6246 i::Handle<i::JSObject> promise = Utils::OpenHandle(this); | 6262 auto context = ContextFromHeapObject(Utils::OpenHandle(this)); |
6247 i::Isolate* isolate = promise->GetIsolate(); | 6263 RETURN_TO_LOCAL_UNCHECKED(Then(context, handler), Promise); |
6248 LOG_API(isolate, "Promise::Then"); | |
6249 ENTER_V8(isolate); | |
6250 EXCEPTION_PREAMBLE(isolate); | |
6251 i::Handle<i::Object> argv[] = { Utils::OpenHandle(*handler) }; | |
6252 i::Handle<i::Object> result; | |
6253 has_pending_exception = !i::Execution::Call( | |
6254 isolate, | |
6255 isolate->promise_then(), | |
6256 promise, | |
6257 arraysize(argv), argv, | |
6258 false).ToHandle(&result); | |
6259 EXCEPTION_BAILOUT_CHECK(isolate, Local<Promise>()); | |
6260 return Local<Promise>::Cast(Utils::ToLocal(result)); | |
6261 } | 6264 } |
6262 | 6265 |
6263 | 6266 |
6264 bool Promise::HasHandler() { | 6267 bool Promise::HasHandler() { |
6265 i::Handle<i::JSObject> promise = Utils::OpenHandle(this); | 6268 i::Handle<i::JSObject> promise = Utils::OpenHandle(this); |
6266 i::Isolate* isolate = promise->GetIsolate(); | 6269 i::Isolate* isolate = promise->GetIsolate(); |
6267 LOG_API(isolate, "Promise::HasRejectHandler"); | 6270 LOG_API(isolate, "Promise::HasRejectHandler"); |
6268 ENTER_V8(isolate); | 6271 ENTER_V8(isolate); |
6269 i::Handle<i::Symbol> key = isolate->factory()->promise_has_handler_symbol(); | 6272 i::Handle<i::Symbol> key = isolate->factory()->promise_has_handler_symbol(); |
6270 return i::JSObject::GetDataProperty(promise, key)->IsTrue(); | 6273 return i::JSObject::GetDataProperty(promise, key)->IsTrue(); |
(...skipping 1734 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8005 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); | 8008 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); |
8006 Address callback_address = | 8009 Address callback_address = |
8007 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 8010 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
8008 VMState<EXTERNAL> state(isolate); | 8011 VMState<EXTERNAL> state(isolate); |
8009 ExternalCallbackScope call_scope(isolate, callback_address); | 8012 ExternalCallbackScope call_scope(isolate, callback_address); |
8010 callback(info); | 8013 callback(info); |
8011 } | 8014 } |
8012 | 8015 |
8013 | 8016 |
8014 } } // namespace v8::internal | 8017 } } // namespace v8::internal |
OLD | NEW |