Revision: 14309
Author: [email protected]
Date: Wed Apr 17 08:01:25 2013
Log: Generator objects have [[Class]] === "Generator"
Generator object maps now link to their constructors, which are created
with a "Generator" class name. This does not cause a per-generator
constructor property to be set.
BUG=v8:2355
TEST=mjsunit/harmony/generators-objects
Review URL: https://codereview.chromium.org/14262004
Patch from Andy Wingo <[email protected]>.
http://code.google.com/p/v8/source/detail?r=14309
Modified:
/branches/bleeding_edge/src/compiler.cc
/branches/bleeding_edge/src/factory.cc
/branches/bleeding_edge/src/factory.h
/branches/bleeding_edge/src/generator.js
/branches/bleeding_edge/src/heap.cc
/branches/bleeding_edge/src/heap.h
/branches/bleeding_edge/src/macros.py
/branches/bleeding_edge/src/parser.cc
/branches/bleeding_edge/test/mjsunit/harmony/generators-objects.js
=======================================
--- /branches/bleeding_edge/src/compiler.cc Wed Apr 10 02:24:31 2013
+++ /branches/bleeding_edge/src/compiler.cc Wed Apr 17 08:01:25 2013
@@ -553,6 +553,7 @@
isolate->factory()->NewSharedFunctionInfo(
lit->name(),
lit->materialized_literal_count(),
+ lit->is_generator(),
info->code(),
ScopeInfo::Create(info->scope(), info->zone()));
@@ -1074,6 +1075,7 @@
Handle<SharedFunctionInfo> result =
FACTORY->NewSharedFunctionInfo(literal->name(),
literal->materialized_literal_count(),
+ literal->is_generator(),
info.code(),
scope_info);
SetFunctionInfo(result, literal, false, script);
=======================================
--- /branches/bleeding_edge/src/factory.cc Thu Apr 11 09:28:19 2013
+++ /branches/bleeding_edge/src/factory.cc Wed Apr 17 08:01:25 2013
@@ -1078,6 +1078,7 @@
Handle<SharedFunctionInfo> Factory::NewSharedFunctionInfo(
Handle<String> name,
int number_of_literals,
+ bool is_generator,
Handle<Code> code,
Handle<ScopeInfo> scope_info) {
Handle<SharedFunctionInfo> shared = NewSharedFunctionInfo(name);
@@ -1091,6 +1092,9 @@
literals_array_size += JSFunction::kLiteralsPrefixSize;
}
shared->set_num_literals(literals_array_size);
+ if (is_generator) {
+ shared->set_instance_class_name(isolate()->heap()->Generator_string());
+ }
return shared;
}
=======================================
--- /branches/bleeding_edge/src/factory.h Thu Mar 7 03:42:58 2013
+++ /branches/bleeding_edge/src/factory.h Wed Apr 17 08:01:25 2013
@@ -454,6 +454,7 @@
Handle<SharedFunctionInfo> NewSharedFunctionInfo(
Handle<String> name,
int number_of_literals,
+ bool is_generator,
Handle<Code> code,
Handle<ScopeInfo> scope_info);
Handle<SharedFunctionInfo> NewSharedFunctionInfo(Handle<String> name);
=======================================
--- /branches/bleeding_edge/src/generator.js Fri Apr 12 08:52:44 2013
+++ /branches/bleeding_edge/src/generator.js Wed Apr 17 08:01:25 2013
@@ -39,18 +39,38 @@
//
http://wiki.ecmascript.org/lib/exe/fetch.php?cache=cache&media=harmony:es6_generator_object_model_3-29-13.png
function GeneratorObjectNext() {
+ if (!IS_GENERATOR(this)) {
+ throw MakeTypeError('incompatible_method_receiver',
+ ['[Generator].prototype.next', this]);
+ }
+
// TODO(wingo): Implement.
}
function GeneratorObjectSend(value) {
+ if (!IS_GENERATOR(this)) {
+ throw MakeTypeError('incompatible_method_receiver',
+ ['[Generator].prototype.send', this]);
+ }
+
// TODO(wingo): Implement.
}
function GeneratorObjectThrow(exn) {
+ if (!IS_GENERATOR(this)) {
+ throw MakeTypeError('incompatible_method_receiver',
+ ['[Generator].prototype.throw', this]);
+ }
+
// TODO(wingo): Implement.
}
function GeneratorObjectClose() {
+ if (!IS_GENERATOR(this)) {
+ throw MakeTypeError('incompatible_method_receiver',
+ ['[Generator].prototype.close', this]);
+ }
+
// TODO(wingo): Implement.
}
=======================================
--- /branches/bleeding_edge/src/heap.cc Tue Apr 16 05:30:51 2013
+++ /branches/bleeding_edge/src/heap.cc Wed Apr 17 08:01:25 2013
@@ -4358,6 +4358,7 @@
MaybeObject* maybe_map = AllocateInitialMap(function);
if (!maybe_map->To(&map)) return maybe_map;
function->set_initial_map(map);
+ map->set_constructor(function);
}
ASSERT(map->instance_type() == JS_GENERATOR_OBJECT_TYPE);
return AllocateJSObjectFromMap(map);
=======================================
--- /branches/bleeding_edge/src/heap.h Tue Apr 16 04:00:02 2013
+++ /branches/bleeding_edge/src/heap.h Wed Apr 17 08:01:25 2013
@@ -268,7 +268,8 @@
V(infinity_string, "Infinity") \
V(minus_infinity_string, "-Infinity") \
V(hidden_stack_trace_string, "v8::hidden_stack_trace") \
- V(query_colon_string, "(?:)")
+ V(query_colon_string, "(?:)") \
+ V(Generator_string, "Generator")
// Forward declarations.
class GCTracer;
=======================================
--- /branches/bleeding_edge/src/macros.py Thu Mar 28 05:50:18 2013
+++ /branches/bleeding_edge/src/macros.py Wed Apr 17 08:01:25 2013
@@ -117,6 +117,7 @@
macro IS_ARGUMENTS(arg) = (%_ClassOf(arg) === 'Arguments');
macro IS_GLOBAL(arg) = (%_ClassOf(arg) === 'global');
macro IS_ARRAYBUFFER(arg) = (%_ClassOf(arg) === '__ArrayBuffer');
+macro IS_GENERATOR(arg) = (%_ClassOf(arg) === 'Generator');
macro IS_UNDETECTABLE(arg) = (%_IsUndetectableObject(arg));
macro FLOOR(arg) = $floor(arg);
=======================================
--- /branches/bleeding_edge/src/parser.cc Wed Apr 17 05:47:15 2013
+++ /branches/bleeding_edge/src/parser.cc Wed Apr 17 08:01:25 2013
@@ -1872,9 +1872,10 @@
const int literals = fun->NumberOfLiterals();
Handle<Code> code = Handle<Code>(fun->shared()->code());
Handle<Code> construct_stub =
Handle<Code>(fun->shared()->construct_stub());
+ bool is_generator = false;
Handle<SharedFunctionInfo> shared =
- isolate()->factory()->NewSharedFunctionInfo(name, literals, code,
- Handle<ScopeInfo>(fun->shared()->scope_info()));
+ isolate()->factory()->NewSharedFunctionInfo(name, literals,
is_generator,
+ code, Handle<ScopeInfo>(fun->shared()->scope_info()));
shared->set_construct_stub(*construct_stub);
// Copy the function data to the shared function info.
=======================================
--- /branches/bleeding_edge/test/mjsunit/harmony/generators-objects.js Mon
Apr 15 05:29:44 2013
+++ /branches/bleeding_edge/test/mjsunit/harmony/generators-objects.js Wed
Apr 17 08:01:25 2013
@@ -25,7 +25,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Flags: --harmony-generators --harmony-scoping
+// Flags: --harmony-generators --harmony-scoping --allow-natives-syntax
// Test instantations of generators.
@@ -55,6 +55,8 @@
var iter = g();
assertSame(g.prototype, Object.getPrototypeOf(iter));
assertTrue(iter instanceof g);
+ assertEquals("Generator", %ClassOf(iter));
+ assertEquals("[object Generator]", String(iter));
assertEquals([], Object.getOwnPropertyNames(iter));
assertTrue(iter !== g());
@@ -62,7 +64,30 @@
iter = new g();
assertSame(g.prototype, Object.getPrototypeOf(iter));
assertTrue(iter instanceof g);
+ assertEquals("Generator", %ClassOf(iter));
+ assertEquals("[object Generator]", String(iter));
assertEquals([], Object.getOwnPropertyNames(iter));
assertTrue(iter !== new g());
}
TestGeneratorObject();
+
+
+// Test the methods of generator objects.
+function TestGeneratorObjectMethods() {
+ function* g() { yield 1; }
+ var iter = g();
+
+ function TestNonGenerator(non_generator) {
+ assertThrows(function() { iter.next.call(non_generator); }, TypeError);
+ assertThrows(function() { iter.send.call(non_generator, 1); },
TypeError);
+ assertThrows(function() { iter.throw.call(non_generator, 1); },
TypeError);
+ assertThrows(function() { iter.close.call(non_generator); },
TypeError);
+ }
+
+ TestNonGenerator(1);
+ TestNonGenerator({});
+ TestNonGenerator(function(){});
+ TestNonGenerator(g);
+ TestNonGenerator(g.prototype);
+}
+TestGeneratorObjectMethods();
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.