// 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
// 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;
// ECMAScript 5th Edition, 13.2.3
-Handle<JSFunction> Genesis::CreateThrowTypeErrorFunction(
- Builtins::Name builtin) {
- 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->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;
+Handle<JSFunction> Genesis::GetThrowTypeErrorFunction() {
+ if (throw_type_error_function.is_null()) {
+ Handle<String> name = factory()->LookupAsciiSymbol("ThrowTypeError");
+ 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();
+
+ PreventExtensions(throw_type_error_function);
+ }
+ return throw_type_error_function;
}
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);
}
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);
// 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)));
-}
-
-
// -----------------------------------------------------------------------------
//
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."],
};
}
--- /dev/null
+// 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);