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

Side by Side Diff: test/cctest/test-api.cc

Issue 176843003: Add StackOverflowError and expose error type to api. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: fix test Created 6 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 | Annotate | Revision Log
« no previous file with comments | « src/runtime.js ('k') | tools/v8heapconst.py » ('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 // 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 14239 matching lines...) Expand 10 before | Expand all | Expand 10 after
14250 v8::TryCatch try_catch; 14250 v8::TryCatch try_catch;
14251 v8::Handle<v8::Script> script = v8::Script::Compile(v8::String::NewFromUtf8( 14251 v8::Handle<v8::Script> script = v8::Script::Compile(v8::String::NewFromUtf8(
14252 context->GetIsolate(), 14252 context->GetIsolate(),
14253 "function f() {" 14253 "function f() {"
14254 " return f();" 14254 " return f();"
14255 "}" 14255 "}"
14256 "" 14256 ""
14257 "f();")); 14257 "f();"));
14258 v8::Handle<v8::Value> result = script->Run(); 14258 v8::Handle<v8::Value> result = script->Run();
14259 CHECK(result.IsEmpty()); 14259 CHECK(result.IsEmpty());
14260 CHECK_EQ(v8::Exception::kStackOverflowError,
14261 v8::Exception::NativeErrorType(try_catch.Exception()));
14260 } 14262 }
14261 14263
14262 14264
14263 static void CheckTryCatchSourceInfo(v8::Handle<v8::Script> script, 14265 static void CheckTryCatchSourceInfo(v8::Handle<v8::Script> script,
14264 const char* resource_name, 14266 const char* resource_name,
14265 int line_offset) { 14267 int line_offset) {
14266 v8::HandleScope scope(CcTest::isolate()); 14268 v8::HandleScope scope(CcTest::isolate());
14267 v8::TryCatch try_catch; 14269 v8::TryCatch try_catch;
14268 v8::Handle<v8::Value> result = script->Run(); 14270 v8::Handle<v8::Value> result = script->Run();
14269 CHECK(result.IsEmpty()); 14271 CHECK(result.IsEmpty());
(...skipping 7839 matching lines...) Expand 10 before | Expand all | Expand 10 after
22109 Local<Object> ApiCallOptimizationChecker::holder; 22111 Local<Object> ApiCallOptimizationChecker::holder;
22110 Local<Object> ApiCallOptimizationChecker::callee; 22112 Local<Object> ApiCallOptimizationChecker::callee;
22111 int ApiCallOptimizationChecker::count = 0; 22113 int ApiCallOptimizationChecker::count = 0;
22112 22114
22113 22115
22114 TEST(TestFunctionCallOptimization) { 22116 TEST(TestFunctionCallOptimization) {
22115 i::FLAG_allow_natives_syntax = true; 22117 i::FLAG_allow_natives_syntax = true;
22116 ApiCallOptimizationChecker checker; 22118 ApiCallOptimizationChecker checker;
22117 checker.RunAll(); 22119 checker.RunAll();
22118 } 22120 }
22121
22122
22123 static void CheckExceptionType(
22124 const char* script, v8::Exception::ErrorType expected) {
22125 v8::TryCatch try_catch;
22126 CompileRun(script);
22127 if (!try_catch.HasCaught()) {
22128 CHECK_EQ(expected, v8::Exception::kNoError);
22129 } else {
22130 CHECK_EQ(expected, v8::Exception::NativeErrorType(try_catch.Exception()));
22131 }
22132 }
22133
22134
22135 THREADED_TEST(ExceptionTypes) {
22136 v8::Isolate* isolate = CcTest::isolate();
22137 v8::HandleScope scope(isolate);
22138 LocalContext context;
22139 // Check throw errors.
22140 CheckExceptionType("1", v8::Exception::kNoError);
22141 CheckExceptionType("throw 1", v8::Exception::kNoError);
22142 CheckExceptionType("throw Error", v8::Exception::kNoError);
22143 CheckExceptionType("throw new Error()", v8::Exception::kError);
22144 CheckExceptionType("throw new TypeError()", v8::Exception::kTypeError);
22145 CheckExceptionType("throw new RangeError()", v8::Exception::kRangeError);
22146 CheckExceptionType("throw new SyntaxError()", v8::Exception::kSyntaxError);
22147 CheckExceptionType(
22148 "throw new ReferenceError()", v8::Exception::kReferenceError);
22149 CheckExceptionType("throw new URIError()", v8::Exception::kURIError);
22150 CheckExceptionType("throw new EvalError()", v8::Exception::kEvalError);
22151 // Check api constructed errors.
22152 CHECK_EQ(v8::Exception::kError,
22153 v8::Exception::NativeErrorType(v8::Exception::Error(v8_str(""))));
22154 CHECK_EQ(v8::Exception::kTypeError,
22155 v8::Exception::NativeErrorType(v8::Exception::TypeError(v8_str(""))));
22156 CHECK_EQ(v8::Exception::kURIError,
22157 v8::Exception::NativeErrorType(v8::Exception::URIError(v8_str(""))));
22158 CHECK_EQ(v8::Exception::kEvalError,
22159 v8::Exception::NativeErrorType(v8::Exception::EvalError(v8_str(""))));
22160 CHECK_EQ(v8::Exception::kRangeError,
22161 v8::Exception::NativeErrorType(v8::Exception::RangeError(v8_str(""))));
22162 CHECK_EQ(v8::Exception::kSyntaxError,
22163 v8::Exception::NativeErrorType(v8::Exception::SyntaxError(v8_str(""))));
22164 CHECK_EQ(v8::Exception::kReferenceError,
22165 v8::Exception::NativeErrorType(
22166 v8::Exception::ReferenceError(v8_str(""))));
22167 CHECK_EQ(v8::Exception::kStackOverflowError,
22168 v8::Exception::NativeErrorType(
22169 v8::Exception::StackOverflowError(v8_str(""))));
22170 }
OLDNEW
« no previous file with comments | « src/runtime.js ('k') | tools/v8heapconst.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698