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 2257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2268 ENTER_V8(isolate); | 2268 ENTER_V8(isolate); |
2269 EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate)); | 2269 EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate)); |
2270 auto message = i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this)); | 2270 auto message = i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this)); |
2271 i::Handle<i::Object> stackFramesObj(message->stack_frames(), isolate); | 2271 i::Handle<i::Object> stackFramesObj(message->stack_frames(), isolate); |
2272 if (!stackFramesObj->IsJSArray()) return v8::Local<v8::StackTrace>(); | 2272 if (!stackFramesObj->IsJSArray()) return v8::Local<v8::StackTrace>(); |
2273 auto stackTrace = i::Handle<i::JSArray>::cast(stackFramesObj); | 2273 auto stackTrace = i::Handle<i::JSArray>::cast(stackFramesObj); |
2274 return scope.Escape(Utils::StackTraceToLocal(stackTrace)); | 2274 return scope.Escape(Utils::StackTraceToLocal(stackTrace)); |
2275 } | 2275 } |
2276 | 2276 |
2277 | 2277 |
| 2278 MUST_USE_RESULT static i::MaybeHandle<i::Object> CallV8HeapFunction( |
| 2279 i::Isolate* isolate, const char* name, i::Handle<i::Object> recv, int argc, |
| 2280 i::Handle<i::Object> argv[]) { |
| 2281 i::Handle<i::Object> object_fun = |
| 2282 i::Object::GetProperty( |
| 2283 isolate, isolate->js_builtins_object(), name).ToHandleChecked(); |
| 2284 i::Handle<i::JSFunction> fun = i::Handle<i::JSFunction>::cast(object_fun); |
| 2285 return i::Execution::Call(isolate, fun, recv, argc, argv); |
| 2286 } |
| 2287 |
| 2288 |
| 2289 MUST_USE_RESULT static i::MaybeHandle<i::Object> CallV8HeapFunction( |
| 2290 i::Isolate* isolate, const char* name, i::Handle<i::Object> data) { |
| 2291 i::Handle<i::Object> argv[] = { data }; |
| 2292 return CallV8HeapFunction(isolate, name, isolate->js_builtins_object(), |
| 2293 arraysize(argv), argv); |
| 2294 } |
| 2295 |
| 2296 |
2278 Maybe<int> Message::GetLineNumber(Local<Context> context) const { | 2297 Maybe<int> Message::GetLineNumber(Local<Context> context) const { |
2279 PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Message::GetLineNumber()", int); | 2298 PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Message::GetLineNumber()", int); |
2280 i::Handle<i::JSFunction> fun = isolate->message_get_line_number(); | |
2281 i::Handle<i::Object> undefined = isolate->factory()->undefined_value(); | |
2282 i::Handle<i::Object> args[] = {Utils::OpenHandle(this)}; | |
2283 i::Handle<i::Object> result; | 2299 i::Handle<i::Object> result; |
2284 has_pending_exception = | 2300 has_pending_exception = |
2285 !i::Execution::Call(isolate, fun, undefined, arraysize(args), args) | 2301 !CallV8HeapFunction(isolate, "$messageGetLineNumber", |
2286 .ToHandle(&result); | 2302 Utils::OpenHandle(this)).ToHandle(&result); |
2287 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(int); | 2303 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(int); |
2288 return Just(static_cast<int>(result->Number())); | 2304 return Just(static_cast<int>(result->Number())); |
2289 } | 2305 } |
2290 | 2306 |
2291 | 2307 |
2292 int Message::GetLineNumber() const { | 2308 int Message::GetLineNumber() const { |
2293 auto context = ContextFromHeapObject(Utils::OpenHandle(this)); | 2309 auto context = ContextFromHeapObject(Utils::OpenHandle(this)); |
2294 return GetLineNumber(context).FromMaybe(0); | 2310 return GetLineNumber(context).FromMaybe(0); |
2295 } | 2311 } |
2296 | 2312 |
2297 | 2313 |
2298 int Message::GetStartPosition() const { | 2314 int Message::GetStartPosition() const { |
2299 auto self = Utils::OpenHandle(this); | 2315 auto self = Utils::OpenHandle(this); |
2300 return self->start_position(); | 2316 return self->start_position(); |
2301 } | 2317 } |
2302 | 2318 |
2303 | 2319 |
2304 int Message::GetEndPosition() const { | 2320 int Message::GetEndPosition() const { |
2305 auto self = Utils::OpenHandle(this); | 2321 auto self = Utils::OpenHandle(this); |
2306 return self->end_position(); | 2322 return self->end_position(); |
2307 } | 2323 } |
2308 | 2324 |
2309 | 2325 |
2310 Maybe<int> Message::GetStartColumn(Local<Context> context) const { | 2326 Maybe<int> Message::GetStartColumn(Local<Context> context) const { |
2311 PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Message::GetStartColumn()", | 2327 PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Message::GetStartColumn()", |
2312 int); | 2328 int); |
2313 i::Handle<i::JSFunction> fun = isolate->message_get_column_number(); | 2329 auto self = Utils::OpenHandle(this); |
2314 i::Handle<i::Object> undefined = isolate->factory()->undefined_value(); | 2330 i::Handle<i::Object> start_col_obj; |
2315 i::Handle<i::Object> args[] = {Utils::OpenHandle(this)}; | |
2316 i::Handle<i::Object> result; | |
2317 has_pending_exception = | 2331 has_pending_exception = |
2318 !i::Execution::Call(isolate, fun, undefined, arraysize(args), args) | 2332 !CallV8HeapFunction(isolate, "$messageGetPositionInLine", self) |
2319 .ToHandle(&result); | 2333 .ToHandle(&start_col_obj); |
2320 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(int); | 2334 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(int); |
2321 return Just(static_cast<int>(result->Number())); | 2335 return Just(static_cast<int>(start_col_obj->Number())); |
2322 } | 2336 } |
2323 | 2337 |
2324 | 2338 |
2325 int Message::GetStartColumn() const { | 2339 int Message::GetStartColumn() const { |
2326 auto context = ContextFromHeapObject(Utils::OpenHandle(this)); | 2340 auto context = ContextFromHeapObject(Utils::OpenHandle(this)); |
2327 const int default_value = kNoColumnInfo; | 2341 const int default_value = kNoColumnInfo; |
2328 return GetStartColumn(context).FromMaybe(default_value); | 2342 return GetStartColumn(context).FromMaybe(default_value); |
2329 } | 2343 } |
2330 | 2344 |
2331 | 2345 |
2332 Maybe<int> Message::GetEndColumn(Local<Context> context) const { | 2346 Maybe<int> Message::GetEndColumn(Local<Context> context) const { |
| 2347 PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Message::GetEndColumn()", int); |
2333 auto self = Utils::OpenHandle(this); | 2348 auto self = Utils::OpenHandle(this); |
2334 PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Message::GetEndColumn()", int); | 2349 i::Handle<i::Object> start_col_obj; |
2335 i::Handle<i::JSFunction> fun = isolate->message_get_column_number(); | |
2336 i::Handle<i::Object> undefined = isolate->factory()->undefined_value(); | |
2337 i::Handle<i::Object> args[] = {self}; | |
2338 i::Handle<i::Object> result; | |
2339 has_pending_exception = | 2350 has_pending_exception = |
2340 !i::Execution::Call(isolate, fun, undefined, arraysize(args), args) | 2351 !CallV8HeapFunction(isolate, "$messageGetPositionInLine", self) |
2341 .ToHandle(&result); | 2352 .ToHandle(&start_col_obj); |
2342 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(int); | 2353 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(int); |
2343 int start = self->start_position(); | 2354 int start = self->start_position(); |
2344 int end = self->end_position(); | 2355 int end = self->end_position(); |
2345 return Just(static_cast<int>(result->Number()) + (end - start)); | 2356 return Just(static_cast<int>(start_col_obj->Number()) + (end - start)); |
2346 } | 2357 } |
2347 | 2358 |
2348 | 2359 |
2349 int Message::GetEndColumn() const { | 2360 int Message::GetEndColumn() const { |
2350 auto context = ContextFromHeapObject(Utils::OpenHandle(this)); | 2361 auto context = ContextFromHeapObject(Utils::OpenHandle(this)); |
2351 const int default_value = kNoColumnInfo; | 2362 const int default_value = kNoColumnInfo; |
2352 return GetEndColumn(context).FromMaybe(default_value); | 2363 return GetEndColumn(context).FromMaybe(default_value); |
2353 } | 2364 } |
2354 | 2365 |
2355 | 2366 |
(...skipping 13 matching lines...) Expand all Loading... |
2369 ENTER_V8(isolate); | 2380 ENTER_V8(isolate); |
2370 auto self = Utils::OpenHandle(this); | 2381 auto self = Utils::OpenHandle(this); |
2371 auto script = i::Handle<i::JSValue>::cast( | 2382 auto script = i::Handle<i::JSValue>::cast( |
2372 i::Handle<i::Object>(self->script(), isolate)); | 2383 i::Handle<i::Object>(self->script(), isolate)); |
2373 return i::Script::cast(script->value())->origin_options().IsOpaque(); | 2384 return i::Script::cast(script->value())->origin_options().IsOpaque(); |
2374 } | 2385 } |
2375 | 2386 |
2376 | 2387 |
2377 MaybeLocal<String> Message::GetSourceLine(Local<Context> context) const { | 2388 MaybeLocal<String> Message::GetSourceLine(Local<Context> context) const { |
2378 PREPARE_FOR_EXECUTION(context, "v8::Message::GetSourceLine()", String); | 2389 PREPARE_FOR_EXECUTION(context, "v8::Message::GetSourceLine()", String); |
2379 i::Handle<i::JSFunction> fun = isolate->message_get_source_line(); | |
2380 i::Handle<i::Object> undefined = isolate->factory()->undefined_value(); | |
2381 i::Handle<i::Object> args[] = {Utils::OpenHandle(this)}; | |
2382 i::Handle<i::Object> result; | 2390 i::Handle<i::Object> result; |
2383 has_pending_exception = | 2391 has_pending_exception = |
2384 !i::Execution::Call(isolate, fun, undefined, arraysize(args), args) | 2392 !CallV8HeapFunction(isolate, "$messageGetSourceLine", |
2385 .ToHandle(&result); | 2393 Utils::OpenHandle(this)).ToHandle(&result); |
2386 RETURN_ON_FAILED_EXECUTION(String); | 2394 RETURN_ON_FAILED_EXECUTION(String); |
2387 Local<String> str; | 2395 Local<String> str; |
2388 if (result->IsString()) { | 2396 if (result->IsString()) { |
2389 str = Utils::ToLocal(i::Handle<i::String>::cast(result)); | 2397 str = Utils::ToLocal(i::Handle<i::String>::cast(result)); |
2390 } | 2398 } |
2391 RETURN_ESCAPED(str); | 2399 RETURN_ESCAPED(str); |
2392 } | 2400 } |
2393 | 2401 |
2394 | 2402 |
2395 Local<String> Message::GetSourceLine() const { | 2403 Local<String> Message::GetSourceLine() const { |
(...skipping 969 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3365 auto self = Utils::OpenHandle(this); | 3373 auto self = Utils::OpenHandle(this); |
3366 auto other = Utils::OpenHandle(*that); | 3374 auto other = Utils::OpenHandle(*that); |
3367 if (self->IsSmi() && other->IsSmi()) { | 3375 if (self->IsSmi() && other->IsSmi()) { |
3368 return Just(self->Number() == other->Number()); | 3376 return Just(self->Number() == other->Number()); |
3369 } | 3377 } |
3370 if (self->IsJSObject() && other->IsJSObject()) { | 3378 if (self->IsJSObject() && other->IsJSObject()) { |
3371 return Just(*self == *other); | 3379 return Just(*self == *other); |
3372 } | 3380 } |
3373 PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Value::Equals()", bool); | 3381 PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Value::Equals()", bool); |
3374 i::Handle<i::Object> args[] = { other }; | 3382 i::Handle<i::Object> args[] = { other }; |
3375 i::Handle<i::JSFunction> fun(i::JSFunction::cast( | |
3376 isolate->js_builtins_object()->javascript_builtin(i::Builtins::EQUALS))); | |
3377 i::Handle<i::Object> result; | 3383 i::Handle<i::Object> result; |
3378 has_pending_exception = | 3384 has_pending_exception = |
3379 !i::Execution::Call(isolate, fun, self, arraysize(args), args) | 3385 !CallV8HeapFunction(isolate, "EQUALS", self, arraysize(args), args) |
3380 .ToHandle(&result); | 3386 .ToHandle(&result); |
3381 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); | 3387 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); |
3382 return Just(*result == i::Smi::FromInt(i::EQUAL)); | 3388 return Just(*result == i::Smi::FromInt(i::EQUAL)); |
3383 } | 3389 } |
3384 | 3390 |
3385 | 3391 |
3386 bool Value::Equals(Local<Value> that) const { | 3392 bool Value::Equals(Local<Value> that) const { |
3387 auto self = Utils::OpenHandle(this); | 3393 auto self = Utils::OpenHandle(this); |
3388 auto other = Utils::OpenHandle(*that); | 3394 auto other = Utils::OpenHandle(*that); |
3389 if (self->IsSmi() && other->IsSmi()) { | 3395 if (self->IsSmi() && other->IsSmi()) { |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3499 return Nothing<bool>(); | 3505 return Nothing<bool>(); |
3500 } | 3506 } |
3501 | 3507 |
3502 i::Handle<i::FixedArray> desc = isolate->factory()->NewFixedArray(3); | 3508 i::Handle<i::FixedArray> desc = isolate->factory()->NewFixedArray(3); |
3503 desc->set(0, isolate->heap()->ToBoolean(!(attributes & v8::ReadOnly))); | 3509 desc->set(0, isolate->heap()->ToBoolean(!(attributes & v8::ReadOnly))); |
3504 desc->set(1, isolate->heap()->ToBoolean(!(attributes & v8::DontEnum))); | 3510 desc->set(1, isolate->heap()->ToBoolean(!(attributes & v8::DontEnum))); |
3505 desc->set(2, isolate->heap()->ToBoolean(!(attributes & v8::DontDelete))); | 3511 desc->set(2, isolate->heap()->ToBoolean(!(attributes & v8::DontDelete))); |
3506 i::Handle<i::JSArray> desc_array = | 3512 i::Handle<i::JSArray> desc_array = |
3507 isolate->factory()->NewJSArrayWithElements(desc, i::FAST_ELEMENTS, 3); | 3513 isolate->factory()->NewJSArrayWithElements(desc, i::FAST_ELEMENTS, 3); |
3508 i::Handle<i::Object> args[] = {self, key_obj, value_obj, desc_array}; | 3514 i::Handle<i::Object> args[] = {self, key_obj, value_obj, desc_array}; |
3509 i::Handle<i::Object> undefined = isolate->factory()->undefined_value(); | |
3510 i::Handle<i::JSFunction> fun = isolate->object_define_own_property(); | |
3511 i::Handle<i::Object> result; | 3515 i::Handle<i::Object> result; |
3512 has_pending_exception = | 3516 has_pending_exception = |
3513 !i::Execution::Call(isolate, fun, undefined, arraysize(args), args) | 3517 !CallV8HeapFunction(isolate, "$objectDefineOwnProperty", |
3514 .ToHandle(&result); | 3518 isolate->factory()->undefined_value(), |
| 3519 arraysize(args), args).ToHandle(&result); |
3515 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); | 3520 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); |
3516 return Just(result->BooleanValue()); | 3521 return Just(result->BooleanValue()); |
3517 } | 3522 } |
3518 | 3523 |
3519 | 3524 |
3520 MUST_USE_RESULT | 3525 MUST_USE_RESULT |
3521 static i::MaybeHandle<i::Object> DefineObjectProperty( | 3526 static i::MaybeHandle<i::Object> DefineObjectProperty( |
3522 i::Handle<i::JSObject> js_object, i::Handle<i::Object> key, | 3527 i::Handle<i::JSObject> js_object, i::Handle<i::Object> key, |
3523 i::Handle<i::Object> value, PropertyAttributes attrs) { | 3528 i::Handle<i::Object> value, PropertyAttributes attrs) { |
3524 i::Isolate* isolate = js_object->GetIsolate(); | 3529 i::Isolate* isolate = js_object->GetIsolate(); |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3636 } | 3641 } |
3637 | 3642 |
3638 | 3643 |
3639 MaybeLocal<Value> v8::Object::GetOwnPropertyDescriptor(Local<Context> context, | 3644 MaybeLocal<Value> v8::Object::GetOwnPropertyDescriptor(Local<Context> context, |
3640 Local<String> key) { | 3645 Local<String> key) { |
3641 PREPARE_FOR_EXECUTION(context, "v8::Object::GetOwnPropertyDescriptor()", | 3646 PREPARE_FOR_EXECUTION(context, "v8::Object::GetOwnPropertyDescriptor()", |
3642 Value); | 3647 Value); |
3643 auto obj = Utils::OpenHandle(this); | 3648 auto obj = Utils::OpenHandle(this); |
3644 auto key_name = Utils::OpenHandle(*key); | 3649 auto key_name = Utils::OpenHandle(*key); |
3645 i::Handle<i::Object> args[] = { obj, key_name }; | 3650 i::Handle<i::Object> args[] = { obj, key_name }; |
3646 i::Handle<i::JSFunction> fun = isolate->object_get_own_property_descriptor(); | |
3647 i::Handle<i::Object> undefined = isolate->factory()->undefined_value(); | |
3648 i::Handle<i::Object> result; | 3651 i::Handle<i::Object> result; |
3649 has_pending_exception = | 3652 has_pending_exception = |
3650 !i::Execution::Call(isolate, fun, undefined, arraysize(args), args) | 3653 !CallV8HeapFunction(isolate, "$objectGetOwnPropertyDescriptor", |
3651 .ToHandle(&result); | 3654 isolate->factory()->undefined_value(), |
| 3655 arraysize(args), args).ToHandle(&result); |
3652 RETURN_ON_FAILED_EXECUTION(Value); | 3656 RETURN_ON_FAILED_EXECUTION(Value); |
3653 RETURN_ESCAPED(Utils::ToLocal(result)); | 3657 RETURN_ESCAPED(Utils::ToLocal(result)); |
3654 } | 3658 } |
3655 | 3659 |
3656 | 3660 |
3657 Local<Value> v8::Object::GetOwnPropertyDescriptor(Local<String> key) { | 3661 Local<Value> v8::Object::GetOwnPropertyDescriptor(Local<String> key) { |
3658 auto context = ContextFromHeapObject(Utils::OpenHandle(this)); | 3662 auto context = ContextFromHeapObject(Utils::OpenHandle(this)); |
3659 RETURN_TO_LOCAL_UNCHECKED(GetOwnPropertyDescriptor(context, key), Value); | 3663 RETURN_TO_LOCAL_UNCHECKED(GetOwnPropertyDescriptor(context, key), Value); |
3660 } | 3664 } |
3661 | 3665 |
(...skipping 4748 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8410 Address callback_address = | 8414 Address callback_address = |
8411 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 8415 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
8412 VMState<EXTERNAL> state(isolate); | 8416 VMState<EXTERNAL> state(isolate); |
8413 ExternalCallbackScope call_scope(isolate, callback_address); | 8417 ExternalCallbackScope call_scope(isolate, callback_address); |
8414 callback(info); | 8418 callback(info); |
8415 } | 8419 } |
8416 | 8420 |
8417 | 8421 |
8418 } // namespace internal | 8422 } // namespace internal |
8419 } // namespace v8 | 8423 } // namespace v8 |
OLD | NEW |