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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | 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 2150 matching lines...) Expand 10 before | Expand all | Expand 10 after
2161 options = static_cast<StackTraceOptions>( 2161 options = static_cast<StackTraceOptions>(
2162 static_cast<int>(options) | kExposeFramesAcrossSecurityOrigins); 2162 static_cast<int>(options) | kExposeFramesAcrossSecurityOrigins);
2163 i::Handle<i::JSArray> stackTrace = 2163 i::Handle<i::JSArray> stackTrace =
2164 i_isolate->CaptureCurrentStackTrace(frame_limit, options); 2164 i_isolate->CaptureCurrentStackTrace(frame_limit, options);
2165 return Utils::StackTraceToLocal(stackTrace); 2165 return Utils::StackTraceToLocal(stackTrace);
2166 } 2166 }
2167 2167
2168 2168
2169 // --- S t a c k F r a m e --- 2169 // --- S t a c k F r a m e ---
2170 2170
2171 int StackFrame::GetLineNumber() const { 2171 static int getIntProperty(const StackFrame* f, const char* propertyName,
2172 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); 2172 int defaultValue) {
2173 i::Isolate* isolate = Utils::OpenHandle(f)->GetIsolate();
2173 ENTER_V8(isolate); 2174 ENTER_V8(isolate);
2174 i::HandleScope scope(isolate); 2175 i::HandleScope scope(isolate);
2175 i::Handle<i::JSObject> self = Utils::OpenHandle(this); 2176 i::Handle<i::JSObject> self = Utils::OpenHandle(f);
2176 i::Handle<i::Object> line = i::Object::GetProperty( 2177 i::Handle<i::Object> obj =
2177 isolate, self, "lineNumber").ToHandleChecked(); 2178 i::Object::GetProperty(isolate, self, propertyName).ToHandleChecked();
2178 if (!line->IsSmi()) { 2179 return obj->IsSmi() ? i::Smi::cast(*obj)->value() : defaultValue;
2179 return Message::kNoLineNumberInfo; 2180 }
2180 } 2181
2181 return i::Smi::cast(*line)->value(); 2182
2183 int StackFrame::GetLineNumber() const {
2184 return getIntProperty(this, "lineNumber", Message::kNoLineNumberInfo);
2182 } 2185 }
2183 2186
2184 2187
2185 int StackFrame::GetColumn() const { 2188 int StackFrame::GetColumn() const {
2186 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); 2189 return getIntProperty(this, "column", Message::kNoColumnInfo);
2187 ENTER_V8(isolate);
2188 i::HandleScope scope(isolate);
2189 i::Handle<i::JSObject> self = Utils::OpenHandle(this);
2190 i::Handle<i::Object> column = i::Object::GetProperty(
2191 isolate, self, "column").ToHandleChecked();
2192 if (!column->IsSmi()) {
2193 return Message::kNoColumnInfo;
2194 }
2195 return i::Smi::cast(*column)->value();
2196 } 2190 }
2197 2191
2198 2192
2199 int StackFrame::GetScriptId() const { 2193 int StackFrame::GetScriptId() const {
2200 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); 2194 return getIntProperty(this, "scriptId", Message::kNoScriptIdInfo);
2195 }
2196
2197
2198 static Local<String> getStringProperty(const StackFrame* f,
2199 const char* propertyName) {
2200 i::Isolate* isolate = Utils::OpenHandle(f)->GetIsolate();
2201 ENTER_V8(isolate); 2201 ENTER_V8(isolate);
2202 i::HandleScope scope(isolate); 2202 EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate));
2203 i::Handle<i::JSObject> self = Utils::OpenHandle(this); 2203 i::Handle<i::JSObject> self = Utils::OpenHandle(f);
2204 i::Handle<i::Object> scriptId = i::Object::GetProperty( 2204 i::Handle<i::Object> obj =
2205 isolate, self, "scriptId").ToHandleChecked(); 2205 i::Object::GetProperty(isolate, self, propertyName).ToHandleChecked();
2206 if (!scriptId->IsSmi()) { 2206 return obj->IsString()
2207 return Message::kNoScriptIdInfo; 2207 ? scope.Escape(Local<String>::Cast(Utils::ToLocal(obj)))
2208 } 2208 : Local<String>();
2209 return i::Smi::cast(*scriptId)->value();
2210 } 2209 }
2211 2210
2212 2211
2213 Local<String> StackFrame::GetScriptName() const { 2212 Local<String> StackFrame::GetScriptName() const {
2214 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); 2213 return getStringProperty(this, "scriptName");
2215 ENTER_V8(isolate);
2216 EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate));
2217 i::Handle<i::JSObject> self = Utils::OpenHandle(this);
2218 i::Handle<i::Object> name = i::Object::GetProperty(
2219 isolate, self, "scriptName").ToHandleChecked();
2220 if (!name->IsString()) {
2221 return Local<String>();
2222 }
2223 return scope.Escape(Local<String>::Cast(Utils::ToLocal(name)));
2224 } 2214 }
2225 2215
2226 2216
2227 Local<String> StackFrame::GetScriptNameOrSourceURL() const { 2217 Local<String> StackFrame::GetScriptNameOrSourceURL() const {
2228 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); 2218 return getStringProperty(this, "scriptNameOrSourceURL");
2229 ENTER_V8(isolate);
2230 EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate));
2231 i::Handle<i::JSObject> self = Utils::OpenHandle(this);
2232 i::Handle<i::Object> name = i::Object::GetProperty(
2233 isolate, self, "scriptNameOrSourceURL").ToHandleChecked();
2234 if (!name->IsString()) {
2235 return Local<String>();
2236 }
2237 return scope.Escape(Local<String>::Cast(Utils::ToLocal(name)));
2238 } 2219 }
2239 2220
2240 2221
2241 Local<String> StackFrame::GetFunctionName() const { 2222 Local<String> StackFrame::GetFunctionName() const {
2242 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); 2223 return getStringProperty(this, "functionName");
2243 ENTER_V8(isolate);
2244 EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate));
2245 i::Handle<i::JSObject> self = Utils::OpenHandle(this);
2246 i::Handle<i::Object> name = i::Object::GetProperty(
2247 isolate, self, "functionName").ToHandleChecked();
2248 if (!name->IsString()) {
2249 return Local<String>();
2250 }
2251 return scope.Escape(Local<String>::Cast(Utils::ToLocal(name)));
2252 } 2224 }
2253 2225
2254 2226
2255 bool StackFrame::IsEval() const { 2227 static bool getBoolProperty(const StackFrame* f, const char* propertyName) {
2256 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); 2228 i::Isolate* isolate = Utils::OpenHandle(f)->GetIsolate();
2257 ENTER_V8(isolate); 2229 ENTER_V8(isolate);
2258 i::HandleScope scope(isolate); 2230 i::HandleScope scope(isolate);
2259 i::Handle<i::JSObject> self = Utils::OpenHandle(this); 2231 i::Handle<i::JSObject> self = Utils::OpenHandle(f);
2260 i::Handle<i::Object> is_eval = i::Object::GetProperty( 2232 i::Handle<i::Object> obj =
2261 isolate, self, "isEval").ToHandleChecked(); 2233 i::Object::GetProperty(isolate, self, propertyName).ToHandleChecked();
2262 return is_eval->IsTrue(); 2234 return obj->IsTrue();
2235 }
2236
2237 bool StackFrame::IsEval() const { return getBoolProperty(this, "isEval"); }
2238
2239
2240 bool StackFrame::IsConstructor() const {
2241 return getBoolProperty(this, "isConstructor");
2263 } 2242 }
2264 2243
2265 2244
2266 bool StackFrame::IsConstructor() const {
2267 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
2268 ENTER_V8(isolate);
2269 i::HandleScope scope(isolate);
2270 i::Handle<i::JSObject> self = Utils::OpenHandle(this);
2271 i::Handle<i::Object> is_constructor = i::Object::GetProperty(
2272 isolate, self, "isConstructor").ToHandleChecked();
2273 return is_constructor->IsTrue();
2274 }
2275
2276
2277 // --- J S O N --- 2245 // --- J S O N ---
2278 2246
2279 Local<Value> JSON::Parse(Local<String> json_string) { 2247 Local<Value> JSON::Parse(Local<String> json_string) {
2280 i::Handle<i::String> string = Utils::OpenHandle(*json_string); 2248 i::Handle<i::String> string = Utils::OpenHandle(*json_string);
2281 i::Isolate* isolate = string->GetIsolate(); 2249 i::Isolate* isolate = string->GetIsolate();
2282 EnsureInitializedForIsolate(isolate, "v8::JSON::Parse"); 2250 EnsureInitializedForIsolate(isolate, "v8::JSON::Parse");
2283 ENTER_V8(isolate); 2251 ENTER_V8(isolate);
2284 i::HandleScope scope(isolate); 2252 i::HandleScope scope(isolate);
2285 i::Handle<i::String> source = i::String::Flatten(string); 2253 i::Handle<i::String> source = i::String::Flatten(string);
2286 EXCEPTION_PREAMBLE(isolate); 2254 EXCEPTION_PREAMBLE(isolate);
(...skipping 5343 matching lines...) Expand 10 before | Expand all | Expand 10 after
7630 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); 7598 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate());
7631 Address callback_address = 7599 Address callback_address =
7632 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 7600 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
7633 VMState<EXTERNAL> state(isolate); 7601 VMState<EXTERNAL> state(isolate);
7634 ExternalCallbackScope call_scope(isolate, callback_address); 7602 ExternalCallbackScope call_scope(isolate, callback_address);
7635 callback(info); 7603 callback(info);
7636 } 7604 }
7637 7605
7638 7606
7639 } } // namespace v8::internal 7607 } } // namespace v8::internal
OLDNEW
« 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