Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(407)

Unified Diff: src/bootstrapper.cc

Issue 1061393002: Fix issues with name and length on poison pill function (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: git rebase and refactor Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/mjsunit/es6/throw-type-error-function-restrictions.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/bootstrapper.cc
diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc
index d44f8243a98f89c36d437eddd2a2f03b40d97c85..61017bfa2e1bd402e2e2be01577c8b31157df27a 100644
--- a/src/bootstrapper.cc
+++ b/src/bootstrapper.cc
@@ -137,6 +137,7 @@ class Genesis BASE_EMBEDDED {
// Creates the ThrowTypeError function. ECMA 5th Ed. 13.2.3
Handle<JSFunction> GetRestrictedFunctionPropertiesThrower();
Handle<JSFunction> GetStrictArgumentsPoisonFunction();
+ Handle<JSFunction> GetThrowTypeErrorIntrinsic(Builtins::Name builtin_name);
void CreateStrictModeFunctionMaps(Handle<JSFunction> empty);
void CreateStrongModeFunctionMaps(Handle<JSFunction> empty);
@@ -295,8 +296,8 @@ class Genesis BASE_EMBEDDED {
// prototype, maps.
Handle<Map> sloppy_function_map_writable_prototype_;
Handle<Map> strict_function_map_writable_prototype_;
- Handle<JSFunction> strict_poison_function;
- Handle<JSFunction> restricted_function_properties_thrower;
+ Handle<JSFunction> strict_poison_function_;
+ Handle<JSFunction> restricted_function_properties_thrower_;
BootstrapperActive active_;
friend class Bootstrapper;
@@ -613,39 +614,49 @@ void Genesis::SetStrongFunctionInstanceDescriptor(Handle<Map> map) {
}
+// Creates the %ThrowTypeError% function.
+Handle<JSFunction> Genesis::GetThrowTypeErrorIntrinsic(
+ Builtins::Name builtin_name) {
+ Handle<String> name =
+ factory()->InternalizeOneByteString(STATIC_CHAR_VECTOR("ThrowTypeError"));
+ Handle<Code> code(isolate()->builtins()->builtin(builtin_name));
+ Handle<JSFunction> function =
+ factory()->NewFunctionWithoutPrototype(name, code);
+ function->set_map(native_context()->sloppy_function_map());
+ function->shared()->DontAdaptArguments();
+
+ // %ThrowTypeError% must not have a name property.
+ JSReceiver::DeleteProperty(function, factory()->name_string()).Assert();
+
+ // length needs to be non configurable.
+ Handle<Object> value(Smi::FromInt(function->shared()->length()), isolate());
+ JSObject::SetOwnPropertyIgnoreAttributes(
+ function, factory()->length_string(), value,
+ static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY))
+ .Assert();
+
+ JSObject::PreventExtensions(function).Assert();
+
+ return function;
+}
+
+
// ECMAScript 5th Edition, 13.2.3
Handle<JSFunction> Genesis::GetRestrictedFunctionPropertiesThrower() {
- if (restricted_function_properties_thrower.is_null()) {
- Handle<String> name = factory()->InternalizeOneByteString(
- STATIC_CHAR_VECTOR("ThrowTypeError"));
- Handle<Code> code(isolate()->builtins()->builtin(
- Builtins::kRestrictedFunctionPropertiesThrower));
- restricted_function_properties_thrower =
- factory()->NewFunctionWithoutPrototype(name, code);
- restricted_function_properties_thrower->set_map(
- native_context()->sloppy_function_map());
- restricted_function_properties_thrower->shared()->DontAdaptArguments();
-
- JSObject::PreventExtensions(restricted_function_properties_thrower)
- .Assert();
+ if (restricted_function_properties_thrower_.is_null()) {
+ restricted_function_properties_thrower_ = GetThrowTypeErrorIntrinsic(
+ Builtins::kRestrictedFunctionPropertiesThrower);
}
- return restricted_function_properties_thrower;
+ return restricted_function_properties_thrower_;
}
Handle<JSFunction> Genesis::GetStrictArgumentsPoisonFunction() {
- if (strict_poison_function.is_null()) {
- Handle<String> name = factory()->InternalizeOneByteString(
- STATIC_CHAR_VECTOR("ThrowTypeError"));
- Handle<Code> code(isolate()->builtins()->builtin(
- Builtins::kRestrictedStrictArgumentsPropertiesThrower));
- strict_poison_function = factory()->NewFunctionWithoutPrototype(name, code);
- strict_poison_function->set_map(native_context()->sloppy_function_map());
- strict_poison_function->shared()->DontAdaptArguments();
-
- JSObject::PreventExtensions(strict_poison_function).Assert();
- }
- return strict_poison_function;
+ if (strict_poison_function_.is_null()) {
+ strict_poison_function_ = GetThrowTypeErrorIntrinsic(
+ Builtins::kRestrictedStrictArgumentsPropertiesThrower);
+ }
+ return strict_poison_function_;
}
« no previous file with comments | « no previous file | test/mjsunit/es6/throw-type-error-function-restrictions.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698