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

Side by Side Diff: test/cctest/test-accessors.cc

Issue 116083006: Make Function.length and Function.name configurable properties. (Closed) Base URL: git://github.com/v8/v8.git@bleeding_edge
Patch Set: Make comment + predicate more precise/correct. Created 6 years, 11 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
« no previous file with comments | « src/runtime.cc ('k') | test/mjsunit/harmony/object-observe.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 567 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 v8::HandleScope scope(isolate); 578 v8::HandleScope scope(isolate);
579 v8::Handle<v8::Function> fun = v8::Function::New(isolate, handle_property); 579 v8::Handle<v8::Function> fun = v8::Function::New(isolate, handle_property);
580 LocalContext switch_context; 580 LocalContext switch_context;
581 switch_context->Global()->Set(v8_str("fun"), fun); 581 switch_context->Global()->Set(v8_str("fun"), fun);
582 v8::TryCatch try_catch; 582 v8::TryCatch try_catch;
583 CompileRun( 583 CompileRun(
584 "var o = Object.create(null, { n: { get:fun } });" 584 "var o = Object.create(null, { n: { get:fun } });"
585 "for (var i = 0; i < 10; i++) o.n;"); 585 "for (var i = 0; i < 10; i++) o.n;");
586 CHECK(!try_catch.HasCaught()); 586 CHECK(!try_catch.HasCaught());
587 } 587 }
588
589
590 using namespace v8::internal;
591
592
593 static MaybeObject* ZeroAccessorGet(Isolate*, Object*, void*) {
594 return Smi::FromInt(0);
595 }
596
597
598 static MaybeObject* ReadOnlySetAccessor(Isolate* isolate,
599 JSObject*,
600 Object* value,
601 void*) {
602 return value;
603 }
604
605
606 const AccessorDescriptor kCallbackDescriptor = {
607 ZeroAccessorGet,
608 ReadOnlySetAccessor,
609 0
610 };
611
612
613 THREADED_TEST(RedefineReadOnlyConfigurableForeignCallbackAccessor) {
614 // Verify that property redefinition over foreign callbacks-backed
615 // properties works as expected if the property is non-writable,
616 // but writable. Such a property can be redefined without first
617 // making the property writable (ES5.1 - 8.12.9.10.b)
618 // (bug 3045.)
619 LocalContext env;
620 v8::Isolate* isolate = env->GetIsolate();
621 Factory* factory = CcTest::i_isolate()->factory();
622
623 v8::HandleScope scope(isolate);
624
625 Handle<Map> map = factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize);
626 Handle<DescriptorArray> instance_descriptors(
627 map->instance_descriptors());
628 ASSERT(instance_descriptors->IsEmpty());
629
630 Handle<DescriptorArray> descriptors = factory->NewDescriptorArray(0, 1);
631 DescriptorArray::WhitenessWitness witness(*descriptors);
632 map->set_instance_descriptors(*descriptors);
633
634 Handle<Foreign> foreign = factory->NewForeign(&kCallbackDescriptor);
635 Handle<v8::internal::String> name =
636 factory->InternalizeUtf8String(Vector<const char>("prop", 4));
637
638 // Want a non-writable and configurable property.
639 PropertyAttributes attribs =
640 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY);
641 CallbacksDescriptor d(*name, *foreign, attribs);
642 map->AppendDescriptor(&d, witness);
643
644 Handle<Object> object = factory->NewJSObjectFromMap(map);
645
646 // Put the object on the global object.
647 env->Global()->Set(v8::String::NewFromUtf8(CcTest::isolate(), "Foreign"),
648 v8::Utils::ToLocal(object));
649
650 // ..and redefine the property through JavaScript, returning its value.
651 const char* script =
652 "Object.defineProperty(Foreign, 'prop', {value: 2}); Foreign.prop";
653 v8::Handle<v8::Value> result = v8::Script::Compile(
654 v8::String::NewFromUtf8(CcTest::isolate(), script))->Run();
655 CHECK_EQ(2, result->Int32Value());
656 }
OLDNEW
« no previous file with comments | « src/runtime.cc ('k') | test/mjsunit/harmony/object-observe.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698