RegExp tweaks

Fixed bug where regexps were not callable across contexts since the
callable test used object identity on the regexp constructor.  Changed
typeof RegExp from 'object' to 'function' for compatibility.

Review URL: http://codereview.chromium.org/171039


git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@2696 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
christian.plesner.hansen@gmail.com 2009-08-17 10:19:00 +00:00
parent 910b5ef31a
commit 04a6340227
3 changed files with 7 additions and 7 deletions

View File

@ -174,12 +174,7 @@ Handle<Object> Execution::GetFunctionDelegate(Handle<Object> object) {
// 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) {
if (object->IsJSRegExp()) {
Handle<String> exec = Factory::exec_symbol();
return Handle<Object>(object->GetProperty(*exec));
}

View File

@ -3099,7 +3099,7 @@ static Object* Runtime_Typeof(Arguments args) {
}
ASSERT(heap_obj->IsUndefined());
return Heap::undefined_symbol();
case JS_FUNCTION_TYPE:
case JS_FUNCTION_TYPE: case JS_REGEXP_TYPE:
return Heap::function_symbol();
default:
// For any kind of object not handled above, the spec rule for

View File

@ -278,6 +278,11 @@ js1_2/regexp/beginLine: FAIL_OK
js1_2/regexp/endLine: FAIL_OK
# To be compatible with safari typeof a regexp yields 'function';
# in firefox it yields 'object'.
js1_2/function/regexparg-1: FAIL_OK
# Date trouble?
js1_5/Date/regress-301738-02: FAIL_OK