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..f6f80cbd2baacd03e6ff80c1b4a7932a9ff3125d 100644 |
--- a/test/cctest/test-api-accessors.cc |
+++ b/test/cctest/test-api-accessors.cc |
@@ -8,15 +8,33 @@ |
#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 |
+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 +59,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::NewWithFastHandler( |
+ isolate, CppAccessor, raw_accessor, |
+ v8::Local<v8::Value>(), signature)); |
} |
// Setup child object ( =~ a specific DOM Node, e.g. a <div> ). |
@@ -61,18 +81,18 @@ 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( |
"var m = new Node(); " |
"var sum = 0; " |
- "for (var i = 0; i < 3; ++i) { " |
+ "for (var i = 0; i < 10; ++i) { " |
" sum += m.firstChild; " |
- " sum += m.firstChildJS; " |
+ " sum += m.firstChildRaw; " |
"}; " |
"sum;", |
- 3 * (42 + 41)); |
+ 10 * (42 + 41)); |
// Obtain the accessor and call it via apply on the Node: |
ExpectInt32( |
@@ -84,10 +104,19 @@ 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 |