Commit 538197da authored by yangguo's avatar yangguo Committed by Commit bot

RegExp.prototype is an ordinary object.

R=littledan@chromium.org
BUG=v8:4003
LOG=N

Review URL: https://codereview.chromium.org/1423993006

Cr-Commit-Position: refs/heads/master@{#31730}
parent c03d7a7f
......@@ -1083,7 +1083,6 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
Isolate* isolate = global_object->GetIsolate();
Factory* factory = isolate->factory();
Heap* heap = isolate->heap();
Handle<ScriptContextTable> script_context_table =
factory->NewScriptContextTable();
......@@ -1272,27 +1271,6 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
initial_map->set_unused_property_fields(0);
initial_map->set_instance_size(initial_map->instance_size() +
num_fields * kPointerSize);
// RegExp prototype object is itself a RegExp.
Handle<Map> proto_map = Map::Copy(initial_map, "RegExpPrototype");
DCHECK(proto_map->prototype() == *isolate->initial_object_prototype());
Handle<JSObject> proto = factory->NewJSObjectFromMap(proto_map);
proto->InObjectPropertyAtPut(JSRegExp::kSourceFieldIndex,
heap->query_colon_string());
proto->InObjectPropertyAtPut(JSRegExp::kGlobalFieldIndex,
heap->false_value());
proto->InObjectPropertyAtPut(JSRegExp::kIgnoreCaseFieldIndex,
heap->false_value());
proto->InObjectPropertyAtPut(JSRegExp::kMultilineFieldIndex,
heap->false_value());
proto->InObjectPropertyAtPut(JSRegExp::kLastIndexFieldIndex,
Smi::FromInt(0),
SKIP_WRITE_BARRIER); // It's a Smi.
proto_map->set_is_prototype_map(true);
Map::SetPrototype(initial_map, proto);
factory->SetRegExpIrregexpData(Handle<JSRegExp>::cast(proto),
JSRegExp::IRREGEXP, factory->empty_string(),
JSRegExp::Flags(0), 0);
}
// Initialize the embedder data slot.
......
......@@ -12,6 +12,7 @@
var FLAG_harmony_regexps;
var FLAG_harmony_tolength;
var FLAG_harmony_unicode_regexps;
var GlobalObject = global.Object;
var GlobalRegExp = global.RegExp;
var InternalPackedArray = utils.InternalPackedArray;
var MakeTypeError;
......@@ -336,6 +337,7 @@ function RegExpMakeCaptureGetter(n) {
// -------------------------------------------------------------------
%FunctionSetInstanceClassName(GlobalRegExp, 'RegExp');
%FunctionSetPrototype(GlobalRegExp, new GlobalObject());
%AddNamedProperty(
GlobalRegExp.prototype, 'constructor', GlobalRegExp, DONT_ENUM);
%SetCode(GlobalRegExp, RegExpConstructor);
......
// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// ES6 21.2.4.1
var proto_desc = Object.getOwnPropertyDescriptor(RegExp, "prototype");
assertFalse(proto_desc.writable);
assertFalse(proto_desc.enumerable);
assertFalse(proto_desc.configurable);
// ES6 21.2.5.1
var proto = proto_desc.value;
assertFalse(proto instanceof RegExp);
assertEquals(undefined, Object.getOwnPropertyDescriptor(proto, "valueOf"));
assertEquals(proto.valueOf, Object.prototype.valueOf);
var proto_constr = Object.getOwnPropertyDescriptor(proto, "constructor");
assertEquals(RegExp, proto_constr.value);
......@@ -136,9 +136,9 @@ test(function() {
// kIncompatibleMethodReceiver
test(function() {
RegExp.prototype.compile.call(RegExp.prototype);
}, "Method RegExp.prototype.compile called on incompatible receiver " +
"[object RegExp]", TypeError);
Set.prototype.add.call([]);
}, "Method Set.prototype.add called on incompatible receiver [object Array]",
TypeError);
// kInstanceofFunctionExpected
test(function() {
......
// 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.
// Check that RegExp.prototype is itself a RegExp object.
var proto = RegExp.prototype;
assertEquals("[object RegExp]", Object.prototype.toString.call(proto));
assertEquals("(?:)", proto.source);
assertEquals(false, proto.global);
assertEquals(false, proto.multiline);
assertEquals(false, proto.ignoreCase);
assertEquals(0, proto.lastIndex);
assertEquals("/(?:)/", proto.toString());
var execResult = proto.exec("argle");
assertEquals(1, execResult.length);
assertEquals("", execResult[0]);
assertEquals("argle", execResult.input);
assertEquals(0, execResult.index);
assertTrue(proto.test("argle"));
// We disallow re-compiling the RegExp.prototype object.
assertThrows(function(){ proto.compile("something"); }, TypeError);
......@@ -17,7 +17,6 @@ testEscapes("\\/\\/", new RegExp("\\/\\/"));
testEscapes("\\/\\/\\/\\/", new RegExp("////"));
testEscapes("\\/\\/\\/\\/", new RegExp("\\//\\//"));
testEscapes("(?:)", new RegExp(""));
testEscapes("(?:)", RegExp.prototype);
// Read-only property.
var r = /\/\//;
......
......@@ -155,8 +155,6 @@
'built-ins/RegExp/prototype/ignoreCase/15.10.7.3-1': [FAIL],
'built-ins/RegExp/prototype/ignoreCase/15.10.7.3-2': [FAIL],
'built-ins/RegExp/prototype/ignoreCase/S15.10.7.3_A9': [FAIL],
'built-ins/RegExp/prototype/lastIndex/15.10.7.5-1': [FAIL],
'built-ins/RegExp/prototype/lastIndex/15.10.7.5-2': [FAIL],
'built-ins/RegExp/prototype/multiline/15.10.7.4-1': [FAIL],
'built-ins/RegExp/prototype/multiline/15.10.7.4-2': [FAIL],
'built-ins/RegExp/prototype/multiline/S15.10.7.4_A9': [FAIL],
......@@ -183,8 +181,15 @@
'built-ins/RegExp/from-regexp-like-get-ctor-err': [FAIL],
'built-ins/RegExp/call_with_regexp_not_same_constructor': [FAIL],
# https://code.google.com/p/v8/issues/detail?id=4003
'built-ins/RegExp/prototype/15.10.6': [FAIL],
# https://code.google.com/p/v8/issues/detail?id=4528
'built-ins/RegExp/prototype/source/S15.10.7.1_A8': [FAIL],
'built-ins/RegExp/prototype/source/S15.10.7.1_A10': [FAIL],
'built-ins/RegExp/prototype/global/S15.10.7.2_A8': [FAIL],
'built-ins/RegExp/prototype/global/S15.10.7.2_A10': [FAIL],
'built-ins/RegExp/prototype/ignoreCase/S15.10.7.3_A8': [FAIL],
'built-ins/RegExp/prototype/ignoreCase/S15.10.7.3_A10': [FAIL],
'built-ins/RegExp/prototype/multiline/S15.10.7.4_A8': [FAIL],
'built-ins/RegExp/prototype/multiline/S15.10.7.4_A10': [FAIL],
# https://code.google.com/p/v8/issues/detail?id=4006
'built-ins/String/prototype/S15.5.4_A1': [FAIL],
......
......@@ -113,8 +113,8 @@ PASS str.match(re).toString() is 'Chapter 3.4.5.1,Chapter 3.4.5.1,.1'
PASS str.match(/d/gi).toString() is 'D,d'
PASS /\u0061/.source is '\\u0061'
PASS 'abc'.match(/\u0062/).toString() is 'b'
PASS Object.prototype.toString.apply(RegExp.prototype) is '[object RegExp]'
PASS typeof RegExp.prototype.toString() is 'string'
FAIL Object.prototype.toString.apply(RegExp.prototype) should be [object RegExp]. Was [object Object].
FAIL typeof RegExp.prototype.toString() should be string. Threw exception TypeError: Method RegExp.prototype.toString called on incompatible receiver [object Object]
PASS new RegExp().toString() is '/(?:)/'
PASS (new RegExp('(?:)')).source is '(?:)'
PASS /(?:)/.toString() is '/(?:)/'
......
......@@ -28,10 +28,10 @@ On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE
PASS RegExp('/').source is "\\/"
PASS RegExp('').source is "(?:)"
PASS RegExp.prototype.source is "(?:)"
FAIL RegExp.prototype.source should be (?:) (of type string). Was undefined (of type undefined).
PASS RegExp('/').toString() is "/\\//"
PASS RegExp('').toString() is "/(?:)/"
PASS RegExp.prototype.toString() is "/(?:)/"
FAIL RegExp.prototype.toString() should be /(?:)/. Threw exception TypeError: Method RegExp.prototype.toString called on incompatible receiver [object Object]
PASS testForwardSlash("^/$", "/"); is true
PASS testForwardSlash("^/$", "/"); is true
PASS testForwardSlash("^\/$", "/"); is true
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment