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

Unified Diff: src/api.cc

Issue 388183002: Removed some copy-n-paste from StackFrame::Foo API entries. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index 2c50d753f17e1c4943b4b7372eb75fb6a4af4c85..60e351291a60d6f81765d07af849c8622b0e07c5 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -2168,109 +2168,77 @@ Local<StackTrace> StackTrace::CurrentStackTrace(
// --- S t a c k F r a m e ---
-int StackFrame::GetLineNumber() const {
- i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
+static int getIntProperty(const StackFrame* f, const char* propertyName,
+ int defaultValue) {
+ i::Isolate* isolate = Utils::OpenHandle(f)->GetIsolate();
ENTER_V8(isolate);
i::HandleScope scope(isolate);
- i::Handle<i::JSObject> self = Utils::OpenHandle(this);
- i::Handle<i::Object> line = i::Object::GetProperty(
- isolate, self, "lineNumber").ToHandleChecked();
- if (!line->IsSmi()) {
- return Message::kNoLineNumberInfo;
- }
- return i::Smi::cast(*line)->value();
+ i::Handle<i::JSObject> self = Utils::OpenHandle(f);
+ i::Handle<i::Object> obj =
+ i::Object::GetProperty(isolate, self, propertyName).ToHandleChecked();
+ return obj->IsSmi() ? i::Smi::cast(*obj)->value() : defaultValue;
+}
+
+
+int StackFrame::GetLineNumber() const {
+ return getIntProperty(this, "lineNumber", Message::kNoLineNumberInfo);
}
int StackFrame::GetColumn() const {
- i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
- ENTER_V8(isolate);
- i::HandleScope scope(isolate);
- i::Handle<i::JSObject> self = Utils::OpenHandle(this);
- i::Handle<i::Object> column = i::Object::GetProperty(
- isolate, self, "column").ToHandleChecked();
- if (!column->IsSmi()) {
- return Message::kNoColumnInfo;
- }
- return i::Smi::cast(*column)->value();
+ return getIntProperty(this, "column", Message::kNoColumnInfo);
}
int StackFrame::GetScriptId() const {
- i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
- ENTER_V8(isolate);
- i::HandleScope scope(isolate);
- i::Handle<i::JSObject> self = Utils::OpenHandle(this);
- i::Handle<i::Object> scriptId = i::Object::GetProperty(
- isolate, self, "scriptId").ToHandleChecked();
- if (!scriptId->IsSmi()) {
- return Message::kNoScriptIdInfo;
- }
- return i::Smi::cast(*scriptId)->value();
+ return getIntProperty(this, "scriptId", Message::kNoScriptIdInfo);
}
-Local<String> StackFrame::GetScriptName() const {
- i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
+static Local<String> getStringProperty(const StackFrame* f,
+ const char* propertyName) {
+ i::Isolate* isolate = Utils::OpenHandle(f)->GetIsolate();
ENTER_V8(isolate);
EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate));
- i::Handle<i::JSObject> self = Utils::OpenHandle(this);
- i::Handle<i::Object> name = i::Object::GetProperty(
- isolate, self, "scriptName").ToHandleChecked();
- if (!name->IsString()) {
- return Local<String>();
- }
- return scope.Escape(Local<String>::Cast(Utils::ToLocal(name)));
+ i::Handle<i::JSObject> self = Utils::OpenHandle(f);
+ i::Handle<i::Object> obj =
+ i::Object::GetProperty(isolate, self, propertyName).ToHandleChecked();
+ return obj->IsString()
+ ? scope.Escape(Local<String>::Cast(Utils::ToLocal(obj)))
+ : Local<String>();
+}
+
+
+Local<String> StackFrame::GetScriptName() const {
+ return getStringProperty(this, "scriptName");
}
Local<String> StackFrame::GetScriptNameOrSourceURL() const {
- i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
- ENTER_V8(isolate);
- EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate));
- i::Handle<i::JSObject> self = Utils::OpenHandle(this);
- i::Handle<i::Object> name = i::Object::GetProperty(
- isolate, self, "scriptNameOrSourceURL").ToHandleChecked();
- if (!name->IsString()) {
- return Local<String>();
- }
- return scope.Escape(Local<String>::Cast(Utils::ToLocal(name)));
+ return getStringProperty(this, "scriptNameOrSourceURL");
}
Local<String> StackFrame::GetFunctionName() const {
- i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
- ENTER_V8(isolate);
- EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate));
- i::Handle<i::JSObject> self = Utils::OpenHandle(this);
- i::Handle<i::Object> name = i::Object::GetProperty(
- isolate, self, "functionName").ToHandleChecked();
- if (!name->IsString()) {
- return Local<String>();
- }
- return scope.Escape(Local<String>::Cast(Utils::ToLocal(name)));
+ return getStringProperty(this, "functionName");
}
-bool StackFrame::IsEval() const {
- i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
+static bool getBoolProperty(const StackFrame* f, const char* propertyName) {
+ i::Isolate* isolate = Utils::OpenHandle(f)->GetIsolate();
ENTER_V8(isolate);
i::HandleScope scope(isolate);
- i::Handle<i::JSObject> self = Utils::OpenHandle(this);
- i::Handle<i::Object> is_eval = i::Object::GetProperty(
- isolate, self, "isEval").ToHandleChecked();
- return is_eval->IsTrue();
+ i::Handle<i::JSObject> self = Utils::OpenHandle(f);
+ i::Handle<i::Object> obj =
+ i::Object::GetProperty(isolate, self, propertyName).ToHandleChecked();
+ return obj->IsTrue();
}
+bool StackFrame::IsEval() const { return getBoolProperty(this, "isEval"); }
+
bool StackFrame::IsConstructor() const {
- i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
- ENTER_V8(isolate);
- i::HandleScope scope(isolate);
- i::Handle<i::JSObject> self = Utils::OpenHandle(this);
- i::Handle<i::Object> is_constructor = i::Object::GetProperty(
- isolate, self, "isConstructor").ToHandleChecked();
- return is_constructor->IsTrue();
+ return getBoolProperty(this, "isConstructor");
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698