Index: src/runtime/runtime-test.cc |
diff --git a/src/runtime/runtime-test.cc b/src/runtime/runtime-test.cc |
index 2232b190599a2b1a3025ea72bb44ef23596130ce..87f0a4e52144a384d38828da96cf21038bdd50ad 100644 |
--- a/src/runtime/runtime-test.cc |
+++ b/src/runtime/runtime-test.cc |
@@ -282,6 +282,64 @@ RUNTIME_FUNCTION(Runtime_ClearFunctionTypeFeedback) { |
return isolate->heap()->undefined_value(); |
} |
+RUNTIME_FUNCTION(Runtime_CheckImportExportFunction) { |
Mircea Trofin
2016/08/03 22:52:16
add a comment saying that this only supports the c
|
+ 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()); |
+ DCHECK(export_code->kind() == Code::JS_TO_WASM_FUNCTION); |
+ 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); |
+ } |
+ } |
+ DCHECK(export_fct->kind() == Code::WASM_FUNCTION && count == 1); |
+ // check the type of the $increment |
+ Handle<Code> increment_fct; |
Mircea Trofin
2016/08/03 22:52:16
The notion of "increment" is probably tied to the
|
+ 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; |
+ increment_fct = handle(target); |
+ } |
+ } |
+ DCHECK(increment_fct->kind() == Code::WASM_FUNCTION && count == 1); |
Mircea Trofin
2016/08/03 22:52:16
you probably want to check here that increment_fct
|
+ // 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; |
+ count = 0; |
+ for (RelocIterator it(*increment_fct, mask); !it.done(); it.next()) { |
+ RelocInfo* rinfo = it.rinfo(); |
+ Address target_address = rinfo->target_address(); |
+ Code* target = Code::GetCodeFromTargetAddress(target_address); |
+ if (type->value() == 0) |
Mircea Trofin
2016/08/03 22:52:16
you need {}
Mircea Trofin
2016/08/03 22:52:16
move out of the for loop the target_kind assignmen
|
+ target_kind = Code::WASM_FUNCTION; |
+ else if (type->value() == 1) |
+ target_kind = Code::WASM_TO_JS_FUNCTION; |
Mircea Trofin
2016/08/03 22:52:16
{} also - because the assignment is on the second
|
+ if (target->kind() == target_kind) { |
+ ++count; |
+ imported_fct = handle(target); |
+ } |
+ } |
+ DCHECK(imported_fct->kind() == target_kind && count == 1); |
+ return isolate->heap()->undefined_value(); |
+} |
RUNTIME_FUNCTION(Runtime_NotifyContextDisposed) { |
HandleScope scope(isolate); |