vbscript: Moved creating new dynamic variable to separated function.
authorJacek Caban <jacek@codeweavers.com>
Wed, 21 Sep 2011 12:03:50 +0000 (14:03 +0200)
committerAlexandre Julliard <julliard@winehq.org>
Wed, 21 Sep 2011 12:47:32 +0000 (14:47 +0200)
dlls/vbscript/interp.c

index 232a58283aff289540262c20d0ee2ba867cbb614..46d15fff4a923d5ab1ff04022fcb986adb00214d 100644 (file)
@@ -198,6 +198,46 @@ static HRESULT lookup_identifier(exec_ctx_t *ctx, BSTR name, vbdisp_invoke_type_
     return S_OK;
 }
 
+static HRESULT add_dynamic_var(exec_ctx_t *ctx, const WCHAR *name, VARIANT *val, BOOL own_val)
+{
+    dynamic_var_t *new_var;
+    vbsheap_t *heap;
+    WCHAR *str;
+    unsigned size;
+    HRESULT hres;
+
+    heap = ctx->func->type == FUNC_GLOBAL ? &ctx->script->heap : &ctx->heap;
+
+    new_var = vbsheap_alloc(heap, sizeof(*new_var));
+    if(!new_var)
+        return E_OUTOFMEMORY;
+
+    size = (strlenW(name)+1)*sizeof(WCHAR);
+    str = vbsheap_alloc(heap, size);
+    if(!str)
+        return E_OUTOFMEMORY;
+    memcpy(str, name, size);
+    new_var->name = str;
+
+    if(own_val) {
+        new_var->v = *val;
+    }else {
+        hres = VariantCopy(&new_var->v, val);
+        if(FAILED(hres))
+            return hres;
+    }
+
+    if(ctx->func->type == FUNC_GLOBAL) {
+        new_var->next = ctx->script->global_vars;
+        ctx->script->global_vars = new_var;
+    }else {
+        new_var->next = ctx->dynamic_vars;
+        ctx->dynamic_vars = new_var;
+    }
+
+    return S_OK;
+}
+
 static inline VARIANT *stack_pop(exec_ctx_t *ctx)
 {
     assert(ctx->top);
@@ -491,49 +531,15 @@ static HRESULT assign_ident(exec_ctx_t *ctx, BSTR name, VARIANT *val, BOOL own_v
     case REF_OBJ:
         FIXME("REF_OBJ\n");
         return E_NOTIMPL;
-    case REF_NONE: {
-        dynamic_var_t *new_var;
-        vbsheap_t *heap;
-        WCHAR *str;
-        unsigned size;
-
+    case REF_NONE:
         if(ctx->func->code_ctx->option_explicit) {
             FIXME("throw exception\n");
-            return E_FAIL;
-        }
-
-        TRACE("creating variable %s\n", debugstr_w(name));
-
-        heap = ctx->func->type == FUNC_GLOBAL ? &ctx->script->heap : &ctx->heap;
-
-        new_var = vbsheap_alloc(heap, sizeof(*new_var));
-        if(!new_var)
-            return E_OUTOFMEMORY;
-
-        size = (strlenW(name)+1)*sizeof(WCHAR);
-        str = vbsheap_alloc(heap, size);
-        if(!str)
-            return E_OUTOFMEMORY;
-        memcpy(str, name, size);
-        new_var->name = str;
-
-        if(own_val) {
-            new_var->v = *val;
-        }else {
-            hres = VariantCopy(&new_var->v, val);
-            if(FAILED(hres))
-                return hres;
-        }
-
-        if(ctx->func->type == FUNC_GLOBAL) {
-            new_var->next = ctx->script->global_vars;
-            ctx->script->global_vars = new_var;
+            hres = E_FAIL;
         }else {
-            new_var->next = ctx->dynamic_vars;
-            ctx->dynamic_vars = new_var;
+            TRACE("creating variable %s\n", debugstr_w(name));
+            hres = add_dynamic_var(ctx, name, val, own_val);
         }
     }
-    }
 
     return hres;
 }