Reviewers: Mads Ager,

Description:
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.

Please review this at http://codereview.chromium.org/171039

Affected files:
   M src/execution.cc
   M src/runtime.cc
   M test/mozilla/mozilla.status


Index: src/execution.cc
diff --git a/src/execution.cc b/src/execution.cc
index  
4ab6b6173120c63379f7313e2521a47236536731..9080f5eaaa41b55b08e01fae4bbcc35a020a6d53
  
100644
--- a/src/execution.cc
+++ b/src/execution.cc
@@ -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));
    }
Index: src/runtime.cc
diff --git a/src/runtime.cc b/src/runtime.cc
index  
5518d15529ecfebf64358752696cdf7bc10c4330..36fdd6500000f63ab2b028f2553a1ada59103767
  
100644
--- a/src/runtime.cc
+++ b/src/runtime.cc
@@ -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
Index: test/mozilla/mozilla.status
diff --git a/test/mozilla/mozilla.status b/test/mozilla/mozilla.status
index  
e2de2ef6487ec14fb9829f89a2ed7c3e9cb3e77a..a1551dcdd486e3001c476aa425aa22f13ea7488a
  
100644
--- a/test/mozilla/mozilla.status
+++ b/test/mozilla/mozilla.status
@@ -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




--~--~---------~--~----~------------~-------~--~----~
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
-~----------~----~----~----~------~----~------~--~---

Reply via email to