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

Side by Side Diff: src/api.cc

Issue 7911: Various API changes (Closed)
Patch Set: "Various API changes Created 12 years, 1 month 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 | « include/v8.h ('k') | src/debug.h » ('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 2007-2008 the V8 project authors. All rights reserved. 1 // Copyright 2007-2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 1066 matching lines...) Expand 10 before | Expand all | Expand 10 after
1077 capture_message_(true) { 1077 capture_message_(true) {
1078 i::Top::RegisterTryCatchHandler(this); 1078 i::Top::RegisterTryCatchHandler(this);
1079 } 1079 }
1080 1080
1081 1081
1082 v8::TryCatch::~TryCatch() { 1082 v8::TryCatch::~TryCatch() {
1083 i::Top::UnregisterTryCatchHandler(this); 1083 i::Top::UnregisterTryCatchHandler(this);
1084 } 1084 }
1085 1085
1086 1086
1087 bool v8::TryCatch::HasCaught() { 1087 bool v8::TryCatch::HasCaught() const {
1088 return !reinterpret_cast<i::Object*>(exception_)->IsTheHole(); 1088 return !reinterpret_cast<i::Object*>(exception_)->IsTheHole();
1089 } 1089 }
1090 1090
1091 1091
1092 v8::Local<Value> v8::TryCatch::Exception() { 1092 v8::Local<Value> v8::TryCatch::Exception() const {
1093 if (HasCaught()) { 1093 if (HasCaught()) {
1094 // Check for out of memory exception. 1094 // Check for out of memory exception.
1095 i::Object* exception = reinterpret_cast<i::Object*>(exception_); 1095 i::Object* exception = reinterpret_cast<i::Object*>(exception_);
1096 return v8::Utils::ToLocal(i::Handle<i::Object>(exception)); 1096 return v8::Utils::ToLocal(i::Handle<i::Object>(exception));
1097 } else { 1097 } else {
1098 return v8::Local<Value>(); 1098 return v8::Local<Value>();
1099 } 1099 }
1100 } 1100 }
1101 1101
1102 1102
1103 v8::Local<v8::Message> v8::TryCatch::Message() { 1103 v8::Local<v8::Message> v8::TryCatch::Message() const {
1104 if (HasCaught() && message_ != i::Smi::FromInt(0)) { 1104 if (HasCaught() && message_ != i::Smi::FromInt(0)) {
1105 i::Object* message = reinterpret_cast<i::Object*>(message_); 1105 i::Object* message = reinterpret_cast<i::Object*>(message_);
1106 return v8::Utils::MessageToLocal(i::Handle<i::Object>(message)); 1106 return v8::Utils::MessageToLocal(i::Handle<i::Object>(message));
1107 } else { 1107 } else {
1108 return v8::Local<v8::Message>(); 1108 return v8::Local<v8::Message>();
1109 } 1109 }
1110 } 1110 }
1111 1111
1112 1112
1113 void v8::TryCatch::Reset() { 1113 void v8::TryCatch::Reset() {
(...skipping 18 matching lines...) Expand all
1132 Local<String> Message::Get() { 1132 Local<String> Message::Get() {
1133 ON_BAILOUT("v8::Message::Get()", return Local<String>()); 1133 ON_BAILOUT("v8::Message::Get()", return Local<String>());
1134 HandleScope scope; 1134 HandleScope scope;
1135 i::Handle<i::Object> obj = Utils::OpenHandle(this); 1135 i::Handle<i::Object> obj = Utils::OpenHandle(this);
1136 i::Handle<i::String> raw_result = i::MessageHandler::GetMessage(obj); 1136 i::Handle<i::String> raw_result = i::MessageHandler::GetMessage(obj);
1137 Local<String> result = Utils::ToLocal(raw_result); 1137 Local<String> result = Utils::ToLocal(raw_result);
1138 return scope.Close(result); 1138 return scope.Close(result);
1139 } 1139 }
1140 1140
1141 1141
1142 v8::Handle<String> Message::GetScriptResourceName() { 1142 v8::Handle<Value> Message::GetScriptResourceName() {
1143 if (IsDeadCheck("v8::Message::GetScriptResourceName()")) { 1143 if (IsDeadCheck("v8::Message::GetScriptResourceName()")) {
1144 return Local<String>(); 1144 return Local<String>();
1145 } 1145 }
1146 HandleScope scope; 1146 HandleScope scope;
1147 i::Handle<i::JSObject> obj = 1147 i::Handle<i::JSObject> obj =
1148 i::Handle<i::JSObject>::cast(Utils::OpenHandle(this)); 1148 i::Handle<i::JSObject>::cast(Utils::OpenHandle(this));
1149 // Return this.script.name. 1149 // Return this.script.name.
1150 i::Handle<i::JSValue> script = 1150 i::Handle<i::JSValue> script =
1151 i::Handle<i::JSValue>::cast(GetProperty(obj, "script")); 1151 i::Handle<i::JSValue>::cast(GetProperty(obj, "script"));
1152 i::Handle<i::Object> resource_name(i::Script::cast(script->value())->name()); 1152 i::Handle<i::Object> resource_name(i::Script::cast(script->value())->name());
1153 if (!resource_name->IsString()) { 1153 return scope.Close(Utils::ToLocal(resource_name));
1154 return Local<String>();
1155 }
1156 Local<String> result =
1157 Utils::ToLocal(i::Handle<i::String>::cast(resource_name));
1158 return scope.Close(result);
1159 } 1154 }
1160 1155
1161 1156
1162 // TODO(1240903): Remove this when no longer used in WebKit V8 bindings.
1163 Handle<Value> Message::GetSourceData() {
1164 Handle<String> data = GetScriptResourceName();
1165 if (data.IsEmpty()) return v8::Undefined();
1166 return data;
1167 }
1168
1169 static i::Handle<i::Object> CallV8HeapFunction(const char* name, 1157 static i::Handle<i::Object> CallV8HeapFunction(const char* name,
1170 i::Handle<i::Object> recv, 1158 i::Handle<i::Object> recv,
1171 int argc, 1159 int argc,
1172 i::Object** argv[], 1160 i::Object** argv[],
1173 bool* has_pending_exception) { 1161 bool* has_pending_exception) {
1174 i::Handle<i::String> fmt_str = i::Factory::LookupAsciiSymbol(name); 1162 i::Handle<i::String> fmt_str = i::Factory::LookupAsciiSymbol(name);
1175 i::Object* object_fun = i::Top::builtins()->GetProperty(*fmt_str); 1163 i::Object* object_fun = i::Top::builtins()->GetProperty(*fmt_str);
1176 i::Handle<i::JSFunction> fun = 1164 i::Handle<i::JSFunction> fun =
1177 i::Handle<i::JSFunction>(i::JSFunction::cast(object_fun)); 1165 i::Handle<i::JSFunction>(i::JSFunction::cast(object_fun));
1178 i::Handle<i::Object> value = 1166 i::Handle<i::Object> value =
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1261 &has_pending_exception); 1249 &has_pending_exception);
1262 EXCEPTION_BAILOUT_CHECK(Local<v8::String>()); 1250 EXCEPTION_BAILOUT_CHECK(Local<v8::String>());
1263 if (result->IsString()) { 1251 if (result->IsString()) {
1264 return scope.Close(Utils::ToLocal(i::Handle<i::String>::cast(result))); 1252 return scope.Close(Utils::ToLocal(i::Handle<i::String>::cast(result)));
1265 } else { 1253 } else {
1266 return Local<String>(); 1254 return Local<String>();
1267 } 1255 }
1268 } 1256 }
1269 1257
1270 1258
1271 char* Message::GetUnderline(char* source_line, char underline_char) {
1272 if (IsDeadCheck("v8::Message::GetUnderline()")) return 0;
1273 HandleScope scope;
1274
1275 i::Handle<i::JSObject> data_obj = Utils::OpenHandle(this);
1276 int start_pos = static_cast<int>(GetProperty(data_obj, "startPos")->Number());
1277 int end_pos = static_cast<int>(GetProperty(data_obj, "endPos")->Number());
1278 EXCEPTION_PREAMBLE();
1279 i::Handle<i::Object> start_col_obj = CallV8HeapFunction(
1280 "GetPositionInLine",
1281 data_obj,
1282 &has_pending_exception);
1283 EXCEPTION_BAILOUT_CHECK(0);
1284 int start_col = static_cast<int>(start_col_obj->Number());
1285 int end_col = start_col + (end_pos - start_pos);
1286
1287 // Any tabs before or between the selected columns have to be
1288 // expanded into spaces. We assume that a tab character advances
1289 // the cursor up until the next 8-character boundary and at least
1290 // one character.
1291 int real_start_col = 0;
1292 for (int i = 0; i < start_col; i++) {
1293 real_start_col++;
1294 if (source_line[i] == '\t') {
1295 real_start_col++;
1296 while (real_start_col % 8 != 0)
1297 real_start_col++;
1298 }
1299 }
1300 int real_end_col = real_start_col;
1301 for (int i = start_col; i < end_col; i++) {
1302 real_end_col++;
1303 if (source_line[i] == '\t') {
1304 while (real_end_col % 8 != 0)
1305 real_end_col++;
1306 }
1307 }
1308 char* result = i::NewArray<char>(real_end_col + 1);
1309 for (int i = 0; i < real_start_col; i++)
1310 result[i] = ' ';
1311 for (int i = real_start_col; i < real_end_col; i++)
1312 result[i] = underline_char;
1313 result[real_end_col] = '\0';
1314 return result;
1315 }
1316
1317
1318 void Message::PrintCurrentStackTrace(FILE* out) { 1259 void Message::PrintCurrentStackTrace(FILE* out) {
1319 if (IsDeadCheck("v8::Message::PrintCurrentStackTrace()")) return; 1260 if (IsDeadCheck("v8::Message::PrintCurrentStackTrace()")) return;
1320 i::Top::PrintCurrentStackTrace(out); 1261 i::Top::PrintCurrentStackTrace(out);
1321 } 1262 }
1322 1263
1323 1264
1324 // --- D a t a --- 1265 // --- D a t a ---
1325 1266
1326 bool Value::IsUndefined() { 1267 bool Value::IsUndefined() {
1327 if (IsDeadCheck("v8::Value::IsUndefined()")) return false; 1268 if (IsDeadCheck("v8::Value::IsUndefined()")) return false;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1394 i::Handle<i::Object> obj = Utils::OpenHandle(this); 1335 i::Handle<i::Object> obj = Utils::OpenHandle(this);
1395 if (obj->IsSmi()) return true; 1336 if (obj->IsSmi()) return true;
1396 if (obj->IsNumber()) { 1337 if (obj->IsNumber()) {
1397 double value = obj->Number(); 1338 double value = obj->Number();
1398 return i::FastI2D(i::FastD2I(value)) == value; 1339 return i::FastI2D(i::FastD2I(value)) == value;
1399 } 1340 }
1400 return false; 1341 return false;
1401 } 1342 }
1402 1343
1403 1344
1345 bool Value::IsDate() {
1346 if (IsDeadCheck("v8::Value::IsDate()")) return false;
1347 i::Handle<i::Object> obj = Utils::OpenHandle(this);
1348 return obj->HasSpecificClassOf(i::Heap::Date_symbol());
1349 }
1350
1351
1404 Local<String> Value::ToString() { 1352 Local<String> Value::ToString() {
1405 if (IsDeadCheck("v8::Value::ToString()")) return Local<String>(); 1353 if (IsDeadCheck("v8::Value::ToString()")) return Local<String>();
1406 LOG_API("ToString"); 1354 LOG_API("ToString");
1407 i::Handle<i::Object> obj = Utils::OpenHandle(this); 1355 i::Handle<i::Object> obj = Utils::OpenHandle(this);
1408 i::Handle<i::Object> str; 1356 i::Handle<i::Object> str;
1409 if (obj->IsString()) { 1357 if (obj->IsString()) {
1410 str = obj; 1358 str = obj;
1411 } else { 1359 } else {
1412 EXCEPTION_PREAMBLE(); 1360 EXCEPTION_PREAMBLE();
1413 str = i::Execution::ToString(obj, &has_pending_exception); 1361 str = i::Execution::ToString(obj, &has_pending_exception);
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
1554 v8::Array* v8::Array::Cast(Value* that) { 1502 v8::Array* v8::Array::Cast(Value* that) {
1555 if (IsDeadCheck("v8::Array::Cast()")) return 0; 1503 if (IsDeadCheck("v8::Array::Cast()")) return 0;
1556 i::Handle<i::Object> obj = Utils::OpenHandle(that); 1504 i::Handle<i::Object> obj = Utils::OpenHandle(that);
1557 ApiCheck(obj->IsJSArray(), 1505 ApiCheck(obj->IsJSArray(),
1558 "v8::Array::Cast()", 1506 "v8::Array::Cast()",
1559 "Could not convert to array"); 1507 "Could not convert to array");
1560 return static_cast<v8::Array*>(that); 1508 return static_cast<v8::Array*>(that);
1561 } 1509 }
1562 1510
1563 1511
1512 v8::Date* v8::Date::Cast(v8::Value* that) {
1513 if (IsDeadCheck("v8::Date::Cast()")) return 0;
1514 i::Handle<i::Object> obj = Utils::OpenHandle(that);
1515 ApiCheck(obj->HasSpecificClassOf(i::Heap::Date_symbol()),
1516 "v8::Date::Cast()",
1517 "Could not convert to date");
1518 return static_cast<v8::Date*>(that);
1519 }
1520
1521
1564 bool Value::BooleanValue() { 1522 bool Value::BooleanValue() {
1565 if (IsDeadCheck("v8::Value::BooleanValue()")) return false; 1523 if (IsDeadCheck("v8::Value::BooleanValue()")) return false;
1566 LOG_API("BooleanValue"); 1524 LOG_API("BooleanValue");
1567 i::Handle<i::Object> obj = Utils::OpenHandle(this); 1525 i::Handle<i::Object> obj = Utils::OpenHandle(this);
1568 i::Handle<i::Object> value = 1526 i::Handle<i::Object> value =
1569 obj->IsBoolean() ? obj : i::Execution::ToBoolean(obj); 1527 obj->IsBoolean() ? obj : i::Execution::ToBoolean(obj);
1570 return value->IsTrue(); 1528 return value->IsTrue();
1571 } 1529 }
1572 1530
1573 1531
(...skipping 881 matching lines...) Expand 10 before | Expand all | Expand 10 after
2455 2413
2456 2414
2457 i::Handle<i::String> NewExternalAsciiStringHandle( 2415 i::Handle<i::String> NewExternalAsciiStringHandle(
2458 v8::String::ExternalAsciiStringResource* resource) { 2416 v8::String::ExternalAsciiStringResource* resource) {
2459 i::Handle<i::String> result = 2417 i::Handle<i::String> result =
2460 i::Factory::NewExternalStringFromAscii(resource); 2418 i::Factory::NewExternalStringFromAscii(resource);
2461 return result; 2419 return result;
2462 } 2420 }
2463 2421
2464 2422
2465 static void DisposeExternalString(v8::Persistent<v8::Object> obj, 2423 static void DisposeExternalString(v8::Persistent<v8::Value> obj,
2466 void* parameter) { 2424 void* parameter) {
2467 v8::String::ExternalStringResource* resource = 2425 v8::String::ExternalStringResource* resource =
2468 reinterpret_cast<v8::String::ExternalStringResource*>(parameter); 2426 reinterpret_cast<v8::String::ExternalStringResource*>(parameter);
2469 const size_t total_size = resource->length() * sizeof(*resource->data()); 2427 const size_t total_size = resource->length() * sizeof(*resource->data());
2470 i::Counters::total_external_string_memory.Decrement(total_size); 2428 i::Counters::total_external_string_memory.Decrement(total_size);
2471 delete resource; 2429 delete resource;
2472 obj.Dispose(); 2430 obj.Dispose();
2473 } 2431 }
2474 2432
2475 2433
2476 static void DisposeExternalAsciiString(v8::Persistent<v8::Object> obj, 2434 static void DisposeExternalAsciiString(v8::Persistent<v8::Value> obj,
2477 void* parameter) { 2435 void* parameter) {
2478 v8::String::ExternalAsciiStringResource* resource = 2436 v8::String::ExternalAsciiStringResource* resource =
2479 reinterpret_cast<v8::String::ExternalAsciiStringResource*>(parameter); 2437 reinterpret_cast<v8::String::ExternalAsciiStringResource*>(parameter);
2480 const size_t total_size = resource->length() * sizeof(*resource->data()); 2438 const size_t total_size = resource->length() * sizeof(*resource->data());
2481 i::Counters::total_external_string_memory.Decrement(total_size); 2439 i::Counters::total_external_string_memory.Decrement(total_size);
2482 delete resource; 2440 delete resource;
2483 obj.Dispose(); 2441 obj.Dispose();
2484 } 2442 }
2485 2443
2486 2444
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
2527 EnsureInitialized("v8::Date::New()"); 2485 EnsureInitialized("v8::Date::New()");
2528 LOG_API("Date::New"); 2486 LOG_API("Date::New");
2529 EXCEPTION_PREAMBLE(); 2487 EXCEPTION_PREAMBLE();
2530 i::Handle<i::Object> obj = 2488 i::Handle<i::Object> obj =
2531 i::Execution::NewDate(time, &has_pending_exception); 2489 i::Execution::NewDate(time, &has_pending_exception);
2532 EXCEPTION_BAILOUT_CHECK(Local<v8::Value>()); 2490 EXCEPTION_BAILOUT_CHECK(Local<v8::Value>());
2533 return Utils::ToLocal(obj); 2491 return Utils::ToLocal(obj);
2534 } 2492 }
2535 2493
2536 2494
2495 double v8::Date::NumberValue() {
2496 if (IsDeadCheck("v8::Date::NumberValue()")) return 0;
2497 LOG_API("Date::NumberValue");
2498 i::Handle<i::Object> obj = Utils::OpenHandle(this);
2499 i::Handle<i::JSValue> jsvalue = i::Handle<i::JSValue>::cast(obj);
2500 return jsvalue->value()->Number();
2501 }
2502
2503
2537 Local<v8::Array> v8::Array::New(int length) { 2504 Local<v8::Array> v8::Array::New(int length) {
2538 EnsureInitialized("v8::Array::New()"); 2505 EnsureInitialized("v8::Array::New()");
2539 LOG_API("Array::New"); 2506 LOG_API("Array::New");
2540 i::Handle<i::JSArray> obj = i::Factory::NewJSArray(length); 2507 i::Handle<i::JSArray> obj = i::Factory::NewJSArray(length);
2541 return Utils::ToLocal(obj); 2508 return Utils::ToLocal(obj);
2542 } 2509 }
2543 2510
2544 2511
2545 uint32_t v8::Array::Length() { 2512 uint32_t v8::Array::Length() {
2546 if (IsDeadCheck("v8::Array::Length()")) return 0; 2513 if (IsDeadCheck("v8::Array::Length()")) return 0;
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
2976 reinterpret_cast<HandleScopeImplementer*>(storage); 2943 reinterpret_cast<HandleScopeImplementer*>(storage);
2977 List<void**>* blocks_of_archived_thread = thread_local->Blocks(); 2944 List<void**>* blocks_of_archived_thread = thread_local->Blocks();
2978 ImplementationUtilities::HandleScopeData* handle_data_of_archived_thread = 2945 ImplementationUtilities::HandleScopeData* handle_data_of_archived_thread =
2979 &thread_local->handle_scope_data_; 2946 &thread_local->handle_scope_data_;
2980 Iterate(v, blocks_of_archived_thread, handle_data_of_archived_thread); 2947 Iterate(v, blocks_of_archived_thread, handle_data_of_archived_thread);
2981 2948
2982 return storage + ArchiveSpacePerThread(); 2949 return storage + ArchiveSpacePerThread();
2983 } 2950 }
2984 2951
2985 } } // namespace v8::internal 2952 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « include/v8.h ('k') | src/debug.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698