| Index: test/cctest/test-api-accessors.cc
|
| diff --git a/test/cctest/test-api-accessors.cc b/test/cctest/test-api-accessors.cc
|
| index f6d1ef0718df463f90ed67f1f4734193ad1c1853..dbe5b57a2d2ab4d5a1ba50f7d1f2085d243eb338 100644
|
| --- a/test/cctest/test-api-accessors.cc
|
| +++ b/test/cctest/test-api-accessors.cc
|
| @@ -8,15 +8,34 @@
|
| #include "test/cctest/cctest.h"
|
|
|
| #include "include/v8.h"
|
| +#include "src/compiler/pipeline.h"
|
| +#include "src/compiler/raw-machine-assembler.h"
|
|
|
|
|
| -#ifdef V8_JS_ACCESSORS
|
| +#ifdef V8_FAST_ACCESSORS
|
| +namespace i = v8::internal;
|
| +
|
| static void CppAccessor(const v8::FunctionCallbackInfo<v8::Value>& info) {
|
| info.GetReturnValue().Set(42);
|
| }
|
|
|
| -static const char* JsAccessor =
|
| - "function firstChildJS(value) { return 41; }; firstChildJS";
|
| +
|
| +v8::Local<v8::Value> RawAccessor(v8::Isolate* isolate) {
|
| + i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
|
| + i::Zone zone;
|
| + i::compiler::RawMachineAssembler raw_machine_assembler(
|
| + i_isolate, new (&zone) i::compiler::Graph(&zone),
|
| + i::compiler::Linkage::GetJSCallDescriptor(
|
| + &zone, false, 1, i::compiler::CallDescriptor::kNoFlags));
|
| + raw_machine_assembler.Return(raw_machine_assembler.NumberConstant(41));
|
| + i::CompilationInfo info("firstChildRaw", i_isolate, &zone);
|
| + i::compiler::Schedule* schedule = raw_machine_assembler.Export();
|
| + i::Handle<i::Code> code = i::compiler::Pipeline::GenerateCodeForTesting(
|
| + &info, raw_machine_assembler.call_descriptor(),
|
| + raw_machine_assembler.graph(), schedule);
|
| + return v8::Utils::ToLocal(i::Handle<i::Object>::cast(code));
|
| +}
|
| +
|
|
|
| TEST(JavascriptAccessors) {
|
| v8::Isolate* isolate = CcTest::isolate();
|
| @@ -41,10 +60,12 @@ TEST(JavascriptAccessors) {
|
| v8::FunctionTemplate::New(isolate, CppAccessor, v8::Local<v8::Value>(),
|
| signature));
|
|
|
| - // JS accessor as "firstChildJS":
|
| - auto js_accessor = v8::Local<v8::Function>::Cast(CompileRun(JsAccessor));
|
| - parent->PrototypeTemplate()->SetAccessorProperty(v8_str("firstChildJS"),
|
| - js_accessor);
|
| + // JS accessor as "firstChildRaw":
|
| + auto raw_accessor = RawAccessor(isolate);
|
| + parent->PrototypeTemplate()->SetAccessorProperty(
|
| + v8_str("firstChildRaw"),
|
| + v8::FunctionTemplate::New(isolate, raw_accessor, v8::Local<v8::Value>(),
|
| + signature));
|
| }
|
|
|
| // Setup child object ( =~ a specific DOM Node, e.g. a <div> ).
|
| @@ -61,7 +82,7 @@ TEST(JavascriptAccessors) {
|
|
|
| // The simple case: Run it once.
|
| ExpectInt32("var n = new Node(); n.firstChild", 42);
|
| - ExpectInt32("var n = new Node(); n.firstChildJS", 41);
|
| + ExpectInt32("var n = new Node(); n.firstChildRaw", 41);
|
|
|
| // Run them in a loop. This will likely trigger the optimizing compiler:
|
| ExpectInt32(
|
| @@ -69,7 +90,7 @@ TEST(JavascriptAccessors) {
|
| "var sum = 0; "
|
| "for (var i = 0; i < 3; ++i) { "
|
| " sum += m.firstChild; "
|
| - " sum += m.firstChildJS; "
|
| + " sum += m.firstChildRaw; "
|
| "}; "
|
| "sum;",
|
| 3 * (42 + 41));
|
| @@ -84,10 +105,20 @@ TEST(JavascriptAccessors) {
|
| ExpectInt32(
|
| "var n = new Node(); "
|
| "var g = Object.getOwnPropertyDescriptor("
|
| - " n.__proto__.__proto__, 'firstChildJS')['get']; "
|
| + " n.__proto__.__proto__, 'firstChildRaw')['get']; "
|
| "g.apply(n);",
|
| 41);
|
|
|
| - // TODO(vogelheim): Verify compatible receiver check works.
|
| + ExpectInt32(
|
| + "var n = new Node();"
|
| + "var g = Object.getOwnPropertyDescriptor("
|
| + " n.__proto__.__proto__, 'firstChildRaw')['get'];"
|
| + "try {"
|
| + " var f = { firstChildRaw: '51' };"
|
| + " g.apply(f);"
|
| + "} catch(e) {"
|
| + " 31415;"
|
| + "}",
|
| + 31415);
|
| }
|
| -#endif // V8_JS_ACCESSORS
|
| +#endif // V8_FAST_ACCESSORS
|
|
|