@@ -1803,178 +1803,6 @@ TF_BUILTIN(StringSubstring, StringBuiltinsAssembler) {
18031803 Return (SubString (string, from, to));
18041804}
18051805
1806- // ES6 #sec-string.prototype.trim
1807- TF_BUILTIN (StringPrototypeTrim, StringTrimAssembler) {
1808- TNode<IntPtrT> argc = ChangeInt32ToIntPtr (
1809- UncheckedParameter<Int32T>(Descriptor::kJSActualArgumentsCount ));
1810- auto context = Parameter<Context>(Descriptor::kContext );
1811-
1812- Generate (String::kTrim , " String.prototype.trim" , argc, context);
1813- }
1814-
1815- // https://github.com/tc39/proposal-string-left-right-trim
1816- TF_BUILTIN (StringPrototypeTrimStart, StringTrimAssembler) {
1817- TNode<IntPtrT> argc = ChangeInt32ToIntPtr (
1818- UncheckedParameter<Int32T>(Descriptor::kJSActualArgumentsCount ));
1819- auto context = Parameter<Context>(Descriptor::kContext );
1820-
1821- Generate (String::kTrimStart , " String.prototype.trimLeft" , argc, context);
1822- }
1823-
1824- // https://github.com/tc39/proposal-string-left-right-trim
1825- TF_BUILTIN (StringPrototypeTrimEnd, StringTrimAssembler) {
1826- TNode<IntPtrT> argc = ChangeInt32ToIntPtr (
1827- UncheckedParameter<Int32T>(Descriptor::kJSActualArgumentsCount ));
1828- auto context = Parameter<Context>(Descriptor::kContext );
1829-
1830- Generate (String::kTrimEnd , " String.prototype.trimRight" , argc, context);
1831- }
1832-
1833- void StringTrimAssembler::Generate (String::TrimMode mode,
1834- const char * method_name, TNode<IntPtrT> argc,
1835- TNode<Context> context) {
1836- Label return_emptystring (this ), if_runtime (this );
1837-
1838- CodeStubArguments arguments (this , argc);
1839- TNode<Object> receiver = arguments.GetReceiver ();
1840-
1841- // Check that {receiver} is coercible to Object and convert it to a String.
1842- const TNode<String> string = ToThisString (context, receiver, method_name);
1843- const TNode<IntPtrT> string_length = LoadStringLengthAsWord (string);
1844-
1845- ToDirectStringAssembler to_direct (state (), string);
1846- to_direct.TryToDirect (&if_runtime);
1847- const TNode<RawPtrT> string_data = to_direct.PointerToData (&if_runtime);
1848- const TNode<Int32T> instance_type = to_direct.instance_type ();
1849- const TNode<BoolT> is_stringonebyte =
1850- IsOneByteStringInstanceType (instance_type);
1851- const TNode<IntPtrT> string_data_offset = to_direct.offset ();
1852-
1853- TVARIABLE (IntPtrT, var_start, IntPtrConstant (0 ));
1854- TVARIABLE (IntPtrT, var_end, IntPtrSub (string_length, IntPtrConstant (1 )));
1855-
1856- if (mode == String::kTrimStart || mode == String::kTrim ) {
1857- ScanForNonWhiteSpaceOrLineTerminator (string_data, string_data_offset,
1858- is_stringonebyte, &var_start,
1859- string_length, 1 , &return_emptystring);
1860- }
1861- if (mode == String::kTrimEnd || mode == String::kTrim ) {
1862- ScanForNonWhiteSpaceOrLineTerminator (
1863- string_data, string_data_offset, is_stringonebyte, &var_end,
1864- IntPtrConstant (-1 ), -1 , &return_emptystring);
1865- }
1866-
1867- arguments.PopAndReturn (
1868- SubString (string, var_start.value (),
1869- IntPtrAdd (var_end.value (), IntPtrConstant (1 ))));
1870-
1871- BIND (&if_runtime);
1872- arguments.PopAndReturn (
1873- CallRuntime (Runtime::kStringTrim , context, string, SmiConstant (mode)));
1874-
1875- BIND (&return_emptystring);
1876- arguments.PopAndReturn (EmptyStringConstant ());
1877- }
1878-
1879- void StringTrimAssembler::ScanForNonWhiteSpaceOrLineTerminator (
1880- const TNode<RawPtrT> string_data, const TNode<IntPtrT> string_data_offset,
1881- const TNode<BoolT> is_stringonebyte, TVariable<IntPtrT>* const var_index,
1882- const TNode<IntPtrT> end, int increment, Label* const if_none_found) {
1883- Label if_stringisonebyte (this ), out (this );
1884-
1885- GotoIf (is_stringonebyte, &if_stringisonebyte);
1886-
1887- // Two Byte String
1888- BuildLoop<Uint16T>(
1889- var_index, end, increment, if_none_found, &out,
1890- [&](const TNode<IntPtrT> index) {
1891- return Load<Uint16T>(
1892- string_data,
1893- WordShl (IntPtrAdd (index, string_data_offset), IntPtrConstant (1 )));
1894- });
1895-
1896- BIND (&if_stringisonebyte);
1897- BuildLoop<Uint8T>(var_index, end, increment, if_none_found, &out,
1898- [&](const TNode<IntPtrT> index) {
1899- return Load<Uint8T>(string_data,
1900- IntPtrAdd (index, string_data_offset));
1901- });
1902-
1903- BIND (&out);
1904- }
1905-
1906- template <typename T>
1907- void StringTrimAssembler::BuildLoop (
1908- TVariable<IntPtrT>* const var_index, const TNode<IntPtrT> end,
1909- int increment, Label* const if_none_found, Label* const out,
1910- const std::function<TNode<T>(const TNode<IntPtrT>)>& get_character) {
1911- Label loop (this , var_index);
1912- Goto (&loop);
1913- BIND (&loop);
1914- {
1915- TNode<IntPtrT> index = var_index->value ();
1916- GotoIf (IntPtrEqual (index, end), if_none_found);
1917- GotoIfNotWhiteSpaceOrLineTerminator (
1918- UncheckedCast<Uint32T>(get_character (index)), out);
1919- Increment (var_index, increment);
1920- Goto (&loop);
1921- }
1922- }
1923-
1924- void StringTrimAssembler::GotoIfNotWhiteSpaceOrLineTerminator (
1925- const TNode<Word32T> char_code, Label* const if_not_whitespace) {
1926- Label out (this );
1927-
1928- // 0x0020 - SPACE (Intentionally out of order to fast path a commmon case)
1929- GotoIf (Word32Equal (char_code, Int32Constant (0x0020 )), &out);
1930-
1931- // 0x0009 - HORIZONTAL TAB
1932- GotoIf (Uint32LessThan (char_code, Int32Constant (0x0009 )), if_not_whitespace);
1933- // 0x000A - LINE FEED OR NEW LINE
1934- // 0x000B - VERTICAL TAB
1935- // 0x000C - FORMFEED
1936- // 0x000D - HORIZONTAL TAB
1937- GotoIf (Uint32LessThanOrEqual (char_code, Int32Constant (0x000D )), &out);
1938-
1939- // Common Non-whitespace characters
1940- GotoIf (Uint32LessThan (char_code, Int32Constant (0x00A0 )), if_not_whitespace);
1941-
1942- // 0x00A0 - NO-BREAK SPACE
1943- GotoIf (Word32Equal (char_code, Int32Constant (0x00A0 )), &out);
1944-
1945- // 0x1680 - Ogham Space Mark
1946- GotoIf (Word32Equal (char_code, Int32Constant (0x1680 )), &out);
1947-
1948- // 0x2000 - EN QUAD
1949- GotoIf (Uint32LessThan (char_code, Int32Constant (0x2000 )), if_not_whitespace);
1950- // 0x2001 - EM QUAD
1951- // 0x2002 - EN SPACE
1952- // 0x2003 - EM SPACE
1953- // 0x2004 - THREE-PER-EM SPACE
1954- // 0x2005 - FOUR-PER-EM SPACE
1955- // 0x2006 - SIX-PER-EM SPACE
1956- // 0x2007 - FIGURE SPACE
1957- // 0x2008 - PUNCTUATION SPACE
1958- // 0x2009 - THIN SPACE
1959- // 0x200A - HAIR SPACE
1960- GotoIf (Uint32LessThanOrEqual (char_code, Int32Constant (0x200A )), &out);
1961-
1962- // 0x2028 - LINE SEPARATOR
1963- GotoIf (Word32Equal (char_code, Int32Constant (0x2028 )), &out);
1964- // 0x2029 - PARAGRAPH SEPARATOR
1965- GotoIf (Word32Equal (char_code, Int32Constant (0x2029 )), &out);
1966- // 0x202F - NARROW NO-BREAK SPACE
1967- GotoIf (Word32Equal (char_code, Int32Constant (0x202F )), &out);
1968- // 0x205F - MEDIUM MATHEMATICAL SPACE
1969- GotoIf (Word32Equal (char_code, Int32Constant (0x205F )), &out);
1970- // 0xFEFF - BYTE ORDER MARK
1971- GotoIf (Word32Equal (char_code, Int32Constant (0xFEFF )), &out);
1972- // 0x3000 - IDEOGRAPHIC SPACE
1973- Branch (Word32Equal (char_code, Int32Constant (0x3000 )), &out,
1974- if_not_whitespace);
1975-
1976- BIND (&out);
1977- }
19781806
19791807// Return the |word32| codepoint at {index}. Supports SeqStrings and
19801808// ExternalStrings.
0 commit comments