diff options
author | Ben Noordhuis <info@bnoordhuis.nl> | 2013-08-10 16:27:43 +0200 |
---|---|---|
committer | Ben Noordhuis <info@bnoordhuis.nl> | 2013-08-10 16:27:43 +0200 |
commit | f69be329f0d78f19e71ac9e75d6e4ee816e13c97 (patch) | |
tree | 022e53d1aff74dbe50f3984c154461bf6c19efb0 /deps/v8/test | |
parent | 39aa894035f9e3b58e04ce1a2b598e496e1f6bd6 (diff) | |
download | node-f69be329f0d78f19e71ac9e75d6e4ee816e13c97.tar.gz |
v8: upgrade v8 to 3.20.14.1
Diffstat (limited to 'deps/v8/test')
40 files changed, 1974 insertions, 113 deletions
diff --git a/deps/v8/test/benchmarks/benchmarks.status b/deps/v8/test/benchmarks/benchmarks.status new file mode 100644 index 000000000..651b8d7ad --- /dev/null +++ b/deps/v8/test/benchmarks/benchmarks.status @@ -0,0 +1,29 @@ +# Copyright 2013 the V8 project authors. All rights reserved. +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of Google Inc. nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +# Too slow in Debug mode. +octane/mandreel: PASS, SKIP if $mode == debug diff --git a/deps/v8/test/benchmarks/testcfg.py b/deps/v8/test/benchmarks/testcfg.py new file mode 100644 index 000000000..5fb3f51c7 --- /dev/null +++ b/deps/v8/test/benchmarks/testcfg.py @@ -0,0 +1,181 @@ +# Copyright 2013 the V8 project authors. All rights reserved. +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of Google Inc. nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +import os +import shutil +import subprocess +import tarfile + +from testrunner.local import testsuite +from testrunner.objects import testcase + + +class BenchmarksTestSuite(testsuite.TestSuite): + + def __init__(self, name, root): + super(BenchmarksTestSuite, self).__init__(name, root) + self.testroot = root + + def ListTests(self, context): + tests = [] + for test in [ + "kraken/ai-astar", + "kraken/audio-beat-detection", + "kraken/audio-dft", + "kraken/audio-fft", + "kraken/audio-oscillator", + "kraken/imaging-darkroom", + "kraken/imaging-desaturate", + "kraken/imaging-gaussian-blur", + "kraken/json-parse-financial", + "kraken/json-stringify-tinderbox", + "kraken/stanford-crypto-aes", + "kraken/stanford-crypto-ccm", + "kraken/stanford-crypto-pbkdf2", + "kraken/stanford-crypto-sha256-iterative", + + "octane/box2d", + "octane/code-load", + "octane/crypto", + "octane/deltablue", + "octane/earley-boyer", + "octane/gbemu", + "octane/mandreel", + "octane/navier-stokes", + "octane/pdfjs", + "octane/raytrace", + "octane/regexp", + "octane/richards", + "octane/splay", + + "sunspider/3d-cube", + "sunspider/3d-morph", + "sunspider/3d-raytrace", + "sunspider/access-binary-trees", + "sunspider/access-fannkuch", + "sunspider/access-nbody", + "sunspider/access-nsieve", + "sunspider/bitops-3bit-bits-in-byte", + "sunspider/bitops-bits-in-byte", + "sunspider/bitops-bitwise-and", + "sunspider/bitops-nsieve-bits", + "sunspider/controlflow-recursive", + "sunspider/crypto-aes", + "sunspider/crypto-md5", + "sunspider/crypto-sha1", + "sunspider/date-format-tofte", + "sunspider/date-format-xparb", + "sunspider/math-cordic", + "sunspider/math-partial-sums", + "sunspider/math-spectral-norm", + "sunspider/regexp-dna", + "sunspider/string-base64", + "sunspider/string-fasta", + "sunspider/string-tagcloud", + "sunspider/string-unpack-code", + "sunspider/string-validate-input"]: + tests.append(testcase.TestCase(self, test)) + return tests + + def GetFlagsForTestCase(self, testcase, context): + result = [] + result += context.mode_flags + if testcase.path.startswith("kraken"): + result.append(os.path.join(self.testroot, "%s-data.js" % testcase.path)) + result.append(os.path.join(self.testroot, "%s.js" % testcase.path)) + elif testcase.path.startswith("octane"): + result.append(os.path.join(self.testroot, "octane/base.js")) + result.append(os.path.join(self.testroot, "%s.js" % testcase.path)) + result += ["-e", "BenchmarkSuite.RunSuites({});"] + elif testcase.path.startswith("sunspider"): + result.append(os.path.join(self.testroot, "%s.js" % testcase.path)) + return testcase.flags + result + + def GetSourceForTest(self, testcase): + filename = os.path.join(self.testroot, testcase.path + ".js") + with open(filename) as f: + return f.read() + + def _DownloadIfNecessary(self, url, revision, target_dir): + # Maybe we're still up to date? + revision_file = "CHECKED_OUT_%s" % target_dir + checked_out_revision = None + if os.path.exists(revision_file): + with open(revision_file) as f: + checked_out_revision = f.read() + if checked_out_revision == revision: + return + + # If we have a local archive file with the test data, extract it. + if os.path.exists(target_dir): + shutil.rmtree(target_dir) + archive_file = "downloaded_%s_%s.tar.gz" % (target_dir, revision) + if os.path.exists(archive_file): + with tarfile.open(archive_file, "r:gz") as tar: + tar.extractall() + with open(revision_file, "w") as f: + f.write(revision) + return + + # No cached copy. Check out via SVN, and pack as .tar.gz for later use. + command = "svn co %s -r %s %s" % (url, revision, target_dir) + code = subprocess.call(command, shell=True) + if code != 0: + raise Exception("Error checking out %s benchmark" % target_dir) + with tarfile.open(archive_file, "w:gz") as tar: + tar.add("%s" % target_dir) + with open(revision_file, "w") as f: + f.write(revision) + + def DownloadData(self): + old_cwd = os.getcwd() + os.chdir(os.path.abspath(self.root)) + + self._DownloadIfNecessary( + ("http://svn.webkit.org/repository/webkit/trunk/PerformanceTests/" + "SunSpider/tests/sunspider-1.0/"), + "153700", "sunspider") + + self._DownloadIfNecessary( + ("http://kraken-mirror.googlecode.com/svn/trunk/kraken/tests/" + "kraken-1.1/"), + "8", "kraken") + + self._DownloadIfNecessary( + "http://octane-benchmark.googlecode.com/svn/trunk/", + "22", "octane") + + os.chdir(old_cwd) + + def VariantFlags(self): + # Both --nocrankshaft and --stressopt are very slow. + return [[]] + + +def GetSuite(name, root): + return BenchmarksTestSuite(name, root) diff --git a/deps/v8/test/cctest/cctest.cc b/deps/v8/test/cctest/cctest.cc index 94dcce130..a2caf0f3b 100644 --- a/deps/v8/test/cctest/cctest.cc +++ b/deps/v8/test/cctest/cctest.cc @@ -99,9 +99,10 @@ v8::Isolate* CcTest::default_isolate_; class CcTestArrayBufferAllocator : public v8::ArrayBuffer::Allocator { - public: virtual void* Allocate(size_t length) { return malloc(length); } - virtual void Free(void* data) { free(data); } + virtual void Free(void* data, size_t length) { free(data); } + // TODO(dslomov): Remove when v8:2823 is fixed. + virtual void Free(void* data) { UNREACHABLE(); } }; diff --git a/deps/v8/test/cctest/cctest.h b/deps/v8/test/cctest/cctest.h index 193126a08..1282d7da0 100644 --- a/deps/v8/test/cctest/cctest.h +++ b/deps/v8/test/cctest/cctest.h @@ -300,4 +300,57 @@ static inline void SimulateFullSpace(v8::internal::PagedSpace* space) { } +// Adapted from http://en.wikipedia.org/wiki/Multiply-with-carry +class RandomNumberGenerator { + public: + RandomNumberGenerator() { + init(); + } + + void init(uint32_t seed = 0x5688c73e) { + static const uint32_t phi = 0x9e3779b9; + c = 362436; + i = kQSize-1; + Q[0] = seed; + Q[1] = seed + phi; + Q[2] = seed + phi + phi; + for (unsigned j = 3; j < kQSize; j++) { + Q[j] = Q[j - 3] ^ Q[j - 2] ^ phi ^ j; + } + } + + uint32_t next() { + uint64_t a = 18782; + uint32_t r = 0xfffffffe; + i = (i + 1) & (kQSize-1); + uint64_t t = a * Q[i] + c; + c = (t >> 32); + uint32_t x = static_cast<uint32_t>(t + c); + if (x < c) { + x++; + c++; + } + return (Q[i] = r - x); + } + + uint32_t next(int max) { + return next() % max; + } + + bool next(double threshold) { + ASSERT(threshold >= 0.0 && threshold <= 1.0); + if (threshold == 1.0) return true; + if (threshold == 0.0) return false; + uint32_t value = next() % 100000; + return threshold > static_cast<double>(value)/100000.0; + } + + private: + static const uint32_t kQSize = 4096; + uint32_t Q[kQSize]; + uint32_t c; + uint32_t i; +}; + + #endif // ifndef CCTEST_H_ diff --git a/deps/v8/test/cctest/test-api.cc b/deps/v8/test/cctest/test-api.cc index 3c6f85ed7..664f90510 100644 --- a/deps/v8/test/cctest/test-api.cc +++ b/deps/v8/test/cctest/test-api.cc @@ -3565,6 +3565,7 @@ static void check_message_0(v8::Handle<v8::Message> message, CHECK_EQ(5.76, data->NumberValue()); CHECK_EQ(6.75, message->GetScriptResourceName()->NumberValue()); CHECK_EQ(7.56, message->GetScriptData()->NumberValue()); + CHECK(!message->IsSharedCrossOrigin()); message_received = true; } @@ -3591,6 +3592,7 @@ static void check_message_1(v8::Handle<v8::Message> message, v8::Handle<Value> data) { CHECK(data->IsNumber()); CHECK_EQ(1337, data->Int32Value()); + CHECK(!message->IsSharedCrossOrigin()); message_received = true; } @@ -3615,6 +3617,7 @@ static void check_message_2(v8::Handle<v8::Message> message, v8::Local<v8::Value> hidden_property = v8::Object::Cast(*data)->GetHiddenValue(v8_str("hidden key")); CHECK(v8_str("hidden value")->Equals(hidden_property)); + CHECK(!message->IsSharedCrossOrigin()); message_received = true; } @@ -3636,6 +3639,112 @@ TEST(MessageHandler2) { } +static void check_message_3(v8::Handle<v8::Message> message, + v8::Handle<Value> data) { + CHECK(message->IsSharedCrossOrigin()); + CHECK_EQ(6.75, message->GetScriptResourceName()->NumberValue()); + message_received = true; +} + + +TEST(MessageHandler3) { + message_received = false; + v8::HandleScope scope(v8::Isolate::GetCurrent()); + CHECK(!message_received); + v8::V8::AddMessageListener(check_message_3); + LocalContext context; + v8::ScriptOrigin origin = + v8::ScriptOrigin(v8_str("6.75"), + v8::Integer::New(1), + v8::Integer::New(2), + v8::True()); + v8::Handle<v8::Script> script = Script::Compile(v8_str("throw 'error'"), + &origin); + script->Run(); + CHECK(message_received); + // clear out the message listener + v8::V8::RemoveMessageListeners(check_message_3); +} + + +static void check_message_4(v8::Handle<v8::Message> message, + v8::Handle<Value> data) { + CHECK(!message->IsSharedCrossOrigin()); + CHECK_EQ(6.75, message->GetScriptResourceName()->NumberValue()); + message_received = true; +} + + +TEST(MessageHandler4) { + message_received = false; + v8::HandleScope scope(v8::Isolate::GetCurrent()); + CHECK(!message_received); + v8::V8::AddMessageListener(check_message_4); + LocalContext context; + v8::ScriptOrigin origin = + v8::ScriptOrigin(v8_str("6.75"), + v8::Integer::New(1), + v8::Integer::New(2), + v8::False()); + v8::Handle<v8::Script> script = Script::Compile(v8_str("throw 'error'"), + &origin); + script->Run(); + CHECK(message_received); + // clear out the message listener + v8::V8::RemoveMessageListeners(check_message_4); +} + + +static void check_message_5a(v8::Handle<v8::Message> message, + v8::Handle<Value> data) { + CHECK(message->IsSharedCrossOrigin()); + CHECK_EQ(6.75, message->GetScriptResourceName()->NumberValue()); + message_received = true; +} + + +static void check_message_5b(v8::Handle<v8::Message> message, + v8::Handle<Value> data) { + CHECK(!message->IsSharedCrossOrigin()); + CHECK_EQ(6.75, message->GetScriptResourceName()->NumberValue()); + message_received = true; +} + + +TEST(MessageHandler5) { + message_received = false; + v8::HandleScope scope(v8::Isolate::GetCurrent()); + CHECK(!message_received); + v8::V8::AddMessageListener(check_message_5a); + LocalContext context; + v8::ScriptOrigin origin = + v8::ScriptOrigin(v8_str("6.75"), + v8::Integer::New(1), + v8::Integer::New(2), + v8::True()); + v8::Handle<v8::Script> script = Script::Compile(v8_str("throw 'error'"), + &origin); + script->Run(); + CHECK(message_received); + // clear out the message listener + v8::V8::RemoveMessageListeners(check_message_5a); + + message_received = false; + v8::V8::AddMessageListener(check_message_5b); + origin = + v8::ScriptOrigin(v8_str("6.75"), + v8::Integer::New(1), + v8::Integer::New(2), + v8::False()); + script = Script::Compile(v8_str("throw 'error'"), + &origin); + script->Run(); + CHECK(message_received); + // clear out the message listener + v8::V8::RemoveMessageListeners(check_message_5b); +} + + THREADED_TEST(GetSetProperty) { LocalContext context; v8::HandleScope scope(context->GetIsolate()); @@ -4279,7 +4388,7 @@ TEST(APIThrowMessageOverwrittenToString) { } -static void check_custom_error_message( +static void check_custom_error_tostring( v8::Handle<v8::Message> message, v8::Handle<v8::Value> data) { const char* uncaught_error = "Uncaught MyError toString"; @@ -4290,7 +4399,7 @@ static void check_custom_error_message( TEST(CustomErrorToString) { LocalContext context; v8::HandleScope scope(context->GetIsolate()); - v8::V8::AddMessageListener(check_custom_error_message); + v8::V8::AddMessageListener(check_custom_error_tostring); CompileRun( "function MyError(name, message) { " " this.name = name; " @@ -4301,6 +4410,58 @@ TEST(CustomErrorToString) { " return 'MyError toString'; " "}; " "throw new MyError('my name', 'my message'); "); + v8::V8::RemoveMessageListeners(check_custom_error_tostring); +} + + +static void check_custom_error_message( + v8::Handle<v8::Message> message, + v8::Handle<v8::Value> data) { + const char* uncaught_error = "Uncaught MyError: my message"; + printf("%s\n", *v8::String::Utf8Value(message->Get())); + CHECK(message->Get()->Equals(v8_str(uncaught_error))); +} + + +TEST(CustomErrorMessage) { + LocalContext context; + v8::HandleScope scope(context->GetIsolate()); + v8::V8::AddMessageListener(check_custom_error_message); + + // Handlebars. + CompileRun( + "function MyError(msg) { " + " this.name = 'MyError'; " + " this.message = msg; " + "} " + "MyError.prototype = new Error(); " + "throw new MyError('my message'); "); + + // Closure. + CompileRun( + "function MyError(msg) { " + " this.name = 'MyError'; " + " this.message = msg; " + "} " + "inherits = function(childCtor, parentCtor) { " + " function tempCtor() {}; " + " tempCtor.prototype = parentCtor.prototype; " + " childCtor.superClass_ = parentCtor.prototype; " + " childCtor.prototype = new tempCtor(); " + " childCtor.prototype.constructor = childCtor; " + "}; " + "inherits(MyError, Error); " + "throw new MyError('my message'); "); + + // Object.create. + CompileRun( + "function MyError(msg) { " + " this.name = 'MyError'; " + " this.message = msg; " + "} " + "MyError.prototype = Object.create(Error.prototype); " + "throw new MyError('my message'); "); + v8::V8::RemoveMessageListeners(check_custom_error_message); } @@ -19754,6 +19915,16 @@ THREADED_TEST(Regress260106) { } +THREADED_TEST(JSONParse) { + LocalContext context; + HandleScope scope(context->GetIsolate()); + Local<Object> obj = v8::JSON::Parse(v8_str("{\"x\":42}")); + Handle<Object> global = context->Global(); + global->Set(v8_str("obj"), obj); + ExpectString("JSON.stringify(obj)", "{\"x\":42}"); +} + + #ifndef WIN32 class ThreadInterruptTest { public: diff --git a/deps/v8/test/cctest/test-assembler-arm.cc b/deps/v8/test/cctest/test-assembler-arm.cc index cb677b3bb..cac162e01 100644 --- a/deps/v8/test/cctest/test-assembler-arm.cc +++ b/deps/v8/test/cctest/test-assembler-arm.cc @@ -1418,4 +1418,25 @@ TEST(16) { CHECK_EQ(0x11121313, t.dst4); } + +TEST(17) { + // Test generating labels at high addresses. + // Should not assert. + CcTest::InitializeVM(); + Isolate* isolate = Isolate::Current(); + HandleScope scope(isolate); + + // Generate a code segment that will be longer than 2^24 bytes. + Assembler assm(isolate, NULL, 0); + for (size_t i = 0; i < 1 << 23 ; ++i) { // 2^23 + __ nop(); + } + + Label target; + __ b(eq, &target); + __ bind(&target); + __ nop(); +} + + #undef __ diff --git a/deps/v8/test/cctest/test-code-stubs-ia32.cc b/deps/v8/test/cctest/test-code-stubs-ia32.cc index 6f8de6047..a3c0b54e2 100644 --- a/deps/v8/test/cctest/test-code-stubs-ia32.cc +++ b/deps/v8/test/cctest/test-code-stubs-ia32.cc @@ -94,7 +94,7 @@ ConvertDToIFunc MakeConvertDToIFuncTrampoline(Isolate* isolate, Register reg = Register::from_code(reg_num); if (!reg.is(esp) && !reg.is(ebp) && !reg.is(destination_reg)) { __ cmp(reg, MemOperand(esp, 0)); - __ Assert(equal, "register was clobbered"); + __ Assert(equal, kRegisterWasClobbered); __ add(esp, Immediate(kPointerSize)); } } diff --git a/deps/v8/test/cctest/test-code-stubs-x64.cc b/deps/v8/test/cctest/test-code-stubs-x64.cc index e30c160e7..0bffb87fe 100644 --- a/deps/v8/test/cctest/test-code-stubs-x64.cc +++ b/deps/v8/test/cctest/test-code-stubs-x64.cc @@ -93,7 +93,7 @@ ConvertDToIFunc MakeConvertDToIFuncTrampoline(Isolate* isolate, Register reg = Register::from_code(reg_num); if (!reg.is(rsp) && !reg.is(rbp) && !reg.is(destination_reg)) { __ cmpq(reg, MemOperand(rsp, 0)); - __ Assert(equal, "register was clobbered"); + __ Assert(equal, kRegisterWasClobbered); __ addq(rsp, Immediate(kPointerSize)); } } diff --git a/deps/v8/test/cctest/test-compiler.cc b/deps/v8/test/cctest/test-compiler.cc index bed8a6c92..b5ba46c4c 100644 --- a/deps/v8/test/cctest/test-compiler.cc +++ b/deps/v8/test/cctest/test-compiler.cc @@ -105,6 +105,7 @@ static Handle<JSFunction> Compile(const char* source) { Handle<String>(), 0, 0, + false, Handle<Context>(isolate->native_context()), NULL, NULL, diff --git a/deps/v8/test/cctest/test-cpu-profiler.cc b/deps/v8/test/cctest/test-cpu-profiler.cc index d9ecc41a7..daf8db615 100644 --- a/deps/v8/test/cctest/test-cpu-profiler.cc +++ b/deps/v8/test/cctest/test-cpu-profiler.cc @@ -410,6 +410,21 @@ TEST(GetProfilerWhenIsolateIsNotInitialized) { } +TEST(ProfileStartEndTime) { + LocalContext env; + v8::HandleScope scope(env->GetIsolate()); + v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); + + int64_t time_before_profiling = i::OS::Ticks(); + v8::Local<v8::String> profile_name = v8::String::New("test"); + cpu_profiler->StartCpuProfiling(profile_name); + const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name); + CHECK(time_before_profiling <= profile->GetStartTime()); + CHECK(profile->GetStartTime() <= profile->GetEndTime()); + CHECK(profile->GetEndTime() <= i::OS::Ticks()); +} + + static const v8::CpuProfile* RunProfiler( LocalContext& env, v8::Handle<v8::Function> function, v8::Handle<v8::Value> argv[], int argc, diff --git a/deps/v8/test/cctest/test-global-handles.cc b/deps/v8/test/cctest/test-global-handles.cc index a274d7546..ea11dbcf3 100644 --- a/deps/v8/test/cctest/test-global-handles.cc +++ b/deps/v8/test/cctest/test-global-handles.cc @@ -25,6 +25,9 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#include <map> +#include <vector> + #include "global-handles.h" #include "cctest.h" @@ -315,3 +318,204 @@ TEST(ImplicitReferences) { ASSERT(implicit_refs->at(1)->length == 1); ASSERT(implicit_refs->at(1)->children[0] == g2c1.location()); } + + +static const int kBlockSize = 256; + + +TEST(BlockCollection) { + v8::V8::Initialize(); + Isolate* isolate = Isolate::Current(); + GlobalHandles* global_handles = isolate->global_handles(); + CHECK_EQ(0, global_handles->block_count()); + CHECK_EQ(0, global_handles->global_handles_count()); + Object* object = isolate->heap()->undefined_value(); + const int kNumberOfBlocks = 5; + typedef Handle<Object> Block[kBlockSize]; + for (int round = 0; round < 3; round++) { + Block blocks[kNumberOfBlocks]; + for (int i = 0; i < kNumberOfBlocks; i++) { + for (int j = 0; j < kBlockSize; j++) { + blocks[i][j] = global_handles->Create(object); + } + } + CHECK_EQ(kNumberOfBlocks, global_handles->block_count()); + for (int i = 0; i < kNumberOfBlocks; i++) { + for (int j = 0; j < kBlockSize; j++) { + global_handles->Destroy(blocks[i][j].location()); + } + } + isolate->heap()->CollectAllAvailableGarbage("BlockCollection"); + CHECK_EQ(0, global_handles->global_handles_count()); + CHECK_EQ(1, global_handles->block_count()); + } +} + + +class RandomMutationData { + public: + explicit RandomMutationData(Isolate* isolate) + : isolate_(isolate), weak_offset_(0) {} + + void Mutate(double strong_growth_tendency, + double weak_growth_tendency = 0.05) { + for (int i = 0; i < kBlockSize * 100; i++) { + if (rng_.next(strong_growth_tendency)) { + AddStrong(); + } else if (strong_nodes_.size() != 0) { + size_t to_remove = rng_.next(static_cast<int>(strong_nodes_.size())); + RemoveStrong(to_remove); + } + if (rng_.next(weak_growth_tendency)) AddWeak(); + if (rng_.next(0.05)) { +#ifdef DEBUG + isolate_->global_handles()->VerifyBlockInvariants(); +#endif + } + if (rng_.next(0.0001)) { + isolate_->heap()->PerformScavenge(); + } else if (rng_.next(0.00003)) { + isolate_->heap()->CollectAllAvailableGarbage(); + } + CheckSizes(); + } + } + + void RemoveAll() { + while (strong_nodes_.size() != 0) { + RemoveStrong(strong_nodes_.size() - 1); + } + isolate_->heap()->PerformScavenge(); + isolate_->heap()->CollectAllAvailableGarbage(); + CheckSizes(); + } + + private: + typedef std::vector<Object**> NodeVector; + typedef std::map<int32_t, Object**> NodeMap; + + void CheckSizes() { + int stored_sizes = + static_cast<int>(strong_nodes_.size() + weak_nodes_.size()); + CHECK_EQ(isolate_->global_handles()->global_handles_count(), stored_sizes); + } + + void AddStrong() { + Object* object = isolate_->heap()->undefined_value(); + Object** location = isolate_->global_handles()->Create(object).location(); + strong_nodes_.push_back(location); + } + + void RemoveStrong(size_t offset) { + isolate_->global_handles()->Destroy(strong_nodes_.at(offset)); + strong_nodes_.erase(strong_nodes_.begin() + offset); + } + + void AddWeak() { + v8::Isolate* isolate = reinterpret_cast<v8::Isolate*>(isolate_); + v8::HandleScope scope(isolate); + v8::Local<v8::Object> object = v8::Object::New(); + int32_t offset = ++weak_offset_; + object->Set(7, v8::Integer::New(offset, isolate)); + v8::Persistent<v8::Object> persistent(isolate, object); + persistent.MakeWeak(isolate, this, WeakCallback); + persistent.MarkIndependent(); + Object** location = v8::Utils::OpenPersistent(persistent).location(); + bool inserted = + weak_nodes_.insert(std::make_pair(offset, location)).second; + CHECK(inserted); + } + + static void WeakCallback(v8::Isolate* isolate, + v8::Persistent<v8::Object>* persistent, + RandomMutationData* data) { + v8::Local<v8::Object> object = + v8::Local<v8::Object>::New(isolate, *persistent); + int32_t offset = + v8::Local<v8::Integer>::Cast(object->Get(7))->Int32Value(); + Object** location = v8::Utils::OpenPersistent(persistent).location(); + NodeMap& weak_nodes = data->weak_nodes_; + NodeMap::iterator it = weak_nodes.find(offset); + CHECK(it != weak_nodes.end()); + CHECK(it->second == location); + weak_nodes.erase(it); + persistent->Dispose(); + } + + Isolate* isolate_; + RandomNumberGenerator rng_; + NodeVector strong_nodes_; + NodeMap weak_nodes_; + int32_t weak_offset_; +}; + + +TEST(RandomMutation) { + v8::V8::Initialize(); + Isolate* isolate = Isolate::Current(); + CHECK_EQ(0, isolate->global_handles()->block_count()); + HandleScope handle_scope(isolate); + v8::Context::Scope context_scope( + v8::Context::New(reinterpret_cast<v8::Isolate*>(isolate))); + RandomMutationData data(isolate); + // grow some + data.Mutate(0.65); + data.Mutate(0.55); + // balanced mutation + for (int i = 0; i < 3; i++) data.Mutate(0.50); + // shrink some + data.Mutate(0.45); + data.Mutate(0.35); + // clear everything + data.RemoveAll(); +} + + +TEST(EternalHandles) { + CcTest::InitializeVM(); + Isolate* isolate = Isolate::Current(); + v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); + EternalHandles* eternals = isolate->eternal_handles(); + + // Create a number of handles that will not be on a block boundary + const int kArrayLength = 2048-1; + int indices[kArrayLength]; + + CHECK_EQ(0, eternals->NumberOfHandles()); + for (int i = 0; i < kArrayLength; i++) { + HandleScope scope(isolate); + v8::Local<v8::Object> object = v8::Object::New(); + object->Set(i, v8::Integer::New(i, v8_isolate)); + if (i % 2 == 0) { + // Create with internal api + indices[i] = eternals->Create(isolate, *v8::Utils::OpenHandle(*object)); + } else { + // Create with external api + indices[i] = object.Eternalize(v8_isolate); + } + } + + isolate->heap()->CollectAllAvailableGarbage(); + + for (int i = 0; i < kArrayLength; i++) { + for (int j = 0; j < 2; j++) { + HandleScope scope(isolate); + v8::Local<v8::Object> object; + if (j == 0) { + // Test internal api + v8::Local<v8::Value> local = + v8::Utils::ToLocal(eternals->Get(indices[i])); + object = v8::Handle<v8::Object>::Cast(local); + } else { + // Test external api + object = v8::Local<v8::Object>::GetEternal(v8_isolate, indices[i]); + } + v8::Local<v8::Value> value = object->Get(i); + CHECK(value->IsInt32()); + CHECK_EQ(i, value->Int32Value()); + } + } + + CHECK_EQ(kArrayLength, eternals->NumberOfHandles()); +} + diff --git a/deps/v8/test/cctest/test-heap.cc b/deps/v8/test/cctest/test-heap.cc index 6af9962bd..5f713503e 100644 --- a/deps/v8/test/cctest/test-heap.cc +++ b/deps/v8/test/cctest/test-heap.cc @@ -960,7 +960,7 @@ TEST(Regression39128) { Factory* factory = isolate->factory(); // Increase the chance of 'bump-the-pointer' allocation in old space. - HEAP->CollectAllGarbage(Heap::kNoGCFlags); + HEAP->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); v8::HandleScope scope(CcTest::isolate()); @@ -984,7 +984,7 @@ TEST(Regression39128) { // just enough room to allocate JSObject and thus fill the newspace. int allocation_amount = Min(FixedArray::kMaxSize, - Page::kMaxNonCodeHeapObjectSize); + Page::kMaxNonCodeHeapObjectSize + kPointerSize); int allocation_len = LenFromSize(allocation_amount); NewSpace* new_space = HEAP->new_space(); Address* top_addr = new_space->allocation_top_address(); diff --git a/deps/v8/test/cctest/test-strings.cc b/deps/v8/test/cctest/test-strings.cc index 310d93c04..d6591a09b 100644 --- a/deps/v8/test/cctest/test-strings.cc +++ b/deps/v8/test/cctest/test-strings.cc @@ -40,58 +40,6 @@ #include "cctest.h" #include "zone-inl.h" -// Adapted from http://en.wikipedia.org/wiki/Multiply-with-carry -class RandomNumberGenerator { - public: - RandomNumberGenerator() { - init(); - } - - void init(uint32_t seed = 0x5688c73e) { - static const uint32_t phi = 0x9e3779b9; - c = 362436; - i = kQSize-1; - Q[0] = seed; - Q[1] = seed + phi; - Q[2] = seed + phi + phi; - for (unsigned j = 3; j < kQSize; j++) { - Q[j] = Q[j - 3] ^ Q[j - 2] ^ phi ^ j; - } - } - - uint32_t next() { - uint64_t a = 18782; - uint32_t r = 0xfffffffe; - i = (i + 1) & (kQSize-1); - uint64_t t = a * Q[i] + c; - c = (t >> 32); - uint32_t x = static_cast<uint32_t>(t + c); - if (x < c) { - x++; - c++; - } - return (Q[i] = r - x); - } - - uint32_t next(int max) { - return next() % max; - } - - bool next(double threshold) { - ASSERT(threshold >= 0.0 && threshold <= 1.0); - if (threshold == 1.0) return true; - if (threshold == 0.0) return false; - uint32_t value = next() % 100000; - return threshold > static_cast<double>(value)/100000.0; - } - - private: - static const uint32_t kQSize = 4096; - uint32_t Q[kQSize]; - uint32_t c; - uint32_t i; -}; - using namespace v8::internal; diff --git a/deps/v8/test/intl/break-iterator/default-locale.js b/deps/v8/test/intl/break-iterator/default-locale.js index 39a88574f..d8d5aeadb 100644 --- a/deps/v8/test/intl/break-iterator/default-locale.js +++ b/deps/v8/test/intl/break-iterator/default-locale.js @@ -38,7 +38,7 @@ assertFalse(options.locale === ''); assertFalse(options.locale === undefined); // Then check for equality. -assertEquals(options.locale, getDefaultLocale()); +assertEquals(options.locale, %GetDefaultICULocale()); var iteratorNone = new Intl.v8BreakIterator(); assertEquals(options.locale, iteratorNone.resolvedOptions().locale); diff --git a/deps/v8/test/intl/break-iterator/wellformed-unsupported-locale.js b/deps/v8/test/intl/break-iterator/wellformed-unsupported-locale.js index 56457b482..5ac8fbcd4 100644 --- a/deps/v8/test/intl/break-iterator/wellformed-unsupported-locale.js +++ b/deps/v8/test/intl/break-iterator/wellformed-unsupported-locale.js @@ -29,4 +29,4 @@ var iterator = Intl.v8BreakIterator(['xx']); -assertEquals(iterator.resolvedOptions().locale, getDefaultLocale()); +assertEquals(iterator.resolvedOptions().locale, %GetDefaultICULocale()); diff --git a/deps/v8/test/intl/collator/default-locale.js b/deps/v8/test/intl/collator/default-locale.js index f6ffba8e1..db9b1e733 100644 --- a/deps/v8/test/intl/collator/default-locale.js +++ b/deps/v8/test/intl/collator/default-locale.js @@ -38,7 +38,7 @@ assertFalse(options.locale === ''); assertFalse(options.locale === undefined); // Then check for equality. -assertEquals(options.locale, getDefaultLocale()); +assertEquals(options.locale, %GetDefaultICULocale()); var collatorNone = new Intl.Collator(); assertEquals(options.locale, collatorNone.resolvedOptions().locale); @@ -48,5 +48,5 @@ var collatorBraket = new Intl.Collator({}); assertEquals(options.locale, collatorBraket.resolvedOptions().locale); var collatorWithOptions = new Intl.Collator(undefined, {usage: 'search'}); -assertEquals(getDefaultLocale() + '-u-co-search', +assertEquals(%GetDefaultICULocale() + '-u-co-search', collatorWithOptions.resolvedOptions().locale); diff --git a/deps/v8/test/intl/collator/wellformed-unsupported-locale.js b/deps/v8/test/intl/collator/wellformed-unsupported-locale.js index ea143fdc6..3963d47a6 100644 --- a/deps/v8/test/intl/collator/wellformed-unsupported-locale.js +++ b/deps/v8/test/intl/collator/wellformed-unsupported-locale.js @@ -29,4 +29,4 @@ var collator = Intl.Collator(['xx']); -assertEquals(collator.resolvedOptions().locale, getDefaultLocale()); +assertEquals(collator.resolvedOptions().locale, %GetDefaultICULocale()); diff --git a/deps/v8/test/intl/date-format/default-locale.js b/deps/v8/test/intl/date-format/default-locale.js index 2dcb0f8ae..8e9b7fcec 100644 --- a/deps/v8/test/intl/date-format/default-locale.js +++ b/deps/v8/test/intl/date-format/default-locale.js @@ -38,7 +38,7 @@ assertFalse(options.locale === ''); assertFalse(options.locale === undefined); // Then check for equality. -assertEquals(options.locale, getDefaultLocale()); +assertEquals(options.locale, %GetDefaultICULocale()); var dtfNone = new Intl.DateTimeFormat(); assertEquals(options.locale, dtfNone.resolvedOptions().locale); diff --git a/deps/v8/test/intl/date-format/wellformed-unsupported-locale.js b/deps/v8/test/intl/date-format/wellformed-unsupported-locale.js index 8867ec644..6f063abbd 100644 --- a/deps/v8/test/intl/date-format/wellformed-unsupported-locale.js +++ b/deps/v8/test/intl/date-format/wellformed-unsupported-locale.js @@ -29,4 +29,4 @@ var dtf = Intl.DateTimeFormat(['xx']); -assertEquals(dtf.resolvedOptions().locale, getDefaultLocale()); +assertEquals(dtf.resolvedOptions().locale, %GetDefaultICULocale()); diff --git a/deps/v8/test/intl/intl.status b/deps/v8/test/intl/intl.status index 913626b1f..7ef0abb4d 100644 --- a/deps/v8/test/intl/intl.status +++ b/deps/v8/test/intl/intl.status @@ -27,15 +27,7 @@ prefix intl -# The following tests use getDefaultLocale() or getDefaultTimezone(). -break-iterator/default-locale: FAIL -break-iterator/wellformed-unsupported-locale: FAIL -collator/default-locale: FAIL -collator/wellformed-unsupported-locale: FAIL -date-format/default-locale: FAIL +# The following tests use getDefaultTimeZone(). date-format/resolved-options: FAIL date-format/timezone: FAIL -date-format/wellformed-unsupported-locale: FAIL general/v8Intl-exists: FAIL -number-format/default-locale: FAIL -number-format/wellformed-unsupported-locale: FAIL diff --git a/deps/v8/test/intl/number-format/default-locale.js b/deps/v8/test/intl/number-format/default-locale.js index 0d5e24dd7..cd67ba724 100644 --- a/deps/v8/test/intl/number-format/default-locale.js +++ b/deps/v8/test/intl/number-format/default-locale.js @@ -38,7 +38,7 @@ assertFalse(options.locale === ''); assertFalse(options.locale === undefined); // Then check for equality. -assertEquals(options.locale, getDefaultLocale()); +assertEquals(options.locale, %GetDefaultICULocale()); var nfNone = new Intl.NumberFormat(); assertEquals(options.locale, nfNone.resolvedOptions().locale); diff --git a/deps/v8/test/intl/number-format/wellformed-unsupported-locale.js b/deps/v8/test/intl/number-format/wellformed-unsupported-locale.js index e3fe9cc08..195eba4c1 100644 --- a/deps/v8/test/intl/number-format/wellformed-unsupported-locale.js +++ b/deps/v8/test/intl/number-format/wellformed-unsupported-locale.js @@ -29,4 +29,4 @@ var nf = Intl.NumberFormat(['xx']); -assertEquals(nf.resolvedOptions().locale, getDefaultLocale()); +assertEquals(nf.resolvedOptions().locale, %GetDefaultICULocale()); diff --git a/deps/v8/test/intl/testcfg.py b/deps/v8/test/intl/testcfg.py index d25683bed..09d29d0be 100644 --- a/deps/v8/test/intl/testcfg.py +++ b/deps/v8/test/intl/testcfg.py @@ -52,7 +52,7 @@ class IntlTestSuite(testsuite.TestSuite): return tests def GetFlagsForTestCase(self, testcase, context): - flags = [] + context.mode_flags + flags = ["--allow-natives-syntax"] + context.mode_flags files = [] files.append(os.path.join(self.root, "assert.js")) diff --git a/deps/v8/test/mjsunit/harmony/array-find.js b/deps/v8/test/mjsunit/harmony/array-find.js new file mode 100644 index 000000000..906c9cde7 --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/array-find.js @@ -0,0 +1,280 @@ +// Copyright 2013 the V8 project authors. All rights reserved. +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following +// disclaimer in the documentation and/or other materials provided +// with the distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Flags: --harmony-arrays + +assertEquals(1, Array.prototype.find.length); + +var a = [21, 22, 23, 24]; +assertEquals(undefined, a.find(function() { return false; })); +assertEquals(21, a.find(function() { return true; })); +assertEquals(undefined, a.find(function(val) { return 121 === val; })); +assertEquals(24, a.find(function(val) { return 24 === val; })); +assertEquals(23, a.find(function(val) { return 23 === val; }), null); +assertEquals(22, a.find(function(val) { return 22 === val; }), undefined); + + +// +// Test predicate is not called when array is empty +// +(function() { + var a = []; + var l = -1; + var o = -1; + var v = -1; + var k = -1; + + a.find(function(val, key, obj) { + o = obj; + l = obj.length; + v = val; + k = key; + + return false; + }); + + assertEquals(-1, l); + assertEquals(-1, o); + assertEquals(-1, v); + assertEquals(-1, k); +})(); + + +// +// Test predicate is called with correct argumetns +// +(function() { + var a = ["b"]; + var l = -1; + var o = -1; + var v = -1; + var k = -1; + + var found = a.find(function(val, key, obj) { + o = obj; + l = obj.length; + v = val; + k = key; + + return false; + }); + + assertArrayEquals(a, o); + assertEquals(a.length, l); + assertEquals("b", v); + assertEquals(0, k); + assertEquals(undefined, found); +})(); + + +// +// Test predicate is called array.length times +// +(function() { + var a = [1, 2, 3, 4, 5]; + var l = 0; + var found = a.find(function() { + l++; + return false; + }); + + assertEquals(a.length, l); + assertEquals(undefined, found); +})(); + + +// +// Test Array.prototype.find works with String +// +(function() { + var a = "abcd"; + var l = -1; + var o = -1; + var v = -1; + var k = -1; + var found = Array.prototype.find.call(a, function(val, key, obj) { + o = obj.toString(); + l = obj.length; + v = val; + k = key; + + return false; + }); + + assertEquals(a, o); + assertEquals(a.length, l); + assertEquals("d", v); + assertEquals(3, k); + assertEquals(undefined, found); + + found = Array.prototype.find.apply(a, [function(val, key, obj) { + o = obj.toString(); + l = obj.length; + v = val; + k = key; + + return true; + }]); + + assertEquals(a, o); + assertEquals(a.length, l); + assertEquals("a", v); + assertEquals(0, k); + assertEquals("a", found); +})(); + + +// +// Test Array.prototype.find works with exotic object +// +(function() { + var l = -1; + var o = -1; + var v = -1; + var k = -1; + var a = { + prop1: "val1", + prop2: "val2", + isValid: function() { + return this.prop1 === "val1" && this.prop2 === "val2"; + } + }; + + Array.prototype.push.apply(a, [30, 31, 32]); + var found = Array.prototype.find.call(a, function(val, key, obj) { + o = obj; + l = obj.length; + v = val; + k = key; + + return !obj.isValid(); + }); + + assertArrayEquals(a, o); + assertEquals(3, l); + assertEquals(32, v); + assertEquals(2, k); + assertEquals(undefined, found); +})(); + + +// +// Test array modifications +// +(function() { + var a = [1, 2, 3]; + var found = a.find(function(val) { a.push(val); return false; }); + assertArrayEquals([1, 2, 3, 1, 2, 3], a); + assertEquals(6, a.length); + assertEquals(undefined, found); + + a = [1, 2, 3]; + found = a.find(function(val, key) { a[key] = ++val; return false; }); + assertArrayEquals([2, 3, 4], a); + assertEquals(3, a.length); + assertEquals(undefined, found); +})(); + + +// +// Test predicate is only called for existing elements +// +(function() { + var a = new Array(30); + a[11] = 21; + a[7] = 10; + a[29] = 31; + + var count = 0; + a.find(function() { count++; return false; }); + assertEquals(3, count); +})(); + + +// +// Test thisArg +// +(function() { + // Test String as a thisArg + var found = [1, 2, 3].find(function(val, key) { + return this.charAt(Number(key)) === String(val); + }, "321"); + assertEquals(2, found); + + // Test object as a thisArg + var thisArg = { + elementAt: function(key) { + return this[key]; + } + }; + Array.prototype.push.apply(thisArg, ["c", "b", "a"]); + + found = ["a", "b", "c"].find(function(val, key) { + return this.elementAt(key) === val; + }, thisArg); + assertEquals("b", found); +})(); + +// Test exceptions +assertThrows('Array.prototype.find.call(null, function() { })', + TypeError); +assertThrows('Array.prototype.find.call(undefined, function() { })', + TypeError); +assertThrows('Array.prototype.find.apply(null, function() { }, [])', + TypeError); +assertThrows('Array.prototype.find.apply(undefined, function() { }, [])', + TypeError); + +assertThrows('[].find(null)', TypeError); +assertThrows('[].find(undefined)', TypeError); +assertThrows('[].find(0)', TypeError); +assertThrows('[].find(true)', TypeError); +assertThrows('[].find(false)', TypeError); +assertThrows('[].find("")', TypeError); +assertThrows('[].find({})', TypeError); +assertThrows('[].find([])', TypeError); +assertThrows('[].find(/\d+/)', TypeError); + +assertThrows('Array.prototype.find.call({}, null)', TypeError); +assertThrows('Array.prototype.find.call({}, undefined)', TypeError); +assertThrows('Array.prototype.find.call({}, 0)', TypeError); +assertThrows('Array.prototype.find.call({}, true)', TypeError); +assertThrows('Array.prototype.find.call({}, false)', TypeError); +assertThrows('Array.prototype.find.call({}, "")', TypeError); +assertThrows('Array.prototype.find.call({}, {})', TypeError); +assertThrows('Array.prototype.find.call({}, [])', TypeError); +assertThrows('Array.prototype.find.call({}, /\d+/)', TypeError); + +assertThrows('Array.prototype.find.apply({}, null, [])', TypeError); +assertThrows('Array.prototype.find.apply({}, undefined, [])', TypeError); +assertThrows('Array.prototype.find.apply({}, 0, [])', TypeError); +assertThrows('Array.prototype.find.apply({}, true, [])', TypeError); +assertThrows('Array.prototype.find.apply({}, false, [])', TypeError); +assertThrows('Array.prototype.find.apply({}, "", [])', TypeError); +assertThrows('Array.prototype.find.apply({}, {}, [])', TypeError); +assertThrows('Array.prototype.find.apply({}, [], [])', TypeError); +assertThrows('Array.prototype.find.apply({}, /\d+/, [])', TypeError);
\ No newline at end of file diff --git a/deps/v8/test/mjsunit/harmony/array-findindex.js b/deps/v8/test/mjsunit/harmony/array-findindex.js new file mode 100644 index 000000000..928cad79e --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/array-findindex.js @@ -0,0 +1,280 @@ +// Copyright 2013 the V8 project authors. All rights reserved. +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following +// disclaimer in the documentation and/or other materials provided +// with the distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Flags: --harmony-arrays + +assertEquals(1, Array.prototype.findIndex.length); + +var a = [21, 22, 23, 24]; +assertEquals(-1, a.findIndex(function() { return false; })); +assertEquals(-1, a.findIndex(function(val) { return 121 === val; })); +assertEquals(0, a.findIndex(function() { return true; })); +assertEquals(1, a.findIndex(function(val) { return 22 === val; }), undefined); +assertEquals(2, a.findIndex(function(val) { return 23 === val; }), null); +assertEquals(3, a.findIndex(function(val) { return 24 === val; })); + + +// +// Test predicate is not called when array is empty +// +(function() { + var a = []; + var l = -1; + var o = -1; + var v = -1; + var k = -1; + + a.findIndex(function(val, key, obj) { + o = obj; + l = obj.length; + v = val; + k = key; + + return false; + }); + + assertEquals(-1, l); + assertEquals(-1, o); + assertEquals(-1, v); + assertEquals(-1, k); +})(); + + +// +// Test predicate is called with correct argumetns +// +(function() { + var a = ["b"]; + var l = -1; + var o = -1; + var v = -1; + var k = -1; + + var index = a.findIndex(function(val, key, obj) { + o = obj; + l = obj.length; + v = val; + k = key; + + return false; + }); + + assertArrayEquals(a, o); + assertEquals(a.length, l); + assertEquals("b", v); + assertEquals(0, k); + assertEquals(-1, index); +})(); + + +// +// Test predicate is called array.length times +// +(function() { + var a = [1, 2, 3, 4, 5]; + var l = 0; + + a.findIndex(function() { + l++; + return false; + }); + + assertEquals(a.length, l); +})(); + + +// +// Test Array.prototype.findIndex works with String +// +(function() { + var a = "abcd"; + var l = -1; + var o = -1; + var v = -1; + var k = -1; + + var index = Array.prototype.findIndex.call(a, function(val, key, obj) { + o = obj.toString(); + l = obj.length; + v = val; + k = key; + + return false; + }); + + assertEquals(a, o); + assertEquals(a.length, l); + assertEquals("d", v); + assertEquals(3, k); + assertEquals(-1, index); + + index = Array.prototype.findIndex.apply(a, [function(val, key, obj) { + o = obj.toString(); + l = obj.length; + v = val; + k = key; + + return true; + }]); + + assertEquals(a, o); + assertEquals(a.length, l); + assertEquals("a", v); + assertEquals(0, k); + assertEquals(0, index); +})(); + + +// +// Test Array.prototype.findIndex works with exotic object +// +(function() { + var l = -1; + var o = -1; + var v = -1; + var k = -1; + var a = { + prop1: "val1", + prop2: "val2", + isValid: function() { + return this.prop1 === "val1" && this.prop2 === "val2"; + } + }; + + Array.prototype.push.apply(a, [30, 31, 32]); + + var index = Array.prototype.findIndex.call(a, function(val, key, obj) { + o = obj; + l = obj.length; + v = val; + k = key; + + return !obj.isValid(); + }); + + assertArrayEquals(a, o); + assertEquals(3, l); + assertEquals(32, v); + assertEquals(2, k); + assertEquals(-1, index); +})(); + + +// +// Test array modifications +// +(function() { + var a = [1, 2, 3]; + a.findIndex(function(val) { a.push(val); return false; }); + assertArrayEquals([1, 2, 3, 1, 2, 3], a); + assertEquals(6, a.length); + + a = [1, 2, 3]; + a.findIndex(function(val, key) { a[key] = ++val; return false; }); + assertArrayEquals([2, 3, 4], a); + assertEquals(3, a.length); +})(); + + +// +// Test predicate is only called for existing elements +// +(function() { + var a = new Array(30); + a[11] = 21; + a[7] = 10; + a[29] = 31; + + var count = 0; + a.findIndex(function() { count++; return false; }); + assertEquals(3, count); +})(); + + +// +// Test thisArg +// +(function() { + // Test String as a thisArg + var index = [1, 2, 3].findIndex(function(val, key) { + return this.charAt(Number(key)) === String(val); + }, "321"); + assertEquals(1, index); + + // Test object as a thisArg + var thisArg = { + elementAt: function(key) { + return this[key]; + } + }; + Array.prototype.push.apply(thisArg, ["c", "b", "a"]); + + index = ["a", "b", "c"].findIndex(function(val, key) { + return this.elementAt(key) === val; + }, thisArg); + assertEquals(1, index); +})(); + +// Test exceptions +assertThrows('Array.prototype.findIndex.call(null, function() { })', + TypeError); +assertThrows('Array.prototype.findIndex.call(undefined, function() { })', + TypeError); +assertThrows('Array.prototype.findIndex.apply(null, function() { }, [])', + TypeError); +assertThrows('Array.prototype.findIndex.apply(undefined, function() { }, [])', + TypeError); + +assertThrows('[].findIndex(null)', TypeError); +assertThrows('[].findIndex(undefined)', TypeError); +assertThrows('[].findIndex(0)', TypeError); +assertThrows('[].findIndex(true)', TypeError); +assertThrows('[].findIndex(false)', TypeError); +assertThrows('[].findIndex("")', TypeError); +assertThrows('[].findIndex({})', TypeError); +assertThrows('[].findIndex([])', TypeError); +assertThrows('[].findIndex(/\d+/)', TypeError); + +assertThrows('Array.prototype.findIndex.call({}, null)', TypeError); +assertThrows('Array.prototype.findIndex.call({}, undefined)', TypeError); +assertThrows('Array.prototype.findIndex.call({}, 0)', TypeError); +assertThrows('Array.prototype.findIndex.call({}, true)', TypeError); +assertThrows('Array.prototype.findIndex.call({}, false)', TypeError); +assertThrows('Array.prototype.findIndex.call({}, "")', TypeError); +assertThrows('Array.prototype.findIndex.call({}, {})', TypeError); +assertThrows('Array.prototype.findIndex.call({}, [])', TypeError); +assertThrows('Array.prototype.findIndex.call({}, /\d+/)', TypeError); + +assertThrows('Array.prototype.findIndex.apply({}, null, [])', TypeError); +assertThrows('Array.prototype.findIndex.apply({}, undefined, [])', TypeError); +assertThrows('Array.prototype.findIndex.apply({}, 0, [])', TypeError); +assertThrows('Array.prototype.findIndex.apply({}, true, [])', TypeError); +assertThrows('Array.prototype.findIndex.apply({}, false, [])', TypeError); +assertThrows('Array.prototype.findIndex.apply({}, "", [])', TypeError); +assertThrows('Array.prototype.findIndex.apply({}, {}, [])', TypeError); +assertThrows('Array.prototype.findIndex.apply({}, [], [])', TypeError); +assertThrows('Array.prototype.findIndex.apply({}, /\d+/, [])', TypeError);
\ No newline at end of file diff --git a/deps/v8/test/mjsunit/harmony/array-iterator.js b/deps/v8/test/mjsunit/harmony/array-iterator.js index f3a2627b5..6a402e739 100644 --- a/deps/v8/test/mjsunit/harmony/array-iterator.js +++ b/deps/v8/test/mjsunit/harmony/array-iterator.js @@ -39,7 +39,7 @@ function TestArrayPrototype() { TestArrayPrototype(); function assertIteratorResult(value, done, result) { - assertEquals({ value: value, done: done}, result); + assertEquals({value: value, done: done}, result); } function TestValues() { @@ -70,9 +70,9 @@ TestValuesMutate(); function TestKeys() { var array = ['a', 'b', 'c']; var iterator = array.keys(); - assertIteratorResult('0', false, iterator.next()); - assertIteratorResult('1', false, iterator.next()); - assertIteratorResult('2', false, iterator.next()); + assertIteratorResult(0, false, iterator.next()); + assertIteratorResult(1, false, iterator.next()); + assertIteratorResult(2, false, iterator.next()); assertIteratorResult(void 0, true, iterator.next()); array.push('d'); @@ -83,11 +83,11 @@ TestKeys(); function TestKeysMutate() { var array = ['a', 'b', 'c']; var iterator = array.keys(); - assertIteratorResult('0', false, iterator.next()); - assertIteratorResult('1', false, iterator.next()); - assertIteratorResult('2', false, iterator.next()); + assertIteratorResult(0, false, iterator.next()); + assertIteratorResult(1, false, iterator.next()); + assertIteratorResult(2, false, iterator.next()); array.push('d'); - assertIteratorResult('3', false, iterator.next()); + assertIteratorResult(3, false, iterator.next()); assertIteratorResult(void 0, true, iterator.next()); } TestKeysMutate(); @@ -95,9 +95,9 @@ TestKeysMutate(); function TestEntries() { var array = ['a', 'b', 'c']; var iterator = array.entries(); - assertIteratorResult(['0', 'a'], false, iterator.next()); - assertIteratorResult(['1', 'b'], false, iterator.next()); - assertIteratorResult(['2', 'c'], false, iterator.next()); + assertIteratorResult([0, 'a'], false, iterator.next()); + assertIteratorResult([1, 'b'], false, iterator.next()); + assertIteratorResult([2, 'c'], false, iterator.next()); assertIteratorResult(void 0, true, iterator.next()); array.push('d'); @@ -108,11 +108,11 @@ TestEntries(); function TestEntriesMutate() { var array = ['a', 'b', 'c']; var iterator = array.entries(); - assertIteratorResult(['0', 'a'], false, iterator.next()); - assertIteratorResult(['1', 'b'], false, iterator.next()); - assertIteratorResult(['2', 'c'], false, iterator.next()); + assertIteratorResult([0, 'a'], false, iterator.next()); + assertIteratorResult([1, 'b'], false, iterator.next()); + assertIteratorResult([2, 'c'], false, iterator.next()); array.push('d'); - assertIteratorResult(['3', 'd'], false, iterator.next()); + assertIteratorResult([3, 'd'], false, iterator.next()); assertIteratorResult(void 0, true, iterator.next()); } TestEntriesMutate(); @@ -168,7 +168,7 @@ function TestForArrayKeys() { assertEquals(8, buffer.length); for (var i = 0; i < buffer.length; i++) { - assertEquals(String(i), buffer[i]); + assertEquals(i, buffer[i]); } } TestForArrayKeys(); @@ -189,7 +189,7 @@ function TestForArrayEntries() { assertTrue(isNaN(buffer[buffer.length - 1][1])); for (var i = 0; i < buffer.length; i++) { - assertEquals(String(i), buffer[i][0]); + assertEquals(i, buffer[i][0]); } } TestForArrayEntries(); diff --git a/deps/v8/test/mjsunit/harmony/collections.js b/deps/v8/test/mjsunit/harmony/collections.js index 3e87e6b53..174d3d1dc 100644 --- a/deps/v8/test/mjsunit/harmony/collections.js +++ b/deps/v8/test/mjsunit/harmony/collections.js @@ -207,10 +207,10 @@ TestArbitrary(new WeakMap); // Test direct constructor call -assertTrue(Set() instanceof Set); -assertTrue(Map() instanceof Map); -assertTrue(WeakMap() instanceof WeakMap); -assertTrue(WeakSet() instanceof WeakSet); +assertThrows(function() { Set(); }, TypeError); +assertThrows(function() { Map(); }, TypeError); +assertThrows(function() { WeakMap(); }, TypeError); +assertThrows(function() { WeakSet(); }, TypeError); // Test whether NaN values as keys are treated correctly. @@ -308,7 +308,6 @@ TestPrototype(WeakSet); function TestConstructor(C) { assertFalse(C === Object.prototype.constructor); assertSame(C, C.prototype.constructor); - assertSame(C, C().__proto__.constructor); assertSame(C, (new C).__proto__.constructor); } TestConstructor(Set); diff --git a/deps/v8/test/mjsunit/harmony/object-observe.js b/deps/v8/test/mjsunit/harmony/object-observe.js index 103dda656..06254ee6d 100644 --- a/deps/v8/test/mjsunit/harmony/object-observe.js +++ b/deps/v8/test/mjsunit/harmony/object-observe.js @@ -259,6 +259,16 @@ records = undefined; Object.deliverChangeRecords(observer.callback); observer.assertRecordCount(1); +// Get notifier prior to observing +reset(); +var obj = {}; +Object.getNotifier(obj); +Object.observe(obj, observer.callback); +obj.id = 1; +Object.deliverChangeRecords(observer.callback); +observer.assertCallbackRecords([ + { object: obj, type: 'new', name: 'id' }, +]); // Observing a continuous stream of changes, while itermittantly unobserving. reset(); @@ -636,8 +646,8 @@ function recursiveObserver2(r) { Object.observe(obj1, recursiveObserver2); Object.observe(obj2, recursiveObserver2); ++obj1.a; -Object.deliverChangeRecords(recursiveObserver2); // TODO(verwaest): Disabled because of bug 2774. +// Object.deliverChangeRecords(recursiveObserver2); // assertEquals(199, recordCount); @@ -783,6 +793,8 @@ observer.assertNotCalled(); // Test all kinds of objects generically. function TestObserveConfigurable(obj, prop) { reset(); + Object.observe(obj, observer.callback); + Object.unobserve(obj, observer.callback); obj[prop] = 1; Object.observe(obj, observer.callback); obj[prop] = 2; @@ -852,6 +864,8 @@ function TestObserveConfigurable(obj, prop) { function TestObserveNonConfigurable(obj, prop, desc) { reset(); + Object.observe(obj, observer.callback); + Object.unobserve(obj, observer.callback); obj[prop] = 1; Object.observe(obj, observer.callback); obj[prop] = 4; diff --git a/deps/v8/test/mjsunit/harmony/proxies-example-membrane.js b/deps/v8/test/mjsunit/harmony/proxies-example-membrane.js index c6e7f9f9b..9e2228a63 100644 --- a/deps/v8/test/mjsunit/harmony/proxies-example-membrane.js +++ b/deps/v8/test/mjsunit/harmony/proxies-example-membrane.js @@ -285,8 +285,8 @@ assertEquals(4, wh4.q); // http://wiki.ecmascript.org/doku.php?id=harmony:proxies#an_identity-preserving_membrane function createMembrane(wetTarget) { - var wet2dry = WeakMap(); - var dry2wet = WeakMap(); + var wet2dry = new WeakMap(); + var dry2wet = new WeakMap(); function asDry(obj) { registerObject(obj) diff --git a/deps/v8/test/mjsunit/harmony/proxies-hash.js b/deps/v8/test/mjsunit/harmony/proxies-hash.js index abfc0f5f0..789de35f6 100644 --- a/deps/v8/test/mjsunit/harmony/proxies-hash.js +++ b/deps/v8/test/mjsunit/harmony/proxies-hash.js @@ -51,7 +51,7 @@ function TestSet2(construct, fix, create) { var p3 = create(handler) fix(p3) - var s = construct(); + var s = new construct(); s.add(p1); s.add(p2); assertTrue(s.has(p1)); @@ -88,7 +88,7 @@ function TestMap2(construct, fix, create) { var p3 = create(handler) fix(p3) - var m = construct(); + var m = new construct(); m.set(p1, 123); m.set(p2, 321); assertTrue(m.has(p1)); diff --git a/deps/v8/test/mjsunit/harmony/string-contains.js b/deps/v8/test/mjsunit/harmony/string-contains.js new file mode 100644 index 000000000..700a6ed6b --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/string-contains.js @@ -0,0 +1,151 @@ +// Copyright 2013 the V8 project authors. All rights reserved. +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following +// disclaimer in the documentation and/or other materials provided +// with the distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Flags: --harmony-strings + +assertEquals(1, String.prototype.contains.length); + +var reString = "asdf[a-z]+(asdf)?"; +assertTrue(reString.contains("[a-z]+")); +assertTrue(reString.contains("(asdf)?")); + +// Random greek letters +var twoByteString = "\u039a\u0391\u03a3\u03a3\u0395"; + +// Test single char pattern +assertTrue(twoByteString.contains("\u039a"), "Lamda"); +assertTrue(twoByteString.contains("\u0391"), "Alpha"); +assertTrue(twoByteString.contains("\u03a3"), "First Sigma"); +assertTrue(twoByteString.contains("\u03a3",3), "Second Sigma"); +assertTrue(twoByteString.contains("\u0395"), "Epsilon"); +assertFalse(twoByteString.contains("\u0392"), "Not beta"); + +// Test multi-char pattern +assertTrue(twoByteString.contains("\u039a\u0391"), "lambda Alpha"); +assertTrue(twoByteString.contains("\u0391\u03a3"), "Alpha Sigma"); +assertTrue(twoByteString.contains("\u03a3\u03a3"), "Sigma Sigma"); +assertTrue(twoByteString.contains("\u03a3\u0395"), "Sigma Epsilon"); + +assertFalse(twoByteString.contains("\u0391\u03a3\u0395"), + "Not Alpha Sigma Epsilon"); + +//single char pattern +assertTrue(twoByteString.contains("\u0395")); + +assertThrows("String.prototype.contains.call(null, 'test')", TypeError); +assertThrows("String.prototype.contains.call(null, null)", TypeError); +assertThrows("String.prototype.contains.call(undefined, undefined)", TypeError); + +assertThrows("String.prototype.contains.apply(null, ['test'])", TypeError); +assertThrows("String.prototype.contains.apply(null, [null])", TypeError); +assertThrows("String.prototype.contains.apply(undefined, [undefined])", TypeError); + +var TEST_INPUT = [{ + msg: "Empty string", val: "" +}, { + msg: "Number 1234.34", val: 1234.34 +}, { + msg: "Integer number 0", val: 0 +}, { + msg: "Negative number -1", val: -1 +}, { + msg: "Boolean true", val: true +}, { + msg: "Boolean false", val: false +}, { + msg: "Regular expression /\d+/", val: /\d+/ +}, { + msg: "Empty array []", val: [] +}, { + msg: "Empty object {}", val: {} +}, { + msg: "Array of size 3", val: new Array(3) +}]; + +var i = 0; +var l = TEST_INPUT.length; + +for (; i < l; i++) { + var e = TEST_INPUT[i]; + var v = e.val; + var s = String(v); + assertTrue(s.contains(v), e.msg); + assertTrue(String.prototype.contains.call(v, v), e.msg); + assertTrue(String.prototype.contains.apply(v, [v]), e.msg); +} + +// Test cases found in FF +assertTrue("abc".contains("a")); +assertTrue("abc".contains("b")); +assertTrue("abc".contains("abc")); +assertTrue("abc".contains("bc")); +assertFalse("abc".contains("d")); +assertFalse("abc".contains("abcd")); +assertFalse("abc".contains("ac")); +assertTrue("abc".contains("abc", 0)); +assertTrue("abc".contains("bc", 0)); +assertFalse("abc".contains("de", 0)); +assertTrue("abc".contains("bc", 1)); +assertTrue("abc".contains("c", 1)); +assertFalse("abc".contains("a", 1)); +assertFalse("abc".contains("abc", 1)); +assertTrue("abc".contains("c", 2)); +assertFalse("abc".contains("d", 2)); +assertFalse("abc".contains("dcd", 2)); +assertFalse("abc".contains("a", 42)); +assertFalse("abc".contains("a", Infinity)); +assertTrue("abc".contains("ab", -43)); +assertFalse("abc".contains("cd", -42)); +assertTrue("abc".contains("ab", -Infinity)); +assertFalse("abc".contains("cd", -Infinity)); +assertTrue("abc".contains("ab", NaN)); +assertFalse("abc".contains("cd", NaN)); +assertFalse("xyzzy".contains("zy\0", 2)); + +var dots = Array(10000).join('.'); +assertFalse(dots.contains("\x01", 10000)); +assertFalse(dots.contains("\0", 10000)); + +var myobj = { + toString: function () { + return "abc"; + }, + contains: String.prototype.contains +}; +assertTrue(myobj.contains("abc")); +assertFalse(myobj.contains("cd")); + +var gotStr = false; +var gotPos = false; +myobj = { + toString: function () { + assertFalse(gotPos); + gotStr = true; + return "xyz"; + }, + contains: String.prototype.contains +}; diff --git a/deps/v8/test/mjsunit/harmony/string-endswith.js b/deps/v8/test/mjsunit/harmony/string-endswith.js new file mode 100644 index 000000000..128cf1d02 --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/string-endswith.js @@ -0,0 +1,136 @@ +// Copyright 2013 the V8 project authors. All rights reserved. +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following +// disclaimer in the documentation and/or other materials provided +// with the distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Flags: --harmony-strings + +assertEquals(1, String.prototype.endsWith.length); + +var testString = "Hello World"; +assertTrue(testString.endsWith("")); +assertTrue(testString.endsWith("World")); +assertFalse(testString.endsWith("world")); +assertFalse(testString.endsWith("Hello World!")); +assertFalse(testString.endsWith(null)); +assertFalse(testString.endsWith(undefined)); + +assertTrue("null".endsWith(null)); +assertTrue("undefined".endsWith(undefined)); + +var georgianUnicodeString = "\u10D0\u10D1\u10D2\u10D3\u10D4\u10D5\u10D6\u10D7"; +assertTrue(georgianUnicodeString.endsWith(georgianUnicodeString)); +assertTrue(georgianUnicodeString.endsWith("\u10D4\u10D5\u10D6\u10D7")); +assertFalse(georgianUnicodeString.endsWith("\u10D0")); + +assertThrows("String.prototype.endsWith.call(null, 'test')", TypeError); +assertThrows("String.prototype.endsWith.call(null, null)", TypeError); +assertThrows("String.prototype.endsWith.call(undefined, undefined)", TypeError); + +assertThrows("String.prototype.endsWith.apply(null, ['test'])", TypeError); +assertThrows("String.prototype.endsWith.apply(null, [null])", TypeError); +assertThrows("String.prototype.endsWith.apply(undefined, [undefined])", TypeError); + +var TEST_INPUT = [{ + msg: "Empty string", val: "" +}, { + msg: "Number 1234.34", val: 1234.34 +}, { + msg: "Integer number 0", val: 0 +}, { + msg: "Negative number -1", val: -1 +}, { + msg: "Boolean true", val: true +}, { + msg: "Boolean false", val: false +}, { + msg: "Regular expression /\d+/", val: /\d+/ +}, { + msg: "Empty array []", val: [] +}, { + msg: "Empty object {}", val: {} +}, { + msg: "Array of size 3", val: new Array(3) +}]; + +function testNonStringValues() { + var i = 0; + var l = TEST_INPUT.length; + + for (; i < l; i++) { + var e = TEST_INPUT[i]; + var v = e.val; + var s = String(v); + assertTrue(s.endsWith(v), e.msg); + assertTrue(String.prototype.endsWith.call(v, v), e.msg); + assertTrue(String.prototype.endsWith.apply(v, [v]), e.msg); + } +} +testNonStringValues(); + +var CustomType = function(value) { + this.endsWith = String.prototype.endsWith; + this.toString = function() { + return String(value); + } +}; + +function testCutomType() { + var i = 0; + var l = TEST_INPUT.length; + + for (; i < l; i++) { + var e = TEST_INPUT[i]; + var v = e.val; + var o = new CustomType(v); + assertTrue(o.endsWith(v), e.msg); + } +} +testCutomType(); + + +// Test cases found in FF +assertTrue("abc".endsWith("abc")); +assertTrue("abcd".endsWith("bcd")); +assertTrue("abc".endsWith("c")); +assertFalse("abc".endsWith("abcd")); +assertFalse("abc".endsWith("bbc")); +assertFalse("abc".endsWith("b")); +assertTrue("abc".endsWith("abc", 3)); +assertTrue("abc".endsWith("bc", 3)); +assertFalse("abc".endsWith("a", 3)); +assertTrue("abc".endsWith("bc", 3)); +assertTrue("abc".endsWith("a", 1)); +assertFalse("abc".endsWith("abc", 1)); +assertTrue("abc".endsWith("b", 2)); +assertFalse("abc".endsWith("d", 2)); +assertFalse("abc".endsWith("dcd", 2)); +assertFalse("abc".endsWith("a", 42)); +assertTrue("abc".endsWith("bc", Infinity)); +assertFalse("abc".endsWith("a", Infinity)); +assertTrue("abc".endsWith("bc", undefined)); +assertFalse("abc".endsWith("bc", -43)); +assertFalse("abc".endsWith("bc", -Infinity)); +assertFalse("abc".endsWith("bc", NaN)); diff --git a/deps/v8/test/mjsunit/harmony/string-repeat.js b/deps/v8/test/mjsunit/harmony/string-repeat.js new file mode 100644 index 000000000..182e5c0e0 --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/string-repeat.js @@ -0,0 +1,74 @@ +// Copyright 2013 the V8 project authors. All rights reserved. +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following +// disclaimer in the documentation and/or other materials provided +// with the distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Flags: --harmony-strings + +assertEquals("000", String.prototype.repeat.call(0, 3)); +assertEquals("-1-1-1", String.prototype.repeat.call(-1, 3)); +assertEquals("2.12.12.1", String.prototype.repeat.call(2.1, 3)); +assertEquals("", String.prototype.repeat.call([], 3)); +assertEquals("1,2,3", String.prototype.repeat.call([1, 2, 3], 1)); +assertEquals("true", String.prototype.repeat.call(true, 1)); +assertEquals("false", String.prototype.repeat.call(false, 1)); +assertEquals("[object Object]", String.prototype.repeat.call({}, 1)); + +assertEquals("000", String.prototype.repeat.apply(0, [3])); +assertEquals("-1-1-1", String.prototype.repeat.apply(-1, [3])); +assertEquals("2.12.12.1", String.prototype.repeat.apply(2.1, [3])); +assertEquals("", String.prototype.repeat.apply([], [3])); +assertEquals("1,2,3", String.prototype.repeat.apply([1, 2, 3], [1])); +assertEquals("true", String.prototype.repeat.apply(true, [1])); +assertEquals("false", String.prototype.repeat.apply(false, [1])); +assertEquals("[object Object]", String.prototype.repeat.apply({}, [1])); + +assertEquals("\u10D8\u10D8\u10D8", "\u10D8".repeat(3)); + +assertThrows('String.prototype.repeat.call(null, 1)', TypeError); +assertThrows('String.prototype.repeat.call(undefined, 1)', TypeError); +assertThrows('String.prototype.repeat.apply(null, [1])', TypeError); +assertThrows('String.prototype.repeat.apply(undefined, [1])', TypeError); + +// Test cases found in FF +assertEquals("abc", "abc".repeat(1)); +assertEquals("abcabc", "abc".repeat(2)); +assertEquals("abcabcabc", "abc".repeat(3)); +assertEquals("aaaaaaaaaa", "a".repeat(10)); +assertEquals("", "".repeat(5)); +assertEquals("", "abc".repeat(0)); +assertEquals("abcabc", "abc".repeat(2.0)); + +assertThrows('"a".repeat(-1)', RangeError); +assertThrows('"a".repeat(Number.POSITIVE_INFINITY)', RangeError); + +var myobj = { + toString: function() { + return "abc"; + }, + repeat : String.prototype.repeat +}; +assertEquals("abc", myobj.repeat(1)); +assertEquals("abcabc", myobj.repeat(2));
\ No newline at end of file diff --git a/deps/v8/test/mjsunit/harmony/string-startswith.js b/deps/v8/test/mjsunit/harmony/string-startswith.js new file mode 100644 index 000000000..60c85d31b --- /dev/null +++ b/deps/v8/test/mjsunit/harmony/string-startswith.js @@ -0,0 +1,135 @@ +// Copyright 2013 the V8 project authors. All rights reserved. +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following +// disclaimer in the documentation and/or other materials provided +// with the distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Flags: --harmony-strings + +assertEquals(1, String.prototype.startsWith.length); + +var testString = "Hello World"; +assertTrue(testString.startsWith("")); +assertTrue(testString.startsWith("Hello")); +assertFalse(testString.startsWith("hello")); +assertFalse(testString.startsWith("Hello World!")); +assertFalse(testString.startsWith(null)); +assertFalse(testString.startsWith(undefined)); + +assertTrue("null".startsWith(null)); +assertTrue("undefined".startsWith(undefined)); + +var georgianUnicodeString = "\u10D0\u10D1\u10D2\u10D3\u10D4\u10D5\u10D6\u10D7"; +assertTrue(georgianUnicodeString.startsWith(georgianUnicodeString)); +assertTrue(georgianUnicodeString.startsWith("\u10D0\u10D1\u10D2")); +assertFalse(georgianUnicodeString.startsWith("\u10D8")); + +assertThrows("String.prototype.startsWith.call(null, 'test')", TypeError); +assertThrows("String.prototype.startsWith.call(null, null)", TypeError); +assertThrows("String.prototype.startsWith.call(undefined, undefined)", TypeError); + +assertThrows("String.prototype.startsWith.apply(null, ['test'])", TypeError); +assertThrows("String.prototype.startsWith.apply(null, [null])", TypeError); +assertThrows("String.prototype.startsWith.apply(undefined, [undefined])", TypeError); + +var TEST_INPUT = [{ + msg: "Empty string", val: "" +}, { + msg: "Number 1234.34", val: 1234.34 +}, { + msg: "Integer number 0", val: 0 +}, { + msg: "Negative number -1", val: -1 +}, { + msg: "Boolean true", val: true +}, { + msg: "Boolean false", val: false +}, { + msg: "Regular expression /\d+/", val: /\d+/ +}, { + msg: "Empty array []", val: [] +}, { + msg: "Empty object {}", val: {} +}, { + msg: "Array of size 3", val: new Array(3) +}]; + +function testNonStringValues() { + var i = 0; + var l = TEST_INPUT.length; + + for (; i < l; i++) { + var e = TEST_INPUT[i]; + var v = e.val; + var s = String(v); + assertTrue(s.startsWith(v), e.msg); + assertTrue(String.prototype.startsWith.call(v, v), e.msg); + assertTrue(String.prototype.startsWith.apply(v, [v]), e.msg); + } +} +testNonStringValues(); + +var CustomType = function(value) { + this.startsWith = String.prototype.startsWith; + this.toString = function() { + return String(value); + } +}; + +function testCutomType() { + var i = 0; + var l = TEST_INPUT.length; + + for (; i < l; i++) { + var e = TEST_INPUT[i]; + var v = e.val; + var o = new CustomType(v); + assertTrue(o.startsWith(v), e.msg); + } +} +testCutomType(); + +// Test cases found in FF +assertTrue("abc".startsWith("abc")); +assertTrue("abcd".startsWith("abc")); +assertTrue("abc".startsWith("a")); +assertFalse("abc".startsWith("abcd")); +assertFalse("abc".startsWith("bcde")); +assertFalse("abc".startsWith("b")); +assertTrue("abc".startsWith("abc", 0)); +assertFalse("abc".startsWith("bc", 0)); +assertTrue("abc".startsWith("bc", 1)); +assertFalse("abc".startsWith("c", 1)); +assertFalse("abc".startsWith("abc", 1)); +assertTrue("abc".startsWith("c", 2)); +assertFalse("abc".startsWith("d", 2)); +assertFalse("abc".startsWith("dcd", 2)); +assertFalse("abc".startsWith("a", 42)); +assertFalse("abc".startsWith("a", Infinity)); +assertTrue("abc".startsWith("a", NaN)); +assertFalse("abc".startsWith("b", NaN)); +assertTrue("abc".startsWith("ab", -43)); +assertTrue("abc".startsWith("ab", -Infinity)); +assertFalse("abc".startsWith("bc", -42)); +assertFalse("abc".startsWith("bc", -Infinity)); diff --git a/deps/v8/test/mjsunit/math-abs.js b/deps/v8/test/mjsunit/math-abs.js index 2b079546e..d6ee3f2da 100644 --- a/deps/v8/test/mjsunit/math-abs.js +++ b/deps/v8/test/mjsunit/math-abs.js @@ -109,3 +109,14 @@ for(var i = 0; i < 1000; i++) { assertEquals(42, foo(-42)); %OptimizeFunctionOnNextCall(foo) assertEquals(42, foo(-42)); + +// Regression test for SMI input of Math.abs on X64, see: +// https://codereview.chromium.org/21180004/ +var a = [-1, -2]; +function foo2() { + return Math.abs(a[0]); +} +assertEquals(1, foo2()); +assertEquals(1, foo2()); +%OptimizeFunctionOnNextCall(foo2); +assertEquals(1, foo2()); diff --git a/deps/v8/test/intl/general/v8Intl-exists.js b/deps/v8/test/mjsunit/regress/regress-264203.js index 610767e37..fa0075662 100644 --- a/deps/v8/test/intl/general/v8Intl-exists.js +++ b/deps/v8/test/mjsunit/regress/regress-264203.js @@ -25,12 +25,20 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// Make sure that v8Intl is mapped into Intl for backward compatibility. +// Flags: --allow-natives-syntax -assertEquals(v8Intl, Intl); +function foo(x) { + var a = [1, 2, 3, 4, 5, 6, 7, 8]; + a[x + 5]; + var result; + for (var i = 0; i < 3; i++) { + result = a[0 - x]; + } + return result; +} -// Extra checks. -assertTrue(v8Intl.hasOwnProperty('DateTimeFormat')); -assertTrue(v8Intl.hasOwnProperty('NumberFormat')); -assertTrue(v8Intl.hasOwnProperty('Collator')); -assertTrue(v8Intl.hasOwnProperty('v8BreakIterator')); +foo(0); +foo(0); +%OptimizeFunctionOnNextCall(foo); +var r = foo(-2); +assertEquals(3, r); diff --git a/deps/v8/test/mjsunit/regress/regress-2813.js b/deps/v8/test/mjsunit/regress/regress-2813.js new file mode 100644 index 000000000..97ae43b31 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-2813.js @@ -0,0 +1,44 @@ +// Copyright 2013 the V8 project authors. All rights reserved. +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following +// disclaimer in the documentation and/or other materials provided +// with the distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Flags: --allow-natives-syntax + +function foo(x) { + var a = x + 1; + var b = x + 2; + if (x != 0) { + if (x > 0 & x < 100) { + return a; + } + } + return 0; +} + +assertEquals(0, foo(0)); +assertEquals(0, foo(0)); +%OptimizeFunctionOnNextCall(foo); +assertEquals(3, foo(2)); diff --git a/deps/v8/test/mjsunit/regress/regress-omit-checks.js b/deps/v8/test/mjsunit/regress/regress-omit-checks.js new file mode 100644 index 000000000..e5d507498 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-omit-checks.js @@ -0,0 +1,55 @@ +// Copyright 2013 the V8 project authors. All rights reserved. +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following +// disclaimer in the documentation and/or other materials provided +// with the distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Flags: --allow-natives-syntax + +var a = {x:1}; +var a_deprecate = {x:1}; +a_deprecate.x = 1.5; +function create() { + return {__proto__:a, y:1}; +} +var b1 = create(); +var b2 = create(); +var b3 = create(); +var b4 = create(); + +function set(b) { + b.x = 5; + b.z = 10; +} + +set(b1); +set(b2); +%OptimizeFunctionOnNextCall(set); +set(b3); +var called = false; +a.x = 1.5; +Object.defineProperty(a, "z", {set:function(v) { called = true; }}); +set(b4); +assertTrue(called); +assertEquals(undefined, b4.z); diff --git a/deps/v8/test/mjsunit/unary-minus-deopt.js b/deps/v8/test/mjsunit/unary-minus-deopt.js new file mode 100644 index 000000000..367ef75c8 --- /dev/null +++ b/deps/v8/test/mjsunit/unary-minus-deopt.js @@ -0,0 +1,55 @@ +// Copyright 2013 the V8 project authors. All rights reserved. +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following +// disclaimer in the documentation and/or other materials provided +// with the distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Flags: --allow-natives-syntax + +// This is a boiled-down example happening in the Epic Citadel demo: +// After deopting, the multiplication for unary minus stayed in Smi +// mode instead of going to double mode, leading to deopt loops. + +function unaryMinusTest(x) { + var g = (1 << x) | 0; + // Optimized code will contain a LMulI with -1 as right operand. + return (g & -g) - 1 | 0; +} + +unaryMinusTest(3); +unaryMinusTest(3); +%OptimizeFunctionOnNextCall(unaryMinusTest); +unaryMinusTest(3); +assertOptimized(unaryMinusTest); + +// Deopt on kMinInt +unaryMinusTest(31); +// The following is normally true, but not with --stress-opt. :-/ +// assertUnoptimized(unaryMinusTest); + +// We should have learned something from the deopt. +unaryMinusTest(31); +%OptimizeFunctionOnNextCall(unaryMinusTest); +unaryMinusTest(31); +assertOptimized(unaryMinusTest); diff --git a/deps/v8/test/webkit/webkit.status b/deps/v8/test/webkit/webkit.status index 4aaf8a97f..a437e9374 100644 --- a/deps/v8/test/webkit/webkit.status +++ b/deps/v8/test/webkit/webkit.status @@ -33,3 +33,6 @@ sort-large-array: PASS, SKIP if $mode == debug ############################################################################## [ $deopt_fuzzer == True ] + +# Issue 2815. +fast/js/kde/encode_decode_uri: SKIP |