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

Side by Side Diff: src/bootstrapper.cc

Issue 6691003: Strict mode poision pills. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 // triggered during environment creation there may be weak handle 200 // triggered during environment creation there may be weak handle
201 // processing callbacks which may create new environments. 201 // processing callbacks which may create new environments.
202 Genesis* previous_; 202 Genesis* previous_;
203 203
204 Handle<Context> global_context() { return global_context_; } 204 Handle<Context> global_context() { return global_context_; }
205 205
206 // Creates some basic objects. Used for creating a context from scratch. 206 // Creates some basic objects. Used for creating a context from scratch.
207 void CreateRoots(); 207 void CreateRoots();
208 // Creates the empty function. Used for creating a context from scratch. 208 // Creates the empty function. Used for creating a context from scratch.
209 Handle<JSFunction> CreateEmptyFunction(); 209 Handle<JSFunction> CreateEmptyFunction();
210 void CreateThrowTypeErrorCallbacks(
211 Handle<FixedArray> callbacks,
212 Builtins::Name builtin);
213 void CreateThrowTypeError(Handle<JSFunction> empty);
210 // Creates the global objects using the global and the template passed in 214 // Creates the global objects using the global and the template passed in
211 // through the API. We call this regardless of whether we are building a 215 // through the API. We call this regardless of whether we are building a
212 // context from scratch or using a deserialized one from the partial snapshot 216 // context from scratch or using a deserialized one from the partial snapshot
213 // but in the latter case we don't use the objects it produces directly, as 217 // but in the latter case we don't use the objects it produces directly, as
214 // we have to used the deserialized ones that are linked together with the 218 // we have to used the deserialized ones that are linked together with the
215 // rest of the context snapshot. 219 // rest of the context snapshot.
216 Handle<JSGlobalProxy> CreateNewGlobals( 220 Handle<JSGlobalProxy> CreateNewGlobals(
217 v8::Handle<v8::ObjectTemplate> global_template, 221 v8::Handle<v8::ObjectTemplate> global_template,
218 Handle<Object> global_object, 222 Handle<Object> global_object,
219 Handle<GlobalObject>* global_proxy_out); 223 Handle<GlobalObject>* global_proxy_out);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 void TransferIndexedProperties(Handle<JSObject> from, Handle<JSObject> to); 260 void TransferIndexedProperties(Handle<JSObject> from, Handle<JSObject> to);
257 261
258 enum PrototypePropertyMode { 262 enum PrototypePropertyMode {
259 DONT_ADD_PROTOTYPE, 263 DONT_ADD_PROTOTYPE,
260 ADD_READONLY_PROTOTYPE, 264 ADD_READONLY_PROTOTYPE,
261 ADD_WRITEABLE_PROTOTYPE 265 ADD_WRITEABLE_PROTOTYPE
262 }; 266 };
263 Handle<DescriptorArray> ComputeFunctionInstanceDescriptor( 267 Handle<DescriptorArray> ComputeFunctionInstanceDescriptor(
264 PrototypePropertyMode prototypeMode); 268 PrototypePropertyMode prototypeMode);
265 void MakeFunctionInstancePrototypeWritable(); 269 void MakeFunctionInstancePrototypeWritable();
270 Handle<DescriptorArray> ComputeStrictFunctionDescriptor(
271 PrototypePropertyMode propertyMode,
272 Handle<FixedArray> arguments,
273 Handle<FixedArray> caller);
266 274
267 static bool CompileBuiltin(int index); 275 static bool CompileBuiltin(int index);
268 static bool CompileNative(Vector<const char> name, Handle<String> source); 276 static bool CompileNative(Vector<const char> name, Handle<String> source);
269 static bool CompileScriptCached(Vector<const char> name, 277 static bool CompileScriptCached(Vector<const char> name,
270 Handle<String> source, 278 Handle<String> source,
271 SourceCodeCache* cache, 279 SourceCodeCache* cache,
272 v8::Extension* extension, 280 v8::Extension* extension,
273 Handle<Context> top_context, 281 Handle<Context> top_context,
274 bool use_runtime_context); 282 bool use_runtime_context);
275 283
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 Handle<Map> empty_fm = Factory::CopyMapDropDescriptors( 500 Handle<Map> empty_fm = Factory::CopyMapDropDescriptors(
493 function_without_prototype_map); 501 function_without_prototype_map);
494 empty_fm->set_instance_descriptors( 502 empty_fm->set_instance_descriptors(
495 *function_without_prototype_map_descriptors); 503 *function_without_prototype_map_descriptors);
496 empty_fm->set_prototype(global_context()->object_function()->prototype()); 504 empty_fm->set_prototype(global_context()->object_function()->prototype());
497 empty_function->set_map(*empty_fm); 505 empty_function->set_map(*empty_fm);
498 return empty_function; 506 return empty_function;
499 } 507 }
500 508
501 509
510 Handle<DescriptorArray> Genesis::ComputeStrictFunctionDescriptor(
511 PrototypePropertyMode prototypeMode,
512 Handle<FixedArray> arguments,
513 Handle<FixedArray> caller) {
514 Handle<DescriptorArray> descriptors =
515 Factory::NewDescriptorArray(prototypeMode == DONT_ADD_PROTOTYPE ? 4 : 5);
516 PropertyAttributes attributes = static_cast<PropertyAttributes>(
517 DONT_ENUM | DONT_DELETE | READ_ONLY);
518
519 { // length
520 Handle<Proxy> proxy = Factory::NewProxy(&Accessors::FunctionLength);
521 CallbacksDescriptor d(*Factory::length_symbol(), *proxy, attributes);
522 descriptors->Set(0, &d);
523 }
524 { // name
525 Handle<Proxy> proxy = Factory::NewProxy(&Accessors::FunctionName);
526 CallbacksDescriptor d(*Factory::name_symbol(), *proxy, attributes);
527 descriptors->Set(1, &d);
528 }
529 { // arguments
530 CallbacksDescriptor d(*Factory::arguments_symbol(), *arguments, attributes);
531 descriptors->Set(2, &d);
532 }
533 { // caller
534 CallbacksDescriptor d(*Factory::caller_symbol(), *caller, attributes);
535 descriptors->Set(3, &d);
536 }
537
538 // prototype
539 if (prototypeMode != DONT_ADD_PROTOTYPE) {
540 if (prototypeMode == ADD_WRITEABLE_PROTOTYPE) {
541 attributes = static_cast<PropertyAttributes>(attributes & ~READ_ONLY);
542 }
543 CallbacksDescriptor d(
544 *Factory::prototype_symbol(),
545 *Factory::NewProxy(&Accessors::FunctionPrototype),
546 attributes);
547 descriptors->Set(4, &d);
548 }
549
550 descriptors->Sort();
551 return descriptors;
552 }
553
554
555 void Genesis::CreateThrowTypeErrorCallbacks(
556 Handle<FixedArray> callbacks,
557 Builtins::Name builtin) {
558 // Create the ThrowTypeError function.
559 Handle<String> name = Factory::LookupAsciiSymbol("ThrowTypeError");
560 Handle<JSFunction> pill = Factory::NewFunctionWithoutPrototypeStrict(name);
561 Handle<Code> code = Handle<Code>(Builtins::builtin(builtin));
562 pill->set_code(*code);
563 pill->shared()->set_code(*code);
564 pill->shared()->DontAdaptArguments();
565
566 // Install the poison pills into the calbacks array.
567 callbacks->set(0, *pill);
568 callbacks->set(1, *pill);
569
570 PreventExtensions(pill);
571 }
572
573
574 // ECMAScript 5th Edition, 13.2.3
575 void Genesis::CreateThrowTypeError(Handle<JSFunction> empty) {
576 // Create the pill callbacks arrays. The get/set callacks are installed
577 // after the maps get created below.
578 Handle<FixedArray> arguments = Factory::NewFixedArray(2, TENURED);
579 Handle<FixedArray> caller = Factory::NewFixedArray(2, TENURED);
580
581 { // Allocate map for the strict mode function instances.
582 Handle<Map> map = Factory::NewMap(JS_FUNCTION_TYPE, JSFunction::kSize);
583 global_context()->set_function_instance_map_strict(*map);
584 Handle<DescriptorArray> descriptors = ComputeStrictFunctionDescriptor(
585 ADD_WRITEABLE_PROTOTYPE, arguments, caller);
586 map->set_instance_descriptors(*descriptors);
587 map->set_function_with_prototype(true);
588 map->set_prototype(*empty);
589 }
590
591 { // Allocate map for the prototype-less strict mode instances.
592 Handle<Map> map = Factory::NewMap(JS_FUNCTION_TYPE, JSFunction::kSize);
593 global_context()->set_function_without_prototype_map_strict(*map);
594 Handle<DescriptorArray> descriptors = ComputeStrictFunctionDescriptor(
595 DONT_ADD_PROTOTYPE, arguments, caller);
596 map->set_instance_descriptors(*descriptors);
597 map->set_function_with_prototype(false);
598 map->set_prototype(*empty);
599 }
600
601 { // Allocate map for the strict mode functions.
602 Handle<Map> map = Factory::NewMap(JS_FUNCTION_TYPE, JSFunction::kSize);
603 global_context()->set_function_map_strict(*map);
604 Handle<DescriptorArray> descriptors = ComputeStrictFunctionDescriptor(
605 ADD_READONLY_PROTOTYPE, arguments, caller);
606 map->set_instance_descriptors(*descriptors);
607 map->set_function_with_prototype(true);
608 map->set_prototype(*empty);
609 }
610
611 CreateThrowTypeErrorCallbacks(arguments, Builtins::StrictFunctionArguments);
612 CreateThrowTypeErrorCallbacks(caller, Builtins::StrictFunctionCaller);
613 }
614
615
502 static void AddToWeakGlobalContextList(Context* context) { 616 static void AddToWeakGlobalContextList(Context* context) {
503 ASSERT(context->IsGlobalContext()); 617 ASSERT(context->IsGlobalContext());
504 #ifdef DEBUG 618 #ifdef DEBUG
505 { // NOLINT 619 { // NOLINT
506 ASSERT(context->get(Context::NEXT_CONTEXT_LINK)->IsUndefined()); 620 ASSERT(context->get(Context::NEXT_CONTEXT_LINK)->IsUndefined());
507 // Check that context is not in the list yet. 621 // Check that context is not in the list yet.
508 for (Object* current = Heap::global_contexts_list(); 622 for (Object* current = Heap::global_contexts_list();
509 !current->IsUndefined(); 623 !current->IsUndefined();
510 current = Context::cast(current)->get(Context::NEXT_CONTEXT_LINK)) { 624 current = Context::cast(current)->get(Context::NEXT_CONTEXT_LINK)) {
511 ASSERT(current != context); 625 ASSERT(current != context);
(...skipping 1339 matching lines...) Expand 10 before | Expand all | Expand 10 after
1851 &inner_global); 1965 &inner_global);
1852 1966
1853 HookUpGlobalProxy(inner_global, global_proxy); 1967 HookUpGlobalProxy(inner_global, global_proxy);
1854 HookUpInnerGlobal(inner_global); 1968 HookUpInnerGlobal(inner_global);
1855 1969
1856 if (!ConfigureGlobalObjects(global_template)) return; 1970 if (!ConfigureGlobalObjects(global_template)) return;
1857 } else { 1971 } else {
1858 // We get here if there was no context snapshot. 1972 // We get here if there was no context snapshot.
1859 CreateRoots(); 1973 CreateRoots();
1860 Handle<JSFunction> empty_function = CreateEmptyFunction(); 1974 Handle<JSFunction> empty_function = CreateEmptyFunction();
1975 CreateThrowTypeError(empty_function);
1861 Handle<GlobalObject> inner_global; 1976 Handle<GlobalObject> inner_global;
1862 Handle<JSGlobalProxy> global_proxy = 1977 Handle<JSGlobalProxy> global_proxy =
1863 CreateNewGlobals(global_template, global_object, &inner_global); 1978 CreateNewGlobals(global_template, global_object, &inner_global);
1864 HookUpGlobalProxy(inner_global, global_proxy); 1979 HookUpGlobalProxy(inner_global, global_proxy);
1865 InitializeGlobal(inner_global, empty_function); 1980 InitializeGlobal(inner_global, empty_function);
1866 InstallJSFunctionResultCaches(); 1981 InstallJSFunctionResultCaches();
1867 InitializeNormalizedMapCaches(); 1982 InitializeNormalizedMapCaches();
1868 if (!InstallNatives()) return; 1983 if (!InstallNatives()) return;
1869 1984
1870 MakeFunctionInstancePrototypeWritable(); 1985 MakeFunctionInstancePrototypeWritable();
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1917 } 2032 }
1918 2033
1919 2034
1920 // Restore statics that are thread local. 2035 // Restore statics that are thread local.
1921 char* BootstrapperActive::RestoreState(char* from) { 2036 char* BootstrapperActive::RestoreState(char* from) {
1922 nesting_ = *reinterpret_cast<int*>(from); 2037 nesting_ = *reinterpret_cast<int*>(from);
1923 return from + sizeof(nesting_); 2038 return from + sizeof(nesting_);
1924 } 2039 }
1925 2040
1926 } } // namespace v8::internal 2041 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698