Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(336)

Side by Side Diff: src/api.cc

Issue 1775973002: Add GetProperty/GetElement to JSReceiver and use it where possible (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/bootstrapper.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 2208 matching lines...) Expand 10 before | Expand all | Expand 10 after
2219 if (!raw_obj->IsJSObject()) return v8::Local<Value>(); 2219 if (!raw_obj->IsJSObject()) return v8::Local<Value>();
2220 PREPARE_FOR_EXECUTION(context, "v8::TryCatch::StackTrace", Value); 2220 PREPARE_FOR_EXECUTION(context, "v8::TryCatch::StackTrace", Value);
2221 i::Handle<i::JSObject> obj(i::JSObject::cast(raw_obj), isolate_); 2221 i::Handle<i::JSObject> obj(i::JSObject::cast(raw_obj), isolate_);
2222 i::Handle<i::String> name = isolate->factory()->stack_string(); 2222 i::Handle<i::String> name = isolate->factory()->stack_string();
2223 Maybe<bool> maybe = i::JSReceiver::HasProperty(obj, name); 2223 Maybe<bool> maybe = i::JSReceiver::HasProperty(obj, name);
2224 has_pending_exception = !maybe.IsJust(); 2224 has_pending_exception = !maybe.IsJust();
2225 RETURN_ON_FAILED_EXECUTION(Value); 2225 RETURN_ON_FAILED_EXECUTION(Value);
2226 if (!maybe.FromJust()) return v8::Local<Value>(); 2226 if (!maybe.FromJust()) return v8::Local<Value>();
2227 Local<Value> result; 2227 Local<Value> result;
2228 has_pending_exception = 2228 has_pending_exception =
2229 !ToLocal<Value>(i::Object::GetProperty(obj, name), &result); 2229 !ToLocal<Value>(i::JSReceiver::GetProperty(obj, name), &result);
2230 RETURN_ON_FAILED_EXECUTION(Value); 2230 RETURN_ON_FAILED_EXECUTION(Value);
2231 RETURN_ESCAPED(result); 2231 RETURN_ESCAPED(result);
2232 } 2232 }
2233 2233
2234 2234
2235 v8::Local<Value> v8::TryCatch::StackTrace() const { 2235 v8::Local<Value> v8::TryCatch::StackTrace() const {
2236 auto context = reinterpret_cast<v8::Isolate*>(isolate_)->GetCurrentContext(); 2236 auto context = reinterpret_cast<v8::Isolate*>(isolate_)->GetCurrentContext();
2237 RETURN_TO_LOCAL_UNCHECKED(StackTrace(context), Value); 2237 RETURN_TO_LOCAL_UNCHECKED(StackTrace(context), Value);
2238 } 2238 }
2239 2239
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
2450 } 2450 }
2451 2451
2452 2452
2453 // --- S t a c k T r a c e --- 2453 // --- S t a c k T r a c e ---
2454 2454
2455 Local<StackFrame> StackTrace::GetFrame(uint32_t index) const { 2455 Local<StackFrame> StackTrace::GetFrame(uint32_t index) const {
2456 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); 2456 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
2457 ENTER_V8(isolate); 2457 ENTER_V8(isolate);
2458 EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate)); 2458 EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate));
2459 auto self = Utils::OpenHandle(this); 2459 auto self = Utils::OpenHandle(this);
2460 auto obj = i::Object::GetElement(isolate, self, index).ToHandleChecked(); 2460 auto obj = i::JSReceiver::GetElement(isolate, self, index).ToHandleChecked();
2461 auto jsobj = i::Handle<i::JSObject>::cast(obj); 2461 auto jsobj = i::Handle<i::JSObject>::cast(obj);
2462 return scope.Escape(Utils::StackFrameToLocal(jsobj)); 2462 return scope.Escape(Utils::StackFrameToLocal(jsobj));
2463 } 2463 }
2464 2464
2465 2465
2466 int StackTrace::GetFrameCount() const { 2466 int StackTrace::GetFrameCount() const {
2467 return i::Smi::cast(Utils::OpenHandle(this)->length())->value(); 2467 return i::Smi::cast(Utils::OpenHandle(this)->length())->value();
2468 } 2468 }
2469 2469
2470 2470
(...skipping 19 matching lines...) Expand all
2490 2490
2491 // --- S t a c k F r a m e --- 2491 // --- S t a c k F r a m e ---
2492 2492
2493 static int getIntProperty(const StackFrame* f, const char* propertyName, 2493 static int getIntProperty(const StackFrame* f, const char* propertyName,
2494 int defaultValue) { 2494 int defaultValue) {
2495 i::Isolate* isolate = Utils::OpenHandle(f)->GetIsolate(); 2495 i::Isolate* isolate = Utils::OpenHandle(f)->GetIsolate();
2496 ENTER_V8(isolate); 2496 ENTER_V8(isolate);
2497 i::HandleScope scope(isolate); 2497 i::HandleScope scope(isolate);
2498 i::Handle<i::JSObject> self = Utils::OpenHandle(f); 2498 i::Handle<i::JSObject> self = Utils::OpenHandle(f);
2499 i::Handle<i::Object> obj = 2499 i::Handle<i::Object> obj =
2500 i::Object::GetProperty(isolate, self, propertyName).ToHandleChecked(); 2500 i::JSReceiver::GetProperty(isolate, self, propertyName).ToHandleChecked();
2501 return obj->IsSmi() ? i::Smi::cast(*obj)->value() : defaultValue; 2501 return obj->IsSmi() ? i::Smi::cast(*obj)->value() : defaultValue;
2502 } 2502 }
2503 2503
2504 2504
2505 int StackFrame::GetLineNumber() const { 2505 int StackFrame::GetLineNumber() const {
2506 return getIntProperty(this, "lineNumber", Message::kNoLineNumberInfo); 2506 return getIntProperty(this, "lineNumber", Message::kNoLineNumberInfo);
2507 } 2507 }
2508 2508
2509 2509
2510 int StackFrame::GetColumn() const { 2510 int StackFrame::GetColumn() const {
2511 return getIntProperty(this, "column", Message::kNoColumnInfo); 2511 return getIntProperty(this, "column", Message::kNoColumnInfo);
2512 } 2512 }
2513 2513
2514 2514
2515 int StackFrame::GetScriptId() const { 2515 int StackFrame::GetScriptId() const {
2516 return getIntProperty(this, "scriptId", Message::kNoScriptIdInfo); 2516 return getIntProperty(this, "scriptId", Message::kNoScriptIdInfo);
2517 } 2517 }
2518 2518
2519 2519
2520 static Local<String> getStringProperty(const StackFrame* f, 2520 static Local<String> getStringProperty(const StackFrame* f,
2521 const char* propertyName) { 2521 const char* propertyName) {
2522 i::Isolate* isolate = Utils::OpenHandle(f)->GetIsolate(); 2522 i::Isolate* isolate = Utils::OpenHandle(f)->GetIsolate();
2523 ENTER_V8(isolate); 2523 ENTER_V8(isolate);
2524 EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate)); 2524 EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate));
2525 i::Handle<i::JSObject> self = Utils::OpenHandle(f); 2525 i::Handle<i::JSObject> self = Utils::OpenHandle(f);
2526 i::Handle<i::Object> obj = 2526 i::Handle<i::Object> obj =
2527 i::Object::GetProperty(isolate, self, propertyName).ToHandleChecked(); 2527 i::JSReceiver::GetProperty(isolate, self, propertyName).ToHandleChecked();
2528 return obj->IsString() 2528 return obj->IsString()
2529 ? scope.Escape(Local<String>::Cast(Utils::ToLocal(obj))) 2529 ? scope.Escape(Local<String>::Cast(Utils::ToLocal(obj)))
2530 : Local<String>(); 2530 : Local<String>();
2531 } 2531 }
2532 2532
2533 2533
2534 Local<String> StackFrame::GetScriptName() const { 2534 Local<String> StackFrame::GetScriptName() const {
2535 return getStringProperty(this, "scriptName"); 2535 return getStringProperty(this, "scriptName");
2536 } 2536 }
2537 2537
2538 2538
2539 Local<String> StackFrame::GetScriptNameOrSourceURL() const { 2539 Local<String> StackFrame::GetScriptNameOrSourceURL() const {
2540 return getStringProperty(this, "scriptNameOrSourceURL"); 2540 return getStringProperty(this, "scriptNameOrSourceURL");
2541 } 2541 }
2542 2542
2543 2543
2544 Local<String> StackFrame::GetFunctionName() const { 2544 Local<String> StackFrame::GetFunctionName() const {
2545 return getStringProperty(this, "functionName"); 2545 return getStringProperty(this, "functionName");
2546 } 2546 }
2547 2547
2548 2548
2549 static bool getBoolProperty(const StackFrame* f, const char* propertyName) { 2549 static bool getBoolProperty(const StackFrame* f, const char* propertyName) {
2550 i::Isolate* isolate = Utils::OpenHandle(f)->GetIsolate(); 2550 i::Isolate* isolate = Utils::OpenHandle(f)->GetIsolate();
2551 ENTER_V8(isolate); 2551 ENTER_V8(isolate);
2552 i::HandleScope scope(isolate); 2552 i::HandleScope scope(isolate);
2553 i::Handle<i::JSObject> self = Utils::OpenHandle(f); 2553 i::Handle<i::JSObject> self = Utils::OpenHandle(f);
2554 i::Handle<i::Object> obj = 2554 i::Handle<i::Object> obj =
2555 i::Object::GetProperty(isolate, self, propertyName).ToHandleChecked(); 2555 i::JSReceiver::GetProperty(isolate, self, propertyName).ToHandleChecked();
2556 return obj->IsTrue(); 2556 return obj->IsTrue();
2557 } 2557 }
2558 2558
2559 bool StackFrame::IsEval() const { return getBoolProperty(this, "isEval"); } 2559 bool StackFrame::IsEval() const { return getBoolProperty(this, "isEval"); }
2560 2560
2561 2561
2562 bool StackFrame::IsConstructor() const { 2562 bool StackFrame::IsConstructor() const {
2563 return getBoolProperty(this, "isConstructor"); 2563 return getBoolProperty(this, "isConstructor");
2564 } 2564 }
2565 2565
(...skipping 1083 matching lines...) Expand 10 before | Expand all | Expand 10 after
3649 auto context = ContextFromHeapObject(Utils::OpenHandle(this)); 3649 auto context = ContextFromHeapObject(Utils::OpenHandle(this));
3650 RETURN_TO_LOCAL_UNCHECKED(Get(context, key), Value); 3650 RETURN_TO_LOCAL_UNCHECKED(Get(context, key), Value);
3651 } 3651 }
3652 3652
3653 3653
3654 MaybeLocal<Value> v8::Object::Get(Local<Context> context, uint32_t index) { 3654 MaybeLocal<Value> v8::Object::Get(Local<Context> context, uint32_t index) {
3655 PREPARE_FOR_EXECUTION(context, "v8::Object::Get()", Value); 3655 PREPARE_FOR_EXECUTION(context, "v8::Object::Get()", Value);
3656 auto self = Utils::OpenHandle(this); 3656 auto self = Utils::OpenHandle(this);
3657 i::Handle<i::Object> result; 3657 i::Handle<i::Object> result;
3658 has_pending_exception = 3658 has_pending_exception =
3659 !i::Object::GetElement(isolate, self, index).ToHandle(&result); 3659 !i::JSReceiver::GetElement(isolate, self, index).ToHandle(&result);
3660 RETURN_ON_FAILED_EXECUTION(Value); 3660 RETURN_ON_FAILED_EXECUTION(Value);
3661 RETURN_ESCAPED(Utils::ToLocal(result)); 3661 RETURN_ESCAPED(Utils::ToLocal(result));
3662 } 3662 }
3663 3663
3664 3664
3665 Local<Value> v8::Object::Get(uint32_t index) { 3665 Local<Value> v8::Object::Get(uint32_t index) {
3666 auto context = ContextFromHeapObject(Utils::OpenHandle(this)); 3666 auto context = ContextFromHeapObject(Utils::OpenHandle(this));
3667 RETURN_TO_LOCAL_UNCHECKED(Get(context, index), Value); 3667 RETURN_TO_LOCAL_UNCHECKED(Get(context, index), Value);
3668 } 3668 }
3669 3669
(...skipping 4300 matching lines...) Expand 10 before | Expand all | Expand 10 after
7970 7970
7971 7971
7972 MaybeLocal<Value> Debug::GetMirror(Local<Context> context, 7972 MaybeLocal<Value> Debug::GetMirror(Local<Context> context,
7973 v8::Local<v8::Value> obj) { 7973 v8::Local<v8::Value> obj) {
7974 PREPARE_FOR_EXECUTION(context, "v8::Debug::GetMirror()", Value); 7974 PREPARE_FOR_EXECUTION(context, "v8::Debug::GetMirror()", Value);
7975 i::Debug* isolate_debug = isolate->debug(); 7975 i::Debug* isolate_debug = isolate->debug();
7976 has_pending_exception = !isolate_debug->Load(); 7976 has_pending_exception = !isolate_debug->Load();
7977 RETURN_ON_FAILED_EXECUTION(Value); 7977 RETURN_ON_FAILED_EXECUTION(Value);
7978 i::Handle<i::JSObject> debug(isolate_debug->debug_context()->global_object()); 7978 i::Handle<i::JSObject> debug(isolate_debug->debug_context()->global_object());
7979 auto name = isolate->factory()->NewStringFromStaticChars("MakeMirror"); 7979 auto name = isolate->factory()->NewStringFromStaticChars("MakeMirror");
7980 auto fun_obj = i::Object::GetProperty(debug, name).ToHandleChecked(); 7980 auto fun_obj = i::JSReceiver::GetProperty(debug, name).ToHandleChecked();
7981 auto v8_fun = Utils::CallableToLocal(i::Handle<i::JSFunction>::cast(fun_obj)); 7981 auto v8_fun = Utils::CallableToLocal(i::Handle<i::JSFunction>::cast(fun_obj));
7982 const int kArgc = 1; 7982 const int kArgc = 1;
7983 v8::Local<v8::Value> argv[kArgc] = {obj}; 7983 v8::Local<v8::Value> argv[kArgc] = {obj};
7984 Local<Value> result; 7984 Local<Value> result;
7985 has_pending_exception = 7985 has_pending_exception =
7986 !v8_fun->Call(context, Utils::ToLocal(debug), kArgc, argv) 7986 !v8_fun->Call(context, Utils::ToLocal(debug), kArgc, argv)
7987 .ToLocal(&result); 7987 .ToLocal(&result);
7988 RETURN_ON_FAILED_EXECUTION(Value); 7988 RETURN_ON_FAILED_EXECUTION(Value);
7989 RETURN_ESCAPED(result); 7989 RETURN_ESCAPED(result);
7990 } 7990 }
(...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after
8694 Address callback_address = 8694 Address callback_address =
8695 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 8695 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
8696 VMState<EXTERNAL> state(isolate); 8696 VMState<EXTERNAL> state(isolate);
8697 ExternalCallbackScope call_scope(isolate, callback_address); 8697 ExternalCallbackScope call_scope(isolate, callback_address);
8698 callback(info); 8698 callback(info);
8699 } 8699 }
8700 8700
8701 8701
8702 } // namespace internal 8702 } // namespace internal
8703 } // namespace v8 8703 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | src/bootstrapper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698