aboutsummaryrefslogtreecommitdiff
path: root/files/ja/mozilla/tech/xpcom/reference/ns_ensure_true/index.html
blob: cf931e4a211f4f557b8c645e205063707d4c189f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
---
title: NS ENSURE TRUE
slug: Mozilla/Tech/XPCOM/Reference/NS_ENSURE_TRUE
tags:
  - XPCOM
  - XPCOM_Macros
translation_of: Mozilla/Tech/XPCOM/Reference/NS_ENSURE_TRUE
---
<h3 id="Summary" name="Summary">概要</h3>

<p><strong>マクロ</strong></p>

<p><em>expr</em> の評価値が <strong>false</strong> の場合に <em>return-value </em>を返す。</p>

<h3 id="Syntax" name="Syntax">構文</h3>

<pre>NS_ENSURE_TRUE( expr, return-value );
</pre>

<p> </p>

<h3 id="Usage" name="Usage">使い方</h3>

<pre>nsresult mozMyClass::MozStringMucking()
{
  char *foo = new char[123];
  NS_ENSURE_TRUE(foo, NS_ERROR_OUT_OF_MEMORY);

  // This is equivalent to doing:
  // これは以下の式と同等です。
  if (!foo)
    return NS_ERROR_OUT_OF_MEMORY;

  // Thou shalt not return NS_ERROR_FAILURE..
  // これは、NS_ERROR_FAILURE を返さない。。
  int i = 3;
  NS_ENSURE_TRUE(i == 3, NS_ERROR_FAILURE);

  return NS_OK;
}

char* mozMyClass::DoStuff()
{
  char* bar = new char[321];
  NS_ENSURE_TRUE(bar, nsnull);

  return bar;
}
</pre>