| 181 | } |
| 182 | |
| 183 | void ModuleInternal::RequireCallbackImpl(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 184 | auto isolate = args.GetIsolate(); |
| 185 | |
| 186 | if (args.Length() != 2) { |
| 187 | throw NativeScriptException(string("require should be called with two parameters")); |
| 188 | } |
| 189 | if (!args[0]->IsString()) { |
| 190 | throw NativeScriptException(string("require's first parameter should be string")); |
| 191 | } |
| 192 | if (!args[1]->IsString()) { |
| 193 | throw NativeScriptException(string("require's second parameter should be string")); |
| 194 | } |
| 195 | |
| 196 | string moduleName = ArgConverter::ConvertToString(args[0].As<String>()); |
| 197 | tns::instrumentation::Frame frame("RequireCallback " + moduleName); |
| 198 | string callingModuleDirName = ArgConverter::ConvertToString(args[1].As<String>()); |
| 199 | auto isData = false; |
| 200 | |
| 201 | auto moduleObj = LoadImpl(isolate, moduleName, callingModuleDirName, isData); |
| 202 | |
| 203 | if (isData) { |
| 204 | assert(!moduleObj.IsEmpty()); |
| 205 | |
| 206 | args.GetReturnValue().Set(moduleObj); |
| 207 | } else { |
| 208 | auto context = isolate->GetCurrentContext(); |
| 209 | Local<Value> exportsVal; |
| 210 | moduleObj->Get(context, ArgConverter::ConvertToV8String(isolate, "exports")).ToLocal(&exportsVal); |
| 211 | |
| 212 | assert(!exportsVal.IsEmpty()); |
| 213 | |
| 214 | auto exportsObj = exportsVal.As<Object>(); |
| 215 | args.GetReturnValue().Set(exportsObj); |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | void ModuleInternal::RequireNativeCallback(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 220 | TNSPERF(); |
no test coverage detected