From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Ricardo Wurmus Newsgroups: gmane.emacs.devel Subject: [PATCH 04/15] xwidget: Do not use `xwidget-execute-script-rv' to insert string Date: Mon, 24 Oct 2016 18:40:50 +0200 Message-ID: <20161024164101.26043-5-rekado@elephly.net> References: <20161024164101.26043-1-rekado@elephly.net> NNTP-Posting-Host: blaine.gmane.org X-Trace: blaine.gmane.org 1477327534 869 195.159.176.226 (24 Oct 2016 16:45:34 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 24 Oct 2016 16:45:34 +0000 (UTC) Cc: Ricardo Wurmus To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Oct 24 18:45:30 2016 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1byiMs-000512-Je for ged-emacs-devel@m.gmane.org; Mon, 24 Oct 2016 18:44:58 +0200 Original-Received: from localhost ([::1]:48149 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1byiMu-0000zr-KP for ged-emacs-devel@m.gmane.org; Mon, 24 Oct 2016 12:45:00 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:41042) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1byiKY-0007EJ-ID for emacs-devel@gnu.org; Mon, 24 Oct 2016 12:42:35 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1byiKU-0002Pg-Qy for emacs-devel@gnu.org; Mon, 24 Oct 2016 12:42:34 -0400 Original-Received: from sender163-mail.zoho.com ([74.201.84.163]:21451) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1byiKU-0002P6-ID for emacs-devel@gnu.org; Mon, 24 Oct 2016 12:42:30 -0400 Original-Received: from localhost (89.204.138.233 [89.204.138.233]) by mx.zohomail.com with SMTPS id 1477327345458761.8728915689379; Mon, 24 Oct 2016 09:42:25 -0700 (PDT) X-Mailer: git-send-email 2.10.1 In-Reply-To: <20161024164101.26043-1-rekado@elephly.net> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 74.201.84.163 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:208711 Archived-At: * lisp/xwidget.el (xwidget-webkit-insert-string): Obtain JavaScript return value via callback instead of using `xwidget-webkit-execute-script-rv'. --- lisp/xwidget.el | 47 +++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/lisp/xwidget.el b/lisp/xwidget.el index d2b9a09..a252fd7 100644 --- a/lisp/xwidget.el +++ b/lisp/xwidget.el @@ -286,31 +286,30 @@ function findactiveelement(doc){ ;;TODO the activeelement type needs to be examined, for iframe, etc. ) -(defun xwidget-webkit-insert-string (xw str) - "Insert string STR in the active field in the webkit XW." +(defun xwidget-webkit-insert-string () + "Prompt for a string and insert it in the active field in the +current webkit widget." ;; Read out the string in the field first and provide for edit. - (interactive - (let* ((xww (xwidget-webkit-current-session)) - - (field-value - (progn - (xwidget-webkit-execute-script xww xwidget-webkit-activeelement-js) - (xwidget-webkit-execute-script-rv - xww - "findactiveelement(document).value;"))) - (field-type (xwidget-webkit-execute-script-rv - xww - "findactiveelement(document).type;"))) - (list xww - (cond ((equal "text" field-type) - (read-string "Text: " field-value)) - ((equal "password" field-type) - (read-passwd "Password: " nil field-value)) - ((equal "textarea" field-type) - (xwidget-webkit-begin-edit-textarea xww field-value)))))) - (xwidget-webkit-execute-script - xw - (format "findactiveelement(document).value='%s'" str))) + (interactive) + (let ((xww (xwidget-webkit-current-session))) + (xwidget-webkit-execute-script + xww + (concat xwidget-webkit-activeelement-js " +(function () { + var res = findactiveelement(document); + return [res.value, res.type]; +})();") + (lambda (field) + (let ((str (pcase field + (`[,val "text"] + (read-string "Text: " val)) + (`[,val "password"] + (read-passwd "Password: " nil val)) + (`[,val "textarea"] + (xwidget-webkit-begin-edit-textarea xww val))))) + (xwidget-webkit-execute-script + xww + (format "findactiveelement(document).value='%s'" str))))))) (defvar xwidget-xwbl) (defun xwidget-webkit-begin-edit-textarea (xw text) -- 2.10.1