Commit 80b1b2a4 authored by littledan's avatar littledan Committed by Commit bot

Put RegExp js code in strict mode

src/js/regexp.js was one of the few files that was left in sloppy
mode. The ES2017 draft specification requires that writes to
lastIndex throw when the property is non-writable, and test262
tests enforce this behavior. This patch puts that file in strict
mode.

BUG=v8:4504
R=yangguo@chromium.org
LOG=Y

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

Cr-Commit-Position: refs/heads/master@{#34801}
parent 4348c3a3
......@@ -4,6 +4,8 @@
(function(global, utils) {
'use strict';
%CheckIsBootstrapping();
// -------------------------------------------------------------------
......
// Copyright 2016 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.
// lastIndex is set according to funny rules. It is typically set only
// for global or sticky RegExps, but on a failure to find a match, it is
// set unconditionally. If a set fails, then it acts as if in strict mode
// and throws.
var re = /x/;
Object.defineProperty(re, 'lastIndex', {writable: false});
assertThrows(() => re.exec(""), TypeError);
assertEquals(["x"], re.exec("x"));
var re = /x/y;
Object.defineProperty(re, 'lastIndex', {writable: false});
assertThrows(() => re.exec(""), TypeError);
assertThrows(() => re.exec("x"), TypeError);
......@@ -110,10 +110,6 @@
'built-ins/RegExp/prototype/exec/get-sticky-err': [FAIL],
'built-ins/RegExp/prototype/test/get-sticky-err': [FAIL],
# https://code.google.com/p/v8/issues/detail?id=4504
'built-ins/RegExp/prototype/exec/y-fail-lastindex-no-write': [PASS, FAIL],
'built-ins/RegExp/prototype/test/y-fail-lastindex-no-write': [PASS, FAIL],
# https://code.google.com/p/v8/issues/detail?id=4305
# SKIP rather than FAIL some tests, as they may check for an exception which
# happens to be thrown for some other reason (e.g,
......
......@@ -42,10 +42,10 @@ PASS var re = Object.defineProperty(/x/, 'lastIndex', {value:42}); re.lastIndex
PASS Object.defineProperty(Object.defineProperty(/x/, 'lastIndex', {writable:false}), 'lastIndex', {writable:true}); true threw exception TypeError: Cannot redefine property: lastIndex.
PASS Object.defineProperty(Object.defineProperty(/x/, 'lastIndex', {writable:false}), 'lastIndex', {value:42}); true threw exception TypeError: Cannot redefine property: lastIndex.
PASS Object.defineProperty(Object.defineProperty(/x/, 'lastIndex', {writable:false}), 'lastIndex', {value:0}); true is true
PASS Object.defineProperty(/x/, 'lastIndex', {writable:false}).exec('') is null
FAIL Object.defineProperty(/x/, 'lastIndex', {writable:false}).exec('') should be null. Threw exception TypeError: Cannot assign to read only property 'lastIndex' of object '[object RegExp]'
PASS Object.defineProperty(/x/, 'lastIndex', {writable:false}).exec('x') is ["x"]
FAIL Object.defineProperty(/x/g, 'lastIndex', {writable:false}).exec('') should throw an exception. Was null.
FAIL Object.defineProperty(/x/g, 'lastIndex', {writable:false}).exec('x') should throw an exception. Was x.
PASS Object.defineProperty(/x/g, 'lastIndex', {writable:false}).exec('') threw exception TypeError: Cannot assign to read only property 'lastIndex' of object '[object RegExp]'.
PASS Object.defineProperty(/x/g, 'lastIndex', {writable:false}).exec('x') threw exception TypeError: Cannot assign to read only property 'lastIndex' of object '[object RegExp]'.
PASS var re = /x/; Object.freeze(re); Object.isFrozen(re); is true
PASS successfullyParsed 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