Index: src/runtime/runtime-test.cc |
diff --git a/src/runtime/runtime-test.cc b/src/runtime/runtime-test.cc |
index 2232b190599a2b1a3025ea72bb44ef23596130ce..6fff4cffe18340873dfe2e3d26d5b4f6944f51fd 100644 |
--- a/src/runtime/runtime-test.cc |
+++ b/src/runtime/runtime-test.cc |
@@ -282,6 +282,75 @@ RUNTIME_FUNCTION(Runtime_ClearFunctionTypeFeedback) { |
return isolate->heap()->undefined_value(); |
} |
+RUNTIME_FUNCTION(Runtime_CheckWasmWrapperElision) { |
+ // This only supports the case where the function being exported |
+ // calls exactly one import |
+ HandleScope scope(isolate); |
+ DCHECK(args.length() == 2); |
+ CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); |
+ // If type is 0, it means that it is supposed to be a direct call to WASM |
+ // function |
+ // If type is 1, it means that it is supposed to have wrappers |
+ CONVERT_ARG_HANDLE_CHECKED(Smi, type, 1); |
+ Handle<Code> export_code = handle(function->code()); |
+ if (export_code->kind() != Code::JS_TO_WASM_FUNCTION) { |
Mircea Trofin
2016/08/04 18:21:08
actually, this is a fine place to fail (CHECK). Th
Chen
2016/08/04 20:05:07
Done.
|
+ return isolate->heap()->ToBoolean(false); |
+ } |
+ int const mask = RelocInfo::ModeMask(RelocInfo::CODE_TARGET); |
+ // check the type of the $export_fct |
+ Handle<Code> export_fct; |
+ int count = 0; |
+ for (RelocIterator it(*export_code, mask); !it.done(); it.next()) { |
+ RelocInfo* rinfo = it.rinfo(); |
+ Address target_address = rinfo->target_address(); |
+ Code* target = Code::GetCodeFromTargetAddress(target_address); |
+ if (target->kind() == Code::WASM_FUNCTION) { |
+ ++count; |
+ export_fct = handle(target); |
+ } |
+ } |
+ if (count != 1) { |
Mircea Trofin
2016/08/04 18:21:08
This is also a CHECK - an export is expected to wr
Chen
2016/08/04 20:05:07
Done.
|
+ return isolate->heap()->ToBoolean(false); |
+ } |
+ // check the type of the $increment |
Mircea Trofin
2016/08/04 18:21:08
$increment?
Chen
2016/08/04 20:05:07
Done.
|
+ Handle<Code> wrapped_fct; |
+ count = 0; |
+ for (RelocIterator it(*export_fct, mask); !it.done(); it.next()) { |
+ RelocInfo* rinfo = it.rinfo(); |
+ Address target_address = rinfo->target_address(); |
+ Code* target = Code::GetCodeFromTargetAddress(target_address); |
+ if (target->kind() == Code::WASM_FUNCTION) { |
+ ++count; |
+ wrapped_fct = handle(target); |
+ } |
+ } |
+ if (count != 1) { |
Mircea Trofin
2016/08/04 18:21:08
also a CHECK
Chen
2016/08/04 20:05:07
Done.
|
+ return isolate->heap()->ToBoolean(false); |
+ } |
+ // check the type of the imported exported function, it should be also a WASM |
+ // function in our case |
+ Handle<Code> imported_fct; |
+ Code::Kind target_kind; |
+ if (type->value() == 0) { |
+ target_kind = Code::WASM_FUNCTION; |
+ } else if (type->value() == 1) { |
+ target_kind = Code::WASM_TO_JS_FUNCTION; |
+ } |
+ count = 0; |
+ for (RelocIterator it(*wrapped_fct, mask); !it.done(); it.next()) { |
+ RelocInfo* rinfo = it.rinfo(); |
+ Address target_address = rinfo->target_address(); |
+ Code* target = Code::GetCodeFromTargetAddress(target_address); |
+ if (target->kind() == target_kind) { |
+ ++count; |
+ imported_fct = handle(target); |
+ } |
+ } |
Mircea Trofin
2016/08/04 18:21:08
CHECK_LE(count, 1)
Chen
2016/08/04 20:05:07
Done.
|
+ if (count != 1) { |
+ return isolate->heap()->ToBoolean(false); |
+ } |
+ return isolate->heap()->ToBoolean(true); |
+} |
RUNTIME_FUNCTION(Runtime_NotifyContextDisposed) { |
HandleScope scope(isolate); |