mirror of https://github.com/lukechilds/node.git
Ryan Dahl
14 years ago
74 changed files with 2626 additions and 2021 deletions
@ -0,0 +1,200 @@ |
|||||
|
# Copyright 2011 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. |
||||
|
|
||||
|
# Definitions to be used when building stand-alone V8 binaries. |
||||
|
|
||||
|
{ |
||||
|
'variables': { |
||||
|
'library%': 'static_library', |
||||
|
'component%': 'static_library', |
||||
|
'visibility%': 'hidden', |
||||
|
'msvs_multi_core_compile%': '1', |
||||
|
'variables': { |
||||
|
'variables': { |
||||
|
'conditions': [ |
||||
|
[ 'OS=="linux" or OS=="freebsd" or OS=="openbsd"', { |
||||
|
# This handles the Linux platforms we generally deal with. Anything |
||||
|
# else gets passed through, which probably won't work very well; such |
||||
|
# hosts should pass an explicit target_arch to gyp. |
||||
|
'host_arch%': |
||||
|
'<!(uname -m | sed -e "s/i.86/ia32/;s/x86_64/x64/;s/amd64/x64/;s/arm.*/arm/")', |
||||
|
}, { # OS!="linux" and OS!="freebsd" and OS!="openbsd" |
||||
|
'host_arch%': 'ia32', |
||||
|
}], |
||||
|
], |
||||
|
}, |
||||
|
'host_arch%': '<(host_arch)', |
||||
|
'target_arch%': '<(host_arch)', |
||||
|
'v8_target_arch%': '<(target_arch)', |
||||
|
}, |
||||
|
'host_arch%': '<(host_arch)', |
||||
|
'target_arch%': '<(target_arch)', |
||||
|
'v8_target_arch%': '<(v8_target_arch)', |
||||
|
'conditions': [ |
||||
|
['(v8_target_arch=="arm" and host_arch!="arm") or \ |
||||
|
(v8_target_arch=="x64" and host_arch!="x64")', { |
||||
|
'want_separate_host_toolset': 1, |
||||
|
}, { |
||||
|
'want_separate_host_toolset': 0, |
||||
|
}], |
||||
|
], |
||||
|
}, |
||||
|
'target_defaults': { |
||||
|
'default_configuration': 'Debug', |
||||
|
'configurations': { |
||||
|
'Debug': { |
||||
|
'cflags': [ '-g', '-O0' ], |
||||
|
}, |
||||
|
}, |
||||
|
}, |
||||
|
'conditions': [ |
||||
|
[ 'OS=="linux" or OS=="freebsd" or OS=="openbsd" or OS=="solaris"', { |
||||
|
'target_defaults': { |
||||
|
'cflags': [ '-Wall', '-Werror', '-W', '-Wno-unused-parameter', |
||||
|
'-Wnon-virtual-dtor', '-pthread', '-fno-rtti', |
||||
|
'-fno-exceptions', '-pedantic' ], |
||||
|
'ldflags': [ '-pthread', ], |
||||
|
'conditions': [ |
||||
|
[ 'target_arch=="ia32"', { |
||||
|
'cflags': [ '-m32' ], |
||||
|
'ldflags': [ '-m32' ], |
||||
|
}], |
||||
|
[ 'OS=="linux"', { |
||||
|
'cflags': [ '-ansi' ], |
||||
|
}], |
||||
|
[ 'visibility=="hidden"', { |
||||
|
'cflags': [ '-fvisibility=hidden' ], |
||||
|
}], |
||||
|
[ 'component=="shared_library"', { |
||||
|
'cflags': [ '-fPIC', ], |
||||
|
}], |
||||
|
], |
||||
|
}, |
||||
|
}], # 'OS=="linux" or OS=="freebsd" or OS=="openbsd" or OS=="solaris"' |
||||
|
['OS=="win"', { |
||||
|
'target_defaults': { |
||||
|
'defines': [ |
||||
|
'WIN32', |
||||
|
'_CRT_SECURE_NO_DEPRECATE', |
||||
|
'_CRT_NONSTDC_NO_DEPRECATE', |
||||
|
], |
||||
|
'conditions': [ |
||||
|
['component=="static_library"', { |
||||
|
'defines': [ |
||||
|
'_HAS_EXCEPTIONS=0', |
||||
|
], |
||||
|
}], |
||||
|
], |
||||
|
'msvs_cygwin_dirs': ['<(DEPTH)/third_party/cygwin'], |
||||
|
'msvs_disabled_warnings': [4355, 4800], |
||||
|
'msvs_settings': { |
||||
|
'VCCLCompilerTool': { |
||||
|
'MinimalRebuild': 'false', |
||||
|
'BufferSecurityCheck': 'true', |
||||
|
'EnableFunctionLevelLinking': 'true', |
||||
|
'RuntimeTypeInfo': 'false', |
||||
|
'WarningLevel': '3', |
||||
|
'WarnAsError': 'true', |
||||
|
'DebugInformationFormat': '3', |
||||
|
'Detect64BitPortabilityProblems': 'false', |
||||
|
'conditions': [ |
||||
|
[ 'msvs_multi_core_compile', { |
||||
|
'AdditionalOptions': ['/MP'], |
||||
|
}], |
||||
|
['component=="shared_library"', { |
||||
|
'ExceptionHandling': '1', # /EHsc |
||||
|
}, { |
||||
|
'ExceptionHandling': '0', |
||||
|
}], |
||||
|
], |
||||
|
}, |
||||
|
'VCLibrarianTool': { |
||||
|
'AdditionalOptions': ['/ignore:4221'], |
||||
|
}, |
||||
|
'VCLinkerTool': { |
||||
|
'AdditionalDependencies': [ |
||||
|
'ws2_32.lib', |
||||
|
], |
||||
|
'GenerateDebugInformation': 'true', |
||||
|
'MapFileName': '$(OutDir)\\$(TargetName).map', |
||||
|
'ImportLibrary': '$(OutDir)\\lib\\$(TargetName).lib', |
||||
|
'FixedBaseAddress': '1', |
||||
|
# LinkIncremental values: |
||||
|
# 0 == default |
||||
|
# 1 == /INCREMENTAL:NO |
||||
|
# 2 == /INCREMENTAL |
||||
|
'LinkIncremental': '1', |
||||
|
# SubSystem values: |
||||
|
# 0 == not set |
||||
|
# 1 == /SUBSYSTEM:CONSOLE |
||||
|
# 2 == /SUBSYSTEM:WINDOWS |
||||
|
'SubSystem': '1', |
||||
|
}, |
||||
|
}, |
||||
|
}, |
||||
|
}], # OS=="win" |
||||
|
['OS=="mac"', { |
||||
|
'target_defaults': { |
||||
|
'xcode_settings': { |
||||
|
'ALWAYS_SEARCH_USER_PATHS': 'NO', |
||||
|
'GCC_C_LANGUAGE_STANDARD': 'ansi', # -ansi |
||||
|
'GCC_CW_ASM_SYNTAX': 'NO', # No -fasm-blocks |
||||
|
'GCC_DYNAMIC_NO_PIC': 'NO', # No -mdynamic-no-pic |
||||
|
# (Equivalent to -fPIC) |
||||
|
'GCC_ENABLE_CPP_EXCEPTIONS': 'NO', # -fno-exceptions |
||||
|
'GCC_ENABLE_CPP_RTTI': 'NO', # -fno-rtti |
||||
|
'GCC_ENABLE_PASCAL_STRINGS': 'NO', # No -mpascal-strings |
||||
|
# GCC_INLINES_ARE_PRIVATE_EXTERN maps to -fvisibility-inlines-hidden |
||||
|
'GCC_INLINES_ARE_PRIVATE_EXTERN': 'YES', |
||||
|
'GCC_SYMBOLS_PRIVATE_EXTERN': 'YES', # -fvisibility=hidden |
||||
|
'GCC_THREADSAFE_STATICS': 'NO', # -fno-threadsafe-statics |
||||
|
'GCC_TREAT_WARNINGS_AS_ERRORS': 'YES', # -Werror |
||||
|
'GCC_VERSION': '4.2', |
||||
|
'GCC_WARN_ABOUT_MISSING_NEWLINE': 'YES', # -Wnewline-eof |
||||
|
'MACOSX_DEPLOYMENT_TARGET': '10.4', # -mmacosx-version-min=10.4 |
||||
|
'PREBINDING': 'NO', # No -Wl,-prebind |
||||
|
'USE_HEADERMAP': 'NO', |
||||
|
'OTHER_CFLAGS': [ |
||||
|
'-fno-strict-aliasing', |
||||
|
], |
||||
|
'WARNING_CFLAGS': [ |
||||
|
'-Wall', |
||||
|
'-Wendif-labels', |
||||
|
'-W', |
||||
|
'-Wno-unused-parameter', |
||||
|
'-Wnon-virtual-dtor', |
||||
|
], |
||||
|
}, |
||||
|
'target_conditions': [ |
||||
|
['_type!="static_library"', { |
||||
|
'xcode_settings': {'OTHER_LDFLAGS': ['-Wl,-search_paths_first']}, |
||||
|
}], |
||||
|
], # target_conditions |
||||
|
}, # target_defaults |
||||
|
}], # OS=="mac" |
||||
|
], |
||||
|
} |
@ -1,132 +0,0 @@ |
|||||
# Copyright 2011 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. |
|
||||
|
|
||||
# TODO(sgjesse): This is currently copied from v8.gyp, should probably |
|
||||
# be refactored. |
|
||||
{ |
|
||||
'variables': { |
|
||||
'use_system_v8%': 0, |
|
||||
'msvs_use_common_release': 0, |
|
||||
'gcc_version%': 'unknown', |
|
||||
'v8_compress_startup_data%': 'off', |
|
||||
'v8_target_arch%': '<(target_arch)', |
|
||||
|
|
||||
# Setting 'v8_can_use_unaligned_accesses' to 'true' will allow the code |
|
||||
# generated by V8 to do unaligned memory access, and setting it to 'false' |
|
||||
# will ensure that the generated code will always do aligned memory |
|
||||
# accesses. The default value of 'default' will try to determine the correct |
|
||||
# setting. Note that for Intel architectures (ia32 and x64) unaligned memory |
|
||||
# access is allowed for all CPUs. |
|
||||
'v8_can_use_unaligned_accesses%': 'default', |
|
||||
|
|
||||
# Setting 'v8_can_use_vfp_instructions' to 'true' will enable use of ARM VFP |
|
||||
# instructions in the V8 generated code. VFP instructions will be enabled |
|
||||
# both for the snapshot and for the ARM target. Leaving the default value |
|
||||
# of 'false' will avoid VFP instructions in the snapshot and use CPU feature |
|
||||
# probing when running on the target. |
|
||||
'v8_can_use_vfp_instructions%': 'false', |
|
||||
|
|
||||
# Setting v8_use_arm_eabi_hardfloat to true will turn on V8 support for ARM |
|
||||
# EABI calling convention where double arguments are passed in VFP |
|
||||
# registers. Note that the GCC flag '-mfloat-abi=hard' should be used as |
|
||||
# well when compiling for the ARM target. |
|
||||
'v8_use_arm_eabi_hardfloat%': 'false', |
|
||||
|
|
||||
'v8_use_snapshot%': 'true', |
|
||||
'host_os%': '<(OS)', |
|
||||
'v8_use_liveobjectlist%': 'false', |
|
||||
}, |
|
||||
'target_defaults': { |
|
||||
'conditions': [ |
|
||||
['OS!="mac"', { |
|
||||
'conditions': [ |
|
||||
['v8_target_arch=="arm"', { |
|
||||
'defines': [ |
|
||||
'V8_TARGET_ARCH_ARM', |
|
||||
], |
|
||||
'conditions': [ |
|
||||
[ 'v8_can_use_unaligned_accesses=="true"', { |
|
||||
'defines': [ |
|
||||
'CAN_USE_UNALIGNED_ACCESSES=1', |
|
||||
], |
|
||||
}], |
|
||||
[ 'v8_can_use_unaligned_accesses=="false"', { |
|
||||
'defines': [ |
|
||||
'CAN_USE_UNALIGNED_ACCESSES=0', |
|
||||
], |
|
||||
}], |
|
||||
[ 'v8_can_use_vfp_instructions=="true"', { |
|
||||
'defines': [ |
|
||||
'CAN_USE_VFP_INSTRUCTIONS', |
|
||||
], |
|
||||
}], |
|
||||
[ 'v8_use_arm_eabi_hardfloat=="true"', { |
|
||||
'defines': [ |
|
||||
'USE_EABI_HARDFLOAT=1', |
|
||||
'CAN_USE_VFP_INSTRUCTIONS', |
|
||||
], |
|
||||
'cflags': [ |
|
||||
'-mfloat-abi=hard', |
|
||||
], |
|
||||
}, { |
|
||||
'defines': [ |
|
||||
'USE_EABI_HARDFLOAT=0', |
|
||||
], |
|
||||
}], |
|
||||
], |
|
||||
}], |
|
||||
['v8_target_arch=="ia32"', { |
|
||||
'defines': [ |
|
||||
'V8_TARGET_ARCH_IA32', |
|
||||
], |
|
||||
}], |
|
||||
['v8_target_arch=="mips"', { |
|
||||
'defines': [ |
|
||||
'V8_TARGET_ARCH_MIPS', |
|
||||
], |
|
||||
}], |
|
||||
['v8_target_arch=="x64"', { |
|
||||
'defines': [ |
|
||||
'V8_TARGET_ARCH_X64', |
|
||||
], |
|
||||
}], |
|
||||
], |
|
||||
}], |
|
||||
], |
|
||||
'configurations': { |
|
||||
'Debug': { |
|
||||
'defines': [ |
|
||||
'DEBUG', |
|
||||
'_DEBUG', |
|
||||
'ENABLE_DISASSEMBLER', |
|
||||
'V8_ENABLE_CHECKS', |
|
||||
'OBJECT_PRINT', |
|
||||
], |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
} |
|
@ -0,0 +1,81 @@ |
|||||
|
// Copyright 2009 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: --string-slices
|
||||
|
|
||||
|
//assertEquals('345"12345 6"1234567"123',
|
||||
|
// '12345""12345 6""1234567""1234'.slice(2,-1).replace(/""/g, '"'));
|
||||
|
|
||||
|
var foo = "lsdfj sldkfj sdklfj læsdfjl sdkfjlsdk fjsdl fjsdljskdj flsj flsdkj flskd regexp: /foobar/\nldkfj sdlkfj sdkl"; |
||||
|
for(var i = 0; i < 1000; i++) { |
||||
|
assertTrue(/^([a-z]+): (.*)/.test(foo.substring(foo.indexOf("regexp:")))); |
||||
|
assertEquals("regexp", RegExp.$1, "RegExp.$1"); |
||||
|
} |
||||
|
|
||||
|
var re = /^(((N({)?)|(R)|(U)|(V)|(B)|(H)|(n((n)|(r)|(v)|(h))?)|(r(r)?)|(v)|(b((n)|(b))?)|(h))|((Y)|(A)|(E)|(o(u)?)|(p(u)?)|(q(u)?)|(s)|(t)|(u)|(w)|(x(u)?)|(y)|(z)|(a((T)|(A)|(L))?)|(c)|(e)|(f(u)?)|(g(u)?)|(i)|(j)|(l)|(m(u)?)))+/; |
||||
|
var r = new RegExp(re) |
||||
|
var str = "_Avtnennan gunzvmu pubExnY nEvln vaTxh rmuhguhaTxnY_".slice(1,-1); |
||||
|
str = str + str; |
||||
|
assertTrue(r.test(str)); |
||||
|
assertTrue(r.test(str)); |
||||
|
var re = /x/; |
||||
|
assertEquals("a.yb", "_axyb_".slice(1,-1).replace(re, ".")); |
||||
|
re.compile("y"); |
||||
|
assertEquals("ax.b", "_axyb_".slice(1,-1).replace(re, ".")); |
||||
|
re.compile("(x)"); |
||||
|
assertEquals(["x", "x"], re.exec("_axyb_".slice(1,-1))); |
||||
|
re.compile("(y)"); |
||||
|
assertEquals(["y", "y"], re.exec("_axyb_".slice(1,-1))); |
||||
|
|
||||
|
for(var i = 0; i < 100; i++) { |
||||
|
var a = "aaaaaaaaaaaaaaaaaaaaaaaabbaacabbabaaaaabbaaaabbac".slice(24,-1); |
||||
|
var b = "bbaacabbabaaaaabbaaaabba" + a; |
||||
|
// The first time, the cons string will be flattened and handled by the
|
||||
|
// runtime system.
|
||||
|
assertEquals(["bbaa", "a", "", "a"], /((\3|b)\2(a)){2,}/.exec(b)); |
||||
|
// The second time, the cons string is already flattened and will be
|
||||
|
// handled by generated code.
|
||||
|
assertEquals(["bbaa", "a", "", "a"], /((\3|b)\2(a)){2,}/.exec(b)); |
||||
|
assertEquals(["bbaa", "a", "", "a"], /((\3|b)\2(a)){2,}/.exec(a)); |
||||
|
assertEquals(["bbaa", "a", "", "a"], /((\3|b)\2(a)){2,}/.exec(a)); |
||||
|
} |
||||
|
|
||||
|
var c = "ABCDEFGHIJKLMN".slice(2,-2); |
||||
|
var d = "ABCDEF\u1234GHIJKLMN".slice(2,-2); |
||||
|
var e = "ABCDEFGHIJKLMN".slice(0,-2); |
||||
|
assertTrue(/^C.*L$/.test(c)); |
||||
|
assertTrue(/^C.*L$/.test(c)); |
||||
|
assertTrue(/^C.*L$/.test(d)); |
||||
|
assertTrue(/^C.*L$/.test(d)); |
||||
|
assertTrue(/^A\w{10}L$/.test(e)); |
||||
|
assertTrue(/^A\w{10}L$/.test(e)); |
||||
|
|
||||
|
var e = "qui-opIasd-fghjklzx-cvbn-mqwer-tyuio-pasdf-ghIjkl-zx".slice(6,-6); |
||||
|
var e_split = e.split("-"); |
||||
|
assertEquals(e_split[0], "Iasd"); |
||||
|
assertEquals(e_split[1], "fghjklzx"); |
||||
|
assertEquals(e_split[6], "ghI"); |
@ -0,0 +1,198 @@ |
|||||
|
// Copyright 2008 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: --string-slices --expose-externalize-string
|
||||
|
|
||||
|
var s = 'abcdefghijklmn'; |
||||
|
assertEquals(s, s.substr()); |
||||
|
assertEquals(s, s.substr(0)); |
||||
|
assertEquals(s, s.substr('0')); |
||||
|
assertEquals(s, s.substr(void 0)); |
||||
|
assertEquals(s, s.substr(null)); |
||||
|
assertEquals(s, s.substr(false)); |
||||
|
assertEquals(s, s.substr(0.9)); |
||||
|
assertEquals(s, s.substr({ valueOf: function() { return 0; } })); |
||||
|
assertEquals(s, s.substr({ toString: function() { return '0'; } })); |
||||
|
|
||||
|
var s1 = s.substring(1); |
||||
|
assertEquals(s1, s.substr(1)); |
||||
|
assertEquals(s1, s.substr('1')); |
||||
|
assertEquals(s1, s.substr(true)); |
||||
|
assertEquals(s1, s.substr(1.1)); |
||||
|
assertEquals(s1, s.substr({ valueOf: function() { return 1; } })); |
||||
|
assertEquals(s1, s.substr({ toString: function() { return '1'; } })); |
||||
|
|
||||
|
|
||||
|
assertEquals(s.substring(s.length - 1), s.substr(-1)); |
||||
|
assertEquals(s.substring(s.length - 1), s.substr(-1.2)); |
||||
|
assertEquals(s.substring(s.length - 1), s.substr(-1.7)); |
||||
|
assertEquals(s.substring(s.length - 2), s.substr(-2)); |
||||
|
assertEquals(s.substring(s.length - 2), s.substr(-2.3)); |
||||
|
assertEquals(s.substring(s.length - 2, s.length - 1), s.substr(-2, 1)); |
||||
|
assertEquals(s, s.substr(-100)); |
||||
|
assertEquals('abc', s.substr(-100, 3)); |
||||
|
assertEquals(s1, s.substr(-s.length + 1)); |
||||
|
|
||||
|
// assertEquals('', s.substr(0, void 0)); // smjs and rhino
|
||||
|
assertEquals('abcdefghijklmn', s.substr(0, void 0)); // kjs and v8
|
||||
|
assertEquals('', s.substr(0, null)); |
||||
|
assertEquals(s, s.substr(0, String(s.length))); |
||||
|
assertEquals('a', s.substr(0, true)); |
||||
|
|
||||
|
|
||||
|
// Test substrings of different lengths and alignments.
|
||||
|
// First ASCII.
|
||||
|
var x = "ASCII"; |
||||
|
for (var i = 0; i < 25; i++) { |
||||
|
x += (i >> 4).toString(16) + (i & 0x0f).toString(16); |
||||
|
} |
||||
|
/x/.exec(x); // Try to force a flatten.
|
||||
|
for (var i = 5; i < 25; i++) { |
||||
|
for (var j = 12; j < 25; j++) { |
||||
|
var z = x.substring(i, i+j); |
||||
|
var w = Math.random() * 42; // Allocate something new in new-space.
|
||||
|
assertEquals(j, z.length); |
||||
|
for (var k = 0; k < j; k++) { |
||||
|
assertEquals(x.charAt(i+k), z.charAt(k)); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
// Then two-byte strings.
|
||||
|
x = "UC16\u2028"; // Non-ascii char forces two-byte string.
|
||||
|
for (var i = 0; i < 25; i++) { |
||||
|
x += (i >> 4).toString(16) + (i & 0x0f).toString(16); |
||||
|
} |
||||
|
/x/.exec(x); // Try to force a flatten.
|
||||
|
for (var i = 5; i < 25; i++) { |
||||
|
for (var j = 0; j < 25; j++) { |
||||
|
var z = x.substring(i, i + j); |
||||
|
var w = Math.random() * 42; // Allocate something new in new-space.
|
||||
|
assertEquals(j, z.length); |
||||
|
for (var k = 0; k < j; k++) { |
||||
|
assertEquals(x.charAt(i+k), z.charAt(k)); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// Keep creating strings to to force allocation failure on substring creation.
|
||||
|
var x = "0123456789ABCDEF"; |
||||
|
x += x; // 2^5
|
||||
|
x += x; |
||||
|
x += x; |
||||
|
x += x; |
||||
|
x += x; |
||||
|
x += x; // 2^10
|
||||
|
x += x; |
||||
|
x += x; |
||||
|
var xl = x.length; |
||||
|
var cache = []; |
||||
|
for (var i = 0; i < 10000; i++) { |
||||
|
var z = x.substring(i % xl); |
||||
|
assertEquals(xl - (i % xl), z.length); |
||||
|
cache.push(z); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
// Same with two-byte strings
|
||||
|
var x = "\u2028123456789ABCDEF"; |
||||
|
x += x; // 2^5
|
||||
|
x += x; |
||||
|
x += x; |
||||
|
x += x; |
||||
|
x += x; |
||||
|
x += x; // 2^10
|
||||
|
x += x; |
||||
|
x += x; |
||||
|
var xl = x.length; |
||||
|
var cache = []; |
||||
|
for (var i = 0; i < 10000; i++) { |
||||
|
var z = x.substring(i % xl); |
||||
|
assertEquals(xl - (i % xl), z.length); |
||||
|
cache.push(z); |
||||
|
} |
||||
|
|
||||
|
// Substring of substring.
|
||||
|
var cache = []; |
||||
|
var last = x; |
||||
|
var offset = 0; |
||||
|
for (var i = 0; i < 64; i++) { |
||||
|
var z = last.substring(i); |
||||
|
last = z; |
||||
|
cache.push(z); |
||||
|
offset += i; |
||||
|
} |
||||
|
for (var i = 63; i >= 0; i--) { |
||||
|
var z = cache.pop(); |
||||
|
assertTrue(/\u2028123456789ABCDEF/.test(z)); |
||||
|
assertEquals(xl - offset, z.length); |
||||
|
offset -= i; |
||||
|
} |
||||
|
|
||||
|
// Test charAt for different strings.
|
||||
|
function f(s1, s2, s3, i) { |
||||
|
assertEquals(String.fromCharCode(97+i%11), s1.charAt(i%11)); |
||||
|
assertEquals(String.fromCharCode(97+i%11), s2.charAt(i%11)); |
||||
|
assertEquals(String.fromCharCode(98+i%11), s3.charAt(i%11)); |
||||
|
assertEquals(String.fromCharCode(101), s3.charAt(3)); |
||||
|
} |
||||
|
|
||||
|
flat = "abcdefghijkl12345"; |
||||
|
cons = flat + flat.toUpperCase(); |
||||
|
slice = "abcdefghijklmn12345".slice(1, -1); |
||||
|
for ( var i = 0; i < 1000; i++) { |
||||
|
f(flat, cons, slice, i); |
||||
|
} |
||||
|
flat = "abcdefghijkl1\u20232345"; |
||||
|
cons = flat + flat.toUpperCase(); |
||||
|
slice = "abcdefghijklmn1\u20232345".slice(1, -1); |
||||
|
for ( var i = 0; i < 1000; i++) { |
||||
|
f(flat, cons, slice, i); |
||||
|
} |
||||
|
|
||||
|
// Concatenate substrings.
|
||||
|
var ascii = 'abcdefghijklmnop'; |
||||
|
var utf = '\u03B1\u03B2\u03B3\u03B4\u03B5\u03B6\u03B7\u03B8\u03B9\u03BA\u03BB'; |
||||
|
assertEquals("klmno", ascii.substring(10,15) + ascii.substring(16)); |
||||
|
assertEquals("\u03B4\u03B7", utf.substring(3,4) + utf.substring(6,7)); |
||||
|
assertEquals("klp", ascii.substring(10,12) + ascii.substring(15,16)); |
||||
|
assertEquals("\u03B1\u03B4\u03B5", utf.substring(0,1) + utf.substring(5,3)); |
||||
|
assertEquals("", ascii.substring(16) + utf.substring(16)); |
||||
|
assertEquals("bcdef\u03B4\u03B5\u03B6\u03B7\u03B8\u03B9", |
||||
|
ascii.substring(1,6) + utf.substring(3,9)); |
||||
|
assertEquals("\u03B4\u03B5\u03B6\u03B7\u03B8\u03B9abcdefghijklmnop", |
||||
|
utf.substring(3,9) + ascii); |
||||
|
assertEquals("\u03B2\u03B3\u03B4\u03B5\u03B4\u03B5\u03B6\u03B7", |
||||
|
utf.substring(5,1) + utf.substring(3,7)); |
||||
|
|
||||
|
/* |
||||
|
// Externalizing strings.
|
||||
|
var a = "123456789qwertyuiopasdfghjklzxcvbnm"; |
||||
|
var b = a.slice(1,-1); |
||||
|
assertEquals(a.slice(1,-1), b); |
||||
|
externalizeString(a); |
||||
|
assertEquals(a.slice(1,-1), b); |
||||
|
*/ |
Loading…
Reference in new issue