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