Firefox and Safari both allow calling regular expression objects as
functions (as an alias for calling the exec method). For compatibility make call_regexp the default and remove the flag. Review URL: http://codereview.chromium.org/155453 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@2451 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
parent
44be312091
commit
7a80be473d
@ -1121,8 +1121,6 @@ Object* LoadStubCompiler::CompileLoadGlobal(JSObject* object,
|
||||
}
|
||||
|
||||
|
||||
// TODO(1224671): IC stubs for keyed loads have not been implemented
|
||||
// for ARM.
|
||||
Object* KeyedLoadStubCompiler::CompileLoadField(String* name,
|
||||
JSObject* receiver,
|
||||
JSObject* holder,
|
||||
|
@ -164,19 +164,16 @@ Handle<Object> Execution::GetFunctionDelegate(Handle<Object> object) {
|
||||
// If you return a function from here, it will be called when an
|
||||
// attempt is made to call the given object as a function.
|
||||
|
||||
// The regular expression code here is really meant more as an
|
||||
// example than anything else. KJS does not support calling regular
|
||||
// expressions as functions, but SpiderMonkey does.
|
||||
if (FLAG_call_regexp) {
|
||||
bool is_regexp =
|
||||
object->IsHeapObject() &&
|
||||
(HeapObject::cast(*object)->map()->constructor() ==
|
||||
*Top::regexp_function());
|
||||
// Regular expressions can be called as functions in both Firefox
|
||||
// and Safari so we allow it too.
|
||||
bool is_regexp =
|
||||
object->IsHeapObject() &&
|
||||
(HeapObject::cast(*object)->map()->constructor() ==
|
||||
*Top::regexp_function());
|
||||
|
||||
if (is_regexp) {
|
||||
Handle<String> exec = Factory::exec_symbol();
|
||||
return Handle<Object>(object->GetProperty(*exec));
|
||||
}
|
||||
if (is_regexp) {
|
||||
Handle<String> exec = Factory::exec_symbol();
|
||||
return Handle<Object>(object->GetProperty(*exec));
|
||||
}
|
||||
|
||||
// Objects created through the API can have an instance-call handler
|
||||
|
@ -144,9 +144,6 @@ DEFINE_bool(debugger_auto_break, false,
|
||||
"automatically set the debug break flag when debugger commands are "
|
||||
"in the queue (experimental)")
|
||||
|
||||
// execution.cc
|
||||
DEFINE_bool(call_regexp, false, "allow calls to RegExp objects")
|
||||
|
||||
// frames.cc
|
||||
DEFINE_int(max_stack_trace_source_length, 300,
|
||||
"maximum length of function source code printed in a stack trace.")
|
||||
|
36
test/mjsunit/regexp-call-as-function.js
Normal file
36
test/mjsunit/regexp-call-as-function.js
Normal file
@ -0,0 +1,36 @@
|
||||
// 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.
|
||||
|
||||
// Test that regular expressions can be called as functions. Calling
|
||||
// a regular expression as a function corresponds to calling it's exec
|
||||
// method.
|
||||
|
||||
var regexp = /a(b)(c)/;
|
||||
var subject = "xyzabcde";
|
||||
var expected = 'abc,b,c';
|
||||
assertEquals(expected, String(regexp.exec(subject)));
|
||||
assertEquals(expected, String(regexp(subject)));
|
Loading…
Reference in New Issue
Block a user