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

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

Issue 1546493003: Revert of Add web compat workarounds for ES2015 RegExp semantics (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/runtime/runtime-internal.cc ('k') | test/mjsunit/es6/regexp-flags.js » ('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 10 matching lines...) Expand all
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 #include <cstdlib> 28 #include <cstdlib>
29 #include <sstream> 29 #include <sstream>
30 30
31 #include "include/v8.h"
32 #include "src/v8.h" 31 #include "src/v8.h"
33 32
34 #include "src/ast/ast.h" 33 #include "src/ast/ast.h"
35 #include "src/char-predicates-inl.h" 34 #include "src/char-predicates-inl.h"
36 #include "src/ostreams.h" 35 #include "src/ostreams.h"
37 #include "src/parsing/parser.h" 36 #include "src/parsing/parser.h"
38 #include "src/regexp/jsregexp.h" 37 #include "src/regexp/jsregexp.h"
39 #include "src/regexp/regexp-macro-assembler.h" 38 #include "src/regexp/regexp-macro-assembler.h"
40 #include "src/regexp/regexp-macro-assembler-irregexp.h" 39 #include "src/regexp/regexp-macro-assembler-irregexp.h"
41 #include "src/splay-tree-inl.h" 40 #include "src/splay-tree-inl.h"
(...skipping 1799 matching lines...) Expand 10 before | Expand all | Expand 10 after
1841 1840
1842 ZoneList<CharacterRange> first_only(4, &zone); 1841 ZoneList<CharacterRange> first_only(4, &zone);
1843 ZoneList<CharacterRange> second_only(4, &zone); 1842 ZoneList<CharacterRange> second_only(4, &zone);
1844 ZoneList<CharacterRange> both(4, &zone); 1843 ZoneList<CharacterRange> both(4, &zone);
1845 } 1844 }
1846 1845
1847 1846
1848 TEST(Graph) { 1847 TEST(Graph) {
1849 Execute("\\b\\w+\\b", false, true, true); 1848 Execute("\\b\\w+\\b", false, true, true);
1850 } 1849 }
1851
1852
1853 namespace {
1854
1855 int* global_use_counts = NULL;
1856
1857 void MockUseCounterCallback(v8::Isolate* isolate,
1858 v8::Isolate::UseCounterFeature feature) {
1859 ++global_use_counts[feature];
1860 }
1861 }
1862
1863
1864 // Test that ES2015 RegExp compatibility fixes are in place, that they
1865 // are not overly broad, and the appropriate UseCounters are incremented
1866 TEST(UseCountRegExp) {
1867 i::FLAG_harmony_regexps = true;
1868 v8::Isolate* isolate = CcTest::isolate();
1869 v8::HandleScope scope(isolate);
1870 LocalContext env;
1871 int use_counts[v8::Isolate::kUseCounterFeatureCount] = {};
1872 global_use_counts = use_counts;
1873 CcTest::isolate()->SetUseCounterCallback(MockUseCounterCallback);
1874
1875 // Compat fix: RegExp.prototype.sticky == undefined; UseCounter tracks it
1876 v8::Local<v8::Value> resultSticky = CompileRun("RegExp.prototype.sticky");
1877 CHECK_EQ(1, use_counts[v8::Isolate::kRegExpPrototypeStickyGetter]);
1878 CHECK_EQ(0, use_counts[v8::Isolate::kRegExpPrototypeToString]);
1879 CHECK(resultSticky->IsUndefined());
1880
1881 // re.sticky has approriate value and doesn't touch UseCounter
1882 v8::Local<v8::Value> resultReSticky = CompileRun("/a/.sticky");
1883 CHECK_EQ(1, use_counts[v8::Isolate::kRegExpPrototypeStickyGetter]);
1884 CHECK_EQ(0, use_counts[v8::Isolate::kRegExpPrototypeToString]);
1885 CHECK(resultReSticky->IsFalse());
1886
1887 // When the getter is caleld on another object, throw an exception
1888 // and don't increment the UseCounter
1889 v8::Local<v8::Value> resultStickyError = CompileRun(
1890 "var exception;"
1891 "try { "
1892 " Object.getOwnPropertyDescriptor(RegExp.prototype, 'sticky')"
1893 " .get.call(null);"
1894 "} catch (e) {"
1895 " exception = e;"
1896 "}"
1897 "exception");
1898 CHECK_EQ(1, use_counts[v8::Isolate::kRegExpPrototypeStickyGetter]);
1899 CHECK_EQ(0, use_counts[v8::Isolate::kRegExpPrototypeToString]);
1900 CHECK(resultStickyError->IsObject());
1901
1902 // RegExp.prototype.toString() returns '/(?:)/' as a compatibility fix;
1903 // a UseCounter is incremented to track it.
1904 v8::Local<v8::Value> resultToString =
1905 CompileRun("RegExp.prototype.toString().length");
1906 CHECK_EQ(1, use_counts[v8::Isolate::kRegExpPrototypeStickyGetter]);
1907 CHECK_EQ(1, use_counts[v8::Isolate::kRegExpPrototypeToString]);
1908 CHECK(resultToString->IsInt32());
1909 CHECK_EQ(6,
1910 resultToString->Int32Value(isolate->GetCurrentContext()).FromJust());
1911
1912 // .toString() works on normal RegExps
1913 v8::Local<v8::Value> resultReToString = CompileRun("/a/.toString().length");
1914 CHECK_EQ(1, use_counts[v8::Isolate::kRegExpPrototypeStickyGetter]);
1915 CHECK_EQ(1, use_counts[v8::Isolate::kRegExpPrototypeToString]);
1916 CHECK(resultReToString->IsInt32());
1917 CHECK_EQ(
1918 3, resultReToString->Int32Value(isolate->GetCurrentContext()).FromJust());
1919
1920 // .toString() throws on non-RegExps that aren't RegExp.prototype
1921 v8::Local<v8::Value> resultToStringError = CompileRun(
1922 "var exception;"
1923 "try { RegExp.prototype.toString.call(null) }"
1924 "catch (e) { exception = e; }"
1925 "exception");
1926 CHECK_EQ(1, use_counts[v8::Isolate::kRegExpPrototypeStickyGetter]);
1927 CHECK_EQ(1, use_counts[v8::Isolate::kRegExpPrototypeToString]);
1928 CHECK(resultToStringError->IsObject());
1929 }
OLDNEW
« no previous file with comments | « src/runtime/runtime-internal.cc ('k') | test/mjsunit/es6/regexp-flags.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698