Change strict mode poison pill to be the samme type error function (fixes issue 1387).

We are now following the spec, and with regards to the error message we are following firefox (webkit still has different type errors in their nightly)
Review URL: http://codereview.chromium.org/7067017

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@8026 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
ricow@chromium.org 2011-05-24 11:07:06 +00:00
parent 59a7ce37a6
commit ab67432ed0
5 changed files with 72 additions and 66 deletions

View File

@ -171,7 +171,7 @@ class Genesis BASE_EMBEDDED {
// Creates the empty function. Used for creating a context from scratch.
Handle<JSFunction> CreateEmptyFunction(Isolate* isolate);
// Creates the ThrowTypeError function. ECMA 5th Ed. 13.2.3
Handle<JSFunction> CreateThrowTypeErrorFunction(Builtins::Name builtin);
Handle<JSFunction> GetThrowTypeErrorFunction();
void CreateStrictModeFunctionMaps(Handle<JSFunction> empty);
// Creates the global objects using the global and the template passed in
@ -265,6 +265,7 @@ class Genesis BASE_EMBEDDED {
// These are the final, writable prototype, maps.
Handle<Map> function_instance_map_writable_prototype_;
Handle<Map> strict_mode_function_instance_map_writable_prototype_;
Handle<JSFunction> throw_type_error_function;
BootstrapperActive active_;
friend class Bootstrapper;
@ -549,22 +550,22 @@ Handle<DescriptorArray> Genesis::ComputeStrictFunctionInstanceDescriptor(
// ECMAScript 5th Edition, 13.2.3
Handle<JSFunction> Genesis::CreateThrowTypeErrorFunction(
Builtins::Name builtin) {
Handle<JSFunction> Genesis::GetThrowTypeErrorFunction() {
if (throw_type_error_function.is_null()) {
Handle<String> name = factory()->LookupAsciiSymbol("ThrowTypeError");
Handle<JSFunction> throw_type_error =
factory()->NewFunctionWithoutPrototype(name, kStrictMode);
Handle<Code> code = Handle<Code>(
isolate()->builtins()->builtin(builtin));
throw_type_error_function =
factory()->NewFunctionWithoutPrototype(name, kNonStrictMode);
Handle<Code> code(isolate()->builtins()->builtin(
Builtins::kStrictModePoisonPill));
throw_type_error_function->set_map(
global_context()->function_map());
throw_type_error_function->set_code(*code);
throw_type_error_function->shared()->set_code(*code);
throw_type_error_function->shared()->DontAdaptArguments();
throw_type_error->set_map(global_context()->strict_mode_function_map());
throw_type_error->set_code(*code);
throw_type_error->shared()->set_code(*code);
throw_type_error->shared()->DontAdaptArguments();
PreventExtensions(throw_type_error);
return throw_type_error;
PreventExtensions(throw_type_error_function);
}
return throw_type_error_function;
}
@ -621,17 +622,15 @@ void Genesis::CreateStrictModeFunctionMaps(Handle<JSFunction> empty) {
CreateStrictModeFunctionMap(
ADD_WRITEABLE_PROTOTYPE, empty, arguments, caller);
// Create the ThrowTypeError function instances.
Handle<JSFunction> arguments_throw =
CreateThrowTypeErrorFunction(Builtins::kStrictFunctionArguments);
Handle<JSFunction> caller_throw =
CreateThrowTypeErrorFunction(Builtins::kStrictFunctionCaller);
// Create the ThrowTypeError function instance.
Handle<JSFunction> throw_function =
GetThrowTypeErrorFunction();
// Complete the callback fixed arrays.
arguments->set(0, *arguments_throw);
arguments->set(1, *arguments_throw);
caller->set(0, *caller_throw);
caller->set(1, *caller_throw);
arguments->set(0, *throw_function);
arguments->set(1, *throw_function);
caller->set(0, *throw_function);
caller->set(1, *throw_function);
}
@ -1061,16 +1060,14 @@ void Genesis::InitializeGlobal(Handle<GlobalObject> inner_global,
Handle<FixedArray> callee = factory->NewFixedArray(2, TENURED);
Handle<FixedArray> caller = factory->NewFixedArray(2, TENURED);
Handle<JSFunction> callee_throw =
CreateThrowTypeErrorFunction(Builtins::kStrictArgumentsCallee);
Handle<JSFunction> caller_throw =
CreateThrowTypeErrorFunction(Builtins::kStrictArgumentsCaller);
Handle<JSFunction> throw_function =
GetThrowTypeErrorFunction();
// Install the ThrowTypeError functions.
callee->set(0, *callee_throw);
callee->set(1, *callee_throw);
caller->set(0, *caller_throw);
caller->set(1, *caller_throw);
callee->set(0, *throw_function);
callee->set(1, *throw_function);
caller->set(0, *throw_function);
caller->set(1, *throw_function);
// Create the descriptor array for the arguments object.
Handle<DescriptorArray> descriptors = factory->NewDescriptorArray(3);

View File

@ -983,34 +983,12 @@ BUILTIN(ArrayConcat) {
// Strict mode poison pills
BUILTIN(StrictArgumentsCallee) {
BUILTIN(StrictModePoisonPill) {
HandleScope scope;
return isolate->Throw(*isolate->factory()->NewTypeError(
"strict_arguments_callee", HandleVector<Object>(NULL, 0)));
"strict_poison_pill", HandleVector<Object>(NULL, 0)));
}
BUILTIN(StrictArgumentsCaller) {
HandleScope scope;
return isolate->Throw(*isolate->factory()->NewTypeError(
"strict_arguments_caller", HandleVector<Object>(NULL, 0)));
}
BUILTIN(StrictFunctionCaller) {
HandleScope scope;
return isolate->Throw(*isolate->factory()->NewTypeError(
"strict_function_caller", HandleVector<Object>(NULL, 0)));
}
BUILTIN(StrictFunctionArguments) {
HandleScope scope;
return isolate->Throw(*isolate->factory()->NewTypeError(
"strict_function_arguments", HandleVector<Object>(NULL, 0)));
}
// -----------------------------------------------------------------------------
//

View File

@ -60,11 +60,7 @@ enum BuiltinExtraArguments {
V(HandleApiCallAsFunction, NO_EXTRA_ARGUMENTS) \
V(HandleApiCallAsConstructor, NO_EXTRA_ARGUMENTS) \
\
V(StrictArgumentsCallee, NO_EXTRA_ARGUMENTS) \
V(StrictArgumentsCaller, NO_EXTRA_ARGUMENTS) \
V(StrictFunctionCaller, NO_EXTRA_ARGUMENTS) \
V(StrictFunctionArguments, NO_EXTRA_ARGUMENTS)
V(StrictModePoisonPill, NO_EXTRA_ARGUMENTS)
// Define list of builtins implemented in assembly.
#define BUILTIN_LIST_A(V) \

View File

@ -235,10 +235,7 @@ function FormatMessage(message) {
strict_function: ["In strict mode code, functions can only be declared at top level or immediately within another function." ],
strict_read_only_property: ["Cannot assign to read only property '", "%0", "' of ", "%1"],
strict_cannot_assign: ["Cannot assign to read only '", "%0", "' in strict mode"],
strict_arguments_callee: ["Cannot access property 'callee' of strict mode arguments"],
strict_arguments_caller: ["Cannot access property 'caller' of strict mode arguments"],
strict_function_caller: ["Cannot access property 'caller' of a strict mode function"],
strict_function_arguments: ["Cannot access property 'arguments' of a strict mode function"],
strict_poison_pill: ["'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them"],
strict_caller: ["Illegal access to a strict mode caller function."],
};
}

View File

@ -0,0 +1,38 @@
// 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.
// Tests that we always return the same type error function when trying to
// access strict mode caller and callee.
function foo() {
'use strict';
return arguments;
}
var get1 = Object.getOwnPropertyDescriptor(foo(), "caller").get;
var get2 = Object.getOwnPropertyDescriptor(foo(), "callee").get;
assertEquals(get1, get2);