Example #1
0
int Script::GetPropertyNameList(std::wstring* property_names) {
  LOG(TRACE) << "Entering Script::GetPropertyNameList";

  // Loop through the properties, appending the name of each one to the string.
  std::wstring get_names_script = L"(function(){return function() { var name_list = ''; for (var name in arguments[0]) { if (name_list.length > 0) name_list += ','; name_list += name } return name_list;}})();";
  Script get_names_script_wrapper(this->script_engine_host_,
                                  get_names_script,
                                  1);
  get_names_script_wrapper.AddArgument(this->result_);
  int get_names_result = get_names_script_wrapper.Execute();

  if (get_names_result != SUCCESS) {
    LOG(WARN) << "Unable to get property name list, script execution returned error code";
    return get_names_result;
  }

  // Expect the return type to be an string. A non-string means ... (what?)
  if (!get_names_script_wrapper.ResultIsString()) {
    LOG(WARN) << "Result properties are not string";
    return EUNEXPECTEDJSERROR;
  }

  *property_names = get_names_script_wrapper.result().bstrVal;
  return SUCCESS;
}
int ScriptWrapper::GetPropertyNameList(std::wstring *property_names) {
	// Loop through the properties, appending the name of each one to the string.
	std::wstring get_names_script(L"(function(){return function() { var name_list = ''; for (var name in arguments[0]) { if (name_list.length > 0) name_list+= ','; name_list += name } return name_list;}})();");
	ScriptWrapper get_names_script_wrapper(this->script_engine_host_, get_names_script, 1);
	get_names_script_wrapper.AddArgument(this->result_);
	int get_names_result = get_names_script_wrapper.Execute();

	if (get_names_result != SUCCESS) {
		return get_names_result;
	}

	// Expect the return type to be an integer. A non-integer means this was
	// not an array after all.
	if (!get_names_script_wrapper.ResultIsString()) {
		return EUNEXPECTEDJSERROR;
	}

	*property_names = get_names_script_wrapper.result().bstrVal;
	return SUCCESS;
}